@yysports/tools 0.1.5 → 0.1.7
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/dist/Track/index.js +21 -20
- package/dist/Utils/route.js +13 -4
- package/dist/interfaces/track.interface.d.ts +1 -1
- package/lib/Track/index.js +16 -17
- package/lib/Utils/route.js +12 -4
- package/lib/interfaces/track.interface.d.ts +1 -1
- package/package.json +1 -1
package/dist/Track/index.js
CHANGED
|
@@ -56,7 +56,7 @@ var Track = /*#__PURE__*/function () {
|
|
|
56
56
|
data = this.trackQueue.splice(0, this.trackQueue.length);
|
|
57
57
|
compressed = pako.deflate(JSON.stringify(data));
|
|
58
58
|
if (data.length) {
|
|
59
|
-
debug && console.
|
|
59
|
+
debug && console.debug('[track:debug] push data', data);
|
|
60
60
|
navigator.sendBeacon("https://track.yysports.com/pousheng-guard/api/analysis/track", compressed);
|
|
61
61
|
}
|
|
62
62
|
case 4:
|
|
@@ -84,6 +84,7 @@ var Track = /*#__PURE__*/function () {
|
|
|
84
84
|
fileName: filename
|
|
85
85
|
};
|
|
86
86
|
_this.errorLog(errorInfo);
|
|
87
|
+
console.error('[track:error] catch error', event);
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
|
|
@@ -267,9 +268,6 @@ var Track = /*#__PURE__*/function () {
|
|
|
267
268
|
key: "getPageModuleName",
|
|
268
269
|
value: function getPageModuleName() {
|
|
269
270
|
var routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
270
|
-
if (routeInfo !== null && routeInfo !== void 0 && routeInfo.redirect) {
|
|
271
|
-
throw new Error('重定向路径不记录埋点');
|
|
272
|
-
}
|
|
273
271
|
return (routeInfo === null || routeInfo === void 0 ? void 0 : routeInfo.module) || [];
|
|
274
272
|
}
|
|
275
273
|
|
|
@@ -315,23 +313,26 @@ var Track = /*#__PURE__*/function () {
|
|
|
315
313
|
}, {
|
|
316
314
|
key: "visitLog",
|
|
317
315
|
value: function visitLog(_visitLog) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
type: 'visit'
|
|
316
|
+
// 检测当前路由是否为重定向路由,如果是则不记录
|
|
317
|
+
var routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
318
|
+
if (routeInfo !== null && routeInfo !== void 0 && routeInfo.isRedirect) {
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
if (_visitLog === undefined) {
|
|
322
|
+
_visitLog = {
|
|
323
|
+
module: '',
|
|
324
|
+
content: ''
|
|
325
|
+
};
|
|
326
|
+
var routeNames = this.getPageModuleName();
|
|
327
|
+
Object.assign(_visitLog, {
|
|
328
|
+
module: routeNames.join('-'),
|
|
329
|
+
content: "\u8BBF\u95EE\u9875\u9762: ".concat(_toConsumableArray(routeNames).pop())
|
|
333
330
|
});
|
|
334
|
-
}
|
|
331
|
+
}
|
|
332
|
+
this.pushQueue({
|
|
333
|
+
log: _visitLog,
|
|
334
|
+
type: 'visit'
|
|
335
|
+
});
|
|
335
336
|
}
|
|
336
337
|
|
|
337
338
|
// 推送接口访问日志
|
package/dist/Utils/route.js
CHANGED
|
@@ -14,6 +14,15 @@ export var getRoutesMap = function getRoutesMap(routes, menuNameMap) {
|
|
|
14
14
|
name = route.name,
|
|
15
15
|
routes = route.routes,
|
|
16
16
|
redirect = route.redirect;
|
|
17
|
+
if (!path) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
// 初始化路由信息
|
|
21
|
+
var savedRoute = routesMap.get(path);
|
|
22
|
+
if (!savedRoute) {
|
|
23
|
+
routesMap.set(path, {});
|
|
24
|
+
savedRoute = routesMap.get(path);
|
|
25
|
+
}
|
|
17
26
|
var nameArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.name) || []);
|
|
18
27
|
var moduleArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.module) || []);
|
|
19
28
|
if (name) {
|
|
@@ -26,12 +35,12 @@ export var getRoutesMap = function getRoutesMap(routes, menuNameMap) {
|
|
|
26
35
|
var routeInfo = {
|
|
27
36
|
access: access,
|
|
28
37
|
name: nameArr,
|
|
29
|
-
module: moduleArr
|
|
30
|
-
redirect: !!redirect
|
|
38
|
+
module: moduleArr
|
|
31
39
|
};
|
|
32
|
-
if (
|
|
33
|
-
|
|
40
|
+
if (redirect) {
|
|
41
|
+
routeInfo.isRedirect = true;
|
|
34
42
|
}
|
|
43
|
+
Object.assign(savedRoute, routeInfo);
|
|
35
44
|
if (routes) {
|
|
36
45
|
ergodicLocalMenu(routes, routeInfo);
|
|
37
46
|
}
|
package/lib/Track/index.js
CHANGED
|
@@ -51,7 +51,7 @@ var Track = class {
|
|
|
51
51
|
const data = this.trackQueue.splice(0, this.trackQueue.length);
|
|
52
52
|
const compressed = import_pako.default.deflate(JSON.stringify(data));
|
|
53
53
|
if (data.length) {
|
|
54
|
-
debug && console.
|
|
54
|
+
debug && console.debug("[track:debug] push data", data);
|
|
55
55
|
navigator.sendBeacon(
|
|
56
56
|
`https://track.yysports.com/pousheng-guard/api/analysis/track`,
|
|
57
57
|
compressed
|
|
@@ -69,6 +69,7 @@ var Track = class {
|
|
|
69
69
|
fileName: filename
|
|
70
70
|
};
|
|
71
71
|
this.errorLog(errorInfo);
|
|
72
|
+
console.error("[track:error] catch error", event);
|
|
72
73
|
});
|
|
73
74
|
}
|
|
74
75
|
addEventListener("visibilitychange", () => {
|
|
@@ -205,9 +206,6 @@ var Track = class {
|
|
|
205
206
|
// 获取模块名称
|
|
206
207
|
static getPageModuleName() {
|
|
207
208
|
const routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
208
|
-
if (routeInfo == null ? void 0 : routeInfo.redirect) {
|
|
209
|
-
throw new Error("重定向路径不记录埋点");
|
|
210
|
-
}
|
|
211
209
|
return (routeInfo == null ? void 0 : routeInfo.module) || [];
|
|
212
210
|
}
|
|
213
211
|
// 推送错误日志
|
|
@@ -244,21 +242,22 @@ var Track = class {
|
|
|
244
242
|
}
|
|
245
243
|
// 推送页面访问日志
|
|
246
244
|
static visitLog(visitLog) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
log: visitLog,
|
|
258
|
-
type: "visit"
|
|
245
|
+
const routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
246
|
+
if (routeInfo == null ? void 0 : routeInfo.isRedirect) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (visitLog === void 0) {
|
|
250
|
+
visitLog = { module: "", content: "" };
|
|
251
|
+
const routeNames = this.getPageModuleName();
|
|
252
|
+
Object.assign(visitLog, {
|
|
253
|
+
module: routeNames.join("-"),
|
|
254
|
+
content: `访问页面: ${[...routeNames].pop()}`
|
|
259
255
|
});
|
|
260
|
-
} catch (e) {
|
|
261
256
|
}
|
|
257
|
+
this.pushQueue({
|
|
258
|
+
log: visitLog,
|
|
259
|
+
type: "visit"
|
|
260
|
+
});
|
|
262
261
|
}
|
|
263
262
|
// 推送接口访问日志
|
|
264
263
|
static apiLog(apiLog) {
|
package/lib/Utils/route.js
CHANGED
|
@@ -27,6 +27,14 @@ var getRoutesMap = (routes, menuNameMap) => {
|
|
|
27
27
|
const ergodicLocalMenu = (rs, parentMenu) => {
|
|
28
28
|
rs.forEach((route) => {
|
|
29
29
|
const { path, access, name, routes: routes2, redirect } = route;
|
|
30
|
+
if (!path) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
let savedRoute = routesMap.get(path);
|
|
34
|
+
if (!savedRoute) {
|
|
35
|
+
routesMap.set(path, {});
|
|
36
|
+
savedRoute = routesMap.get(path);
|
|
37
|
+
}
|
|
30
38
|
const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
|
|
31
39
|
const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
|
|
32
40
|
if (name) {
|
|
@@ -39,12 +47,12 @@ var getRoutesMap = (routes, menuNameMap) => {
|
|
|
39
47
|
const routeInfo = {
|
|
40
48
|
access,
|
|
41
49
|
name: nameArr,
|
|
42
|
-
module: moduleArr
|
|
43
|
-
redirect: !!redirect
|
|
50
|
+
module: moduleArr
|
|
44
51
|
};
|
|
45
|
-
if (
|
|
46
|
-
|
|
52
|
+
if (redirect) {
|
|
53
|
+
routeInfo.isRedirect = true;
|
|
47
54
|
}
|
|
55
|
+
Object.assign(savedRoute, routeInfo);
|
|
48
56
|
if (routes2) {
|
|
49
57
|
ergodicLocalMenu(routes2, routeInfo);
|
|
50
58
|
}
|