@yysports/tools 0.1.0 → 0.1.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.
@@ -23,7 +23,6 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
23
23
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
24
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
25
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26
- import Cookies from 'js-cookie';
27
26
  import pako from 'pako';
28
27
  import { generateRandomString, getAuthMapByAuthCenter, getRoutesMap } from "../Utils";
29
28
  var Track = /*#__PURE__*/function () {
@@ -49,16 +48,18 @@ var Track = /*#__PURE__*/function () {
49
48
  key: "send",
50
49
  value: function () {
51
50
  var _send = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
52
- var data, compressed;
51
+ var debug, data, compressed;
53
52
  return _regeneratorRuntime().wrap(function _callee$(_context) {
54
53
  while (1) switch (_context.prev = _context.next) {
55
54
  case 0:
55
+ debug = this.config.debug;
56
56
  data = this.trackQueue.splice(0, this.trackQueue.length);
57
57
  compressed = pako.deflate(JSON.stringify(data));
58
58
  if (data.length) {
59
+ debug && console.log('[track:debug] push data', data);
59
60
  navigator.sendBeacon("https://track.yysports.com/pousheng-guard/api/analysis/track", compressed);
60
61
  }
61
- case 3:
62
+ case 4:
62
63
  case "end":
63
64
  return _context.stop();
64
65
  }
@@ -84,16 +85,6 @@ var Track = /*#__PURE__*/function () {
84
85
  };
85
86
  _this.errorLog(errorInfo);
86
87
  });
87
-
88
- // 监听点击事件
89
- // addEventListener(
90
- // 'click',
91
- // (event) => {
92
- // const { target } = event;
93
- // console.log(target.parentElement);
94
- // },
95
- // true
96
- // );
97
88
  }
98
89
 
99
90
  //关闭页面时,发送剩余的埋点数据
@@ -108,18 +99,16 @@ var Track = /*#__PURE__*/function () {
108
99
  }, {
109
100
  key: "getSystemProfile",
110
101
  value: function getSystemProfile() {
111
- var IMEI = Cookies.get('__IMEI__');
102
+ var IMEI = localStorage.getItem('__IMEI__');
112
103
  if (!IMEI) {
113
- Cookies.set('__IMEI__', generateRandomString(16), {
114
- expires: 90
115
- });
104
+ localStorage.setItem('__IMEI__', generateRandomString(16));
116
105
  }
117
106
  return {
118
107
  innerHeight: innerHeight,
119
108
  innerWidth: innerWidth,
120
109
  href: location.href,
121
110
  systemTime: new Date(),
122
- IMEI: Cookies.get('__IMEI__')
111
+ IMEI: localStorage.getItem('__IMEI__')
123
112
  };
124
113
  }
125
114
 
@@ -149,7 +138,7 @@ var Track = /*#__PURE__*/function () {
149
138
  key: "initAuthCenterData",
150
139
  value: function () {
151
140
  var _initAuthCenterData = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
152
- 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, routesMap, accessPage;
141
+ 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;
153
142
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
154
143
  while (1) switch (_context2.prev = _context2.next) {
155
144
  case 0:
@@ -173,23 +162,25 @@ var Track = /*#__PURE__*/function () {
173
162
  _yield$Promise$all2$2 = _yield$Promise$all2[1];
174
163
  menuData = _yield$Promise$all2$2 === void 0 ? [] : _yield$Promise$all2$2;
175
164
  _ref2 = authInfo || {}, _ref2$user = _ref2.user, user = _ref2$user === void 0 ? {} : _ref2$user, _ref2$roles = _ref2.roles, roles = _ref2$roles === void 0 ? [] : _ref2$roles;
176
- isAdmin = roles.includes('admin'); // 获取本地菜单信息映射
177
- routesMap = getRoutesMap(routes, menuNameMap); // 当前用户所拥有的所有页面权限
178
- accessPage = [];
179
- routesMap.forEach(function (value, key) {
180
- var access = value.access;
181
- if (access && (isAdmin || roles.includes(access))) {
182
- accessPage.push(access);
183
- }
184
- });
185
- this.routesMap = routesMap;
165
+ isAdmin = roles.includes('admin'); // 当前用户所拥有的所有页面权限
166
+ accessPage = []; // 获取本地菜单信息映射
167
+ if (routes) {
168
+ routesMap = getRoutesMap(routes, menuNameMap);
169
+ routesMap.forEach(function (value, key) {
170
+ var access = value.access;
171
+ if (access && (isAdmin || roles.includes(access))) {
172
+ accessPage.push(access);
173
+ }
174
+ });
175
+ this.routesMap = routesMap;
176
+ }
186
177
  this.authMap = getAuthMapByAuthCenter(menuData);
187
178
  this.authCenterUserProfile = _objectSpread(_objectSpread({}, user), {}, {
188
179
  roles: roles,
189
180
  accessPage: accessPage
190
181
  });
191
182
  return _context2.abrupt("return", this.authCenterUserProfile);
192
- case 18:
183
+ case 16:
193
184
  case "end":
194
185
  return _context2.stop();
195
186
  }
@@ -211,18 +202,14 @@ var Track = /*#__PURE__*/function () {
211
202
  userProfile = _ref3.userProfile, menuNameMap = _ref3.menuNameMap, routes = _ref3.routes, getAuth = _ref3.getAuth, menuBuild = _ref3.menuBuild, restConfig = _objectWithoutProperties(_ref3, _excluded);
212
203
  this.checkConfig(restConfig);
213
204
  this.config = restConfig;
214
- if (!(routes && menuNameMap)) {
215
- _context3.next = 6;
216
- break;
217
- }
218
- _context3.next = 6;
205
+ _context3.next = 5;
219
206
  return this.initAuthCenterData({
220
207
  getAuth: getAuth,
221
208
  menuBuild: menuBuild,
222
209
  menuNameMap: menuNameMap,
223
210
  routes: routes
224
211
  });
225
- case 6:
212
+ case 5:
226
213
  // 如果对接了权限中心,取权限中心的用户信息
227
214
  if (this.authCenterUserProfile.email) {
228
215
  this.setUserProfile({
@@ -235,7 +222,7 @@ var Track = /*#__PURE__*/function () {
235
222
  }
236
223
  this.mountAutoTask();
237
224
  return _context3.abrupt("return", this.authCenterUserProfile);
238
- case 10:
225
+ case 9:
239
226
  case "end":
240
227
  return _context3.stop();
241
228
  }
@@ -354,7 +341,9 @@ var Track = /*#__PURE__*/function () {
354
341
  }]);
355
342
  return Track;
356
343
  }();
344
+ // 配置信息
357
345
  _defineProperty(Track, "config", {});
346
+ // 需要传入到后端的用户信息
358
347
  _defineProperty(Track, "userProfile", {});
359
348
  // 权限中心用户信息
360
349
  _defineProperty(Track, "authCenterUserProfile", {});
@@ -3,5 +3,8 @@ export type AuthDataType = {
3
3
  name?: string;
4
4
  logAction?: string;
5
5
  permission?: string;
6
+ meta?: {
7
+ title: string;
8
+ };
6
9
  };
7
10
  export declare const getAuthMapByAuthCenter: (authData: AuthDataType[]) => Map<string, string>;
@@ -6,9 +6,11 @@ export var getAuthMapByAuthCenter = function getAuthMapByAuthCenter(authData) {
6
6
  var permission = menu.permission,
7
7
  name = menu.name,
8
8
  logAction = menu.logAction,
9
- children = menu.children;
10
- if (permission && logAction) {
11
- authMap.set(permission, logAction || name || '权限校验');
9
+ children = menu.children,
10
+ meta = menu.meta;
11
+ if (permission) {
12
+ var authLog = logAction || (meta === null || meta === void 0 ? void 0 : meta.title) || name || '权限校验';
13
+ authMap.set(permission, authLog);
12
14
  }
13
15
  if (Array.isArray(children) && children.length > 0) {
14
16
  ergodicAuthMenu(children);
@@ -32,7 +32,6 @@ __export(Track_exports, {
32
32
  default: () => Track_default
33
33
  });
34
34
  module.exports = __toCommonJS(Track_exports);
35
- var import_js_cookie = __toESM(require("js-cookie"));
36
35
  var import_pako = __toESM(require("pako"));
37
36
  var import_Utils = require("../Utils");
38
37
  var Track = class {
@@ -48,9 +47,11 @@ var Track = class {
48
47
  }
49
48
  // 发送埋点数据
50
49
  static async send() {
50
+ const { debug } = this.config;
51
51
  const data = this.trackQueue.splice(0, this.trackQueue.length);
52
52
  const compressed = import_pako.default.deflate(JSON.stringify(data));
53
53
  if (data.length) {
54
+ debug && console.log("[track:debug] push data", data);
54
55
  navigator.sendBeacon(
55
56
  `https://track.yysports.com/pousheng-guard/api/analysis/track`,
56
57
  compressed
@@ -78,18 +79,16 @@ var Track = class {
78
79
  }
79
80
  // 获取系统信息
80
81
  static getSystemProfile() {
81
- const IMEI = import_js_cookie.default.get("__IMEI__");
82
+ const IMEI = localStorage.getItem("__IMEI__");
82
83
  if (!IMEI) {
83
- import_js_cookie.default.set("__IMEI__", (0, import_Utils.generateRandomString)(16), {
84
- expires: 90
85
- });
84
+ localStorage.setItem("__IMEI__", (0, import_Utils.generateRandomString)(16));
86
85
  }
87
86
  return {
88
87
  innerHeight,
89
88
  innerWidth,
90
89
  href: location.href,
91
90
  systemTime: /* @__PURE__ */ new Date(),
92
- IMEI: import_js_cookie.default.get("__IMEI__")
91
+ IMEI: localStorage.getItem("__IMEI__")
93
92
  };
94
93
  }
95
94
  // 获取当前用户信息,返回格式化后的用户信息
@@ -130,15 +129,17 @@ var Track = class {
130
129
  );
131
130
  const { user = {}, roles = [] } = authInfo || {};
132
131
  const isAdmin = roles.includes("admin");
133
- const routesMap = (0, import_Utils.getRoutesMap)(routes, menuNameMap);
134
132
  const accessPage = [];
135
- routesMap.forEach((value, key) => {
136
- const { access } = value;
137
- if (access && (isAdmin || roles.includes(access))) {
138
- accessPage.push(access);
139
- }
140
- });
141
- this.routesMap = routesMap;
133
+ if (routes) {
134
+ const routesMap = (0, import_Utils.getRoutesMap)(routes, menuNameMap);
135
+ routesMap.forEach((value, key) => {
136
+ const { access } = value;
137
+ if (access && (isAdmin || roles.includes(access))) {
138
+ accessPage.push(access);
139
+ }
140
+ });
141
+ this.routesMap = routesMap;
142
+ }
142
143
  this.authMap = (0, import_Utils.getAuthMapByAuthCenter)(menuData);
143
144
  this.authCenterUserProfile = {
144
145
  ...user,
@@ -158,14 +159,12 @@ var Track = class {
158
159
  }) {
159
160
  this.checkConfig(restConfig);
160
161
  this.config = restConfig;
161
- if (routes && menuNameMap) {
162
- await this.initAuthCenterData({
163
- getAuth,
164
- menuBuild,
165
- menuNameMap,
166
- routes
167
- });
168
- }
162
+ await this.initAuthCenterData({
163
+ getAuth,
164
+ menuBuild,
165
+ menuNameMap,
166
+ routes
167
+ });
169
168
  if (this.authCenterUserProfile.email) {
170
169
  this.setUserProfile({
171
170
  userId: this.authCenterUserProfile.userName,
@@ -263,7 +262,9 @@ var Track = class {
263
262
  });
264
263
  }
265
264
  };
265
+ // 配置信息
266
266
  Track.config = {};
267
+ // 需要传入到后端的用户信息
267
268
  Track.userProfile = {};
268
269
  // 权限中心用户信息
269
270
  Track.authCenterUserProfile = {};
@@ -3,5 +3,8 @@ export type AuthDataType = {
3
3
  name?: string;
4
4
  logAction?: string;
5
5
  permission?: string;
6
+ meta?: {
7
+ title: string;
8
+ };
6
9
  };
7
10
  export declare const getAuthMapByAuthCenter: (authData: AuthDataType[]) => Map<string, string>;
package/lib/Utils/auth.js CHANGED
@@ -26,9 +26,10 @@ var getAuthMapByAuthCenter = (authData) => {
26
26
  const authMap = /* @__PURE__ */ new Map();
27
27
  const ergodicAuthMenu = (authCenterData) => {
28
28
  authCenterData.forEach((menu) => {
29
- const { permission, name, logAction, children } = menu;
30
- if (permission && logAction) {
31
- authMap.set(permission, logAction || name || "权限校验");
29
+ const { permission, name, logAction, children, meta } = menu;
30
+ if (permission) {
31
+ const authLog = logAction || (meta == null ? void 0 : meta.title) || name || "权限校验";
32
+ authMap.set(permission, authLog);
32
33
  }
33
34
  if (Array.isArray(children) && children.length > 0) {
34
35
  ergodicAuthMenu(children);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {
@@ -61,14 +61,12 @@
61
61
  },
62
62
  "dependencies": {
63
63
  "image-conversion": "^2.1.1",
64
- "js-cookie": "^3.0.5",
65
64
  "pako": "^2.1.0"
66
65
  },
67
66
  "devDependencies": {
68
67
  "@ant-design/pro-components": "^2.7.13",
69
68
  "@commitlint/cli": "^19.3.0",
70
69
  "@commitlint/config-conventional": "^19.2.2",
71
- "@types/js-cookie": "^3.0.6",
72
70
  "@types/pako": "^2.0.3",
73
71
  "@types/react": "^18.3.3",
74
72
  "@types/react-dom": "^18.3.0",