@yysports/tools 0.1.11 → 1.0.0-alpha.2

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,50 @@ 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 _this$authCenterUserP;
227
+ var userProfile, menuNameMap, routes, getAuth, menuBuild, getDataScopeZonePermissions, restConfig, currentUserProfile;
209
228
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
210
229
  while (1) switch (_context3.prev = _context3.next) {
211
230
  case 0:
212
- userProfile = _ref3.userProfile, menuNameMap = _ref3.menuNameMap, routes = _ref3.routes, getAuth = _ref3.getAuth, menuBuild = _ref3.menuBuild, restConfig = _objectWithoutProperties(_ref3, _excluded);
231
+ userProfile = _ref3.userProfile, menuNameMap = _ref3.menuNameMap, routes = _ref3.routes, getAuth = _ref3.getAuth, menuBuild = _ref3.menuBuild, getDataScopeZonePermissions = _ref3.getDataScopeZonePermissions, restConfig = _objectWithoutProperties(_ref3, _excluded);
213
232
  this.checkConfig(restConfig);
214
233
  this.config = restConfig;
215
234
  _context3.next = 5;
216
235
  return this.initAuthCenterData({
217
236
  getAuth: getAuth,
218
237
  menuBuild: menuBuild,
238
+ getDataScopeZonePermissions: getDataScopeZonePermissions,
219
239
  menuNameMap: menuNameMap,
220
240
  routes: routes
221
241
  });
222
242
  case 5:
223
- // 如果对接了权限中心,取权限中心的用户信息
243
+ currentUserProfile = {}; // 如果对接了权限中心,取权限中心的用户信息
224
244
  if (this.authCenterUserProfile.userName) {
225
- this.setUserProfile({
245
+ Object.assign(currentUserProfile, {
226
246
  userId: this.authCenterUserProfile.userName,
227
- userName: this.authCenterUserProfile.nickName
247
+ userName: this.authCenterUserProfile.nickName,
248
+ orgCode: this.authCenterUserProfile.orgCode
249
+ });
250
+ }
251
+
252
+ // 传入区部数据权限接口时,设置区部权限数据
253
+ if (this.authCenterUserProfile.dataScopeZonePermissions && ((_this$authCenterUserP = this.authCenterUserProfile.dataScopeZonePermissions) === null || _this$authCenterUserP === void 0 || (_this$authCenterUserP = _this$authCenterUserP.list) === null || _this$authCenterUserP === void 0 ? void 0 : _this$authCenterUserP.length) > 0) {
254
+ // 提取出所有 zoneId
255
+ Object.assign(currentUserProfile, {
256
+ dataScopeZonePermissions: this.authCenterUserProfile.dataScopeZonePermissions.list.map(function (item) {
257
+ return item.list.map(function (zone) {
258
+ return zone.zoneId;
259
+ }).join(',');
260
+ }).join(',')
228
261
  });
229
262
  }
230
263
  if (userProfile) {
231
- this.setUserProfile(userProfile);
264
+ Object.assign(currentUserProfile, userProfile);
232
265
  }
266
+ this.setUserProfile(currentUserProfile);
233
267
  this.mountAutoTask();
234
268
  return _context3.abrupt("return", this.authCenterUserProfile);
235
- case 9:
269
+ case 12:
236
270
  case "end":
237
271
  return _context3.stop();
238
272
  }
@@ -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,30 @@ 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
+ list: {
63
+ regionId: string;
64
+ regionName: string;
65
+ list: {
66
+ zoneId: string;
67
+ zoneName: string;
68
+ }[];
69
+ }[];
70
+ };
57
71
  }
58
72
  export interface SystemProfile {
59
73
  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,25 +171,36 @@ var Track = class {
165
171
  routes,
166
172
  getAuth,
167
173
  menuBuild,
174
+ getDataScopeZonePermissions,
168
175
  ...restConfig
169
176
  }) {
177
+ var _a, _b;
170
178
  this.checkConfig(restConfig);
171
179
  this.config = restConfig;
172
180
  await this.initAuthCenterData({
173
181
  getAuth,
174
182
  menuBuild,
183
+ getDataScopeZonePermissions,
175
184
  menuNameMap,
176
185
  routes
177
186
  });
187
+ const currentUserProfile = {};
178
188
  if (this.authCenterUserProfile.userName) {
179
- this.setUserProfile({
189
+ Object.assign(currentUserProfile, {
180
190
  userId: this.authCenterUserProfile.userName,
181
- userName: this.authCenterUserProfile.nickName
191
+ userName: this.authCenterUserProfile.nickName,
192
+ orgCode: this.authCenterUserProfile.orgCode
193
+ });
194
+ }
195
+ if (this.authCenterUserProfile.dataScopeZonePermissions && ((_b = (_a = this.authCenterUserProfile.dataScopeZonePermissions) == null ? void 0 : _a.list) == null ? void 0 : _b.length) > 0) {
196
+ Object.assign(currentUserProfile, {
197
+ dataScopeZonePermissions: this.authCenterUserProfile.dataScopeZonePermissions.list.map((item) => item.list.map((zone) => zone.zoneId).join(",")).join(",")
182
198
  });
183
199
  }
184
200
  if (userProfile) {
185
- this.setUserProfile(userProfile);
201
+ Object.assign(currentUserProfile, userProfile);
186
202
  }
203
+ this.setUserProfile(currentUserProfile);
187
204
  this.mountAutoTask();
188
205
  return this.authCenterUserProfile;
189
206
  }
@@ -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,30 @@ 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
+ list: {
63
+ regionId: string;
64
+ regionName: string;
65
+ list: {
66
+ zoneId: string;
67
+ zoneName: string;
68
+ }[];
69
+ }[];
70
+ };
57
71
  }
58
72
  export interface SystemProfile {
59
73
  IMEI: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "0.1.11",
3
+ "version": "1.0.0-alpha.2",
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.8.4",
68
- "@commitlint/cli": "^19.6.1",
69
- "@commitlint/config-conventional": "^19.6.0",
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.18",
72
- "@types/react-dom": "^18.3.5",
73
- "@umijs/lint": "^4.4.4",
74
- "antd": "^5.23.2",
75
- "dumi": "^2.4.17",
76
- "eslint": "^9.18.0",
77
- "father": "^4.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
78
  "husky": "^9.1.7",
79
- "lint-staged": "^15.4.1",
80
- "prettier": "^3.4.2",
81
- "prettier-plugin-organize-imports": "^3.2.4",
82
- "prettier-plugin-packagejson": "^2.5.8",
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.13.2"
85
+ "stylelint": "^16.21.1"
86
86
  },
87
87
  "publishConfig": {
88
88
  "access": "public"