@tmsfe/tms-core 0.0.125 → 0.0.127

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.125",
3
+ "version": "0.0.127",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -64,7 +64,9 @@ function getBaseData(page: IPage, deviceData: IDeviceData): { arr: DataItem[], n
64
64
  arr[25] = page.depth;
65
65
  // 26: f26,一次小程序生命周期中的埋点统一标记
66
66
  arr[26] = helper.getLifeReportKey();
67
- // 27 ~ 30: 预留字段给后续扩展使用
67
+ // 27: f27,生成用户唯一id,方便追踪未登录接口
68
+ arr[27] = helper.getTmsUUID();
69
+ // 28 ~ 30: 预留字段给后续扩展使用
68
70
  // 31 ~ 40: 提供给开发自定义
69
71
  // --------------------------字段列表--------------------------
70
72
  return { arr, nextIndex: 31 };
@@ -103,6 +103,31 @@ function getNowString(): string {
103
103
  return `${year}${month}${day}${hours}${minutes}${seconds}${ms}`;
104
104
  }
105
105
 
106
+ let uuid = '';
107
+
108
+ /**
109
+ * 生成用户唯一id,方便追踪未登录接口
110
+ */
111
+ function getTmsUUID(): string {
112
+ if (uuid) {
113
+ return uuid;
114
+ }
115
+
116
+ const key = 'tms.user.uuid';
117
+ uuid = wx.getStorageSync(key);
118
+ if (!uuid) {
119
+ const str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
120
+ uuid = str.replace(/[xy]/g, (c) => {
121
+ const r = (Math.random() * 16) | 0;
122
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
123
+ return v.toString(16);
124
+ });
125
+ wx.setStorageSync(key, uuid);
126
+ }
127
+
128
+ return uuid;
129
+ }
130
+
106
131
  let lifeReportKey = '';
107
132
 
108
133
  /**
@@ -181,7 +206,7 @@ function getAppScene(): number {
181
206
  let isCrawler: boolean | null = null;
182
207
 
183
208
  /**
184
- * 判断当前是否需要发埋点(爬虫和插件页不发)
209
+ * 判断当前是否需要发埋点(爬虫和插自动化测试下打开的不发)
185
210
  */
186
211
  function canReport(): boolean {
187
212
  if (isCrawler === null) {
@@ -271,6 +296,7 @@ function post(api: string, params: any): Promise<{ errCode: number, errMsg: stri
271
296
  export default {
272
297
  init,
273
298
  post,
299
+ getTmsUUID,
274
300
  getClientName,
275
301
  getAppVersion,
276
302
  getSystemInfo,
package/src/request.js CHANGED
@@ -30,6 +30,29 @@ const seriesParam = (param) => {
30
30
  return series.join('');
31
31
  };
32
32
 
33
+ let uuid = '';
34
+
35
+ // 生成用户唯一id,方便追踪未登录接口
36
+ const getTmsUUID = () => {
37
+ if (uuid) {
38
+ return uuid;
39
+ }
40
+
41
+ const key = 'tms.user.uuid';
42
+ uuid = wx.getStorageSync(key);
43
+ if (!uuid) {
44
+ const str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
45
+ uuid = str.replace(/[xy]/g, (c) => {
46
+ const r = (Math.random() * 16) | 0;
47
+ const v = c === 'x' ? r : (r & 0x3) | 0x8;
48
+ return v.toString(16);
49
+ });
50
+ wx.setStorageSync(key, uuid);
51
+ }
52
+
53
+ return uuid;
54
+ }
55
+
33
56
  /**
34
57
  * 用于对request请求对象做签名
35
58
  * @private
@@ -70,6 +93,7 @@ const composeParam = async (param = {}, withAuth = true, baseParam = {}) => {
70
93
  timestamp,
71
94
  seqId,
72
95
  wxAppId,
96
+ tmsUUID: getTmsUUID(),
73
97
  },
74
98
  { ...baseParam },
75
99
  { ...paramsWithAuth },
@@ -44,7 +44,10 @@ const loginFn = async () => {
44
44
  if (!wx.tmsLoginPromise) {
45
45
  // eslint-disable-next-line @typescript-eslint/no-misused-promises
46
46
  wx.tmsLoginPromise = new Promise(async (resolve) => {
47
- let userInfo = {} as any;
47
+ let userInfo = {
48
+ // todo: 临时加代码用于分析问题
49
+ token: 'tms-login-fail',
50
+ } as any;
48
51
  try {
49
52
  let userData = await login();
50
53
  if (userData.errCode === 10 || !userData.resData.userInfo || !userData.resData.userInfo.uid) {