@yysports/tools 0.0.10 → 0.1.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.
@@ -32,9 +32,7 @@ __export(Track_exports, {
32
32
  default: () => Track_default
33
33
  });
34
34
  module.exports = __toCommonJS(Track_exports);
35
- var import_js_cookie = __toESM(require("js-cookie"));
36
35
  var import_pako = __toESM(require("pako"));
37
- var import_CurrentUser = __toESM(require("../CurrentUser"));
38
36
  var import_Utils = require("../Utils");
39
37
  var Track = class {
40
38
  // 检查必填配置项
@@ -49,9 +47,11 @@ var Track = class {
49
47
  }
50
48
  // 发送埋点数据
51
49
  static async send() {
50
+ const { debug } = this.config;
52
51
  const data = this.trackQueue.splice(0, this.trackQueue.length);
53
52
  const compressed = import_pako.default.deflate(JSON.stringify(data));
54
53
  if (data.length) {
54
+ debug && console.log("[track:debug] push data", data);
55
55
  navigator.sendBeacon(
56
56
  `https://track.yysports.com/pousheng-guard/api/analysis/track`,
57
57
  compressed
@@ -79,18 +79,16 @@ var Track = class {
79
79
  }
80
80
  // 获取系统信息
81
81
  static getSystemProfile() {
82
- const IMEI = import_js_cookie.default.get("__IMEI__");
82
+ const IMEI = localStorage.getItem("__IMEI__");
83
83
  if (!IMEI) {
84
- import_js_cookie.default.set("__IMEI__", (0, import_Utils.generateRandomString)(16), {
85
- expires: 90
86
- });
84
+ localStorage.setItem("__IMEI__", (0, import_Utils.generateRandomString)(16));
87
85
  }
88
86
  return {
89
87
  innerHeight,
90
88
  innerWidth,
91
89
  href: location.href,
92
90
  systemTime: /* @__PURE__ */ new Date(),
93
- IMEI: import_js_cookie.default.get("__IMEI__")
91
+ IMEI: localStorage.getItem("__IMEI__")
94
92
  };
95
93
  }
96
94
  // 获取当前用户信息,返回格式化后的用户信息
@@ -108,6 +106,48 @@ var Track = class {
108
106
  static setUserProfile(userProfile) {
109
107
  this.userProfile = userProfile;
110
108
  }
109
+ // 初始化权限中心数据
110
+ static async initAuthCenterData({
111
+ getAuth,
112
+ menuBuild,
113
+ menuNameMap,
114
+ routes
115
+ }) {
116
+ const [authInfo = {}, menuData = []] = await Promise.all(
117
+ [
118
+ getAuth,
119
+ // 获取用户权限
120
+ menuBuild
121
+ // 获取权限中心配置的菜单及按钮
122
+ ].map((v) => {
123
+ if (v) {
124
+ return v();
125
+ } else {
126
+ return Promise.resolve();
127
+ }
128
+ })
129
+ );
130
+ const { user = {}, roles = [] } = authInfo || {};
131
+ const isAdmin = roles.includes("admin");
132
+ const accessPage = [];
133
+ if (routes) {
134
+ const routesMap = (0, import_Utils.getRoutesMap)(routes, menuNameMap);
135
+ routesMap.forEach((value, key) => {
136
+ const { access } = value;
137
+ if (access && (isAdmin || roles.includes(access))) {
138
+ accessPage.push(access);
139
+ }
140
+ });
141
+ this.routesMap = routesMap;
142
+ }
143
+ this.authMap = (0, import_Utils.getAuthMapByAuthCenter)(menuData);
144
+ this.authCenterUserProfile = {
145
+ ...user,
146
+ roles,
147
+ accessPage
148
+ };
149
+ return this.authCenterUserProfile;
150
+ }
111
151
  // 挂载初始配置
112
152
  static async init({
113
153
  userProfile,
@@ -117,28 +157,25 @@ var Track = class {
117
157
  menuBuild,
118
158
  ...restConfig
119
159
  }) {
120
- var _a;
121
160
  this.checkConfig(restConfig);
122
161
  this.config = restConfig;
123
- if (routes && menuNameMap) {
124
- await import_CurrentUser.default.init({
125
- getAuth,
126
- menuBuild,
127
- menuNameMap,
128
- routes
129
- });
130
- }
131
- if ((_a = import_CurrentUser.default.profile) == null ? void 0 : _a.email) {
162
+ await this.initAuthCenterData({
163
+ getAuth,
164
+ menuBuild,
165
+ menuNameMap,
166
+ routes
167
+ });
168
+ if (this.authCenterUserProfile.email) {
132
169
  this.setUserProfile({
133
- userId: import_CurrentUser.default.profile.userName,
134
- userName: import_CurrentUser.default.profile.nickName
170
+ userId: this.authCenterUserProfile.userName,
171
+ userName: this.authCenterUserProfile.nickName
135
172
  });
136
173
  }
137
174
  if (userProfile) {
138
175
  this.setUserProfile(userProfile);
139
176
  }
140
177
  this.mountAutoTask();
141
- return import_CurrentUser.default.profile;
178
+ return this.authCenterUserProfile;
142
179
  }
143
180
  // 推送埋点信息进入队列
144
181
  static pushQueue({
@@ -167,12 +204,8 @@ var Track = class {
167
204
  }
168
205
  // 获取模块名称
169
206
  static getPageModuleName() {
170
- let routeNames = [];
171
- const { pathMap } = import_CurrentUser.default;
172
- if (pathMap) {
173
- routeNames = pathMap[this.getFormatBasePath()] || [];
174
- }
175
- return routeNames;
207
+ const routeInfo = this.routesMap.get(this.getFormatBasePath());
208
+ return (routeInfo == null ? void 0 : routeInfo.module) || [];
176
209
  }
177
210
  // 推送错误日志
178
211
  static errorLog(errorLog) {
@@ -183,13 +216,12 @@ var Track = class {
183
216
  }
184
217
  // 推送用户触发日志
185
218
  static eventLog(eventLog) {
186
- var _a;
187
219
  const copyEventLog = {
188
220
  module: "",
189
221
  content: ""
190
222
  };
191
223
  if (typeof eventLog === "string") {
192
- const actionLog = (_a = import_CurrentUser.default.authMap) == null ? void 0 : _a[eventLog];
224
+ const actionLog = this.authMap.get(eventLog);
193
225
  if (actionLog) {
194
226
  copyEventLog.content = "触发: " + actionLog;
195
227
  } else {
@@ -230,8 +262,16 @@ var Track = class {
230
262
  });
231
263
  }
232
264
  };
265
+ // 配置信息
233
266
  Track.config = {};
267
+ // 需要传入到后端的用户信息
234
268
  Track.userProfile = {};
269
+ // 权限中心用户信息
270
+ Track.authCenterUserProfile = {};
271
+ // 路径信息映射
272
+ Track.routesMap = /* @__PURE__ */ new Map();
273
+ // 权限信息映射
274
+ Track.authMap = /* @__PURE__ */ new Map();
235
275
  // 埋点队列
236
276
  Track.trackQueue = [];
237
277
  var Track_default = Track;
@@ -0,0 +1,10 @@
1
+ export type AuthDataType = {
2
+ children: AuthDataType[];
3
+ name?: string;
4
+ logAction?: string;
5
+ permission?: string;
6
+ meta?: {
7
+ title: string;
8
+ };
9
+ };
10
+ export declare const getAuthMapByAuthCenter: (authData: AuthDataType[]) => Map<string, string>;
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/Utils/auth.ts
20
+ var auth_exports = {};
21
+ __export(auth_exports, {
22
+ getAuthMapByAuthCenter: () => getAuthMapByAuthCenter
23
+ });
24
+ module.exports = __toCommonJS(auth_exports);
25
+ var getAuthMapByAuthCenter = (authData) => {
26
+ const authMap = /* @__PURE__ */ new Map();
27
+ const ergodicAuthMenu = (authCenterData) => {
28
+ authCenterData.forEach((menu) => {
29
+ const { permission, name, logAction, children, meta } = menu;
30
+ if (permission) {
31
+ const authLog = logAction || (meta == null ? void 0 : meta.title) || name || "权限校验";
32
+ authMap.set(permission, authLog);
33
+ }
34
+ if (Array.isArray(children) && children.length > 0) {
35
+ ergodicAuthMenu(children);
36
+ }
37
+ });
38
+ };
39
+ ergodicAuthMenu(authData);
40
+ return authMap;
41
+ };
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ getAuthMapByAuthCenter
45
+ });
@@ -2,3 +2,5 @@ export * from './common';
2
2
  export * from './file';
3
3
  export * from './url';
4
4
  export * from './wx';
5
+ export * from './route';
6
+ export * from './auth';
@@ -20,10 +20,14 @@ __reExport(Utils_exports, require("./common"), module.exports);
20
20
  __reExport(Utils_exports, require("./file"), module.exports);
21
21
  __reExport(Utils_exports, require("./url"), module.exports);
22
22
  __reExport(Utils_exports, require("./wx"), module.exports);
23
+ __reExport(Utils_exports, require("./route"), module.exports);
24
+ __reExport(Utils_exports, require("./auth"), module.exports);
23
25
  // Annotate the CommonJS export names for ESM import in node:
24
26
  0 && (module.exports = {
25
27
  ...require("./common"),
26
28
  ...require("./file"),
27
29
  ...require("./url"),
28
- ...require("./wx")
30
+ ...require("./wx"),
31
+ ...require("./route"),
32
+ ...require("./auth")
29
33
  });
@@ -0,0 +1,15 @@
1
+ export type RouteType = {
2
+ path: string;
3
+ redirect?: string;
4
+ name?: string;
5
+ access?: string;
6
+ routes?: RouteType[];
7
+ };
8
+ export type RouteMapValueType = {
9
+ access?: string;
10
+ name?: string[];
11
+ module?: string[];
12
+ };
13
+ export declare const getRoutesMap: (routes: RouteType[], menuNameMap?: {
14
+ [key: string]: string;
15
+ } | undefined) => Map<string, RouteMapValueType>;
@@ -0,0 +1,61 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/Utils/route.ts
20
+ var route_exports = {};
21
+ __export(route_exports, {
22
+ getRoutesMap: () => getRoutesMap
23
+ });
24
+ module.exports = __toCommonJS(route_exports);
25
+ var getRoutesMap = (routes, menuNameMap) => {
26
+ const routesMap = /* @__PURE__ */ new Map();
27
+ const ergodicLocalMenu = (rs, parentMenu) => {
28
+ rs.forEach((route) => {
29
+ const { path, access, name, routes: routes2, redirect } = route;
30
+ if (redirect || !name) {
31
+ return;
32
+ }
33
+ const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
34
+ const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
35
+ if (name) {
36
+ nameArr.push(name);
37
+ if (menuNameMap) {
38
+ const menuKey = ["menu", ...nameArr].join(".");
39
+ moduleArr.push(menuNameMap[menuKey]);
40
+ }
41
+ }
42
+ const routeInfo = {
43
+ access,
44
+ name: nameArr,
45
+ module: moduleArr
46
+ };
47
+ if (path) {
48
+ routesMap.set(path, routeInfo);
49
+ }
50
+ if (routes2) {
51
+ ergodicLocalMenu(routes2, routeInfo);
52
+ }
53
+ });
54
+ };
55
+ ergodicLocalMenu(routes);
56
+ return routesMap;
57
+ };
58
+ // Annotate the CommonJS export names for ESM import in node:
59
+ 0 && (module.exports = {
60
+ getRoutesMap
61
+ });
package/lib/index.d.ts CHANGED
@@ -1,5 +1,3 @@
1
- export { default as CurrentUser } from './CurrentUser';
2
1
  export { default as Track } from './Track';
3
2
  export * as Utils from './Utils';
4
- export * from './interfaces/currentUser.interface';
5
3
  export * from './interfaces/track.interface';
package/lib/index.js CHANGED
@@ -30,21 +30,16 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- CurrentUser: () => import_CurrentUser.default,
34
33
  Track: () => import_Track.default,
35
34
  Utils: () => Utils
36
35
  });
37
36
  module.exports = __toCommonJS(src_exports);
38
- var import_CurrentUser = __toESM(require("./CurrentUser"));
39
37
  var import_Track = __toESM(require("./Track"));
40
38
  var Utils = __toESM(require("./Utils"));
41
- __reExport(src_exports, require("./interfaces/currentUser.interface"), module.exports);
42
39
  __reExport(src_exports, require("./interfaces/track.interface"), module.exports);
43
40
  // Annotate the CommonJS export names for ESM import in node:
44
41
  0 && (module.exports = {
45
- CurrentUser,
46
42
  Track,
47
43
  Utils,
48
- ...require("./interfaces/currentUser.interface"),
49
44
  ...require("./interfaces/track.interface")
50
45
  });
@@ -1,10 +1,35 @@
1
- import { CurrentUserConfig } from './currentUser.interface';
2
- export interface TrackConfig extends Partial<CurrentUserConfig> {
1
+ import { RouteType } from '../Utils';
2
+ export type LocalRouteItemType = {
3
+ access?: string;
4
+ name?: string;
5
+ parentPath?: string;
6
+ path?: string;
7
+ routes?: LocalRouteItemType[];
8
+ };
9
+ export type AuthMenuItemType = {
10
+ logAction: any;
11
+ name: string;
12
+ meta?: {
13
+ title: string;
14
+ };
15
+ permission?: string;
16
+ children?: AuthMenuItemType[];
17
+ path?: string;
18
+ builtIn?: boolean;
19
+ };
20
+ export type MenuNameMapType = {
21
+ [key: string]: string;
22
+ };
23
+ export interface TrackConfig {
3
24
  appId: string;
4
25
  debug?: boolean;
5
26
  autoReportError?: boolean;
6
27
  userProfile?: UserProfile;
7
28
  base?: string;
29
+ getAuth?: () => Promise<any>;
30
+ menuBuild?: () => Promise<AuthMenuItemType[]>;
31
+ menuNameMap?: MenuNameMapType;
32
+ routes?: RouteType[];
8
33
  }
9
34
  export declare enum TrackTypeEnum {
10
35
  error = "\u9519\u8BEF\u4FE1\u606F",
@@ -17,6 +42,20 @@ export interface UserProfile {
17
42
  userId: string;
18
43
  userName: string;
19
44
  }
45
+ export interface AuthCenterUserProfile {
46
+ userName: string;
47
+ department?: string;
48
+ email?: string;
49
+ enabled?: boolean;
50
+ gender?: string;
51
+ isAdmin?: boolean;
52
+ jobs?: string[];
53
+ nickName?: string;
54
+ phone?: string;
55
+ status?: number;
56
+ roles?: string[];
57
+ accessPage?: string[];
58
+ }
20
59
  export interface SystemProfile {
21
60
  IMEI: string;
22
61
  innerHeight: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "0.0.10",
3
+ "version": "0.1.1",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {
@@ -61,32 +61,29 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "image-conversion": "^2.1.1",
64
- "js-cookie": "^3.0.5",
65
64
  "pako": "^2.1.0"
66
65
  },
67
66
  "devDependencies": {
68
- "@ant-design/pro-components": "^2.7.10",
67
+ "@ant-design/pro-components": "^2.7.13",
69
68
  "@commitlint/cli": "^19.3.0",
70
69
  "@commitlint/config-conventional": "^19.2.2",
71
- "@types/js-cookie": "^3.0.6",
72
70
  "@types/pako": "^2.0.3",
73
71
  "@types/react": "^18.3.3",
74
72
  "@types/react-dom": "^18.3.0",
75
- "@umijs/lint": "^4.3.1",
76
- "antd": "^5.19.0",
77
- "dumi": "^2.4.5",
78
- "eslint": "^9.6.0",
79
- "father": "^4.4.4",
73
+ "@umijs/lint": "^4.3.6",
74
+ "antd": "^5.19.2",
75
+ "dumi": "^2.4.6",
76
+ "eslint": "^9.7.0",
77
+ "father": "^4.4.5",
80
78
  "husky": "^9.0.11",
81
79
  "lint-staged": "^15.2.7",
82
- "prettier": "^3.3.2",
80
+ "prettier": "^3.3.3",
83
81
  "prettier-plugin-organize-imports": "^3.2.4",
84
- "prettier-plugin-packagejson": "^2.5.0",
82
+ "prettier-plugin-packagejson": "^2.5.1",
85
83
  "react": "^18.3.1",
86
84
  "react-dom": "^18.3.1",
87
- "stylelint": "^16.6.1"
85
+ "stylelint": "^16.7.0"
88
86
  },
89
- "peerDependencies": {},
90
87
  "publishConfig": {
91
88
  "access": "public"
92
89
  },
@@ -1,13 +0,0 @@
1
- import { AuthMenuItemType, CurrentUserConfig, CurrentUserInfo, LocalRouteItemType, MenuNameMapType } from '../interfaces/currentUser.interface';
2
- export default class CurrentUser {
3
- static profile: CurrentUserInfo | null;
4
- static pathMap: {
5
- [routeStr: string]: string[];
6
- };
7
- static authMap: {
8
- [authStr: string]: string;
9
- };
10
- static formatAuthMenu(authMenuData: AuthMenuItemType[]): void;
11
- static formatLocalMenu(routes: LocalRouteItemType[], menuNameMap: MenuNameMapType, roles: string[]): string[];
12
- static init({ getAuth, menuBuild, menuNameMap, routes, }: CurrentUserConfig): Promise<CurrentUserInfo>;
13
- }
@@ -1,143 +0,0 @@
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 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; }
4
- 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; }
5
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
6
- 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."); }
7
- 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; } }
8
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
9
- 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); } }
10
- 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); }); }; }
11
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
- 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."); }
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); }
14
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
16
- 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; }
17
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
- 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); } }
19
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
20
- 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; }
21
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
- 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); }
23
- var CurrentUser = /*#__PURE__*/function () {
24
- function CurrentUser() {
25
- _classCallCheck(this, CurrentUser);
26
- }
27
- _createClass(CurrentUser, null, [{
28
- key: "formatAuthMenu",
29
- value:
30
- // 格式化权限按钮操作日志
31
- function formatAuthMenu(authMenuData) {
32
- var _this = this;
33
- var ergodicAuthMenu = function ergodicAuthMenu(amd) {
34
- amd.forEach(function (menu) {
35
- var permission = menu.permission,
36
- name = menu.name,
37
- logAction = menu.logAction,
38
- children = menu.children;
39
- if (permission && logAction) {
40
- _this.authMap[permission] = logAction || name;
41
- }
42
- if (Array.isArray(children) && children.length > 0) {
43
- ergodicAuthMenu(children);
44
- }
45
- });
46
- };
47
- ergodicAuthMenu(authMenuData);
48
- }
49
-
50
- // 格式化本地菜单权限数据
51
- }, {
52
- key: "formatLocalMenu",
53
- value: function formatLocalMenu(routes, menuNameMap, roles) {
54
- var _this2 = this;
55
- var isAdmin = roles.includes('admin');
56
- var accessPage = [];
57
- var ergodicLocalMenu = function ergodicLocalMenu(rs, parentMenu) {
58
- rs.forEach(function (route) {
59
- var path = route.path,
60
- access = route.access,
61
- name = route.name,
62
- routes = route.routes;
63
- var nameArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.name) || []);
64
- var moduleArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.module) || []);
65
- if (access && (isAdmin || roles.includes(access))) {
66
- accessPage.push(access);
67
- }
68
- if (name) {
69
- nameArr.push(name);
70
- var menuKey = ['menu'].concat(_toConsumableArray(nameArr)).join('.');
71
- moduleArr.push(menuNameMap[menuKey]);
72
- }
73
- if (path) {
74
- _this2.pathMap[path] = _toConsumableArray(moduleArr);
75
- }
76
- if (routes) {
77
- ergodicLocalMenu(routes, {
78
- path: path,
79
- name: nameArr,
80
- module: moduleArr
81
- });
82
- }
83
- });
84
- };
85
- ergodicLocalMenu(routes);
86
- return accessPage;
87
- }
88
- }, {
89
- key: "init",
90
- value: function () {
91
- var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
92
- 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, accessPage;
93
- return _regeneratorRuntime().wrap(function _callee$(_context) {
94
- while (1) switch (_context.prev = _context.next) {
95
- case 0:
96
- getAuth = _ref.getAuth, menuBuild = _ref.menuBuild, menuNameMap = _ref.menuNameMap, routes = _ref.routes;
97
- _context.next = 3;
98
- return Promise.all([getAuth,
99
- // 获取用户权限
100
- menuBuild // 获取权限中心配置的菜单及按钮
101
- ].map(function (v) {
102
- if (v) {
103
- return v();
104
- } else {
105
- return Promise.resolve();
106
- }
107
- }));
108
- case 3:
109
- _yield$Promise$all = _context.sent;
110
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
111
- _yield$Promise$all2$ = _yield$Promise$all2[0];
112
- authInfo = _yield$Promise$all2$ === void 0 ? {} : _yield$Promise$all2$;
113
- _yield$Promise$all2$2 = _yield$Promise$all2[1];
114
- menuData = _yield$Promise$all2$2 === void 0 ? [] : _yield$Promise$all2$2;
115
- _ref2 = authInfo || {}, _ref2$user = _ref2.user, user = _ref2$user === void 0 ? {} : _ref2$user, _ref2$roles = _ref2.roles, roles = _ref2$roles === void 0 ? [] : _ref2$roles; // 获取本地菜单配置模块名称映射,同时返沪当前用户有权限的页面
116
- accessPage = this.formatLocalMenu(routes, menuNameMap, roles); // 获取权限中心菜单按钮logAction
117
- this.formatAuthMenu(menuData);
118
- this.profile = _objectSpread(_objectSpread({}, user), {}, {
119
- roles: roles,
120
- accessPage: accessPage
121
- });
122
- return _context.abrupt("return", this.profile);
123
- case 14:
124
- case "end":
125
- return _context.stop();
126
- }
127
- }, _callee, this);
128
- }));
129
- function init(_x) {
130
- return _init.apply(this, arguments);
131
- }
132
- return init;
133
- }()
134
- }]);
135
- return CurrentUser;
136
- }();
137
- // 当前用户信息
138
- _defineProperty(CurrentUser, "profile", null);
139
- // 路径信息映射
140
- _defineProperty(CurrentUser, "pathMap", {});
141
- // 权限信息映射
142
- _defineProperty(CurrentUser, "authMap", {});
143
- export { CurrentUser as default };