@yysports/tools 0.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/LICENSE +21 -0
- package/README.md +40 -0
- package/dist/CurrentUser/index.d.ts +35 -0
- package/dist/CurrentUser/index.js +168 -0
- package/dist/Track/index.d.ts +24 -0
- package/dist/Track/index.js +275 -0
- package/dist/Utils/common.d.ts +20 -0
- package/dist/Utils/common.js +55 -0
- package/dist/Utils/file.d.ts +10 -0
- package/dist/Utils/file.js +30 -0
- package/dist/Utils/index.d.ts +4 -0
- package/dist/Utils/index.js +4 -0
- package/dist/Utils/url.d.ts +1 -0
- package/dist/Utils/url.js +29 -0
- package/dist/Utils/wx.d.ts +11 -0
- package/dist/Utils/wx.js +25 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/interfaces/currentUser.interface.d.ts +21 -0
- package/dist/interfaces/currentUser.interface.js +1 -0
- package/dist/interfaces/track.interface.d.ts +35 -0
- package/dist/interfaces/track.interface.js +16 -0
- package/lib/CurrentUser/index.d.ts +35 -0
- package/lib/CurrentUser/index.js +130 -0
- package/lib/Track/index.d.ts +24 -0
- package/lib/Track/index.js +209 -0
- package/lib/Utils/common.d.ts +20 -0
- package/lib/Utils/common.js +66 -0
- package/lib/Utils/file.d.ts +10 -0
- package/lib/Utils/file.js +50 -0
- package/lib/Utils/index.d.ts +4 -0
- package/lib/Utils/index.js +29 -0
- package/lib/Utils/url.d.ts +1 -0
- package/lib/Utils/url.js +45 -0
- package/lib/Utils/wx.d.ts +11 -0
- package/lib/Utils/wx.js +46 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +50 -0
- package/lib/interfaces/currentUser.interface.d.ts +21 -0
- package/lib/interfaces/currentUser.interface.js +17 -0
- package/lib/interfaces/track.interface.d.ts +35 -0
- package/lib/interfaces/track.interface.js +35 -0
- package/package.json +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# antd-mix
|
|
2
|
+
|
|
3
|
+
[](https://npmjs.org/package/antd-mix)
|
|
4
|
+
[](https://npmjs.org/package/antd-mix)
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Usage
|
|
9
|
+
|
|
10
|
+
TODO
|
|
11
|
+
|
|
12
|
+
## Options
|
|
13
|
+
|
|
14
|
+
TODO
|
|
15
|
+
|
|
16
|
+
## Development
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# install dependencies
|
|
20
|
+
$ npm install
|
|
21
|
+
|
|
22
|
+
# develop library by docs demo
|
|
23
|
+
$ npm start
|
|
24
|
+
|
|
25
|
+
# build library source code
|
|
26
|
+
$ npm run build
|
|
27
|
+
|
|
28
|
+
# build library source code in watch mode
|
|
29
|
+
$ npm run build:watch
|
|
30
|
+
|
|
31
|
+
# build docs
|
|
32
|
+
$ npm run docs:build
|
|
33
|
+
|
|
34
|
+
# check your project for potential problems
|
|
35
|
+
$ npm run doctor
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## LICENSE
|
|
39
|
+
|
|
40
|
+
MIT
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { AuthMenuItemType, LocalRouteItemType, MenuNameMapType } from '../interfaces/currentUser.interface';
|
|
2
|
+
export interface CurrentUserConfig {
|
|
3
|
+
getAuth?: () => Promise<any>;
|
|
4
|
+
menuBuild?: () => Promise<AuthMenuItemType[]>;
|
|
5
|
+
menuNameMap: MenuNameMapType;
|
|
6
|
+
routes: LocalRouteItemType[];
|
|
7
|
+
}
|
|
8
|
+
export interface CurrentUserInfo {
|
|
9
|
+
name?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
nickName?: string;
|
|
12
|
+
roles: string[];
|
|
13
|
+
isAdmin: boolean;
|
|
14
|
+
accessPage: string[];
|
|
15
|
+
}
|
|
16
|
+
type PathMapItemType = {
|
|
17
|
+
module?: string[];
|
|
18
|
+
access?: string;
|
|
19
|
+
hasAccess?: boolean;
|
|
20
|
+
options: {
|
|
21
|
+
[key: string]: {
|
|
22
|
+
logAction: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
export default class CurrentUser {
|
|
27
|
+
static profile: CurrentUserInfo | null;
|
|
28
|
+
static pathMap: {
|
|
29
|
+
[key: string]: PathMapItemType;
|
|
30
|
+
};
|
|
31
|
+
static formatAuthMenu(authMenuData: AuthMenuItemType[]): void;
|
|
32
|
+
static formatLocalMenu(routes: LocalRouteItemType[], menuNameMap: MenuNameMapType): void;
|
|
33
|
+
static init({ getAuth, menuBuild, menuNameMap, routes, }: CurrentUserConfig): Promise<CurrentUserInfo>;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
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); }
|
|
2
|
+
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; }
|
|
3
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
4
|
+
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."); }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
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); } }
|
|
8
|
+
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); }); }; }
|
|
9
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
10
|
+
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."); }
|
|
11
|
+
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); }
|
|
12
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
13
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
14
|
+
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; }
|
|
15
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
16
|
+
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); } }
|
|
17
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
18
|
+
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; }
|
|
19
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
20
|
+
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); }
|
|
21
|
+
// 初始化后个人信息
|
|
22
|
+
var CurrentUser = /*#__PURE__*/function () {
|
|
23
|
+
function CurrentUser() {
|
|
24
|
+
_classCallCheck(this, CurrentUser);
|
|
25
|
+
}
|
|
26
|
+
_createClass(CurrentUser, null, [{
|
|
27
|
+
key: "formatAuthMenu",
|
|
28
|
+
value:
|
|
29
|
+
// 格式化权限中心菜单、按钮数据
|
|
30
|
+
function formatAuthMenu(authMenuData) {
|
|
31
|
+
var _this = this;
|
|
32
|
+
var ergodicAuthMenu = function ergodicAuthMenu(amd) {
|
|
33
|
+
var pathArr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
34
|
+
amd.forEach(function (menu) {
|
|
35
|
+
var path = menu.path,
|
|
36
|
+
permission = menu.permission,
|
|
37
|
+
name = menu.name,
|
|
38
|
+
logAction = menu.logAction,
|
|
39
|
+
children = menu.children;
|
|
40
|
+
var currPathArr = _toConsumableArray(pathArr);
|
|
41
|
+
if (path) {
|
|
42
|
+
currPathArr.push(path === null || path === void 0 ? void 0 : path.replaceAll('/', ''));
|
|
43
|
+
}
|
|
44
|
+
var currPathObj = _this.pathMap["/".concat(currPathArr.join('/'))];
|
|
45
|
+
if (currPathObj) {
|
|
46
|
+
currPathObj.hasAccess = true;
|
|
47
|
+
}
|
|
48
|
+
if (path === undefined && currPathObj) {
|
|
49
|
+
// 按钮权限
|
|
50
|
+
currPathObj.options[permission] = {
|
|
51
|
+
logAction: logAction || name
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
if (Array.isArray(children) && children.length > 0) {
|
|
55
|
+
ergodicAuthMenu(children, _toConsumableArray(currPathArr));
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
ergodicAuthMenu(authMenuData);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// 格式化本地菜单权限数据
|
|
63
|
+
}, {
|
|
64
|
+
key: "formatLocalMenu",
|
|
65
|
+
value: function formatLocalMenu(routes, menuNameMap) {
|
|
66
|
+
var _this2 = this;
|
|
67
|
+
var ergodicLocalMenu = function ergodicLocalMenu(rs, parentMenu) {
|
|
68
|
+
rs.forEach(function (route) {
|
|
69
|
+
var path = route.path,
|
|
70
|
+
access = route.access,
|
|
71
|
+
name = route.name,
|
|
72
|
+
routes = route.routes;
|
|
73
|
+
var nameArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.name) || []);
|
|
74
|
+
var moduleArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.module) || []);
|
|
75
|
+
if (name) {
|
|
76
|
+
nameArr.push(name);
|
|
77
|
+
var menuKey = ['menu'].concat(_toConsumableArray(nameArr)).join('.');
|
|
78
|
+
moduleArr.push(menuNameMap[menuKey]);
|
|
79
|
+
}
|
|
80
|
+
if (path) {
|
|
81
|
+
_this2.pathMap[path] = {
|
|
82
|
+
module: _toConsumableArray(moduleArr),
|
|
83
|
+
access: access,
|
|
84
|
+
options: {}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
if (routes) {
|
|
88
|
+
ergodicLocalMenu(routes, {
|
|
89
|
+
path: path,
|
|
90
|
+
name: nameArr,
|
|
91
|
+
module: moduleArr
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
ergodicLocalMenu(routes);
|
|
97
|
+
}
|
|
98
|
+
}, {
|
|
99
|
+
key: "init",
|
|
100
|
+
value: function () {
|
|
101
|
+
var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
102
|
+
var _this3 = this;
|
|
103
|
+
var getAuth, menuBuild, menuNameMap, routes, _yield$Promise$all, _yield$Promise$all2, _yield$Promise$all2$, authInfo, _yield$Promise$all2$2, menuData, _ref2, _ref2$user, user, _ref2$roles, roles, isAdmin, accessPage;
|
|
104
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
105
|
+
while (1) switch (_context.prev = _context.next) {
|
|
106
|
+
case 0:
|
|
107
|
+
getAuth = _ref.getAuth, menuBuild = _ref.menuBuild, menuNameMap = _ref.menuNameMap, routes = _ref.routes;
|
|
108
|
+
_context.next = 3;
|
|
109
|
+
return Promise.all([getAuth,
|
|
110
|
+
// 获取用户权限
|
|
111
|
+
menuBuild // 获取权限中心配置的菜单及按钮
|
|
112
|
+
].map(function (v) {
|
|
113
|
+
if (v) {
|
|
114
|
+
return v();
|
|
115
|
+
} else {
|
|
116
|
+
return Promise.resolve();
|
|
117
|
+
}
|
|
118
|
+
}));
|
|
119
|
+
case 3:
|
|
120
|
+
_yield$Promise$all = _context.sent;
|
|
121
|
+
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
|
|
122
|
+
_yield$Promise$all2$ = _yield$Promise$all2[0];
|
|
123
|
+
authInfo = _yield$Promise$all2$ === void 0 ? {} : _yield$Promise$all2$;
|
|
124
|
+
_yield$Promise$all2$2 = _yield$Promise$all2[1];
|
|
125
|
+
menuData = _yield$Promise$all2$2 === void 0 ? [] : _yield$Promise$all2$2;
|
|
126
|
+
_ref2 = authInfo || {}, _ref2$user = _ref2.user, user = _ref2$user === void 0 ? {} : _ref2$user, _ref2$roles = _ref2.roles, roles = _ref2$roles === void 0 ? [] : _ref2$roles;
|
|
127
|
+
isAdmin = roles.includes('admin');
|
|
128
|
+
this.formatLocalMenu(routes, menuNameMap);
|
|
129
|
+
this.formatAuthMenu(menuData);
|
|
130
|
+
accessPage = [];
|
|
131
|
+
Object.keys(this.pathMap).forEach(function (path) {
|
|
132
|
+
var currObj = _this3.pathMap[path];
|
|
133
|
+
if (currObj.access) {
|
|
134
|
+
if (isAdmin) {
|
|
135
|
+
accessPage.push(currObj.access);
|
|
136
|
+
} else {
|
|
137
|
+
currObj.hasAccess && accessPage.push(currObj.access);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
this.profile = {
|
|
142
|
+
name: user.userName || 'system',
|
|
143
|
+
email: user.email || 'system',
|
|
144
|
+
nickName: user.nickName || 'system',
|
|
145
|
+
roles: roles,
|
|
146
|
+
isAdmin: isAdmin,
|
|
147
|
+
accessPage: accessPage
|
|
148
|
+
};
|
|
149
|
+
return _context.abrupt("return", this.profile);
|
|
150
|
+
case 17:
|
|
151
|
+
case "end":
|
|
152
|
+
return _context.stop();
|
|
153
|
+
}
|
|
154
|
+
}, _callee, this);
|
|
155
|
+
}));
|
|
156
|
+
function init(_x) {
|
|
157
|
+
return _init.apply(this, arguments);
|
|
158
|
+
}
|
|
159
|
+
return init;
|
|
160
|
+
}()
|
|
161
|
+
}]);
|
|
162
|
+
return CurrentUser;
|
|
163
|
+
}();
|
|
164
|
+
// 当前用户信息
|
|
165
|
+
_defineProperty(CurrentUser, "profile", null);
|
|
166
|
+
// 路径信息映射
|
|
167
|
+
_defineProperty(CurrentUser, "pathMap", {});
|
|
168
|
+
export { CurrentUser as default };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { CustomizeProfile, ErrorProfile, SystemProfile, TrackConfig, TrackType, UserProfile } from '../interfaces/track.interface';
|
|
2
|
+
declare class Track {
|
|
3
|
+
static config: TrackConfig;
|
|
4
|
+
static userProfile: UserProfile;
|
|
5
|
+
static trackQueue: any[];
|
|
6
|
+
static checkConfig(config?: TrackConfig): void;
|
|
7
|
+
static send(): Promise<void>;
|
|
8
|
+
static mountAutoTask(): void;
|
|
9
|
+
static getSystemProfile(): SystemProfile;
|
|
10
|
+
static getUserProfile(): UserProfile;
|
|
11
|
+
static setUserProfile(userProfile: UserProfile): void;
|
|
12
|
+
static init({ userProfile, ...restConfig }: TrackConfig): void;
|
|
13
|
+
static pushQueue({ type, log, }: {
|
|
14
|
+
type: TrackType;
|
|
15
|
+
log: ErrorProfile | CustomizeProfile;
|
|
16
|
+
}): void;
|
|
17
|
+
static getFormatBasePath(): string;
|
|
18
|
+
static getPageModuleName(): string[];
|
|
19
|
+
static errorLog(errorLog: ErrorProfile): void;
|
|
20
|
+
static eventLog(eventLog: CustomizeProfile | string): void;
|
|
21
|
+
static visitLog(visitLog?: CustomizeProfile): void;
|
|
22
|
+
static apiLog(apiLog: any): void;
|
|
23
|
+
}
|
|
24
|
+
export default Track;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
var _excluded = ["userProfile"];
|
|
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 _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); }
|
|
6
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
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; }
|
|
9
|
+
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
|
+
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; }
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
14
|
+
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); } }
|
|
15
|
+
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); }); }; }
|
|
16
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
17
|
+
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); } }
|
|
18
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
19
|
+
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; }
|
|
20
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
21
|
+
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); }
|
|
22
|
+
import Cookies from 'js-cookie';
|
|
23
|
+
import pako from 'pako';
|
|
24
|
+
import CurrentUser from "../CurrentUser";
|
|
25
|
+
import { generateRandomString } from "../Utils";
|
|
26
|
+
var Track = /*#__PURE__*/function () {
|
|
27
|
+
function Track() {
|
|
28
|
+
_classCallCheck(this, Track);
|
|
29
|
+
}
|
|
30
|
+
_createClass(Track, null, [{
|
|
31
|
+
key: "checkConfig",
|
|
32
|
+
value:
|
|
33
|
+
// 检查必填配置项
|
|
34
|
+
function checkConfig(config) {
|
|
35
|
+
if (!config) {
|
|
36
|
+
throw new Error('请配置Track');
|
|
37
|
+
}
|
|
38
|
+
if (!config.appId) {
|
|
39
|
+
throw new Error('请设置appId');
|
|
40
|
+
}
|
|
41
|
+
if (CurrentUser.profile === null) {
|
|
42
|
+
throw new Error('请先调用CurrentUser对象设置系统信息');
|
|
43
|
+
}
|
|
44
|
+
this.config = config;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// 发送埋点数据
|
|
48
|
+
}, {
|
|
49
|
+
key: "send",
|
|
50
|
+
value: function () {
|
|
51
|
+
var _send = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
52
|
+
var data, compressed;
|
|
53
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
54
|
+
while (1) switch (_context.prev = _context.next) {
|
|
55
|
+
case 0:
|
|
56
|
+
data = this.trackQueue.splice(0, this.trackQueue.length);
|
|
57
|
+
compressed = pako.deflate(JSON.stringify(data));
|
|
58
|
+
if (data.length) {
|
|
59
|
+
navigator.sendBeacon(this.config.serverUrl, compressed);
|
|
60
|
+
}
|
|
61
|
+
case 3:
|
|
62
|
+
case "end":
|
|
63
|
+
return _context.stop();
|
|
64
|
+
}
|
|
65
|
+
}, _callee, this);
|
|
66
|
+
}));
|
|
67
|
+
function send() {
|
|
68
|
+
return _send.apply(this, arguments);
|
|
69
|
+
}
|
|
70
|
+
return send;
|
|
71
|
+
}() // 挂载自动化任务
|
|
72
|
+
}, {
|
|
73
|
+
key: "mountAutoTask",
|
|
74
|
+
value: function mountAutoTask() {
|
|
75
|
+
var _this = this;
|
|
76
|
+
var autoReportError = this.config.autoReportError;
|
|
77
|
+
if (autoReportError) {
|
|
78
|
+
// TODO 短时间内推送超过10个错误,关闭监听
|
|
79
|
+
addEventListener('error', function (event) {
|
|
80
|
+
var message = event.message,
|
|
81
|
+
filename = event.filename;
|
|
82
|
+
var errorInfo = {
|
|
83
|
+
message: message,
|
|
84
|
+
fileName: filename
|
|
85
|
+
};
|
|
86
|
+
_this.errorLog(errorInfo);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// 监听点击事件
|
|
90
|
+
// addEventListener(
|
|
91
|
+
// 'click',
|
|
92
|
+
// (event) => {
|
|
93
|
+
// const { target } = event;
|
|
94
|
+
// console.log(target.parentElement);
|
|
95
|
+
// },
|
|
96
|
+
// true
|
|
97
|
+
// );
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
//关闭页面时,发送剩余的埋点数据
|
|
101
|
+
addEventListener('visibilitychange', function () {
|
|
102
|
+
if (document.visibilityState === 'hidden') {
|
|
103
|
+
_this.send();
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
// 获取系统信息
|
|
109
|
+
}, {
|
|
110
|
+
key: "getSystemProfile",
|
|
111
|
+
value: function getSystemProfile() {
|
|
112
|
+
var IMEI = Cookies.get('__IMEI__');
|
|
113
|
+
if (!IMEI) {
|
|
114
|
+
Cookies.set('__IMEI__', generateRandomString(16), {
|
|
115
|
+
expires: 90
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
return {
|
|
119
|
+
innerHeight: innerHeight,
|
|
120
|
+
innerWidth: innerWidth,
|
|
121
|
+
href: location.href,
|
|
122
|
+
systemTime: new Date(),
|
|
123
|
+
IMEI: Cookies.get('__IMEI__')
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// 获取当前用户信息,返回格式化后的用户信息
|
|
128
|
+
}, {
|
|
129
|
+
key: "getUserProfile",
|
|
130
|
+
value: function getUserProfile() {
|
|
131
|
+
var userProfile = this.userProfile;
|
|
132
|
+
if (!(userProfile !== null && userProfile !== void 0 && userProfile.userId)) {
|
|
133
|
+
userProfile.userId = '';
|
|
134
|
+
}
|
|
135
|
+
if (!(userProfile !== null && userProfile !== void 0 && userProfile.userName)) {
|
|
136
|
+
userProfile.userName = '';
|
|
137
|
+
}
|
|
138
|
+
return userProfile;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 设置当前用户信息
|
|
142
|
+
}, {
|
|
143
|
+
key: "setUserProfile",
|
|
144
|
+
value: function setUserProfile(userProfile) {
|
|
145
|
+
this.userProfile = userProfile;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// 挂载初始配置
|
|
149
|
+
}, {
|
|
150
|
+
key: "init",
|
|
151
|
+
value: function init(_ref) {
|
|
152
|
+
var userProfile = _ref.userProfile,
|
|
153
|
+
restConfig = _objectWithoutProperties(_ref, _excluded);
|
|
154
|
+
this.checkConfig(restConfig);
|
|
155
|
+
this.config = restConfig;
|
|
156
|
+
if (userProfile) {
|
|
157
|
+
this.setUserProfile(userProfile);
|
|
158
|
+
} else {
|
|
159
|
+
var _CurrentUser$profile, _CurrentUser$profile2;
|
|
160
|
+
this.setUserProfile({
|
|
161
|
+
userId: (_CurrentUser$profile = CurrentUser.profile) === null || _CurrentUser$profile === void 0 ? void 0 : _CurrentUser$profile.email,
|
|
162
|
+
userName: (_CurrentUser$profile2 = CurrentUser.profile) === null || _CurrentUser$profile2 === void 0 ? void 0 : _CurrentUser$profile2.name
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
this.mountAutoTask();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 推送埋点信息进入队列
|
|
169
|
+
}, {
|
|
170
|
+
key: "pushQueue",
|
|
171
|
+
value: function pushQueue(_ref2) {
|
|
172
|
+
var type = _ref2.type,
|
|
173
|
+
log = _ref2.log;
|
|
174
|
+
var config = this.config;
|
|
175
|
+
this.checkConfig(config);
|
|
176
|
+
var reqData = _objectSpread(_objectSpread(_objectSpread({}, this.getSystemProfile()), this.getUserProfile()), {}, {
|
|
177
|
+
type: type,
|
|
178
|
+
appId: config.appId,
|
|
179
|
+
log: JSON.stringify(log)
|
|
180
|
+
});
|
|
181
|
+
this.trackQueue.push(reqData);
|
|
182
|
+
if (this.trackQueue.length > 4) {
|
|
183
|
+
this.send();
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// 获取格式化base后的路径
|
|
188
|
+
}, {
|
|
189
|
+
key: "getFormatBasePath",
|
|
190
|
+
value: function getFormatBasePath() {
|
|
191
|
+
var _this$config$base = this.config.base,
|
|
192
|
+
base = _this$config$base === void 0 ? '/' : _this$config$base;
|
|
193
|
+
var _location = location,
|
|
194
|
+
pathname = _location.pathname;
|
|
195
|
+
return pathname.replace(base, '/');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 获取模块名称
|
|
199
|
+
}, {
|
|
200
|
+
key: "getPageModuleName",
|
|
201
|
+
value: function getPageModuleName() {
|
|
202
|
+
var routeNames = [];
|
|
203
|
+
var pathMap = CurrentUser.pathMap;
|
|
204
|
+
if (pathMap) {
|
|
205
|
+
routeNames = pathMap[this.getFormatBasePath()].module || [];
|
|
206
|
+
}
|
|
207
|
+
return routeNames;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// 推送错误日志
|
|
211
|
+
}, {
|
|
212
|
+
key: "errorLog",
|
|
213
|
+
value: function errorLog(_errorLog) {
|
|
214
|
+
this.pushQueue({
|
|
215
|
+
log: _errorLog,
|
|
216
|
+
type: 'error'
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// 推送用户触发日志
|
|
221
|
+
}, {
|
|
222
|
+
key: "eventLog",
|
|
223
|
+
value: function eventLog(_eventLog) {
|
|
224
|
+
if (typeof _eventLog === 'string') {
|
|
225
|
+
var _CurrentUser$pathMap$;
|
|
226
|
+
var routeNames = this.getPageModuleName();
|
|
227
|
+
_eventLog = {
|
|
228
|
+
module: routeNames.join('-'),
|
|
229
|
+
content: '触发: ' + ((_CurrentUser$pathMap$ = CurrentUser.pathMap[this.getFormatBasePath()]) === null || _CurrentUser$pathMap$ === void 0 || (_CurrentUser$pathMap$ = _CurrentUser$pathMap$.options) === null || _CurrentUser$pathMap$ === void 0 || (_CurrentUser$pathMap$ = _CurrentUser$pathMap$[_eventLog]) === null || _CurrentUser$pathMap$ === void 0 ? void 0 : _CurrentUser$pathMap$.logAction)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
this.pushQueue({
|
|
233
|
+
log: _eventLog,
|
|
234
|
+
type: 'event'
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// 推送页面访问日志
|
|
239
|
+
}, {
|
|
240
|
+
key: "visitLog",
|
|
241
|
+
value: function visitLog(_visitLog) {
|
|
242
|
+
if (_visitLog === undefined) {
|
|
243
|
+
_visitLog = {
|
|
244
|
+
module: '',
|
|
245
|
+
content: ''
|
|
246
|
+
};
|
|
247
|
+
var routeNames = this.getPageModuleName();
|
|
248
|
+
Object.assign(_visitLog, {
|
|
249
|
+
module: routeNames.join('-'),
|
|
250
|
+
content: "\u8BBF\u95EE\u9875\u9762: ".concat(_toConsumableArray(routeNames).pop())
|
|
251
|
+
});
|
|
252
|
+
}
|
|
253
|
+
this.pushQueue({
|
|
254
|
+
log: _visitLog,
|
|
255
|
+
type: 'visit'
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 推送接口访问日志
|
|
260
|
+
}, {
|
|
261
|
+
key: "apiLog",
|
|
262
|
+
value: function apiLog(_apiLog) {
|
|
263
|
+
this.pushQueue({
|
|
264
|
+
log: _apiLog,
|
|
265
|
+
type: 'api'
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}]);
|
|
269
|
+
return Track;
|
|
270
|
+
}();
|
|
271
|
+
_defineProperty(Track, "config", {});
|
|
272
|
+
_defineProperty(Track, "userProfile", {});
|
|
273
|
+
// 埋点队列
|
|
274
|
+
_defineProperty(Track, "trackQueue", []);
|
|
275
|
+
export default Track;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const promisify: (fn: (...params: any[]) => void, ...args: any[]) => Promise<unknown>;
|
|
2
|
+
/**
|
|
3
|
+
* 将数组内某个字段的值转换为对象组
|
|
4
|
+
* @param array
|
|
5
|
+
* @param key
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
export declare function arrayToObj(array: any[], key: string): any;
|
|
9
|
+
/**
|
|
10
|
+
* 检测当前浏览器内核版本是否大于等于指定的Chrome内核版本
|
|
11
|
+
* @param minVersion 指定的Chrome内核版本
|
|
12
|
+
* @returns 是否大于等于指定版本
|
|
13
|
+
*/
|
|
14
|
+
export declare function checkChromeVersion(minVersion: number): boolean;
|
|
15
|
+
/**
|
|
16
|
+
* 生成随机字符串
|
|
17
|
+
* @param length 字符串长度
|
|
18
|
+
* @returns 随机字符串
|
|
19
|
+
*/
|
|
20
|
+
export declare function generateRandomString(length: number): string;
|