befly-admin 3.14.0 → 3.14.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly-admin",
3
- "version": "3.14.0",
4
- "gitHead": "ccc66d5da9c6b84f8346087adc1d24412ce65bec",
3
+ "version": "3.14.5",
4
+ "gitHead": "ba7fa7cc0534c48de2df4970d69a14853cf6b2a6",
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.27",
31
+ "befly-admin-ui": "^1.8.32",
32
32
  "befly-shared": "2.0.3",
33
- "befly-vite": "^1.5.10",
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.3",
37
- "vite": "^8.0.0-beta.16",
38
- "vue": "^3.5.29",
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
@@ -5,6 +5,7 @@ import "befly-admin-ui/styles/variables.scss";
5
5
  // 引入全局基础样式(reset、通用类、滚动条等)
6
6
  import "@/styles/global.scss";
7
7
  import App from "./App.vue";
8
+ import { setupErrorReport } from "@/plugins/errorReport.js";
8
9
 
9
10
  const app = createApp(App);
10
11
 
@@ -14,4 +15,6 @@ app.use(createPinia());
14
15
  // 使用路由
15
16
  app.use($Router);
16
17
 
18
+ setupErrorReport(app);
19
+
17
20
  app.mount("#app");
@@ -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,128 @@
1
+ import { $Http } from "@/plugins/http.js";
2
+ import { $Config } from "@/plugins/config.js";
3
+ import { $Router } from "@/plugins/router.js";
4
+
5
+ let isReportingError = false;
6
+ let lastErrorKey = "";
7
+ let lastErrorTime = 0;
8
+
9
+ function getRouteInfo() {
10
+ const currentRoute = $Router.currentRoute.value || {};
11
+
12
+ return {
13
+ pagePath: String(currentRoute.fullPath || currentRoute.path || window.location.hash || window.location.pathname || ""),
14
+ pageName: String(currentRoute.name || currentRoute.meta?.title || currentRoute.path || document.title || "")
15
+ };
16
+ }
17
+
18
+ function getErrorMessage(error) {
19
+ if (typeof error === "string") {
20
+ return error;
21
+ }
22
+
23
+ if (error && typeof error.message === "string") {
24
+ return error.message;
25
+ }
26
+
27
+ return "未知错误";
28
+ }
29
+
30
+ function getErrorDetail(error) {
31
+ if (!error) {
32
+ return "";
33
+ }
34
+
35
+ if (typeof error === "string") {
36
+ return error;
37
+ }
38
+
39
+ if (typeof error.stack === "string" && error.stack) {
40
+ return error.stack;
41
+ }
42
+
43
+ try {
44
+ return JSON.stringify(error);
45
+ } catch {
46
+ return String(error);
47
+ }
48
+ }
49
+
50
+ function shouldSkipError(message, detail, errorType) {
51
+ const now = Date.now();
52
+ const key = `${errorType}|${message}|${detail}`;
53
+ if (key === lastErrorKey && now - lastErrorTime < 3000) {
54
+ return true;
55
+ }
56
+
57
+ lastErrorKey = key;
58
+ lastErrorTime = now;
59
+ return false;
60
+ }
61
+
62
+ function reportClientError(errorType, message, detail) {
63
+ const safeMessage = String(message || "未知错误").slice(0, 500);
64
+ const safeDetail = String(detail || "").slice(0, 5000);
65
+ if (shouldSkipError(safeMessage, safeDetail, errorType)) {
66
+ return;
67
+ }
68
+
69
+ if (isReportingError) {
70
+ return;
71
+ }
72
+
73
+ const routeInfo = getRouteInfo();
74
+ isReportingError = true;
75
+
76
+ void $Http(
77
+ "/core/tongJi/errorReport",
78
+ {
79
+ pagePath: routeInfo.pagePath,
80
+ pageName: routeInfo.pageName,
81
+ source: "admin",
82
+ productName: $Config.productName,
83
+ productCode: $Config.productCode,
84
+ productVersion: $Config.productVersion,
85
+ errorType: String(errorType || "unknown"),
86
+ message: safeMessage,
87
+ detail: safeDetail
88
+ },
89
+ [""]
90
+ )
91
+ .catch(() => {
92
+ // 静默失败:避免错误上报再次制造错误
93
+ })
94
+ .finally(() => {
95
+ isReportingError = false;
96
+ });
97
+ }
98
+
99
+ export function setupErrorReport(app) {
100
+ app.config.errorHandler = (error, _instance, info) => {
101
+ const message = getErrorMessage(error);
102
+ const detail = `${String(info || "")}${info ? "\n" : ""}${getErrorDetail(error)}`;
103
+
104
+ reportClientError("vue", message, detail);
105
+ };
106
+
107
+ window.addEventListener("error", (event) => {
108
+ const parts = [];
109
+ if (event.filename) {
110
+ parts.push(`file: ${event.filename}`);
111
+ }
112
+ if (event.lineno || event.colno) {
113
+ parts.push(`line: ${event.lineno || 0}, col: ${event.colno || 0}`);
114
+ }
115
+ const stack = getErrorDetail(event.error);
116
+ if (stack) {
117
+ parts.push(stack);
118
+ }
119
+
120
+ reportClientError("window", getErrorMessage(event.message || event.error), parts.join("\n"));
121
+ });
122
+
123
+ window.addEventListener("unhandledrejection", (event) => {
124
+ const reason = event.reason;
125
+
126
+ reportClientError("promise", getErrorMessage(reason), getErrorDetail(reason));
127
+ });
128
+ }
@@ -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,19 @@ $Router.beforeEach((to, _from) => {
54
55
  });
55
56
 
56
57
  // 路由就绪后处理
57
- $Router.afterEach((_to) => {
58
- // 可以在这里添加页面访问统计等
58
+ $Router.afterEach((to) => {
59
+ void $Http(
60
+ "/core/tongJi/visitReport",
61
+ {
62
+ pagePath: to.fullPath || to.path || "",
63
+ pageName: String(to.name || to.meta?.title || to.path || ""),
64
+ source: "admin",
65
+ productName: $Config.productName,
66
+ productCode: $Config.productCode,
67
+ productVersion: $Config.productVersion
68
+ },
69
+ [""]
70
+ ).catch(() => {
71
+ // 静默失败:不阻断路由切换
72
+ });
59
73
  });
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
  });