@yysports/tools 1.1.0 → 2.0.1
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/core/auth.d.ts +16 -0
- package/dist/Track/core/auth.js +83 -0
- package/dist/Track/core/constants.d.ts +14 -0
- package/dist/Track/core/constants.js +25 -0
- package/dist/Track/core/envelope.d.ts +9 -0
- package/dist/Track/core/envelope.js +54 -0
- package/dist/Track/core/instance.d.ts +108 -0
- package/dist/Track/core/instance.js +365 -0
- package/dist/Track/core/lifecycle.d.ts +18 -0
- package/dist/Track/core/lifecycle.js +59 -0
- package/dist/Track/core/profile.d.ts +5 -0
- package/dist/Track/core/profile.js +30 -0
- package/dist/Track/core/queue.d.ts +13 -0
- package/dist/Track/core/queue.js +36 -0
- package/dist/Track/core/replay.d.ts +17 -0
- package/dist/Track/core/replay.js +117 -0
- package/dist/Track/core/router.d.ts +6 -0
- package/dist/Track/core/router.js +15 -0
- package/dist/Track/core/system.d.ts +14 -0
- package/dist/Track/core/system.js +36 -0
- package/dist/Track/core/transport.d.ts +18 -0
- package/dist/Track/core/transport.js +151 -0
- package/dist/Track/index.d.ts +19 -28
- package/dist/Track/index.js +144 -396
- package/dist/Utils/common.js +5 -6
- package/dist/Utils/route.js +1 -6
- package/dist/Utils/url.js +1 -3
- package/dist/Utils/wx.js +2 -7
- package/dist/interfaces/track.interface.d.ts +14 -4
- package/lib/Track/core/auth.d.ts +16 -0
- package/lib/Track/core/auth.js +67 -0
- package/lib/Track/core/constants.d.ts +14 -0
- package/lib/Track/core/constants.js +56 -0
- package/lib/Track/core/envelope.d.ts +9 -0
- package/lib/Track/core/envelope.js +61 -0
- package/lib/Track/core/instance.d.ts +108 -0
- package/lib/Track/core/instance.js +257 -0
- package/lib/Track/core/lifecycle.d.ts +18 -0
- package/lib/Track/core/lifecycle.js +74 -0
- package/lib/Track/core/profile.d.ts +5 -0
- package/lib/Track/core/profile.js +47 -0
- package/lib/Track/core/queue.d.ts +13 -0
- package/lib/Track/core/queue.js +49 -0
- package/lib/Track/core/replay.d.ts +17 -0
- package/lib/Track/core/replay.js +131 -0
- package/lib/Track/core/router.d.ts +6 -0
- package/lib/Track/core/router.js +39 -0
- package/lib/Track/core/system.d.ts +14 -0
- package/lib/Track/core/system.js +53 -0
- package/lib/Track/core/transport.d.ts +18 -0
- package/lib/Track/core/transport.js +115 -0
- package/lib/Track/index.d.ts +19 -28
- package/lib/Track/index.js +93 -317
- package/lib/Utils/common.js +4 -6
- package/lib/interfaces/track.interface.d.ts +14 -4
- package/package.json +11 -10
package/dist/Track/index.js
CHANGED
|
@@ -1,433 +1,181 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
16
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
19
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
20
|
-
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
21
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
22
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
23
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
24
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
26
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
27
|
-
import pako from 'pako';
|
|
28
|
-
import { version } from "../../package.json";
|
|
29
|
-
import { generateRandomString, getAuthMapByAuthCenter, getRoutesMap } from "../Utils";
|
|
30
|
-
var Track = /*#__PURE__*/function () {
|
|
31
|
-
function Track() {
|
|
32
|
-
_classCallCheck(this, Track);
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
|
+
/**
|
|
7
|
+
* 简化版埋点入口(单实例)
|
|
8
|
+
* 提供统一 Track.init(config) 及若干日志方法,未初始化即抛错
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { TrackerInstance } from "./core/instance";
|
|
12
|
+
var TrackFacade = /*#__PURE__*/function () {
|
|
13
|
+
function TrackFacade() {
|
|
14
|
+
_classCallCheck(this, TrackFacade);
|
|
33
15
|
}
|
|
34
|
-
_createClass(
|
|
35
|
-
key: "
|
|
36
|
-
value:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
if (!config.domain) {
|
|
43
|
-
throw new Error('请设置信息采集中心域名');
|
|
44
|
-
}
|
|
45
|
-
if (!config.appId) {
|
|
46
|
-
throw new Error('请设置appId');
|
|
47
|
-
}
|
|
48
|
-
this.config = config;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// 发送埋点数据
|
|
52
|
-
}, {
|
|
53
|
-
key: "send",
|
|
54
|
-
value: function () {
|
|
55
|
-
var _send = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
56
|
-
var debug, data, compressed;
|
|
57
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
58
|
-
while (1) switch (_context.prev = _context.next) {
|
|
16
|
+
_createClass(TrackFacade, null, [{
|
|
17
|
+
key: "init",
|
|
18
|
+
value: ( /** 初始化(必须先调用一次)。重复调用直接返回已存在实例 */function () {
|
|
19
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config) {
|
|
20
|
+
var _this = this;
|
|
21
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
22
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
59
23
|
case 0:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
24
|
+
if (!this._instance) {
|
|
25
|
+
_context2.next = 2;
|
|
26
|
+
break;
|
|
27
|
+
}
|
|
28
|
+
return _context2.abrupt("return", Promise.resolve(this._profile));
|
|
29
|
+
case 2:
|
|
30
|
+
if (!this._initPromise) {
|
|
31
|
+
this._initPromise = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
32
|
+
var ins, profile;
|
|
33
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
34
|
+
while (1) switch (_context.prev = _context.next) {
|
|
35
|
+
case 0:
|
|
36
|
+
ins = new TrackerInstance(config);
|
|
37
|
+
_context.next = 3;
|
|
38
|
+
return ins.init();
|
|
39
|
+
case 3:
|
|
40
|
+
profile = _context.sent;
|
|
41
|
+
// AuthCenterUserProfile
|
|
42
|
+
_this._instance = ins;
|
|
43
|
+
_this._profile = profile;
|
|
44
|
+
return _context.abrupt("return", profile);
|
|
45
|
+
case 7:
|
|
46
|
+
case "end":
|
|
47
|
+
return _context.stop();
|
|
48
|
+
}
|
|
49
|
+
}, _callee);
|
|
50
|
+
}))();
|
|
66
51
|
}
|
|
52
|
+
return _context2.abrupt("return", this._initPromise);
|
|
67
53
|
case 4:
|
|
68
54
|
case "end":
|
|
69
|
-
return
|
|
55
|
+
return _context2.stop();
|
|
70
56
|
}
|
|
71
|
-
},
|
|
57
|
+
}, _callee2, this);
|
|
72
58
|
}));
|
|
73
|
-
function
|
|
74
|
-
return
|
|
75
|
-
}
|
|
76
|
-
return send;
|
|
77
|
-
}() // 挂载自动化任务
|
|
78
|
-
}, {
|
|
79
|
-
key: "mountAutoTask",
|
|
80
|
-
value: function mountAutoTask() {
|
|
81
|
-
var _this = this;
|
|
82
|
-
var autoReportError = this.config.autoReportError;
|
|
83
|
-
if (autoReportError) {
|
|
84
|
-
addEventListener('error', function (event) {
|
|
85
|
-
var message = event.message,
|
|
86
|
-
filename = event.filename;
|
|
87
|
-
var errorInfo = {
|
|
88
|
-
message: message,
|
|
89
|
-
fileName: filename
|
|
90
|
-
};
|
|
91
|
-
_this.errorLog(errorInfo);
|
|
92
|
-
console.error('[track:error] catch error', event);
|
|
93
|
-
});
|
|
59
|
+
function init(_x) {
|
|
60
|
+
return _init.apply(this, arguments);
|
|
94
61
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
addEventListener('visibilitychange', function () {
|
|
98
|
-
if (document.visibilityState === 'hidden') {
|
|
99
|
-
_this.send();
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
// 获取系统信息
|
|
62
|
+
return init;
|
|
63
|
+
}() /** 工具:确保已初始化,否则抛错 */)
|
|
105
64
|
}, {
|
|
106
|
-
key: "
|
|
107
|
-
value: function
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
localStorage.setItem('__IMEI__', generateRandomString(16));
|
|
111
|
-
}
|
|
112
|
-
return {
|
|
113
|
-
innerHeight: innerHeight,
|
|
114
|
-
innerWidth: innerWidth,
|
|
115
|
-
href: location.href,
|
|
116
|
-
systemTime: new Date(),
|
|
117
|
-
IMEI: localStorage.getItem('__IMEI__')
|
|
118
|
-
};
|
|
65
|
+
key: "ensure",
|
|
66
|
+
value: function ensure() {
|
|
67
|
+
if (!this._instance) throw new Error('Track 未初始化,请先调用 Track.init(config)');
|
|
68
|
+
return this._instance;
|
|
119
69
|
}
|
|
120
70
|
|
|
121
|
-
|
|
71
|
+
/**
|
|
72
|
+
* 发送事件日志(通用事件)
|
|
73
|
+
* - 若未初始化:自动排队等待 init 完成后回放
|
|
74
|
+
*/
|
|
122
75
|
}, {
|
|
123
|
-
key: "
|
|
124
|
-
value: function
|
|
125
|
-
var
|
|
126
|
-
|
|
127
|
-
userProfile.userId = '';
|
|
128
|
-
}
|
|
129
|
-
if (!(userProfile !== null && userProfile !== void 0 && userProfile.userName)) {
|
|
130
|
-
userProfile.userName = '';
|
|
131
|
-
}
|
|
132
|
-
return userProfile;
|
|
76
|
+
key: "eventLog",
|
|
77
|
+
value: function eventLog() {
|
|
78
|
+
var _this$ensure;
|
|
79
|
+
(_this$ensure = this.ensure()).eventLog.apply(_this$ensure, arguments);
|
|
133
80
|
}
|
|
134
|
-
|
|
135
|
-
|
|
81
|
+
/**
|
|
82
|
+
* 发送访问/页面曝光日志
|
|
83
|
+
* - 用于记录页面 / 场景进入等行为
|
|
84
|
+
*/
|
|
136
85
|
}, {
|
|
137
|
-
key: "
|
|
138
|
-
value: function
|
|
139
|
-
|
|
86
|
+
key: "visitLog",
|
|
87
|
+
value: function visitLog() {
|
|
88
|
+
var _this$ensure2;
|
|
89
|
+
(_this$ensure2 = this.ensure()).visitLog.apply(_this$ensure2, arguments);
|
|
140
90
|
}
|
|
141
|
-
|
|
142
|
-
|
|
91
|
+
/**
|
|
92
|
+
* 发送错误日志
|
|
93
|
+
* - 适用于运行时异常、资源加载失败、接口异常包装等
|
|
94
|
+
*/
|
|
143
95
|
}, {
|
|
144
|
-
key: "
|
|
145
|
-
value: function () {
|
|
146
|
-
var
|
|
147
|
-
var
|
|
148
|
-
|
|
149
|
-
while (1) switch (_context2.prev = _context2.next) {
|
|
150
|
-
case 0:
|
|
151
|
-
getAuth = _ref.getAuth, menuBuild = _ref.menuBuild, getDataScopeZonePermissions = _ref.getDataScopeZonePermissions, menuNameMap = _ref.menuNameMap, routes = _ref.routes;
|
|
152
|
-
authCenterApi = []; // 获取用户权限
|
|
153
|
-
if (getAuth) {
|
|
154
|
-
authCenterApi.push(getAuth);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// 获取权限中心配置的菜单及按钮
|
|
158
|
-
if (menuBuild) {
|
|
159
|
-
authCenterApi.push(menuBuild);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// 获取权限中心配置的区部数据权限
|
|
163
|
-
if (getDataScopeZonePermissions) {
|
|
164
|
-
authCenterApi.push(getDataScopeZonePermissions);
|
|
165
|
-
}
|
|
166
|
-
_context2.next = 7;
|
|
167
|
-
return Promise.all(authCenterApi.map(function (v) {
|
|
168
|
-
if (v) {
|
|
169
|
-
return v();
|
|
170
|
-
} else {
|
|
171
|
-
return Promise.resolve();
|
|
172
|
-
}
|
|
173
|
-
}));
|
|
174
|
-
case 7:
|
|
175
|
-
_yield$Promise$all = _context2.sent;
|
|
176
|
-
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
|
|
177
|
-
_yield$Promise$all2$ = _yield$Promise$all2[0];
|
|
178
|
-
authInfo = _yield$Promise$all2$ === void 0 ? {} : _yield$Promise$all2$;
|
|
179
|
-
_yield$Promise$all2$2 = _yield$Promise$all2[1];
|
|
180
|
-
menuData = _yield$Promise$all2$2 === void 0 ? [] : _yield$Promise$all2$2;
|
|
181
|
-
dataScopeZonePermissions = _yield$Promise$all2[2];
|
|
182
|
-
_ref2 = authInfo || {}, _ref2$user = _ref2.user, user = _ref2$user === void 0 ? {} : _ref2$user, _ref2$roles = _ref2.roles, roles = _ref2$roles === void 0 ? [] : _ref2$roles;
|
|
183
|
-
dataScopeRoles = user.roles, restUser = _objectWithoutProperties(user, _excluded); // 权限中心的用户信息
|
|
184
|
-
isAdmin = roles.includes('admin'); // 当前用户所拥有的所有页面权限
|
|
185
|
-
accessPage = []; // 获取本地菜单信息映射
|
|
186
|
-
if (routes) {
|
|
187
|
-
routesMap = getRoutesMap(routes, menuNameMap);
|
|
188
|
-
routesMap.forEach(function (value) {
|
|
189
|
-
var access = value.access;
|
|
190
|
-
if (access.length === 0) {
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (isAdmin) {
|
|
194
|
-
accessPage.push.apply(accessPage, _toConsumableArray(access));
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
access.forEach(function (key) {
|
|
198
|
-
if (roles.includes(key)) {
|
|
199
|
-
accessPage.push(key);
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
});
|
|
203
|
-
this.routesMap = routesMap;
|
|
204
|
-
}
|
|
205
|
-
this.authMap = getAuthMapByAuthCenter(menuData);
|
|
206
|
-
authCenterUserProfile = _objectSpread(_objectSpread({}, restUser), {}, {
|
|
207
|
-
dataScopeRoles: dataScopeRoles,
|
|
208
|
-
roles: roles,
|
|
209
|
-
accessPage: accessPage
|
|
210
|
-
});
|
|
211
|
-
if (dataScopeZonePermissions) {
|
|
212
|
-
Object.assign(authCenterUserProfile, {
|
|
213
|
-
dataScopeZonePermissions: dataScopeZonePermissions
|
|
214
|
-
});
|
|
215
|
-
}
|
|
216
|
-
this.authCenterUserProfile = authCenterUserProfile;
|
|
217
|
-
return _context2.abrupt("return", authCenterUserProfile);
|
|
218
|
-
case 24:
|
|
219
|
-
case "end":
|
|
220
|
-
return _context2.stop();
|
|
221
|
-
}
|
|
222
|
-
}, _callee2, this);
|
|
223
|
-
}));
|
|
224
|
-
function initAuthCenterData(_x) {
|
|
225
|
-
return _initAuthCenterData.apply(this, arguments);
|
|
226
|
-
}
|
|
227
|
-
return initAuthCenterData;
|
|
228
|
-
}() // 挂载初始配置
|
|
229
|
-
}, {
|
|
230
|
-
key: "init",
|
|
231
|
-
value: function () {
|
|
232
|
-
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
|
|
233
|
-
var _this$authCenterUserP2;
|
|
234
|
-
var userProfile, menuNameMap, routes, getAuth, menuBuild, getDataScopeZonePermissions, restConfig, currentUserProfile, _this$authCenterUserP;
|
|
96
|
+
key: "errorLog",
|
|
97
|
+
value: (function () {
|
|
98
|
+
var _errorLog = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
99
|
+
var _this$ensure3;
|
|
100
|
+
var _args3 = arguments;
|
|
235
101
|
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
236
102
|
while (1) switch (_context3.prev = _context3.next) {
|
|
237
103
|
case 0:
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
this.config = restConfig;
|
|
241
|
-
_context3.next = 5;
|
|
242
|
-
return this.initAuthCenterData({
|
|
243
|
-
getAuth: getAuth,
|
|
244
|
-
menuBuild: menuBuild,
|
|
245
|
-
getDataScopeZonePermissions: getDataScopeZonePermissions,
|
|
246
|
-
menuNameMap: menuNameMap,
|
|
247
|
-
routes: routes
|
|
248
|
-
});
|
|
249
|
-
case 5:
|
|
250
|
-
currentUserProfile = {}; // 如果对接了权限中心,取权限中心的用户信息
|
|
251
|
-
if (this.authCenterUserProfile.userName) {
|
|
252
|
-
Object.assign(currentUserProfile, {
|
|
253
|
-
userId: this.authCenterUserProfile.userName,
|
|
254
|
-
userName: this.authCenterUserProfile.nickName,
|
|
255
|
-
orgCode: this.authCenterUserProfile.orgCode,
|
|
256
|
-
orgTitle: this.authCenterUserProfile.orgTitle,
|
|
257
|
-
dataScopeRoles: (_this$authCenterUserP = this.authCenterUserProfile.dataScopeRoles) === null || _this$authCenterUserP === void 0 ? void 0 : _this$authCenterUserP.map(function (role) {
|
|
258
|
-
return role.name;
|
|
259
|
-
}).join(',')
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// 传入区部数据权限接口时,设置区部权限数据
|
|
264
|
-
if (this.authCenterUserProfile.dataScopeZonePermissions && ((_this$authCenterUserP2 = this.authCenterUserProfile.dataScopeZonePermissions) === null || _this$authCenterUserP2 === void 0 || (_this$authCenterUserP2 = _this$authCenterUserP2.list) === null || _this$authCenterUserP2 === void 0 ? void 0 : _this$authCenterUserP2.length) > 0) {
|
|
265
|
-
// 提取出所有 zoneId
|
|
266
|
-
Object.assign(currentUserProfile, {
|
|
267
|
-
dataScopeZonePermissions: this.authCenterUserProfile.dataScopeZonePermissions.list.map(function (item) {
|
|
268
|
-
return item.list.map(function (zone) {
|
|
269
|
-
return zone.zoneId;
|
|
270
|
-
}).join(',');
|
|
271
|
-
}).join(',')
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
if (userProfile) {
|
|
275
|
-
Object.assign(currentUserProfile, userProfile);
|
|
276
|
-
}
|
|
277
|
-
this.setUserProfile(currentUserProfile);
|
|
278
|
-
this.mountAutoTask();
|
|
279
|
-
|
|
280
|
-
// 注册应用版本
|
|
281
|
-
this.registerAppInfo();
|
|
282
|
-
return _context3.abrupt("return", this.authCenterUserProfile);
|
|
283
|
-
case 13:
|
|
104
|
+
return _context3.abrupt("return", (_this$ensure3 = this.ensure()).errorLog.apply(_this$ensure3, _args3));
|
|
105
|
+
case 1:
|
|
284
106
|
case "end":
|
|
285
107
|
return _context3.stop();
|
|
286
108
|
}
|
|
287
109
|
}, _callee3, this);
|
|
288
110
|
}));
|
|
289
|
-
function
|
|
290
|
-
return
|
|
111
|
+
function errorLog() {
|
|
112
|
+
return _errorLog.apply(this, arguments);
|
|
291
113
|
}
|
|
292
|
-
return
|
|
293
|
-
}()
|
|
114
|
+
return errorLog;
|
|
115
|
+
}()
|
|
116
|
+
/**
|
|
117
|
+
* 发送接口调用相关日志
|
|
118
|
+
* - 记录接口耗时 / 结果状态
|
|
119
|
+
*/
|
|
120
|
+
)
|
|
294
121
|
}, {
|
|
295
|
-
key: "
|
|
296
|
-
value: function
|
|
297
|
-
var
|
|
298
|
-
|
|
299
|
-
appId: appId,
|
|
300
|
-
version: version
|
|
301
|
-
})));
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
// 推送埋点信息进入队列
|
|
305
|
-
}, {
|
|
306
|
-
key: "pushQueue",
|
|
307
|
-
value: function pushQueue(_ref4) {
|
|
308
|
-
var type = _ref4.type,
|
|
309
|
-
log = _ref4.log;
|
|
310
|
-
var config = this.config;
|
|
311
|
-
this.checkConfig(config);
|
|
312
|
-
var reqData = _objectSpread(_objectSpread(_objectSpread({}, this.getSystemProfile()), this.getUserProfile()), {}, {
|
|
313
|
-
type: type,
|
|
314
|
-
appId: config.appId,
|
|
315
|
-
log: JSON.stringify(log)
|
|
316
|
-
});
|
|
317
|
-
this.trackQueue.push(reqData);
|
|
318
|
-
if (this.trackQueue.length > 4) {
|
|
319
|
-
this.send();
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
// 获取格式化base后的路径
|
|
324
|
-
}, {
|
|
325
|
-
key: "getFormatBasePath",
|
|
326
|
-
value: function getFormatBasePath() {
|
|
327
|
-
var _this$config$base = this.config.base,
|
|
328
|
-
base = _this$config$base === void 0 ? '/' : _this$config$base;
|
|
329
|
-
var _location = location,
|
|
330
|
-
pathname = _location.pathname;
|
|
331
|
-
return pathname.replace(base, '/');
|
|
122
|
+
key: "apiLog",
|
|
123
|
+
value: function apiLog() {
|
|
124
|
+
var _this$ensure4;
|
|
125
|
+
(_this$ensure4 = this.ensure()).apiLog.apply(_this$ensure4, arguments);
|
|
332
126
|
}
|
|
333
|
-
|
|
334
|
-
|
|
127
|
+
/**
|
|
128
|
+
* 强制立即 flush 已缓冲的日志(若实例策略存在缓冲)
|
|
129
|
+
*/
|
|
335
130
|
}, {
|
|
336
|
-
key: "
|
|
337
|
-
value: function
|
|
338
|
-
|
|
339
|
-
return (routeInfo === null || routeInfo === void 0 ? void 0 : routeInfo.module) || [];
|
|
131
|
+
key: "flush",
|
|
132
|
+
value: function flush() {
|
|
133
|
+
this.ensure().flush();
|
|
340
134
|
}
|
|
341
|
-
|
|
342
|
-
|
|
135
|
+
/**
|
|
136
|
+
* 销毁当前单例实例
|
|
137
|
+
* - 停止上报 / 释放资源
|
|
138
|
+
* - 再次使用需重新 init
|
|
139
|
+
*/
|
|
343
140
|
}, {
|
|
344
|
-
key: "
|
|
345
|
-
value: function
|
|
346
|
-
this.
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
141
|
+
key: "destroy",
|
|
142
|
+
value: function destroy() {
|
|
143
|
+
if (!this._instance) return;
|
|
144
|
+
this._instance.destroy();
|
|
145
|
+
this._instance = null;
|
|
146
|
+
this._initPromise = null;
|
|
147
|
+
this._profile = null;
|
|
350
148
|
}
|
|
351
|
-
|
|
352
|
-
|
|
149
|
+
/**
|
|
150
|
+
* 设置用户画像 / 用户基础属性
|
|
151
|
+
* - 若在 init 前调用:会延迟到实例 ready 后再真正执行
|
|
152
|
+
*/
|
|
353
153
|
}, {
|
|
354
|
-
key: "
|
|
355
|
-
value: function
|
|
356
|
-
|
|
357
|
-
module: '',
|
|
358
|
-
content: ''
|
|
359
|
-
};
|
|
360
|
-
if (typeof _eventLog === 'string') {
|
|
361
|
-
var actionLog = this.authMap.get(_eventLog);
|
|
362
|
-
if (actionLog) {
|
|
363
|
-
copyEventLog.content = '触发: ' + actionLog;
|
|
364
|
-
} else {
|
|
365
|
-
copyEventLog.content = _eventLog;
|
|
366
|
-
}
|
|
367
|
-
} else {
|
|
368
|
-
Object.assign(copyEventLog, _eventLog);
|
|
369
|
-
}
|
|
370
|
-
if (!copyEventLog.module) {
|
|
371
|
-
var routeNames = this.getPageModuleName();
|
|
372
|
-
copyEventLog.module = (routeNames === null || routeNames === void 0 ? void 0 : routeNames.join('-')) || '-';
|
|
373
|
-
}
|
|
374
|
-
this.pushQueue({
|
|
375
|
-
log: copyEventLog,
|
|
376
|
-
type: 'event'
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
// 推送页面访问日志
|
|
381
|
-
}, {
|
|
382
|
-
key: "visitLog",
|
|
383
|
-
value: function visitLog(_visitLog) {
|
|
384
|
-
// 检测当前路由是否为重定向路由,如果是则不记录
|
|
385
|
-
var routeInfo = this.routesMap.get(this.getFormatBasePath());
|
|
386
|
-
if (routeInfo !== null && routeInfo !== void 0 && routeInfo.isRedirect) {
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
if (_visitLog === undefined) {
|
|
390
|
-
_visitLog = {
|
|
391
|
-
module: '',
|
|
392
|
-
content: ''
|
|
393
|
-
};
|
|
394
|
-
var routeNames = this.getPageModuleName();
|
|
395
|
-
Object.assign(_visitLog, {
|
|
396
|
-
module: routeNames.join('-'),
|
|
397
|
-
content: "\u8BBF\u95EE\u9875\u9762: ".concat(_toConsumableArray(routeNames).pop())
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
this.pushQueue({
|
|
401
|
-
log: _visitLog,
|
|
402
|
-
type: 'visit'
|
|
403
|
-
});
|
|
154
|
+
key: "setUserProfile",
|
|
155
|
+
value: function setUserProfile(profile) {
|
|
156
|
+
this.ensure().setUserProfile(profile);
|
|
404
157
|
}
|
|
405
|
-
|
|
406
|
-
// 推送接口访问日志
|
|
158
|
+
/** 获取当前配置(未初始化时返回 undefined) */
|
|
407
159
|
}, {
|
|
408
|
-
key: "
|
|
409
|
-
value: function
|
|
410
|
-
|
|
411
|
-
var config = this.config;
|
|
412
|
-
navigator.sendBeacon("".concat(this.config.domain, "/pousheng-guard/api/track"), pako.deflate(JSON.stringify([_objectSpread(_objectSpread({
|
|
413
|
-
appId: config.appId,
|
|
414
|
-
log: _apiLog,
|
|
415
|
-
type: 'api'
|
|
416
|
-
}, this.getSystemProfile()), this.getUserProfile())])));
|
|
160
|
+
key: "getConfig",
|
|
161
|
+
value: function getConfig() {
|
|
162
|
+
return this.ensure().getConfig();
|
|
417
163
|
}
|
|
418
164
|
}]);
|
|
419
|
-
return
|
|
420
|
-
}();
|
|
421
|
-
|
|
422
|
-
_defineProperty(
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
165
|
+
return TrackFacade;
|
|
166
|
+
}(); // 更安全的导出:显式 API 形状 + 绑定 this
|
|
167
|
+
_defineProperty(TrackFacade, "_instance", null);
|
|
168
|
+
_defineProperty(TrackFacade, "_initPromise", null);
|
|
169
|
+
_defineProperty(TrackFacade, "_profile", null);
|
|
170
|
+
var Track = {
|
|
171
|
+
init: TrackFacade.init.bind(TrackFacade),
|
|
172
|
+
eventLog: TrackFacade.eventLog.bind(TrackFacade),
|
|
173
|
+
visitLog: TrackFacade.visitLog.bind(TrackFacade),
|
|
174
|
+
errorLog: TrackFacade.errorLog.bind(TrackFacade),
|
|
175
|
+
apiLog: TrackFacade.apiLog.bind(TrackFacade),
|
|
176
|
+
flush: TrackFacade.flush.bind(TrackFacade),
|
|
177
|
+
destroy: TrackFacade.destroy.bind(TrackFacade),
|
|
178
|
+
setUserProfile: TrackFacade.setUserProfile.bind(TrackFacade),
|
|
179
|
+
getConfig: TrackFacade.getConfig.bind(TrackFacade)
|
|
180
|
+
};
|
|
433
181
|
export default Track;
|
package/dist/Utils/common.js
CHANGED
|
@@ -45,11 +45,10 @@ export function checkChromeVersion(minVersion) {
|
|
|
45
45
|
* @returns 随机字符串
|
|
46
46
|
*/
|
|
47
47
|
export function generateRandomString(length) {
|
|
48
|
-
var result = '';
|
|
49
48
|
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
return Array.from({
|
|
50
|
+
length: length
|
|
51
|
+
}, function () {
|
|
52
|
+
return characters.charAt(Math.floor(Math.random() * characters.length));
|
|
53
|
+
}).join('');
|
|
55
54
|
}
|
package/dist/Utils/route.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
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."); }
|
|
3
|
-
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); }
|
|
4
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
7
2
|
// 根据本地路由配置文件、路由地址名称映射、当前用户权限,生成路由映射关系表
|
|
8
3
|
export var getRoutesMap = function getRoutesMap(routes, menuNameMap) {
|
|
9
4
|
var routesMap = new Map();
|
package/dist/Utils/url.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
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); }
|
|
3
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
4
2
|
export var getUrlParams = function getUrlParams(str) {
|
|
5
3
|
var paramsStr = location.search;
|
|
6
4
|
if (typeof str === 'string') {
|