byt-ui 0.1.3 → 0.1.4
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/lib/byt-ui.common.js +239 -223
- package/lib/byt-ui.umd.js +239 -223
- package/lib/byt-ui.umd.min.js +2 -2
- package/package.json +1 -1
- package/packages/common/modules/{Sentry.js → sentry.js} +53 -36
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* @Description:
|
|
3
3
|
* @Author: 王国火
|
|
4
4
|
* @Date: 2024-04-18 15:37:44
|
|
5
|
-
* @LastEditTime: 2024-04-
|
|
5
|
+
* @LastEditTime: 2024-04-22 08:56:36
|
|
6
6
|
* @LastEditors: 王国火
|
|
7
7
|
*/
|
|
8
8
|
import * as sentry from '@sentry/vue'
|
|
@@ -21,9 +21,34 @@ class Sentry {
|
|
|
21
21
|
this.register();
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
getUserInfo() {
|
|
25
|
+
// 处理要提交的用户信息
|
|
26
|
+
const { fullPath } = this.router.currentRoute;
|
|
27
|
+
const userInfo = getCookie('userInfo') || getStore('userInfo');
|
|
28
|
+
const tenantId = getCookie('tenantId') || ''
|
|
29
|
+
const params = {
|
|
30
|
+
path: fullPath,
|
|
31
|
+
title: document.title,
|
|
32
|
+
ip: window.location.host
|
|
33
|
+
}
|
|
34
|
+
let opts = {};
|
|
35
|
+
if (userInfo) {
|
|
36
|
+
const info = JSON.parse(userInfo);
|
|
37
|
+
const { username, email } = info;
|
|
38
|
+
opts = Object.assign(params, info, {
|
|
39
|
+
id: tenantId,
|
|
40
|
+
username,
|
|
41
|
+
email
|
|
42
|
+
})
|
|
43
|
+
} else {
|
|
44
|
+
opts = params
|
|
45
|
+
}
|
|
46
|
+
return opts
|
|
47
|
+
}
|
|
48
|
+
|
|
24
49
|
captureEvent({
|
|
25
50
|
message = '',
|
|
26
|
-
level = '
|
|
51
|
+
level = 'info',
|
|
27
52
|
tags = {
|
|
28
53
|
type: 'xhr-error',
|
|
29
54
|
category: 'xhr-category'
|
|
@@ -31,6 +56,7 @@ class Sentry {
|
|
|
31
56
|
extra = {},
|
|
32
57
|
breadcrumbs = []
|
|
33
58
|
}) {
|
|
59
|
+
// 错误上报
|
|
34
60
|
sentry.captureEvent({
|
|
35
61
|
message,
|
|
36
62
|
level,
|
|
@@ -40,6 +66,7 @@ class Sentry {
|
|
|
40
66
|
})
|
|
41
67
|
}
|
|
42
68
|
init(dsn) {
|
|
69
|
+
// init调用
|
|
43
70
|
const params = {
|
|
44
71
|
Vue: this.Vue,
|
|
45
72
|
dsn,
|
|
@@ -60,32 +87,16 @@ class Sentry {
|
|
|
60
87
|
},
|
|
61
88
|
beforeSend: (e) => {
|
|
62
89
|
// 请求发送前添加用户信息
|
|
63
|
-
|
|
64
|
-
const userInfo = getCookie('userInfo') || getStore('userInfo');
|
|
65
|
-
const tenantId = getCookie('tenantId') || ''
|
|
66
|
-
const params = {
|
|
67
|
-
path: fullPath,
|
|
68
|
-
title: document.title,
|
|
69
|
-
ip: window.location.host
|
|
70
|
-
}
|
|
71
|
-
if (userInfo) {
|
|
72
|
-
const info = JSON.parse(userInfo);
|
|
73
|
-
const { username, email } = info;
|
|
74
|
-
e.user = Object.assign(params, info, {
|
|
75
|
-
id: tenantId,
|
|
76
|
-
username,
|
|
77
|
-
email
|
|
78
|
-
})
|
|
79
|
-
} else {
|
|
80
|
-
e.user = params
|
|
81
|
-
}
|
|
90
|
+
e.user = this.getUserInfo();
|
|
82
91
|
return e;
|
|
83
92
|
},
|
|
84
93
|
beforeSendTransaction: (e) => {
|
|
94
|
+
// 请求发送前添加用户信息,修改transaction为title
|
|
85
95
|
e.transaction = document.title
|
|
96
|
+
e.user = this.getUserInfo();
|
|
86
97
|
return e
|
|
87
98
|
},
|
|
88
|
-
// 任何请求都会调用的函数,处理请求status_code不是200
|
|
99
|
+
// 任何请求都会调用的函数,处理请求status_code不是200时,或者code=1,自定义上报错误信息
|
|
89
100
|
beforeBreadcrumb: (scope, hint) => {
|
|
90
101
|
if (scope.category == 'xhr') {
|
|
91
102
|
const statusCode = scope.data.status_code;
|
|
@@ -135,23 +146,29 @@ class Sentry {
|
|
|
135
146
|
// 允许自定义配置覆盖、合并默认配置
|
|
136
147
|
sentry.init(Object.assign({}, params, this.options))
|
|
137
148
|
}
|
|
138
|
-
register() {
|
|
139
|
-
this.axios({
|
|
149
|
+
async register() {
|
|
150
|
+
const res = await this.axios({
|
|
140
151
|
url: '/leo-tech-bridge/sysParam/getSentryDsn',
|
|
141
152
|
method: 'GET'
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
})
|
|
153
|
+
});
|
|
154
|
+
// 需要兼容商城和业务中台
|
|
155
|
+
const val = res instanceof Object ? res.data : res;
|
|
156
|
+
if (val) {
|
|
157
|
+
// 重新处理拼接dsn地址
|
|
158
|
+
const localhost = window.location;
|
|
159
|
+
const result = val.split('@');
|
|
160
|
+
const dsn = `${localhost.protocol}//${result[0]}@${localhost.host}${result[1]}`;
|
|
161
|
+
this.init(dsn);
|
|
162
|
+
}
|
|
153
163
|
}
|
|
154
164
|
}
|
|
155
165
|
|
|
156
|
-
export default
|
|
166
|
+
export default {
|
|
167
|
+
install(Vue, options) {
|
|
168
|
+
const sentry = new Sentry(Object.assign({
|
|
169
|
+
Vue
|
|
170
|
+
}, options))
|
|
171
|
+
Vue.prototype.$sentry = sentry
|
|
172
|
+
}
|
|
173
|
+
}
|
|
157
174
|
|