chore: 悦码渲染器增加 ga 分析

This commit is contained in:
wangxuefeng 2025-03-28 16:12:53 +08:00
parent 799a775a8d
commit fcd44e49d2
12 changed files with 1514 additions and 1502 deletions

View File

@ -15,17 +15,17 @@
"typecheck": "vue-tsc --noEmit --skipLibCheck" "typecheck": "vue-tsc --noEmit --skipLibCheck"
}, },
"dependencies": { "dependencies": {
"@vtj/core": "^0.11.7", "@vtj/core": "^0.11.11",
"@vtj/designer": "0.11.7", "@vtj/designer": "0.11.11",
"@vtj/icons": "0.11.7", "@vtj/icons": "0.11.11",
"@vtj/local": "^0.11.7", "@vtj/local": "^0.11.11",
"@vtj/materials": "^0.11.7", "@vtj/materials": "^0.11.11",
"@vtj/node": "0.11.2", "@vtj/node": "0.11.2",
"@vtj/pro": "^0.11.7", "@vtj/pro": "^0.11.11",
"@vtj/renderer": "^0.11.7", "@vtj/renderer": "^0.11.11",
"@vtj/ui": "^0.11.7", "@vtj/ui": "^0.11.11",
"@vtj/utils": "0.11.7", "@vtj/utils": "0.11.11",
"@vtj/web": "^0.11.7", "@vtj/web": "^0.11.11",
"axios": "^1.8.1", "axios": "^1.8.1",
"element-plus": "^2.9.4", "element-plus": "^2.9.4",
"licia-es": "^1.46.0", "licia-es": "^1.46.0",

View File

@ -10,5 +10,18 @@
<body> <body>
<div id="y-code-renderer" style="width: 100%; height: 100%"></div> <div id="y-code-renderer" style="width: 100%; height: 100%"></div>
<script type="module" src="/src/index.ts"></script> <script type="module" src="/src/index.ts"></script>
<!-- Google tag (gtag.js) -->
<script
async
src="https://www.googletagmanager.com/gtag/js?id=G-0Y7ER0SZ2V"
></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-0Y7ER0SZ2V');
</script>
</body> </body>
</html> </html>

View File

@ -16,15 +16,15 @@
"dependencies": { "dependencies": {
"@sentry/vue": "^9.7.0", "@sentry/vue": "^9.7.0",
"@tanstack/vue-query": "^5.69.0", "@tanstack/vue-query": "^5.69.0",
"@vtj/charts": "^0.11.7", "@vtj/charts": "^0.11.11",
"@vtj/core": "^0.11.7", "@vtj/core": "^0.11.11",
"@vtj/icons": "0.11.7", "@vtj/icons": "0.11.11",
"@vtj/materials": "^0.11.7", "@vtj/materials": "^0.11.11",
"@vtj/pro": "^0.11.7", "@vtj/pro": "^0.11.11",
"@vtj/renderer": "^0.11.7", "@vtj/renderer": "^0.11.11",
"@vtj/ui": "^0.11.7", "@vtj/ui": "^0.11.11",
"@vtj/utils": "^0.11.7", "@vtj/utils": "^0.11.11",
"@vtj/web": "^0.11.7", "@vtj/web": "^0.11.11",
"ant-design-vue": "catalog:", "ant-design-vue": "catalog:",
"axios": "catalog:", "axios": "catalog:",
"core-js": "catalog:", "core-js": "catalog:",

View File

@ -7,4 +7,6 @@ VITE_OA_BASEURL = https://oa-pre.shiyue.com
VITE_YCODE_BASEURL = https://custom-chart-pre-api.shiyue.com VITE_YCODE_BASEURL = https://custom-chart-pre-api.shiyue.com
VITE_CLIENT_ID = y-code-v1
VITE_YCODE_BASEURL_FRONT = https://custom-chart.shiyue.com VITE_YCODE_BASEURL_FRONT = https://custom-chart.shiyue.com

View File

@ -7,7 +7,7 @@
<title>悦码后台</title> <title>悦码后台</title>
</head> </head>
<body> <body>
<div id="y-code-app"></div> <div id="app"></div>
<script type="module" src="/src/main.ts"></script> <script type="module" src="/src/main.ts"></script>
</body> </body>
</html> </html>

View File

@ -4,7 +4,7 @@
"private": true, "private": true,
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite start --mode development", "dev": "vite start --mode development --config vite.config.ts",
"dev:staging": "vite start --mode dev-staging", "dev:staging": "vite start --mode dev-staging",
"dev:prod": "vite start --mode dev-production", "dev:prod": "vite start --mode dev-production",
"build": "vite build --mode production", "build": "vite build --mode production",
@ -23,6 +23,7 @@
"core-js": "^3.40.0", "core-js": "^3.40.0",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"dayjs": "catalog:", "dayjs": "catalog:",
"jsrsasign": "11.1.0",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"p-limit": "^6.1.0", "p-limit": "^6.1.0",
"pinia": "catalog:", "pinia": "catalog:",

View File

@ -49,7 +49,7 @@ function render(props: object = {}) {
app.use(router); app.use(router);
app.use(VueGridLayout); app.use(VueGridLayout);
app.use(createPinia()); app.use(createPinia());
app.mount('#y-code-app'); app.mount('#app');
} }
function setStyleSheet(styles: object = {}) { function setStyleSheet(styles: object = {}) {

View File

@ -2,6 +2,8 @@ import type { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import axios, { AxiosError } from 'axios'; import axios, { AxiosError } from 'axios';
// 导入 RSA 相关库
import { KEYUTIL, KJUR } from 'jsrsasign';
export interface ResopnseType<T> { export interface ResopnseType<T> {
reason: string; reason: string;
@ -9,11 +11,55 @@ export interface ResopnseType<T> {
data: T; data: T;
ts: string; ts: string;
} }
// export const YCODE_BASEURL: string = import.meta.env.VITE_YCODE_BASEURL; export const YCODE_BASEURL: string = import.meta.env.VITE_YCODE_BASEURL;
// https://custom-chart-pre-api.shiyue.com // RSA 签名相关配置
const CLIENT_ID = import.meta.env.VITE_CLIENT_ID;
export const YCODE_BASEURL: string = 'https://custom-chart-pre-api.shiyue.com'; // 私钥配置,请在实际使用中安全存储
const PRIVATE_KEY = `-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAySeb8CMlvGzI8KasmiQwMCX4240e8Ap6W8Pb63iX57pBFpmV
fcOy7BAsfOEtp3TrJkssszUxdnCmsASZQNHaJtIhide7DjXjct9MQ3tqeEtc2R2K
EkauK7oLsAiQqkpb9XpWAURfoE+83kCrJuQ49frw/zz7PElTPgjAjPknyF/JJFEp
BoasWhoFBwrZWFwQKWUmFaUodG3UjtXdepYFVfdGKmgPYerm1Os3BQu6oSCKvh+p
4uaRrAyKLBdTYXHfYiJi+oRt9wSSA0eGS8IcMxWn0azzEeZo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4LCbGkvFqJUqTSaI+Lf9+zkHK7EmDWUf+f6jCoLmWDrbLdwlUayTdxfmZqHDdHuJ
8n+kKQKBgA1lR4zITE1qh+eMsueYPlOs32SP9jcx5fbTPxQpaqQJXSqvVb7ZHmfx
qwzhQTzcKjSEhlD15ct5RqxD+4KmGid8bM5fewzYnORw+u2O1g74owgq0ApCVsRU
/wsYRNpoRHJxU69kzkl8rSulJjQ0rOOz0/TyDbONhmM7Bv0cQAAA
-----END RSA PRIVATE KEY-----`;
// 需要添加签名的 API 路径前缀
const NEED_SIGN_PATHS = [
'/v1/project',
'/v1/preview',
'/v1/modular',
'/v1/field',
];
// 初始化私钥
let privateKey: string;
try {
privateKey = KEYUTIL.getKey(PRIVATE_KEY);
} catch (error) {
console.error('RSA 私钥初始化失败:', error);
}
const requestType = { const requestType = {
base: YCODE_BASEURL, base: YCODE_BASEURL,
@ -25,6 +71,57 @@ const baseAxios: AxiosInstance = axios.create({
withCredentials: true, withCredentials: true,
}); });
// 创建 RSA 签名
function createSignature(message: string): string {
try {
const sig = new KJUR.crypto.Signature({ alg: 'SHA256withRSA' });
sig.init(privateKey);
sig.updateString(message);
return btoa(sig.sign());
} catch (error) {
console.error('签名创建失败:', error);
return '';
}
}
// 请求拦截器 - 添加 RSA 签名认证
baseAxios.interceptors.request.use(
(config) => {
// 检查是否需要添加签名
const needSign = NEED_SIGN_PATHS.some(
(path) => config.url && config.url.startsWith(path),
);
if (needSign && privateKey) {
// 生成当前时间戳(秒)
const timestamp = Math.floor(Date.now() / 1000).toString();
// 构建要签名的消息: clientID + timestamp
const message = CLIENT_ID + timestamp;
// 创建签名
const signature = createSignature(message);
// 设置请求头
config.headers = config.headers || {};
config.headers['X-Client-ID'] = CLIENT_ID;
config.headers['X-Timestamp'] = timestamp;
config.headers['X-Signature'] = signature;
console.log('已添加签名认证:', {
url: config.url,
clientId: CLIENT_ID,
timestamp,
});
}
return config;
},
(error) => {
return Promise.reject(error);
},
);
const errorHandle = (error: AxiosError) => { const errorHandle = (error: AxiosError) => {
if (error.response) { if (error.response) {
const status = error.response?.status; const status = error.response?.status;

13
apps/y-code-v1/start/components.d.ts vendored Normal file
View File

@ -0,0 +1,13 @@
/* eslint-disable */
/* prettier-ignore */
// @ts-nocheck
// Generated by unplugin-vue-components
// Read more: https://github.com/vuejs/core/pull/3399
export {}
declare module 'vue' {
export interface GlobalComponents {
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
}
}

View File

@ -9,7 +9,7 @@ import mkcert from 'vite-plugin-mkcert';
import qiankun from 'vite-plugin-qiankun'; import qiankun from 'vite-plugin-qiankun';
export default defineConfig(({ mode }) => { export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), ['VITE_']); const env = loadEnv(mode, process.cwd());
const isDev = env.VITE_NODE_ENV === 'development'; const isDev = env.VITE_NODE_ENV === 'development';
return { return {

2836
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -166,7 +166,7 @@ catalog:
unbuild: ^3.5.0 unbuild: ^3.5.0
unplugin-element-plus: ^0.9.1 unplugin-element-plus: ^0.9.1
vee-validate: ^4.15.0 vee-validate: ^4.15.0
vite: ^6.2.1 vite: ^6.2.2
vite-plugin-compression: ^0.5.1 vite-plugin-compression: ^0.5.1
vite-plugin-dts: ^4.5.3 vite-plugin-dts: ^4.5.3
vite-plugin-html: ^3.2.2 vite-plugin-html: ^3.2.2