@yysports/tools 0.0.2 → 0.0.4

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/README.md CHANGED
@@ -2,39 +2,3 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/@yysports/tools.svg?style=flat)](https://npmjs.org/package/@yysports/tools)
4
4
  [![NPM downloads](http://img.shields.io/npm/dm/@yysports/tools.svg?style=flat)](https://npmjs.org/package/@yysports/tools)
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
@@ -1,10 +1,13 @@
1
- import { AuthMenuItemType, CurrentUserConfig, CurrentUserInfo, LocalRouteItemType, MenuNameMapType, PathMapItemType } from '../interfaces/currentUser.interface';
1
+ import { AuthMenuItemType, CurrentUserConfig, CurrentUserInfo, LocalRouteItemType, MenuNameMapType } from '../interfaces/currentUser.interface';
2
2
  export default class CurrentUser {
3
3
  static profile: CurrentUserInfo | null;
4
4
  static pathMap: {
5
- [key: string]: PathMapItemType;
5
+ [routeStr: string]: string[];
6
+ };
7
+ static authMap: {
8
+ [authStr: string]: string;
6
9
  };
7
10
  static formatAuthMenu(authMenuData: AuthMenuItemType[]): void;
8
- static formatLocalMenu(routes: LocalRouteItemType[], menuNameMap: MenuNameMapType): void;
11
+ static formatLocalMenu(routes: LocalRouteItemType[], menuNameMap: MenuNameMapType, roles: string[]): string[];
9
12
  static init({ getAuth, menuBuild, menuNameMap, routes, }: CurrentUserConfig): Promise<CurrentUserInfo>;
10
13
  }
@@ -27,33 +27,20 @@ var CurrentUser = /*#__PURE__*/function () {
27
27
  _createClass(CurrentUser, null, [{
28
28
  key: "formatAuthMenu",
29
29
  value:
30
- // 格式化权限中心菜单、按钮数据
30
+ // 格式化权限按钮操作日志
31
31
  function formatAuthMenu(authMenuData) {
32
32
  var _this = this;
33
33
  var ergodicAuthMenu = function ergodicAuthMenu(amd) {
34
- var pathArr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
35
34
  amd.forEach(function (menu) {
36
- var path = menu.path,
37
- permission = menu.permission,
35
+ var permission = menu.permission,
38
36
  name = menu.name,
39
37
  logAction = menu.logAction,
40
38
  children = menu.children;
41
- var currPathArr = _toConsumableArray(pathArr);
42
- if (path) {
43
- currPathArr.push(path === null || path === void 0 ? void 0 : path.replaceAll('/', ''));
44
- }
45
- var currPathObj = _this.pathMap["/".concat(currPathArr.join('/'))];
46
- if (currPathObj) {
47
- currPathObj.hasAccess = true;
48
- }
49
- if (path === undefined && currPathObj) {
50
- // 按钮权限
51
- currPathObj.options[permission] = {
52
- logAction: logAction || name
53
- };
39
+ if (permission && logAction) {
40
+ _this.authMap[permission] = logAction || name;
54
41
  }
55
42
  if (Array.isArray(children) && children.length > 0) {
56
- ergodicAuthMenu(children, _toConsumableArray(currPathArr));
43
+ ergodicAuthMenu(children);
57
44
  }
58
45
  });
59
46
  };
@@ -63,8 +50,9 @@ var CurrentUser = /*#__PURE__*/function () {
63
50
  // 格式化本地菜单权限数据
64
51
  }, {
65
52
  key: "formatLocalMenu",
66
- value: function formatLocalMenu(routes, menuNameMap) {
53
+ value: function formatLocalMenu(routes, menuNameMap, roles) {
67
54
  var _this2 = this;
55
+ var accessPage = [];
68
56
  var ergodicLocalMenu = function ergodicLocalMenu(rs, parentMenu) {
69
57
  rs.forEach(function (route) {
70
58
  var path = route.path,
@@ -73,17 +61,16 @@ var CurrentUser = /*#__PURE__*/function () {
73
61
  routes = route.routes;
74
62
  var nameArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.name) || []);
75
63
  var moduleArr = _toConsumableArray((parentMenu === null || parentMenu === void 0 ? void 0 : parentMenu.module) || []);
64
+ if (access && roles.includes(access)) {
65
+ accessPage.push(access);
66
+ }
76
67
  if (name) {
77
68
  nameArr.push(name);
78
69
  var menuKey = ['menu'].concat(_toConsumableArray(nameArr)).join('.');
79
70
  moduleArr.push(menuNameMap[menuKey]);
80
71
  }
81
72
  if (path) {
82
- _this2.pathMap[path] = {
83
- module: _toConsumableArray(moduleArr),
84
- access: access,
85
- options: {}
86
- };
73
+ _this2.pathMap[path] = _toConsumableArray(moduleArr);
87
74
  }
88
75
  if (routes) {
89
76
  ergodicLocalMenu(routes, {
@@ -95,12 +82,12 @@ var CurrentUser = /*#__PURE__*/function () {
95
82
  });
96
83
  };
97
84
  ergodicLocalMenu(routes);
85
+ return accessPage;
98
86
  }
99
87
  }, {
100
88
  key: "init",
101
89
  value: function () {
102
90
  var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
103
- var _this3 = this;
104
91
  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;
105
92
  return _regeneratorRuntime().wrap(function _callee$(_context) {
106
93
  while (1) switch (_context.prev = _context.next) {
@@ -124,26 +111,15 @@ var CurrentUser = /*#__PURE__*/function () {
124
111
  authInfo = _yield$Promise$all2$ === void 0 ? {} : _yield$Promise$all2$;
125
112
  _yield$Promise$all2$2 = _yield$Promise$all2[1];
126
113
  menuData = _yield$Promise$all2$2 === void 0 ? [] : _yield$Promise$all2$2;
127
- _ref2 = authInfo || {}, _ref2$user = _ref2.user, user = _ref2$user === void 0 ? {} : _ref2$user, _ref2$roles = _ref2.roles, roles = _ref2$roles === void 0 ? [] : _ref2$roles;
128
- this.formatLocalMenu(routes, menuNameMap);
114
+ _ref2 = authInfo || {}, _ref2$user = _ref2.user, user = _ref2$user === void 0 ? {} : _ref2$user, _ref2$roles = _ref2.roles, roles = _ref2$roles === void 0 ? [] : _ref2$roles; // 获取本地菜单配置模块名称映射,同时返沪当前用户有权限的页面
115
+ accessPage = this.formatLocalMenu(routes, menuNameMap, roles); // 获取权限中心菜单按钮logAction
129
116
  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 (user.isAdmin) {
135
- accessPage.push(currObj.access);
136
- } else {
137
- currObj.hasAccess && accessPage.push(currObj.access);
138
- }
139
- }
140
- });
141
117
  this.profile = _objectSpread(_objectSpread({}, user), {}, {
142
118
  roles: roles,
143
119
  accessPage: accessPage
144
120
  });
145
121
  return _context.abrupt("return", this.profile);
146
- case 16:
122
+ case 14:
147
123
  case "end":
148
124
  return _context.stop();
149
125
  }
@@ -161,4 +137,6 @@ var CurrentUser = /*#__PURE__*/function () {
161
137
  _defineProperty(CurrentUser, "profile", null);
162
138
  // 路径信息映射
163
139
  _defineProperty(CurrentUser, "pathMap", {});
140
+ // 权限信息映射
141
+ _defineProperty(CurrentUser, "authMap", {});
164
142
  export { CurrentUser as default };
@@ -56,7 +56,7 @@ var Track = /*#__PURE__*/function () {
56
56
  data = this.trackQueue.splice(0, this.trackQueue.length);
57
57
  compressed = pako.deflate(JSON.stringify(data));
58
58
  if (data.length) {
59
- navigator.sendBeacon("".concat(TrackServer, "/pousheng-guard/api/analysis/track"), compressed);
59
+ navigator.sendBeacon("https://track.yysports.com/pousheng-guard/api/analysis/track", compressed);
60
60
  }
61
61
  case 3:
62
62
  case "end":
@@ -205,8 +205,7 @@ var Track = /*#__PURE__*/function () {
205
205
  var routeNames = [];
206
206
  var pathMap = CurrentUser.pathMap;
207
207
  if (pathMap) {
208
- var _pathMap$this$getForm;
209
- routeNames = ((_pathMap$this$getForm = pathMap[this.getFormatBasePath()]) === null || _pathMap$this$getForm === void 0 ? void 0 : _pathMap$this$getForm.module) || [];
208
+ routeNames = pathMap[this.getFormatBasePath()] || [];
210
209
  }
211
210
  return routeNames;
212
211
  }
@@ -226,11 +225,11 @@ var Track = /*#__PURE__*/function () {
226
225
  key: "eventLog",
227
226
  value: function eventLog(_eventLog) {
228
227
  if (typeof _eventLog === 'string') {
229
- var _CurrentUser$pathMap$;
228
+ var _CurrentUser$authMap;
230
229
  var routeNames = this.getPageModuleName();
231
230
  _eventLog = {
232
231
  module: routeNames.join('-'),
233
- 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)
232
+ content: '触发: ' + ((_CurrentUser$authMap = CurrentUser.authMap) === null || _CurrentUser$authMap === void 0 ? void 0 : _CurrentUser$authMap[_eventLog])
234
233
  };
235
234
  }
236
235
  this.pushQueue({
@@ -39,13 +39,3 @@ export interface CurrentUserInfo {
39
39
  roles: string[];
40
40
  accessPage: string[];
41
41
  }
42
- export type PathMapItemType = {
43
- module?: string[];
44
- access?: string;
45
- hasAccess?: boolean;
46
- options: {
47
- [key: string]: {
48
- logAction: string;
49
- };
50
- };
51
- };
@@ -1,10 +1,13 @@
1
- import { AuthMenuItemType, CurrentUserConfig, CurrentUserInfo, LocalRouteItemType, MenuNameMapType, PathMapItemType } from '../interfaces/currentUser.interface';
1
+ import { AuthMenuItemType, CurrentUserConfig, CurrentUserInfo, LocalRouteItemType, MenuNameMapType } from '../interfaces/currentUser.interface';
2
2
  export default class CurrentUser {
3
3
  static profile: CurrentUserInfo | null;
4
4
  static pathMap: {
5
- [key: string]: PathMapItemType;
5
+ [routeStr: string]: string[];
6
+ };
7
+ static authMap: {
8
+ [authStr: string]: string;
6
9
  };
7
10
  static formatAuthMenu(authMenuData: AuthMenuItemType[]): void;
8
- static formatLocalMenu(routes: LocalRouteItemType[], menuNameMap: MenuNameMapType): void;
11
+ static formatLocalMenu(routes: LocalRouteItemType[], menuNameMap: MenuNameMapType, roles: string[]): string[];
9
12
  static init({ getAuth, menuBuild, menuNameMap, routes, }: CurrentUserConfig): Promise<CurrentUserInfo>;
10
13
  }
@@ -23,49 +23,39 @@ __export(CurrentUser_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(CurrentUser_exports);
25
25
  var CurrentUser = class {
26
- // 格式化权限中心菜单、按钮数据
26
+ // 格式化权限按钮操作日志
27
27
  static formatAuthMenu(authMenuData) {
28
- const ergodicAuthMenu = (amd, pathArr = []) => {
28
+ const ergodicAuthMenu = (amd) => {
29
29
  amd.forEach((menu) => {
30
- const { path, permission, name, logAction, children } = menu;
31
- const currPathArr = [...pathArr];
32
- if (path) {
33
- currPathArr.push(path == null ? void 0 : path.replaceAll("/", ""));
34
- }
35
- const currPathObj = this.pathMap[`/${currPathArr.join("/")}`];
36
- if (currPathObj) {
37
- currPathObj.hasAccess = true;
38
- }
39
- if (path === void 0 && currPathObj) {
40
- currPathObj.options[permission] = {
41
- logAction: logAction || name
42
- };
30
+ const { permission, name, logAction, children } = menu;
31
+ if (permission && logAction) {
32
+ this.authMap[permission] = logAction || name;
43
33
  }
44
34
  if (Array.isArray(children) && children.length > 0) {
45
- ergodicAuthMenu(children, [...currPathArr]);
35
+ ergodicAuthMenu(children);
46
36
  }
47
37
  });
48
38
  };
49
39
  ergodicAuthMenu(authMenuData);
50
40
  }
51
41
  // 格式化本地菜单权限数据
52
- static formatLocalMenu(routes, menuNameMap) {
42
+ static formatLocalMenu(routes, menuNameMap, roles) {
43
+ const accessPage = [];
53
44
  const ergodicLocalMenu = (rs, parentMenu) => {
54
45
  rs.forEach((route) => {
55
46
  const { path, access, name, routes: routes2 } = route;
56
47
  const nameArr = [...(parentMenu == null ? void 0 : parentMenu.name) || []];
57
48
  const moduleArr = [...(parentMenu == null ? void 0 : parentMenu.module) || []];
49
+ if (access && roles.includes(access)) {
50
+ accessPage.push(access);
51
+ }
58
52
  if (name) {
59
53
  nameArr.push(name);
60
54
  const menuKey = ["menu", ...nameArr].join(".");
61
55
  moduleArr.push(menuNameMap[menuKey]);
62
56
  }
63
57
  if (path) {
64
- this.pathMap[path] = {
65
- module: [...moduleArr],
66
- access,
67
- options: {}
68
- };
58
+ this.pathMap[path] = [...moduleArr];
69
59
  }
70
60
  if (routes2) {
71
61
  ergodicLocalMenu(routes2, {
@@ -77,6 +67,7 @@ var CurrentUser = class {
77
67
  });
78
68
  };
79
69
  ergodicLocalMenu(routes);
70
+ return accessPage;
80
71
  }
81
72
  static async init({
82
73
  getAuth,
@@ -99,19 +90,8 @@ var CurrentUser = class {
99
90
  })
100
91
  );
101
92
  const { user = {}, roles = [] } = authInfo || {};
102
- this.formatLocalMenu(routes, menuNameMap);
93
+ const accessPage = this.formatLocalMenu(routes, menuNameMap, roles);
103
94
  this.formatAuthMenu(menuData);
104
- const accessPage = [];
105
- Object.keys(this.pathMap).forEach((path) => {
106
- const currObj = this.pathMap[path];
107
- if (currObj.access) {
108
- if (user.isAdmin) {
109
- accessPage.push(currObj.access);
110
- } else {
111
- currObj.hasAccess && accessPage.push(currObj.access);
112
- }
113
- }
114
- });
115
95
  this.profile = {
116
96
  ...user,
117
97
  roles,
@@ -124,3 +104,5 @@ var CurrentUser = class {
124
104
  CurrentUser.profile = null;
125
105
  // 路径信息映射
126
106
  CurrentUser.pathMap = {};
107
+ // 权限信息映射
108
+ CurrentUser.authMap = {};
@@ -56,7 +56,7 @@ var Track = class {
56
56
  const compressed = import_pako.default.deflate(JSON.stringify(data));
57
57
  if (data.length) {
58
58
  navigator.sendBeacon(
59
- `${TrackServer}/pousheng-guard/api/analysis/track`,
59
+ `https://track.yysports.com/pousheng-guard/api/analysis/track`,
60
60
  compressed
61
61
  );
62
62
  }
@@ -154,11 +154,10 @@ var Track = class {
154
154
  }
155
155
  // 获取模块名称
156
156
  static getPageModuleName() {
157
- var _a;
158
157
  let routeNames = [];
159
158
  const { pathMap } = import_CurrentUser.default;
160
159
  if (pathMap) {
161
- routeNames = ((_a = pathMap[this.getFormatBasePath()]) == null ? void 0 : _a.module) || [];
160
+ routeNames = pathMap[this.getFormatBasePath()] || [];
162
161
  }
163
162
  return routeNames;
164
163
  }
@@ -171,12 +170,12 @@ var Track = class {
171
170
  }
172
171
  // 推送用户触发日志
173
172
  static eventLog(eventLog) {
174
- var _a, _b, _c;
173
+ var _a;
175
174
  if (typeof eventLog === "string") {
176
175
  const routeNames = this.getPageModuleName();
177
176
  eventLog = {
178
177
  module: routeNames.join("-"),
179
- content: "触发: " + ((_c = (_b = (_a = import_CurrentUser.default.pathMap[this.getFormatBasePath()]) == null ? void 0 : _a.options) == null ? void 0 : _b[eventLog]) == null ? void 0 : _c.logAction)
178
+ content: "触发: " + ((_a = import_CurrentUser.default.authMap) == null ? void 0 : _a[eventLog])
180
179
  };
181
180
  }
182
181
  this.pushQueue({
@@ -39,13 +39,3 @@ export interface CurrentUserInfo {
39
39
  roles: string[];
40
40
  accessPage: string[];
41
41
  }
42
- export type PathMapItemType = {
43
- module?: string[];
44
- access?: string;
45
- hasAccess?: boolean;
46
- options: {
47
- [key: string]: {
48
- logAction: string;
49
- };
50
- };
51
- };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "0.0.2",
4
- "description": "[![NPM version](https://img.shields.io/npm/v/@yysports/tools.svg?style=flat)](https://npmjs.org/package/@yysports/tools) [![NPM downloads](http://img.shields.io/npm/dm/@yysports/tools.svg?style=flat)](https://npmjs.org/package/@yysports/tools)",
3
+ "version": "0.0.4",
4
+ "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {
7
7
  "url": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools/issues"
@@ -72,9 +72,9 @@
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.0",
75
+ "@umijs/lint": "^4.3.1",
76
76
  "antd": "^5.19.0",
77
- "dumi": "^2.4.4",
77
+ "dumi": "^2.4.5",
78
78
  "eslint": "^9.6.0",
79
79
  "father": "^4.4.4",
80
80
  "husky": "^9.0.11",
@@ -86,10 +86,7 @@
86
86
  "react-dom": "^18.3.1",
87
87
  "stylelint": "^16.6.1"
88
88
  },
89
- "peerDependencies": {
90
- "react": ">=16.9.0",
91
- "react-dom": ">=16.9.0"
92
- },
89
+ "peerDependencies": {},
93
90
  "publishConfig": {
94
91
  "access": "public"
95
92
  },