@yysports/tools 0.1.7 → 0.1.9

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
  }
@@ -1,5 +1,5 @@
1
1
  import type { compressAccuratelyConfig } from 'image-conversion';
2
- export declare const downloadFile: (href: string, fileName?: string) => void;
2
+ export declare const downloadFile: (href: string, fileName?: string, target?: '_blank' | '_self' | '_parent' | '_top') => void;
3
3
  export declare const compressImg: (file: Blob, config?: number | compressAccuratelyConfig | undefined) => Promise<Blob>;
4
4
  /**
5
5
  * 检查文件类型
@@ -1,7 +1,8 @@
1
1
  import { compressAccurately } from 'image-conversion';
2
2
  export var downloadFile = function downloadFile(href, fileName) {
3
+ var target = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '_blank';
3
4
  var aEle = document.createElement('a');
4
- aEle.target = '_blank';
5
+ aEle.target = target;
5
6
  aEle.href = href;
6
7
  aEle.download = fileName || '';
7
8
  aEle.click();
@@ -15,7 +16,7 @@ export var compressImg = function compressImg(file, config) {
15
16
  * 检查文件类型
16
17
  * @param file File 文件对象
17
18
  * @param accept string 文件类型,使用“,”分割,如:image/png,image/jpeg
18
- * @returns
19
+ * @returns
19
20
  */
20
21
  export var checkFileType = function checkFileType(file, accept) {
21
22
  if (accept) {
@@ -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
  }
@@ -1,5 +1,5 @@
1
1
  import type { compressAccuratelyConfig } from 'image-conversion';
2
- export declare const downloadFile: (href: string, fileName?: string) => void;
2
+ export declare const downloadFile: (href: string, fileName?: string, target?: '_blank' | '_self' | '_parent' | '_top') => void;
3
3
  export declare const compressImg: (file: Blob, config?: number | compressAccuratelyConfig | undefined) => Promise<Blob>;
4
4
  /**
5
5
  * 检查文件类型
package/lib/Utils/file.js CHANGED
@@ -25,9 +25,9 @@ __export(file_exports, {
25
25
  });
26
26
  module.exports = __toCommonJS(file_exports);
27
27
  var import_image_conversion = require("image-conversion");
28
- var downloadFile = (href, fileName) => {
28
+ var downloadFile = (href, fileName, target = "_blank") => {
29
29
  const aEle = document.createElement("a");
30
- aEle.target = "_blank";
30
+ aEle.target = target;
31
31
  aEle.href = href;
32
32
  aEle.download = fileName || "";
33
33
  aEle.click();
@@ -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.9",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {
@@ -64,25 +64,25 @@
64
64
  "pako": "^2.1.0"
65
65
  },
66
66
  "devDependencies": {
67
- "@ant-design/pro-components": "^2.7.13",
67
+ "@ant-design/pro-components": "^2.7.14",
68
68
  "@commitlint/cli": "^19.3.0",
69
69
  "@commitlint/config-conventional": "^19.2.2",
70
70
  "@types/pako": "^2.0.3",
71
71
  "@types/react": "^18.3.3",
72
72
  "@types/react-dom": "^18.3.0",
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",
78
- "husky": "^9.0.11",
73
+ "@umijs/lint": "^4.3.11",
74
+ "antd": "^5.19.4",
75
+ "dumi": "^2.4.7",
76
+ "eslint": "^9.8.0",
77
+ "father": "^4.4.6",
78
+ "husky": "^9.1.4",
79
79
  "lint-staged": "^15.2.7",
80
80
  "prettier": "^3.3.3",
81
81
  "prettier-plugin-organize-imports": "^3.2.4",
82
82
  "prettier-plugin-packagejson": "^2.5.1",
83
83
  "react": "^18.3.1",
84
84
  "react-dom": "^18.3.1",
85
- "stylelint": "^16.7.0"
85
+ "stylelint": "^16.8.1"
86
86
  },
87
87
  "publishConfig": {
88
88
  "access": "public"