@yysports/tools 0.0.9 → 0.1.0

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.
@@ -0,0 +1,44 @@
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 } = menu;
30
+ if (permission && logAction) {
31
+ authMap.set(permission, logAction || name || "权限校验");
32
+ }
33
+ if (Array.isArray(children) && children.length > 0) {
34
+ ergodicAuthMenu(children);
35
+ }
36
+ });
37
+ };
38
+ ergodicAuthMenu(authData);
39
+ return authMap;
40
+ };
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ getAuthMapByAuthCenter
44
+ });
@@ -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.9",
3
+ "version": "0.1.0",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {
@@ -65,28 +65,27 @@
65
65
  "pako": "^2.1.0"
66
66
  },
67
67
  "devDependencies": {
68
- "@ant-design/pro-components": "^2.7.10",
68
+ "@ant-design/pro-components": "^2.7.13",
69
69
  "@commitlint/cli": "^19.3.0",
70
70
  "@commitlint/config-conventional": "^19.2.2",
71
71
  "@types/js-cookie": "^3.0.6",
72
72
  "@types/pako": "^2.0.3",
73
73
  "@types/react": "^18.3.3",
74
74
  "@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",
75
+ "@umijs/lint": "^4.3.6",
76
+ "antd": "^5.19.2",
77
+ "dumi": "^2.4.6",
78
+ "eslint": "^9.7.0",
79
+ "father": "^4.4.5",
80
80
  "husky": "^9.0.11",
81
81
  "lint-staged": "^15.2.7",
82
- "prettier": "^3.3.2",
82
+ "prettier": "^3.3.3",
83
83
  "prettier-plugin-organize-imports": "^3.2.4",
84
- "prettier-plugin-packagejson": "^2.5.0",
84
+ "prettier-plugin-packagejson": "^2.5.1",
85
85
  "react": "^18.3.1",
86
86
  "react-dom": "^18.3.1",
87
- "stylelint": "^16.6.1"
87
+ "stylelint": "^16.7.0"
88
88
  },
89
- "peerDependencies": {},
90
89
  "publishConfig": {
91
90
  "access": "public"
92
91
  },
@@ -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 };
@@ -1,41 +0,0 @@
1
- export type LocalRouteItemType = {
2
- access?: string;
3
- name?: string;
4
- parentPath?: string;
5
- path?: string;
6
- routes?: LocalRouteItemType[];
7
- };
8
- export type AuthMenuItemType = {
9
- logAction: any;
10
- name: string;
11
- meta?: {
12
- title: string;
13
- };
14
- permission?: string;
15
- children?: AuthMenuItemType[];
16
- path?: string;
17
- builtIn?: boolean;
18
- };
19
- export type MenuNameMapType = {
20
- [key: string]: string;
21
- };
22
- export interface CurrentUserConfig {
23
- getAuth?: () => Promise<any>;
24
- menuBuild?: () => Promise<AuthMenuItemType[]>;
25
- menuNameMap: MenuNameMapType;
26
- routes: LocalRouteItemType[];
27
- }
28
- export interface CurrentUserInfo {
29
- userName: string;
30
- department: string;
31
- email: string;
32
- enabled: boolean;
33
- gender: string;
34
- isAdmin: boolean;
35
- jobs: string[];
36
- nickName: string;
37
- phone: string;
38
- status: number;
39
- roles: string[];
40
- accessPage: string[];
41
- }
@@ -1 +0,0 @@
1
- export {};
@@ -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,109 +0,0 @@
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/CurrentUser/index.tsx
20
- var CurrentUser_exports = {};
21
- __export(CurrentUser_exports, {
22
- default: () => CurrentUser
23
- });
24
- module.exports = __toCommonJS(CurrentUser_exports);
25
- var CurrentUser = class {
26
- // 格式化权限按钮操作日志
27
- static formatAuthMenu(authMenuData) {
28
- const ergodicAuthMenu = (amd) => {
29
- amd.forEach((menu) => {
30
- const { permission, name, logAction, children } = menu;
31
- if (permission && logAction) {
32
- this.authMap[permission] = logAction || name;
33
- }
34
- if (Array.isArray(children) && children.length > 0) {
35
- ergodicAuthMenu(children);
36
- }
37
- });
38
- };
39
- ergodicAuthMenu(authMenuData);
40
- }
41
- // 格式化本地菜单权限数据
42
- static formatLocalMenu(routes, menuNameMap, roles) {
43
- const isAdmin = roles.includes("admin");
44
- const accessPage = [];
45
- const ergodicLocalMenu = (rs, parentMenu) => {
46
- rs.forEach((route) => {
47
- const { path, access, name, routes: routes2 } = route;
48
- const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
49
- const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
50
- if (access && (isAdmin || roles.includes(access))) {
51
- accessPage.push(access);
52
- }
53
- if (name) {
54
- nameArr.push(name);
55
- const menuKey = ["menu", ...nameArr].join(".");
56
- moduleArr.push(menuNameMap[menuKey]);
57
- }
58
- if (path) {
59
- this.pathMap[path] = [...moduleArr];
60
- }
61
- if (routes2) {
62
- ergodicLocalMenu(routes2, {
63
- path,
64
- name: nameArr,
65
- module: moduleArr
66
- });
67
- }
68
- });
69
- };
70
- ergodicLocalMenu(routes);
71
- return accessPage;
72
- }
73
- static async init({
74
- getAuth,
75
- menuBuild,
76
- menuNameMap,
77
- routes
78
- }) {
79
- const [authInfo = {}, menuData = []] = await Promise.all(
80
- [
81
- getAuth,
82
- // 获取用户权限
83
- menuBuild
84
- // 获取权限中心配置的菜单及按钮
85
- ].map((v) => {
86
- if (v) {
87
- return v();
88
- } else {
89
- return Promise.resolve();
90
- }
91
- })
92
- );
93
- const { user = {}, roles = [] } = authInfo || {};
94
- const accessPage = this.formatLocalMenu(routes, menuNameMap, roles);
95
- this.formatAuthMenu(menuData);
96
- this.profile = {
97
- ...user,
98
- roles,
99
- accessPage
100
- };
101
- return this.profile;
102
- }
103
- };
104
- // 当前用户信息
105
- CurrentUser.profile = null;
106
- // 路径信息映射
107
- CurrentUser.pathMap = {};
108
- // 权限信息映射
109
- CurrentUser.authMap = {};