befly-admin 3.14.0 → 3.14.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +7 -7
- package/src/main.js +2 -0
- package/src/plugins/config.js +5 -0
- package/src/plugins/errorReport.js +250 -0
- package/src/plugins/router.js +30 -2
- package/vite.config.js +8 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly-admin",
|
|
3
|
-
"version": "3.14.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.14.6",
|
|
4
|
+
"gitHead": "84b6e4e0adde7f566cfc890887b024ccf10b0516",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly Admin - 基于 Vue3 + TDesign Vue Next 的后台管理系统",
|
|
7
7
|
"files": [
|
|
@@ -28,14 +28,14 @@
|
|
|
28
28
|
"preview": "bunx --bun vite preview"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"befly-admin-ui": "1.8.
|
|
31
|
+
"befly-admin-ui": "^1.8.33",
|
|
32
32
|
"befly-shared": "2.0.3",
|
|
33
|
-
"befly-vite": "^1.5.
|
|
33
|
+
"befly-vite": "^1.5.15",
|
|
34
34
|
"pinia": "^3.0.4",
|
|
35
35
|
"tdesign-icons-vue-next": "^0.4.0",
|
|
36
|
-
"tdesign-vue-next": "^1.18.
|
|
37
|
-
"vite": "^8.0.0
|
|
38
|
-
"vue": "^3.5.
|
|
36
|
+
"tdesign-vue-next": "^1.18.5",
|
|
37
|
+
"vite": "^8.0.0",
|
|
38
|
+
"vue": "^3.5.30",
|
|
39
39
|
"vue-router": "^5.0.3"
|
|
40
40
|
},
|
|
41
41
|
"engines": {
|
package/src/main.js
CHANGED
package/src/plugins/config.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import adminPackageInfo from "../../package.json";
|
|
2
|
+
|
|
1
3
|
export const $Config = {
|
|
2
4
|
appTitle: "野蜂飞舞",
|
|
3
5
|
appDesc: "轻量级业务快速开发框架",
|
|
6
|
+
productName: "野蜂飞舞",
|
|
7
|
+
productCode: adminPackageInfo.name,
|
|
8
|
+
productVersion: adminPackageInfo.version,
|
|
4
9
|
loginFootnote: "",
|
|
5
10
|
tokenName: "befly-admin-token",
|
|
6
11
|
loginPath: "/core/login",
|
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
let isReportingError = false;
|
|
2
|
+
let lastErrorKey = "";
|
|
3
|
+
let lastErrorTime = 0;
|
|
4
|
+
let fetchWrapped = false;
|
|
5
|
+
|
|
6
|
+
function getRouteInfo() {
|
|
7
|
+
const currentRoute = $Router.currentRoute.value || {};
|
|
8
|
+
|
|
9
|
+
return {
|
|
10
|
+
pagePath: String(currentRoute.fullPath || currentRoute.path || window.location.hash || window.location.pathname || ""),
|
|
11
|
+
pageName: String(currentRoute.name || currentRoute.meta?.title || currentRoute.path || document.title || "")
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function getErrorMessage(error) {
|
|
16
|
+
if (typeof error === "string") {
|
|
17
|
+
return error;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (error && typeof error.message === "string") {
|
|
21
|
+
return error.message;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return "未知错误";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getErrorDetail(error) {
|
|
28
|
+
if (!error) {
|
|
29
|
+
return "";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (typeof error === "string") {
|
|
33
|
+
return error;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (typeof error.stack === "string" && error.stack) {
|
|
37
|
+
return error.stack;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
return JSON.stringify(error);
|
|
42
|
+
} catch {
|
|
43
|
+
return String(error);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function shouldSkipError(message, detail, errorType) {
|
|
48
|
+
const now = Date.now();
|
|
49
|
+
const key = `${errorType}|${message}|${detail}`;
|
|
50
|
+
if (key === lastErrorKey && now - lastErrorTime < 3000) {
|
|
51
|
+
return true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
lastErrorKey = key;
|
|
55
|
+
lastErrorTime = now;
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function reportClientError(errorType, message, detail) {
|
|
60
|
+
const safeMessage = String(message || "未知错误").slice(0, 500);
|
|
61
|
+
const safeDetail = String(detail || "").slice(0, 5000);
|
|
62
|
+
if (shouldSkipError(safeMessage, safeDetail, errorType)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
if (isReportingError) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const routeInfo = getRouteInfo();
|
|
71
|
+
isReportingError = true;
|
|
72
|
+
|
|
73
|
+
void $Http(
|
|
74
|
+
"/core/tongJi/errorReport",
|
|
75
|
+
{
|
|
76
|
+
pagePath: routeInfo.pagePath,
|
|
77
|
+
pageName: routeInfo.pageName,
|
|
78
|
+
source: "admin",
|
|
79
|
+
productName: $Config.productName,
|
|
80
|
+
productCode: $Config.productCode,
|
|
81
|
+
productVersion: $Config.productVersion,
|
|
82
|
+
errorType: String(errorType || "unknown"),
|
|
83
|
+
message: safeMessage,
|
|
84
|
+
detail: safeDetail
|
|
85
|
+
},
|
|
86
|
+
[""]
|
|
87
|
+
)
|
|
88
|
+
.catch(() => {
|
|
89
|
+
// 静默失败:避免错误上报再次制造错误
|
|
90
|
+
})
|
|
91
|
+
.finally(() => {
|
|
92
|
+
isReportingError = false;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function setupFetchErrorReport() {
|
|
97
|
+
if (fetchWrapped) {
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (typeof window.fetch !== "function") {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const originalFetch = window.fetch.bind(window);
|
|
106
|
+
|
|
107
|
+
window.fetch = async (...args) => {
|
|
108
|
+
const input = args[0];
|
|
109
|
+
const url = typeof input === "string" ? input : input && typeof input.url === "string" ? input.url : "";
|
|
110
|
+
const apiPath = String($Config.apiPath || "");
|
|
111
|
+
const isApiRequest = Boolean(apiPath) && String(url || "").startsWith(apiPath);
|
|
112
|
+
const isErrorReportRequest = String(url || "").includes("/core/tongJi/errorReport");
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
const response = await originalFetch(...args);
|
|
116
|
+
|
|
117
|
+
if (isApiRequest && !isErrorReportRequest) {
|
|
118
|
+
if (!response.ok) {
|
|
119
|
+
const parts = [];
|
|
120
|
+
|
|
121
|
+
if (url) {
|
|
122
|
+
parts.push(`url: ${url}`);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (response.status) {
|
|
126
|
+
parts.push(`status: ${response.status}`);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
reportClientError("http", `请求失败:HTTP ${response.status}`, parts.join("\n"));
|
|
130
|
+
} else {
|
|
131
|
+
try {
|
|
132
|
+
const payload = await response.clone().json();
|
|
133
|
+
|
|
134
|
+
if (payload?.code !== 0) {
|
|
135
|
+
const parts = [];
|
|
136
|
+
|
|
137
|
+
if (url) {
|
|
138
|
+
parts.push(`url: ${url}`);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (response.status) {
|
|
142
|
+
parts.push(`status: ${response.status}`);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (payload?.code !== undefined) {
|
|
146
|
+
parts.push(`code: ${payload.code}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (payload?.msg) {
|
|
150
|
+
parts.push(`msg: ${payload.msg}`);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (payload?.detail) {
|
|
154
|
+
parts.push(`detail: ${payload.detail}`);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
reportClientError("http", payload.msg || "请求失败", parts.join("\n"));
|
|
158
|
+
}
|
|
159
|
+
} catch {
|
|
160
|
+
// 忽略非 JSON 响应
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return response;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
if (isApiRequest && !isErrorReportRequest) {
|
|
168
|
+
const parts = [];
|
|
169
|
+
|
|
170
|
+
if (url) {
|
|
171
|
+
parts.push(`url: ${url}`);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const errorDetail = getErrorDetail(error);
|
|
175
|
+
if (errorDetail) {
|
|
176
|
+
parts.push(`detail: ${errorDetail}`);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
reportClientError("http", getErrorMessage(error), parts.join("\n"));
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
throw error;
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
fetchWrapped = true;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
export function setupErrorReport(app) {
|
|
190
|
+
setupFetchErrorReport();
|
|
191
|
+
|
|
192
|
+
app.config.errorHandler = (error, _instance, info) => {
|
|
193
|
+
const message = getErrorMessage(error);
|
|
194
|
+
const detail = `${String(info || "")}${info ? "\n" : ""}${getErrorDetail(error)}`;
|
|
195
|
+
|
|
196
|
+
reportClientError("vue", message, detail);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
window.addEventListener(
|
|
200
|
+
"error",
|
|
201
|
+
(event) => {
|
|
202
|
+
const target = event.target;
|
|
203
|
+
|
|
204
|
+
if (target && target !== window) {
|
|
205
|
+
const resourceName = target.tagName ? `${String(target.tagName).toLowerCase()} 资源加载失败` : "资源加载失败";
|
|
206
|
+
const parts = [];
|
|
207
|
+
|
|
208
|
+
if (target?.tagName) {
|
|
209
|
+
parts.push(`tag: ${String(target.tagName).toLowerCase()}`);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (target?.src) {
|
|
213
|
+
parts.push(`src: ${target.src}`);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (target?.href) {
|
|
217
|
+
parts.push(`href: ${target.href}`);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
reportClientError("resource", resourceName, parts.join("\n"));
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const parts = [];
|
|
225
|
+
if (event.filename) {
|
|
226
|
+
parts.push(`file: ${event.filename}`);
|
|
227
|
+
}
|
|
228
|
+
if (event.lineno || event.colno) {
|
|
229
|
+
parts.push(`line: ${event.lineno || 0}, col: ${event.colno || 0}`);
|
|
230
|
+
}
|
|
231
|
+
const stack = getErrorDetail(event.error);
|
|
232
|
+
if (stack) {
|
|
233
|
+
parts.push(stack);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
reportClientError("window", getErrorMessage(event.message || event.error), parts.join("\n"));
|
|
237
|
+
},
|
|
238
|
+
true
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
window.addEventListener("unhandledrejection", (event) => {
|
|
242
|
+
const reason = event.reason;
|
|
243
|
+
|
|
244
|
+
reportClientError("promise", getErrorMessage(reason), getErrorDetail(reason));
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
$Router.onError((error) => {
|
|
248
|
+
reportClientError("router", getErrorMessage(error), getErrorDetail(error));
|
|
249
|
+
});
|
|
250
|
+
}
|
package/src/plugins/router.js
CHANGED
|
@@ -2,6 +2,7 @@ import { Layouts } from "befly-vite";
|
|
|
2
2
|
import { createRouter, createWebHashHistory } from "vue-router";
|
|
3
3
|
import { routes } from "vue-router/auto-routes";
|
|
4
4
|
import { $Config } from "@/plugins/config.js";
|
|
5
|
+
import { $Http } from "@/plugins/http.js";
|
|
5
6
|
|
|
6
7
|
// 应用自定义布局系统(同时可选注入根路径重定向)
|
|
7
8
|
const finalRoutes = Layouts(routes, $Config.homePath, (layoutName) => {
|
|
@@ -54,6 +55,33 @@ $Router.beforeEach((to, _from) => {
|
|
|
54
55
|
});
|
|
55
56
|
|
|
56
57
|
// 路由就绪后处理
|
|
57
|
-
$Router.afterEach((
|
|
58
|
-
|
|
58
|
+
$Router.afterEach((to) => {
|
|
59
|
+
void Promise.allSettled([
|
|
60
|
+
$Http(
|
|
61
|
+
"/core/tongJi/onlineReport",
|
|
62
|
+
{
|
|
63
|
+
pagePath: to.fullPath || to.path || "",
|
|
64
|
+
pageName: String(to.name || to.meta?.title || to.path || ""),
|
|
65
|
+
source: "admin",
|
|
66
|
+
productName: $Config.productName,
|
|
67
|
+
productCode: $Config.productCode,
|
|
68
|
+
productVersion: $Config.productVersion
|
|
69
|
+
},
|
|
70
|
+
[""]
|
|
71
|
+
),
|
|
72
|
+
$Http(
|
|
73
|
+
"/core/tongJi/infoReport",
|
|
74
|
+
{
|
|
75
|
+
pagePath: to.fullPath || to.path || "",
|
|
76
|
+
pageName: String(to.name || to.meta?.title || to.path || ""),
|
|
77
|
+
source: "admin",
|
|
78
|
+
productName: $Config.productName,
|
|
79
|
+
productCode: $Config.productCode,
|
|
80
|
+
productVersion: $Config.productVersion
|
|
81
|
+
},
|
|
82
|
+
[""]
|
|
83
|
+
)
|
|
84
|
+
]).catch(() => {
|
|
85
|
+
// 静默失败:不阻断路由切换
|
|
86
|
+
});
|
|
59
87
|
});
|
package/vite.config.js
CHANGED
|
@@ -3,5 +3,12 @@ import { fileURLToPath } from "node:url";
|
|
|
3
3
|
import { createBeflyViteConfig } from "befly-vite";
|
|
4
4
|
|
|
5
5
|
export default createBeflyViteConfig({
|
|
6
|
-
root: fileURLToPath(new URL(".", import.meta.url))
|
|
6
|
+
root: fileURLToPath(new URL(".", import.meta.url)),
|
|
7
|
+
analyzer: true,
|
|
8
|
+
devtool: false,
|
|
9
|
+
viteConfig: {
|
|
10
|
+
server: {
|
|
11
|
+
port: 5206
|
|
12
|
+
}
|
|
13
|
+
}
|
|
7
14
|
});
|