@yysports/tools 0.1.10 → 1.0.0-alpha.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.
@@ -12,8 +12,8 @@ declare class Track {
12
12
  static getSystemProfile(): SystemProfile;
13
13
  static getUserProfile(): UserProfile;
14
14
  static setUserProfile(userProfile: UserProfile): void;
15
- static initAuthCenterData({ getAuth, menuBuild, menuNameMap, routes, }: Pick<TrackConfig, 'getAuth' | 'menuBuild' | 'menuNameMap' | 'routes'>): Promise<AuthCenterUserProfile>;
16
- static init({ userProfile, menuNameMap, routes, getAuth, menuBuild, ...restConfig }: TrackConfig): Promise<AuthCenterUserProfile>;
15
+ static initAuthCenterData({ getAuth, menuBuild, getDataScopeZonePermissions, menuNameMap, routes, }: Pick<TrackConfig, 'getAuth' | 'menuBuild' | 'menuNameMap' | 'routes' | 'getDataScopeZonePermissions'>): Promise<AuthCenterUserProfile>;
16
+ static init({ userProfile, menuNameMap, routes, getAuth, menuBuild, getDataScopeZonePermissions, ...restConfig }: TrackConfig): Promise<AuthCenterUserProfile>;
17
17
  static pushQueue({ type, log, }: {
18
18
  type: TrackType;
19
19
  log: ErrorProfile | CustomizeProfile;
@@ -1,4 +1,4 @@
1
- var _excluded = ["userProfile", "menuNameMap", "routes", "getAuth", "menuBuild"];
1
+ var _excluded = ["userProfile", "menuNameMap", "routes", "getAuth", "menuBuild", "getDataScopeZonePermissions"];
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
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; }
4
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; }
@@ -139,29 +139,41 @@ var Track = /*#__PURE__*/function () {
139
139
  key: "initAuthCenterData",
140
140
  value: function () {
141
141
  var _initAuthCenterData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
142
- 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, isAdmin, accessPage, routesMap;
142
+ var getAuth, menuBuild, getDataScopeZonePermissions, menuNameMap, routes, authCenterApi, _yield$Promise$all, _yield$Promise$all2, _yield$Promise$all2$, authInfo, _yield$Promise$all2$2, menuData, dataScopeZonePermissions, _ref2, _ref2$user, user, _ref2$roles, roles, isAdmin, accessPage, routesMap, authCenterUserProfile;
143
143
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
144
144
  while (1) switch (_context2.prev = _context2.next) {
145
145
  case 0:
146
- getAuth = _ref.getAuth, menuBuild = _ref.menuBuild, menuNameMap = _ref.menuNameMap, routes = _ref.routes;
147
- _context2.next = 3;
148
- return Promise.all([getAuth,
149
- // 获取用户权限
150
- menuBuild // 获取权限中心配置的菜单及按钮
151
- ].map(function (v) {
146
+ getAuth = _ref.getAuth, menuBuild = _ref.menuBuild, getDataScopeZonePermissions = _ref.getDataScopeZonePermissions, menuNameMap = _ref.menuNameMap, routes = _ref.routes;
147
+ authCenterApi = []; // 获取用户权限
148
+ if (getAuth) {
149
+ authCenterApi.push(getAuth);
150
+ }
151
+
152
+ // 获取权限中心配置的菜单及按钮
153
+ if (menuBuild) {
154
+ authCenterApi.push(menuBuild);
155
+ }
156
+
157
+ // 获取权限中心配置的区部数据权限
158
+ if (getDataScopeZonePermissions) {
159
+ authCenterApi.push(getDataScopeZonePermissions);
160
+ }
161
+ _context2.next = 7;
162
+ return Promise.all(authCenterApi.map(function (v) {
152
163
  if (v) {
153
164
  return v();
154
165
  } else {
155
166
  return Promise.resolve();
156
167
  }
157
168
  }));
158
- case 3:
169
+ case 7:
159
170
  _yield$Promise$all = _context2.sent;
160
- _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 2);
171
+ _yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 3);
161
172
  _yield$Promise$all2$ = _yield$Promise$all2[0];
162
173
  authInfo = _yield$Promise$all2$ === void 0 ? {} : _yield$Promise$all2$;
163
174
  _yield$Promise$all2$2 = _yield$Promise$all2[1];
164
175
  menuData = _yield$Promise$all2$2 === void 0 ? [] : _yield$Promise$all2$2;
176
+ dataScopeZonePermissions = _yield$Promise$all2[2];
165
177
  _ref2 = authInfo || {}, _ref2$user = _ref2.user, user = _ref2$user === void 0 ? {} : _ref2$user, _ref2$roles = _ref2.roles, roles = _ref2$roles === void 0 ? [] : _ref2$roles;
166
178
  isAdmin = roles.includes('admin'); // 当前用户所拥有的所有页面权限
167
179
  accessPage = []; // 获取本地菜单信息映射
@@ -185,12 +197,18 @@ var Track = /*#__PURE__*/function () {
185
197
  this.routesMap = routesMap;
186
198
  }
187
199
  this.authMap = getAuthMapByAuthCenter(menuData);
188
- this.authCenterUserProfile = _objectSpread(_objectSpread({}, user), {}, {
200
+ authCenterUserProfile = _objectSpread(_objectSpread({}, user), {}, {
189
201
  roles: roles,
190
202
  accessPage: accessPage
191
203
  });
192
- return _context2.abrupt("return", this.authCenterUserProfile);
193
- case 16:
204
+ if (dataScopeZonePermissions) {
205
+ Object.assign(authCenterUserProfile, {
206
+ dataScopeZonePermissions: dataScopeZonePermissions
207
+ });
208
+ }
209
+ this.authCenterUserProfile = authCenterUserProfile;
210
+ return _context2.abrupt("return", authCenterUserProfile);
211
+ case 23:
194
212
  case "end":
195
213
  return _context2.stop();
196
214
  }
@@ -205,34 +223,49 @@ var Track = /*#__PURE__*/function () {
205
223
  key: "init",
206
224
  value: function () {
207
225
  var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(_ref3) {
208
- var userProfile, menuNameMap, routes, getAuth, menuBuild, restConfig;
226
+ var userProfile, menuNameMap, routes, getAuth, menuBuild, getDataScopeZonePermissions, restConfig, currentUserProfile;
209
227
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
210
228
  while (1) switch (_context3.prev = _context3.next) {
211
229
  case 0:
212
- userProfile = _ref3.userProfile, menuNameMap = _ref3.menuNameMap, routes = _ref3.routes, getAuth = _ref3.getAuth, menuBuild = _ref3.menuBuild, restConfig = _objectWithoutProperties(_ref3, _excluded);
230
+ userProfile = _ref3.userProfile, menuNameMap = _ref3.menuNameMap, routes = _ref3.routes, getAuth = _ref3.getAuth, menuBuild = _ref3.menuBuild, getDataScopeZonePermissions = _ref3.getDataScopeZonePermissions, restConfig = _objectWithoutProperties(_ref3, _excluded);
213
231
  this.checkConfig(restConfig);
214
232
  this.config = restConfig;
215
233
  _context3.next = 5;
216
234
  return this.initAuthCenterData({
217
235
  getAuth: getAuth,
218
236
  menuBuild: menuBuild,
237
+ getDataScopeZonePermissions: getDataScopeZonePermissions,
219
238
  menuNameMap: menuNameMap,
220
239
  routes: routes
221
240
  });
222
241
  case 5:
223
- // 如果对接了权限中心,取权限中心的用户信息
224
- if (this.authCenterUserProfile.email) {
225
- this.setUserProfile({
242
+ currentUserProfile = {}; // 如果对接了权限中心,取权限中心的用户信息
243
+ if (this.authCenterUserProfile.userName) {
244
+ Object.assign(currentUserProfile, {
226
245
  userId: this.authCenterUserProfile.userName,
227
- userName: this.authCenterUserProfile.nickName
246
+ userName: this.authCenterUserProfile.nickName,
247
+ orgCode: this.authCenterUserProfile.orgCode
248
+ });
249
+ }
250
+
251
+ // 传入区部数据权限接口时,设置区部权限数据
252
+ if (this.authCenterUserProfile.dataScopeZonePermissions && this.authCenterUserProfile.dataScopeZonePermissions.size > 0) {
253
+ // 提取出所有 zoneId
254
+ Object.assign(currentUserProfile, {
255
+ dataScopeZonePermissions: this.authCenterUserProfile.dataScopeZonePermissions.list.map(function (item) {
256
+ return item.list.map(function (zone) {
257
+ return zone.zoneId;
258
+ }).join(',');
259
+ }).join(',')
228
260
  });
229
261
  }
230
262
  if (userProfile) {
231
- this.setUserProfile(userProfile);
263
+ Object.assign(currentUserProfile, userProfile);
232
264
  }
265
+ this.setUserProfile(currentUserProfile);
233
266
  this.mountAutoTask();
234
267
  return _context3.abrupt("return", this.authCenterUserProfile);
235
- case 9:
268
+ case 12:
236
269
  case "end":
237
270
  return _context3.stop();
238
271
  }
@@ -29,6 +29,10 @@ export interface TrackConfig {
29
29
  menuBuild?: () => Promise<AuthMenuItemType[]>;
30
30
  menuNameMap?: MenuNameMapType;
31
31
  routes?: RouteType[];
32
+ getDataScopeZonePermissions?: () => Promise<{
33
+ zoneId: number;
34
+ zoneName: string;
35
+ }[]>;
32
36
  }
33
37
  export declare enum TrackTypeEnum {
34
38
  error = "\u9519\u8BEF\u4FE1\u606F",
@@ -40,20 +44,32 @@ export type TrackType = keyof typeof TrackTypeEnum;
40
44
  export interface UserProfile {
41
45
  userId: string;
42
46
  userName: string;
47
+ orgCode?: string;
48
+ dataScopeZonePermissions?: string;
43
49
  }
44
50
  export interface AuthCenterUserProfile {
45
51
  userName: string;
52
+ nickName: string;
53
+ isAdmin: boolean;
46
54
  department?: string;
47
55
  email?: string;
48
- enabled?: boolean;
49
56
  gender?: string;
50
- isAdmin?: boolean;
51
- jobs?: string[];
52
- nickName?: string;
53
57
  phone?: string;
54
- status?: number;
55
58
  roles?: string[];
56
59
  accessPage?: string[];
60
+ orgCode: string;
61
+ dataScopeZonePermissions?: {
62
+ size: number;
63
+ list: {
64
+ regionId: string;
65
+ regionName: string;
66
+ list: {
67
+ id: string;
68
+ zoneId: string;
69
+ zoneName: string;
70
+ }[];
71
+ }[];
72
+ };
57
73
  }
58
74
  export interface SystemProfile {
59
75
  IMEI: string;
@@ -12,8 +12,8 @@ declare class Track {
12
12
  static getSystemProfile(): SystemProfile;
13
13
  static getUserProfile(): UserProfile;
14
14
  static setUserProfile(userProfile: UserProfile): void;
15
- static initAuthCenterData({ getAuth, menuBuild, menuNameMap, routes, }: Pick<TrackConfig, 'getAuth' | 'menuBuild' | 'menuNameMap' | 'routes'>): Promise<AuthCenterUserProfile>;
16
- static init({ userProfile, menuNameMap, routes, getAuth, menuBuild, ...restConfig }: TrackConfig): Promise<AuthCenterUserProfile>;
15
+ static initAuthCenterData({ getAuth, menuBuild, getDataScopeZonePermissions, menuNameMap, routes, }: Pick<TrackConfig, 'getAuth' | 'menuBuild' | 'menuNameMap' | 'routes' | 'getDataScopeZonePermissions'>): Promise<AuthCenterUserProfile>;
16
+ static init({ userProfile, menuNameMap, routes, getAuth, menuBuild, getDataScopeZonePermissions, ...restConfig }: TrackConfig): Promise<AuthCenterUserProfile>;
17
17
  static pushQueue({ type, log, }: {
18
18
  type: TrackType;
19
19
  log: ErrorProfile | CustomizeProfile;
@@ -111,16 +111,22 @@ var Track = class {
111
111
  static async initAuthCenterData({
112
112
  getAuth,
113
113
  menuBuild,
114
+ getDataScopeZonePermissions,
114
115
  menuNameMap,
115
116
  routes
116
117
  }) {
117
- const [authInfo = {}, menuData = []] = await Promise.all(
118
- [
119
- getAuth,
120
- // 获取用户权限
121
- menuBuild
122
- // 获取权限中心配置的菜单及按钮
123
- ].map((v) => {
118
+ const authCenterApi = [];
119
+ if (getAuth) {
120
+ authCenterApi.push(getAuth);
121
+ }
122
+ if (menuBuild) {
123
+ authCenterApi.push(menuBuild);
124
+ }
125
+ if (getDataScopeZonePermissions) {
126
+ authCenterApi.push(getDataScopeZonePermissions);
127
+ }
128
+ const [authInfo = {}, menuData = [], dataScopeZonePermissions] = await Promise.all(
129
+ authCenterApi.map((v) => {
124
130
  if (v) {
125
131
  return v();
126
132
  } else {
@@ -151,12 +157,12 @@ var Track = class {
151
157
  this.routesMap = routesMap;
152
158
  }
153
159
  this.authMap = (0, import_Utils.getAuthMapByAuthCenter)(menuData);
154
- this.authCenterUserProfile = {
155
- ...user,
156
- roles,
157
- accessPage
158
- };
159
- return this.authCenterUserProfile;
160
+ const authCenterUserProfile = { ...user, roles, accessPage };
161
+ if (dataScopeZonePermissions) {
162
+ Object.assign(authCenterUserProfile, { dataScopeZonePermissions });
163
+ }
164
+ this.authCenterUserProfile = authCenterUserProfile;
165
+ return authCenterUserProfile;
160
166
  }
161
167
  // 挂载初始配置
162
168
  static async init({
@@ -165,6 +171,7 @@ var Track = class {
165
171
  routes,
166
172
  getAuth,
167
173
  menuBuild,
174
+ getDataScopeZonePermissions,
168
175
  ...restConfig
169
176
  }) {
170
177
  this.checkConfig(restConfig);
@@ -172,18 +179,27 @@ var Track = class {
172
179
  await this.initAuthCenterData({
173
180
  getAuth,
174
181
  menuBuild,
182
+ getDataScopeZonePermissions,
175
183
  menuNameMap,
176
184
  routes
177
185
  });
178
- if (this.authCenterUserProfile.email) {
179
- this.setUserProfile({
186
+ const currentUserProfile = {};
187
+ if (this.authCenterUserProfile.userName) {
188
+ Object.assign(currentUserProfile, {
180
189
  userId: this.authCenterUserProfile.userName,
181
- userName: this.authCenterUserProfile.nickName
190
+ userName: this.authCenterUserProfile.nickName,
191
+ orgCode: this.authCenterUserProfile.orgCode
192
+ });
193
+ }
194
+ if (this.authCenterUserProfile.dataScopeZonePermissions && this.authCenterUserProfile.dataScopeZonePermissions.size > 0) {
195
+ Object.assign(currentUserProfile, {
196
+ dataScopeZonePermissions: this.authCenterUserProfile.dataScopeZonePermissions.list.map((item) => item.list.map((zone) => zone.zoneId).join(",")).join(",")
182
197
  });
183
198
  }
184
199
  if (userProfile) {
185
- this.setUserProfile(userProfile);
200
+ Object.assign(currentUserProfile, userProfile);
186
201
  }
202
+ this.setUserProfile(currentUserProfile);
187
203
  this.mountAutoTask();
188
204
  return this.authCenterUserProfile;
189
205
  }
@@ -29,6 +29,10 @@ export interface TrackConfig {
29
29
  menuBuild?: () => Promise<AuthMenuItemType[]>;
30
30
  menuNameMap?: MenuNameMapType;
31
31
  routes?: RouteType[];
32
+ getDataScopeZonePermissions?: () => Promise<{
33
+ zoneId: number;
34
+ zoneName: string;
35
+ }[]>;
32
36
  }
33
37
  export declare enum TrackTypeEnum {
34
38
  error = "\u9519\u8BEF\u4FE1\u606F",
@@ -40,20 +44,32 @@ export type TrackType = keyof typeof TrackTypeEnum;
40
44
  export interface UserProfile {
41
45
  userId: string;
42
46
  userName: string;
47
+ orgCode?: string;
48
+ dataScopeZonePermissions?: string;
43
49
  }
44
50
  export interface AuthCenterUserProfile {
45
51
  userName: string;
52
+ nickName: string;
53
+ isAdmin: boolean;
46
54
  department?: string;
47
55
  email?: string;
48
- enabled?: boolean;
49
56
  gender?: string;
50
- isAdmin?: boolean;
51
- jobs?: string[];
52
- nickName?: string;
53
57
  phone?: string;
54
- status?: number;
55
58
  roles?: string[];
56
59
  accessPage?: string[];
60
+ orgCode: string;
61
+ dataScopeZonePermissions?: {
62
+ size: number;
63
+ list: {
64
+ regionId: string;
65
+ regionName: string;
66
+ list: {
67
+ id: string;
68
+ zoneId: string;
69
+ zoneName: string;
70
+ }[];
71
+ }[];
72
+ };
57
73
  }
58
74
  export interface SystemProfile {
59
75
  IMEI: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "0.1.10",
3
+ "version": "1.0.0-alpha.1",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {
@@ -26,7 +26,7 @@
26
26
  "scripts": {
27
27
  "build": "father build",
28
28
  "build:watch": "father dev",
29
- "dev": "dumi dev",
29
+ "dev": "SOCKET_SERVER=http://127.0.0.1:8000 dumi dev",
30
30
  "docs:build": "dumi build",
31
31
  "doctor": "father doctor",
32
32
  "lint": "npm run lint:es && npm run lint:css",
@@ -64,25 +64,25 @@
64
64
  "pako": "^2.1.0"
65
65
  },
66
66
  "devDependencies": {
67
- "@ant-design/pro-components": "^2.7.16",
68
- "@commitlint/cli": "^19.4.1",
69
- "@commitlint/config-conventional": "^19.4.1",
67
+ "@ant-design/pro-components": "^2.8.9",
68
+ "@commitlint/cli": "^19.8.1",
69
+ "@commitlint/config-conventional": "^19.8.1",
70
70
  "@types/pako": "^2.0.3",
71
- "@types/react": "^18.3.5",
72
- "@types/react-dom": "^18.3.0",
73
- "@umijs/lint": "^4.3.20",
74
- "antd": "^5.20.6",
75
- "dumi": "^2.4.10",
76
- "eslint": "^9.10.0",
77
- "father": "^4.5.0",
78
- "husky": "^9.1.5",
79
- "lint-staged": "^15.2.10",
80
- "prettier": "^3.3.3",
81
- "prettier-plugin-organize-imports": "^3.2.4",
82
- "prettier-plugin-packagejson": "^2.5.2",
71
+ "@types/react": "^18.3.23",
72
+ "@types/react-dom": "^18.3.7",
73
+ "@umijs/lint": "^4.4.11",
74
+ "antd": "^5.26.4",
75
+ "dumi": "^2.4.21",
76
+ "eslint": "^9.30.1",
77
+ "father": "^4.5.6",
78
+ "husky": "^9.1.7",
79
+ "lint-staged": "^16.1.2",
80
+ "prettier": "^3.6.2",
81
+ "prettier-plugin-organize-imports": "^4.1.0",
82
+ "prettier-plugin-packagejson": "^2.5.18",
83
83
  "react": "^18.3.1",
84
84
  "react-dom": "^18.3.1",
85
- "stylelint": "^16.9.0"
85
+ "stylelint": "^16.21.1"
86
86
  },
87
87
  "publishConfig": {
88
88
  "access": "public"