@yysports/tools 0.1.7 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,13 @@
1
1
  var _excluded = ["userProfile", "menuNameMap", "routes", "getAuth", "menuBuild"];
2
2
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
6
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
7
3
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
8
4
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
9
5
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
6
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
11
11
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
12
12
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
13
13
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -167,11 +167,20 @@ var Track = /*#__PURE__*/function () {
167
167
  accessPage = []; // 获取本地菜单信息映射
168
168
  if (routes) {
169
169
  routesMap = getRoutesMap(routes, menuNameMap);
170
- routesMap.forEach(function (value, key) {
170
+ routesMap.forEach(function (value) {
171
171
  var access = value.access;
172
- if (access && (isAdmin || roles.includes(access))) {
173
- accessPage.push(access);
172
+ if (access.length === 0) {
173
+ return;
174
+ }
175
+ if (isAdmin) {
176
+ accessPage.push.apply(accessPage, _toConsumableArray(access));
177
+ return;
174
178
  }
179
+ access.forEach(function (key) {
180
+ if (roles.includes(key)) {
181
+ accessPage.push(key);
182
+ }
183
+ });
175
184
  });
176
185
  this.routesMap = routesMap;
177
186
  }
@@ -20,9 +20,20 @@ export var getRoutesMap = function getRoutesMap(routes, menuNameMap) {
20
20
  // 初始化路由信息
21
21
  var savedRoute = routesMap.get(path);
22
22
  if (!savedRoute) {
23
- routesMap.set(path, {});
23
+ routesMap.set(path, {
24
+ access: [],
25
+ name: [],
26
+ module: [],
27
+ isRedirect: false
28
+ });
24
29
  savedRoute = routesMap.get(path);
25
30
  }
31
+ if (redirect) {
32
+ Object.assign(savedRoute, {
33
+ isRedirect: true
34
+ });
35
+ return;
36
+ }
26
37
  var nameArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.name) || []);
27
38
  var moduleArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.module) || []);
28
39
  if (name) {
@@ -32,14 +43,15 @@ export var getRoutesMap = function getRoutesMap(routes, menuNameMap) {
32
43
  moduleArr.push(menuNameMap[menuKey]);
33
44
  }
34
45
  }
46
+ if (access) {
47
+ Object.assign(savedRoute, {
48
+ access: [].concat(_toConsumableArray(savedRoute.access || []), [access])
49
+ });
50
+ }
35
51
  var routeInfo = {
36
- access: access,
37
52
  name: nameArr,
38
53
  module: moduleArr
39
54
  };
40
- if (redirect) {
41
- routeInfo.isRedirect = true;
42
- }
43
55
  Object.assign(savedRoute, routeInfo);
44
56
  if (routes) {
45
57
  ergodicLocalMenu(routes, routeInfo);
@@ -80,10 +80,10 @@ export type RouteType = {
80
80
  [key: string]: any;
81
81
  };
82
82
  export type RouteMapValueType = {
83
- access?: string;
84
- name?: string[];
85
- module?: string[];
86
- isRedirect?: boolean;
83
+ access: string[];
84
+ name: string[];
85
+ module: string[];
86
+ isRedirect: boolean;
87
87
  };
88
88
  export type AuthDataType = {
89
89
  children: AuthDataType[];
@@ -133,11 +133,20 @@ var Track = class {
133
133
  const accessPage = [];
134
134
  if (routes) {
135
135
  const routesMap = (0, import_Utils.getRoutesMap)(routes, menuNameMap);
136
- routesMap.forEach((value, key) => {
136
+ routesMap.forEach((value) => {
137
137
  const { access } = value;
138
- if (access && (isAdmin || roles.includes(access))) {
139
- accessPage.push(access);
138
+ if (access.length === 0) {
139
+ return;
140
140
  }
141
+ if (isAdmin) {
142
+ accessPage.push(...access);
143
+ return;
144
+ }
145
+ access.forEach((key) => {
146
+ if (roles.includes(key)) {
147
+ accessPage.push(key);
148
+ }
149
+ });
141
150
  });
142
151
  this.routesMap = routesMap;
143
152
  }
@@ -32,9 +32,18 @@ var getRoutesMap = (routes, menuNameMap) => {
32
32
  }
33
33
  let savedRoute = routesMap.get(path);
34
34
  if (!savedRoute) {
35
- routesMap.set(path, {});
35
+ routesMap.set(path, {
36
+ access: [],
37
+ name: [],
38
+ module: [],
39
+ isRedirect: false
40
+ });
36
41
  savedRoute = routesMap.get(path);
37
42
  }
43
+ if (redirect) {
44
+ Object.assign(savedRoute, { isRedirect: true });
45
+ return;
46
+ }
38
47
  const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
39
48
  const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
40
49
  if (name) {
@@ -44,14 +53,15 @@ var getRoutesMap = (routes, menuNameMap) => {
44
53
  moduleArr.push(menuNameMap[menuKey]);
45
54
  }
46
55
  }
56
+ if (access) {
57
+ Object.assign(savedRoute, {
58
+ access: [...savedRoute.access || [], access]
59
+ });
60
+ }
47
61
  const routeInfo = {
48
- access,
49
62
  name: nameArr,
50
63
  module: moduleArr
51
64
  };
52
- if (redirect) {
53
- routeInfo.isRedirect = true;
54
- }
55
65
  Object.assign(savedRoute, routeInfo);
56
66
  if (routes2) {
57
67
  ergodicLocalMenu(routes2, routeInfo);
@@ -80,10 +80,10 @@ export type RouteType = {
80
80
  [key: string]: any;
81
81
  };
82
82
  export type RouteMapValueType = {
83
- access?: string;
84
- name?: string[];
85
- module?: string[];
86
- isRedirect?: boolean;
83
+ access: string[];
84
+ name: string[];
85
+ module: string[];
86
+ isRedirect: boolean;
87
87
  };
88
88
  export type AuthDataType = {
89
89
  children: AuthDataType[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {