@yysports/tools 0.1.6 → 0.1.8
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 +37 -27
- package/dist/Utils/route.js +17 -5
- package/dist/interfaces/track.interface.d.ts +4 -4
- package/lib/Track/index.js +28 -20
- package/lib/Utils/route.js +15 -5
- package/lib/interfaces/track.interface.d.ts +4 -4
- package/package.json +1 -1
package/dist/Track/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
var _excluded = ["userProfile", "menuNameMap", "routes", "getAuth", "menuBuild"];
|
|
2
2
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
8
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
9
5
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
10
6
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
7
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
9
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
11
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
12
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
13
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -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
|
|
|
@@ -166,11 +167,20 @@ var Track = /*#__PURE__*/function () {
|
|
|
166
167
|
accessPage = []; // 获取本地菜单信息映射
|
|
167
168
|
if (routes) {
|
|
168
169
|
routesMap = getRoutesMap(routes, menuNameMap);
|
|
169
|
-
routesMap.forEach(function (value
|
|
170
|
+
routesMap.forEach(function (value) {
|
|
170
171
|
var access = value.access;
|
|
171
|
-
if (access
|
|
172
|
-
|
|
172
|
+
if (access.length === 0) {
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
if (isAdmin) {
|
|
176
|
+
accessPage.push.apply(accessPage, _toConsumableArray(access));
|
|
177
|
+
return;
|
|
173
178
|
}
|
|
179
|
+
access.forEach(function (key) {
|
|
180
|
+
if (roles.includes(key)) {
|
|
181
|
+
accessPage.push(key);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
174
184
|
});
|
|
175
185
|
this.routesMap = routesMap;
|
|
176
186
|
}
|
|
@@ -267,9 +277,6 @@ var Track = /*#__PURE__*/function () {
|
|
|
267
277
|
key: "getPageModuleName",
|
|
268
278
|
value: function getPageModuleName() {
|
|
269
279
|
var routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
270
|
-
if (routeInfo !== null && routeInfo !== void 0 && routeInfo.redirect) {
|
|
271
|
-
throw new Error('重定向路径不记录埋点');
|
|
272
|
-
}
|
|
273
280
|
return (routeInfo === null || routeInfo === void 0 ? void 0 : routeInfo.module) || [];
|
|
274
281
|
}
|
|
275
282
|
|
|
@@ -315,23 +322,26 @@ var Track = /*#__PURE__*/function () {
|
|
|
315
322
|
}, {
|
|
316
323
|
key: "visitLog",
|
|
317
324
|
value: function visitLog(_visitLog) {
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
type: 'visit'
|
|
325
|
+
// 检测当前路由是否为重定向路由,如果是则不记录
|
|
326
|
+
var routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
327
|
+
if (routeInfo !== null && routeInfo !== void 0 && routeInfo.isRedirect) {
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
if (_visitLog === undefined) {
|
|
331
|
+
_visitLog = {
|
|
332
|
+
module: '',
|
|
333
|
+
content: ''
|
|
334
|
+
};
|
|
335
|
+
var routeNames = this.getPageModuleName();
|
|
336
|
+
Object.assign(_visitLog, {
|
|
337
|
+
module: routeNames.join('-'),
|
|
338
|
+
content: "\u8BBF\u95EE\u9875\u9762: ".concat(_toConsumableArray(routeNames).pop())
|
|
333
339
|
});
|
|
334
|
-
}
|
|
340
|
+
}
|
|
341
|
+
this.pushQueue({
|
|
342
|
+
log: _visitLog,
|
|
343
|
+
type: 'visit'
|
|
344
|
+
});
|
|
335
345
|
}
|
|
336
346
|
|
|
337
347
|
// 推送接口访问日志
|
package/dist/Utils/route.js
CHANGED
|
@@ -20,9 +20,20 @@ export var getRoutesMap = function getRoutesMap(routes, menuNameMap) {
|
|
|
20
20
|
// 初始化路由信息
|
|
21
21
|
var savedRoute = routesMap.get(path);
|
|
22
22
|
if (!savedRoute) {
|
|
23
|
-
routesMap.set(path, {
|
|
23
|
+
routesMap.set(path, {
|
|
24
|
+
access: [],
|
|
25
|
+
name: [],
|
|
26
|
+
module: [],
|
|
27
|
+
isRedirect: false
|
|
28
|
+
});
|
|
24
29
|
savedRoute = routesMap.get(path);
|
|
25
30
|
}
|
|
31
|
+
if (redirect) {
|
|
32
|
+
Object.assign(savedRoute, {
|
|
33
|
+
isRedirect: true
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
26
37
|
var nameArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.name) || []);
|
|
27
38
|
var moduleArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.module) || []);
|
|
28
39
|
if (name) {
|
|
@@ -32,14 +43,15 @@ export var getRoutesMap = function getRoutesMap(routes, menuNameMap) {
|
|
|
32
43
|
moduleArr.push(menuNameMap[menuKey]);
|
|
33
44
|
}
|
|
34
45
|
}
|
|
46
|
+
if (access) {
|
|
47
|
+
Object.assign(savedRoute, {
|
|
48
|
+
access: [].concat(_toConsumableArray(savedRoute.access || []), [access])
|
|
49
|
+
});
|
|
50
|
+
}
|
|
35
51
|
var routeInfo = {
|
|
36
|
-
access: access,
|
|
37
52
|
name: nameArr,
|
|
38
53
|
module: moduleArr
|
|
39
54
|
};
|
|
40
|
-
if (redirect) {
|
|
41
|
-
routeInfo.redirect = true;
|
|
42
|
-
}
|
|
43
55
|
Object.assign(savedRoute, routeInfo);
|
|
44
56
|
if (routes) {
|
|
45
57
|
ergodicLocalMenu(routes, routeInfo);
|
|
@@ -80,10 +80,10 @@ export type RouteType = {
|
|
|
80
80
|
[key: string]: any;
|
|
81
81
|
};
|
|
82
82
|
export type RouteMapValueType = {
|
|
83
|
-
access
|
|
84
|
-
name
|
|
85
|
-
module
|
|
86
|
-
|
|
83
|
+
access: string[];
|
|
84
|
+
name: string[];
|
|
85
|
+
module: string[];
|
|
86
|
+
isRedirect: boolean;
|
|
87
87
|
};
|
|
88
88
|
export type AuthDataType = {
|
|
89
89
|
children: AuthDataType[];
|
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", () => {
|
|
@@ -132,11 +133,20 @@ var Track = class {
|
|
|
132
133
|
const accessPage = [];
|
|
133
134
|
if (routes) {
|
|
134
135
|
const routesMap = (0, import_Utils.getRoutesMap)(routes, menuNameMap);
|
|
135
|
-
routesMap.forEach((value
|
|
136
|
+
routesMap.forEach((value) => {
|
|
136
137
|
const { access } = value;
|
|
137
|
-
if (access
|
|
138
|
-
|
|
138
|
+
if (access.length === 0) {
|
|
139
|
+
return;
|
|
139
140
|
}
|
|
141
|
+
if (isAdmin) {
|
|
142
|
+
accessPage.push(...access);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
access.forEach((key) => {
|
|
146
|
+
if (roles.includes(key)) {
|
|
147
|
+
accessPage.push(key);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
140
150
|
});
|
|
141
151
|
this.routesMap = routesMap;
|
|
142
152
|
}
|
|
@@ -205,9 +215,6 @@ var Track = class {
|
|
|
205
215
|
// 获取模块名称
|
|
206
216
|
static getPageModuleName() {
|
|
207
217
|
const routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
208
|
-
if (routeInfo == null ? void 0 : routeInfo.redirect) {
|
|
209
|
-
throw new Error("重定向路径不记录埋点");
|
|
210
|
-
}
|
|
211
218
|
return (routeInfo == null ? void 0 : routeInfo.module) || [];
|
|
212
219
|
}
|
|
213
220
|
// 推送错误日志
|
|
@@ -244,21 +251,22 @@ var Track = class {
|
|
|
244
251
|
}
|
|
245
252
|
// 推送页面访问日志
|
|
246
253
|
static visitLog(visitLog) {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
log: visitLog,
|
|
258
|
-
type: "visit"
|
|
254
|
+
const routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
255
|
+
if (routeInfo == null ? void 0 : routeInfo.isRedirect) {
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
if (visitLog === void 0) {
|
|
259
|
+
visitLog = { module: "", content: "" };
|
|
260
|
+
const routeNames = this.getPageModuleName();
|
|
261
|
+
Object.assign(visitLog, {
|
|
262
|
+
module: routeNames.join("-"),
|
|
263
|
+
content: `访问页面: ${[...routeNames].pop()}`
|
|
259
264
|
});
|
|
260
|
-
} catch (e) {
|
|
261
265
|
}
|
|
266
|
+
this.pushQueue({
|
|
267
|
+
log: visitLog,
|
|
268
|
+
type: "visit"
|
|
269
|
+
});
|
|
262
270
|
}
|
|
263
271
|
// 推送接口访问日志
|
|
264
272
|
static apiLog(apiLog) {
|
package/lib/Utils/route.js
CHANGED
|
@@ -32,9 +32,18 @@ var getRoutesMap = (routes, menuNameMap) => {
|
|
|
32
32
|
}
|
|
33
33
|
let savedRoute = routesMap.get(path);
|
|
34
34
|
if (!savedRoute) {
|
|
35
|
-
routesMap.set(path, {
|
|
35
|
+
routesMap.set(path, {
|
|
36
|
+
access: [],
|
|
37
|
+
name: [],
|
|
38
|
+
module: [],
|
|
39
|
+
isRedirect: false
|
|
40
|
+
});
|
|
36
41
|
savedRoute = routesMap.get(path);
|
|
37
42
|
}
|
|
43
|
+
if (redirect) {
|
|
44
|
+
Object.assign(savedRoute, { isRedirect: true });
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
38
47
|
const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
|
|
39
48
|
const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
|
|
40
49
|
if (name) {
|
|
@@ -44,14 +53,15 @@ var getRoutesMap = (routes, menuNameMap) => {
|
|
|
44
53
|
moduleArr.push(menuNameMap[menuKey]);
|
|
45
54
|
}
|
|
46
55
|
}
|
|
56
|
+
if (access) {
|
|
57
|
+
Object.assign(savedRoute, {
|
|
58
|
+
access: [...savedRoute.access || [], access]
|
|
59
|
+
});
|
|
60
|
+
}
|
|
47
61
|
const routeInfo = {
|
|
48
|
-
access,
|
|
49
62
|
name: nameArr,
|
|
50
63
|
module: moduleArr
|
|
51
64
|
};
|
|
52
|
-
if (redirect) {
|
|
53
|
-
routeInfo.redirect = true;
|
|
54
|
-
}
|
|
55
65
|
Object.assign(savedRoute, routeInfo);
|
|
56
66
|
if (routes2) {
|
|
57
67
|
ergodicLocalMenu(routes2, routeInfo);
|
|
@@ -80,10 +80,10 @@ export type RouteType = {
|
|
|
80
80
|
[key: string]: any;
|
|
81
81
|
};
|
|
82
82
|
export type RouteMapValueType = {
|
|
83
|
-
access
|
|
84
|
-
name
|
|
85
|
-
module
|
|
86
|
-
|
|
83
|
+
access: string[];
|
|
84
|
+
name: string[];
|
|
85
|
+
module: string[];
|
|
86
|
+
isRedirect: boolean;
|
|
87
87
|
};
|
|
88
88
|
export type AuthDataType = {
|
|
89
89
|
children: AuthDataType[];
|