@yysports/tools 0.0.5 → 0.0.7

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.
@@ -9,7 +9,7 @@ declare class Track {
9
9
  static getSystemProfile(): SystemProfile;
10
10
  static getUserProfile(): UserProfile;
11
11
  static setUserProfile(userProfile: UserProfile): void;
12
- static init({ userProfile, ...restConfig }: TrackConfig): void;
12
+ static init({ userProfile, menuNameMap, routes, getAuth, menuBuild, ...restConfig }: TrackConfig): Promise<void>;
13
13
  static pushQueue({ type, log, }: {
14
14
  type: TrackType;
15
15
  log: ErrorProfile | CustomizeProfile;
@@ -1,4 +1,4 @@
1
- var _excluded = ["userProfile"];
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
3
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
4
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."); }
@@ -148,27 +148,50 @@ var Track = /*#__PURE__*/function () {
148
148
  // 挂载初始配置
149
149
  }, {
150
150
  key: "init",
151
- value: function init(_ref) {
152
- var _CurrentUser$profile;
153
- var userProfile = _ref.userProfile,
154
- restConfig = _objectWithoutProperties(_ref, _excluded);
155
- this.checkConfig(restConfig);
156
- this.config = restConfig;
157
-
158
- // 如果对接了权限中心,取权限中心的用户信息
159
- if ((_CurrentUser$profile = CurrentUser.profile) !== null && _CurrentUser$profile !== void 0 && _CurrentUser$profile.email) {
160
- this.setUserProfile({
161
- userId: CurrentUser.profile.userName,
162
- userName: CurrentUser.profile.nickName
163
- });
164
- }
165
- if (userProfile) {
166
- this.setUserProfile(userProfile);
151
+ value: function () {
152
+ var _init = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref) {
153
+ var _CurrentUser$profile;
154
+ var userProfile, menuNameMap, routes, getAuth, menuBuild, restConfig;
155
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
156
+ while (1) switch (_context2.prev = _context2.next) {
157
+ case 0:
158
+ userProfile = _ref.userProfile, menuNameMap = _ref.menuNameMap, routes = _ref.routes, getAuth = _ref.getAuth, menuBuild = _ref.menuBuild, restConfig = _objectWithoutProperties(_ref, _excluded);
159
+ this.checkConfig(restConfig);
160
+ this.config = restConfig;
161
+ if (!(routes && menuNameMap)) {
162
+ _context2.next = 6;
163
+ break;
164
+ }
165
+ _context2.next = 6;
166
+ return CurrentUser.init({
167
+ getAuth: getAuth,
168
+ menuBuild: menuBuild,
169
+ menuNameMap: menuNameMap,
170
+ routes: routes
171
+ });
172
+ case 6:
173
+ // 如果对接了权限中心,取权限中心的用户信息
174
+ if ((_CurrentUser$profile = CurrentUser.profile) !== null && _CurrentUser$profile !== void 0 && _CurrentUser$profile.email) {
175
+ this.setUserProfile({
176
+ userId: CurrentUser.profile.userName,
177
+ userName: CurrentUser.profile.nickName
178
+ });
179
+ }
180
+ if (userProfile) {
181
+ this.setUserProfile(userProfile);
182
+ }
183
+ this.mountAutoTask();
184
+ case 9:
185
+ case "end":
186
+ return _context2.stop();
187
+ }
188
+ }, _callee2, this);
189
+ }));
190
+ function init(_x) {
191
+ return _init.apply(this, arguments);
167
192
  }
168
- this.mountAutoTask();
169
- }
170
-
171
- // 推送埋点信息进入队列
193
+ return init;
194
+ }() // 推送埋点信息进入队列
172
195
  }, {
173
196
  key: "pushQueue",
174
197
  value: function pushQueue(_ref2) {
@@ -224,16 +247,27 @@ var Track = /*#__PURE__*/function () {
224
247
  }, {
225
248
  key: "eventLog",
226
249
  value: function eventLog(_eventLog) {
250
+ var copyEventLog = {
251
+ module: '',
252
+ content: ''
253
+ };
227
254
  if (typeof _eventLog === 'string') {
228
255
  var _CurrentUser$authMap;
256
+ var actionLog = (_CurrentUser$authMap = CurrentUser.authMap) === null || _CurrentUser$authMap === void 0 ? void 0 : _CurrentUser$authMap[_eventLog];
257
+ if (actionLog) {
258
+ copyEventLog.content = '触发: ' + actionLog;
259
+ } else {
260
+ copyEventLog.content = _eventLog;
261
+ }
262
+ } else {
263
+ Object.assign(copyEventLog, _eventLog);
264
+ }
265
+ if (!copyEventLog.module) {
229
266
  var routeNames = this.getPageModuleName();
230
- _eventLog = {
231
- module: routeNames.join('-'),
232
- content: '触发: ' + ((_CurrentUser$authMap = CurrentUser.authMap) === null || _CurrentUser$authMap === void 0 ? void 0 : _CurrentUser$authMap[_eventLog])
233
- };
267
+ copyEventLog.module = (routeNames === null || routeNames === void 0 ? void 0 : routeNames.join('-')) || '-';
234
268
  }
235
269
  this.pushQueue({
236
- log: _eventLog,
270
+ log: copyEventLog,
237
271
  type: 'event'
238
272
  });
239
273
  }
@@ -1,4 +1,5 @@
1
- export interface TrackConfig {
1
+ import { CurrentUserConfig } from './currentUser.interface';
2
+ export interface TrackConfig extends Partial<CurrentUserConfig> {
2
3
  appId: string;
3
4
  debug?: boolean;
4
5
  autoReportError?: boolean;
@@ -25,7 +26,7 @@ export interface SystemProfile {
25
26
  }
26
27
  export interface CustomizeProfile {
27
28
  content: string;
28
- module: string;
29
+ module?: string;
29
30
  [key: string]: any;
30
31
  }
31
32
  export interface ErrorProfile {
@@ -9,7 +9,7 @@ declare class Track {
9
9
  static getSystemProfile(): SystemProfile;
10
10
  static getUserProfile(): UserProfile;
11
11
  static setUserProfile(userProfile: UserProfile): void;
12
- static init({ userProfile, ...restConfig }: TrackConfig): void;
12
+ static init({ userProfile, menuNameMap, routes, getAuth, menuBuild, ...restConfig }: TrackConfig): Promise<void>;
13
13
  static pushQueue({ type, log, }: {
14
14
  type: TrackType;
15
15
  log: ErrorProfile | CustomizeProfile;
@@ -112,10 +112,25 @@ var Track = class {
112
112
  this.userProfile = userProfile;
113
113
  }
114
114
  // 挂载初始配置
115
- static init({ userProfile, ...restConfig }) {
115
+ static async init({
116
+ userProfile,
117
+ menuNameMap,
118
+ routes,
119
+ getAuth,
120
+ menuBuild,
121
+ ...restConfig
122
+ }) {
116
123
  var _a;
117
124
  this.checkConfig(restConfig);
118
125
  this.config = restConfig;
126
+ if (routes && menuNameMap) {
127
+ await import_CurrentUser.default.init({
128
+ getAuth,
129
+ menuBuild,
130
+ menuNameMap,
131
+ routes
132
+ });
133
+ }
119
134
  if ((_a = import_CurrentUser.default.profile) == null ? void 0 : _a.email) {
120
135
  this.setUserProfile({
121
136
  userId: import_CurrentUser.default.profile.userName,
@@ -171,15 +186,26 @@ var Track = class {
171
186
  // 推送用户触发日志
172
187
  static eventLog(eventLog) {
173
188
  var _a;
189
+ const copyEventLog = {
190
+ module: "",
191
+ content: ""
192
+ };
174
193
  if (typeof eventLog === "string") {
194
+ const actionLog = (_a = import_CurrentUser.default.authMap) == null ? void 0 : _a[eventLog];
195
+ if (actionLog) {
196
+ copyEventLog.content = "触发: " + actionLog;
197
+ } else {
198
+ copyEventLog.content = eventLog;
199
+ }
200
+ } else {
201
+ Object.assign(copyEventLog, eventLog);
202
+ }
203
+ if (!copyEventLog.module) {
175
204
  const routeNames = this.getPageModuleName();
176
- eventLog = {
177
- module: routeNames.join("-"),
178
- content: "触发: " + ((_a = import_CurrentUser.default.authMap) == null ? void 0 : _a[eventLog])
179
- };
205
+ copyEventLog.module = (routeNames == null ? void 0 : routeNames.join("-")) || "-";
180
206
  }
181
207
  this.pushQueue({
182
- log: eventLog,
208
+ log: copyEventLog,
183
209
  type: "event"
184
210
  });
185
211
  }
@@ -1,4 +1,5 @@
1
- export interface TrackConfig {
1
+ import { CurrentUserConfig } from './currentUser.interface';
2
+ export interface TrackConfig extends Partial<CurrentUserConfig> {
2
3
  appId: string;
3
4
  debug?: boolean;
4
5
  autoReportError?: boolean;
@@ -25,7 +26,7 @@ export interface SystemProfile {
25
26
  }
26
27
  export interface CustomizeProfile {
27
28
  content: string;
28
- module: string;
29
+ module?: string;
29
30
  [key: string]: any;
30
31
  }
31
32
  export interface ErrorProfile {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yysports/tools",
3
- "version": "0.0.5",
3
+ "version": "0.0.7",
4
4
  "description": "常用工具函数库",
5
5
  "homepage": "https://git.pousheng.com/sport-service-department/pousheng-guard/yysports_tools#readme",
6
6
  "bugs": {