@tmsfe/tms-core 0.0.80 → 0.0.81

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.80",
3
+ "version": "0.0.81",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -45,6 +45,8 @@ function getBaseData(deviceData: IDeviceData): DataItem[] {
45
45
  arr[18] = location.cityName;
46
46
  // 19: f19,当前小程序运行的宿主环境
47
47
  arr[19] = host;
48
+ // 22: f22,小程序启动时的url和参数(与f36一致)
49
+ arr[22] = helper.getLaunchOptions();
48
50
  // 28: f28,sinan、mycar等
49
51
  arr[28] = client;
50
52
  // 29: f29,小程序场景值
@@ -16,19 +16,25 @@ let initOptions: IInitOptions;
16
16
  * 初始化
17
17
  */
18
18
  function init(options: IInitOptions): void {
19
- if (!initOptions) {
20
- initOptions = options;
21
-
22
- // 从上次缓存中读取,方便首次Report可以先带上
23
- const loc = wx.getStorageSync('home.location_city') || wx.getStorageSync('home.city');
24
- deviceData = {
25
- networkType: '',
26
- location: {
27
- province: loc?.province as string,
28
- cityName: loc?.cityName as string,
29
- },
30
- };
19
+ if (initOptions) {
20
+ return;
31
21
  }
22
+
23
+ initOptions = options;
24
+
25
+ // 从上次缓存中读取,方便首次Report可以先带上
26
+ const loc = wx.getStorageSync('home.location_city') || wx.getStorageSync('home.city');
27
+ deviceData = {
28
+ networkType: '',
29
+ location: {
30
+ province: loc?.province as string,
31
+ cityName: loc?.cityName as string,
32
+ },
33
+ };
34
+
35
+ wx.onAppShow((options) => {
36
+ launchOptions = options;
37
+ });
32
38
  }
33
39
 
34
40
  /**
@@ -128,7 +134,7 @@ function getPageInfo(): IPage {
128
134
  let depth: number; // 页面深度
129
135
  // 刚启动时首页未渲染
130
136
  if (pages.length === 0) {
131
- const launch = syncApi.getLaunchOptionsSync() as any;
137
+ const launch = getLaunchOptions();
132
138
  route = launch.path;
133
139
  options = launch.qurey;
134
140
  depth = 1;
@@ -146,12 +152,12 @@ function getPageInfo(): IPage {
146
152
  return { route, options, depth };
147
153
  }
148
154
 
149
- let launchOptions: object | null = null;
155
+ let launchOptions: any = null;
150
156
 
151
157
  /**
152
158
  * 获取小程序启动参数
153
159
  */
154
- function getLaunchOptions(): object {
160
+ function getLaunchOptions(): any {
155
161
  if (launchOptions === null) {
156
162
  launchOptions = syncApi.getLaunchOptionsSync();
157
163
  }
@@ -162,7 +168,7 @@ function getLaunchOptions(): object {
162
168
  * 获取小程序启动时的from参数
163
169
  */
164
170
  function getLaunchFrom(): string {
165
- const obj = syncApi.getLaunchOptionsSync() as any;
171
+ const obj = getLaunchOptions();
166
172
  return obj.query?.from;
167
173
  }
168
174
 
@@ -170,7 +176,7 @@ function getLaunchFrom(): string {
170
176
  * 获取小程序启动场景值
171
177
  */
172
178
  function getAppScene(): number {
173
- const { scene = -1 } = syncApi.getLaunchOptionsSync() as any;
179
+ const { scene = -1 } = getLaunchOptions();
174
180
  return scene;
175
181
  }
176
182
 
@@ -244,6 +250,18 @@ function getCacheDeviceData(): IDeviceData {
244
250
  return deviceData;
245
251
  }
246
252
 
253
+ /**
254
+ * 设置字段到上报的SystemInfo中
255
+ * 用于携带自定义信息区分用户场景,比如新旧首页的区分
256
+ * @param fieldName
257
+ * @param value
258
+ */
259
+ function setSystemField(fieldName: string, value: number | string): void {
260
+ const systemInfo = getSystemInfo();
261
+ // @ts-ignore
262
+ systemInfo[fieldName] = value;
263
+ }
264
+
247
265
  export default {
248
266
  init,
249
267
  getTms,
@@ -260,4 +278,5 @@ export default {
260
278
  dataArrLen,
261
279
  getDeviceData,
262
280
  getCacheDeviceData,
281
+ setSystemField,
263
282
  };
@@ -55,23 +55,11 @@ function fastReport2(...data: any[]): void {
55
55
  }
56
56
  }
57
57
 
58
- /**
59
- * 设置字段到上报的SystemInfo中
60
- * 用于携带自定义信息区分用户场景,比如新旧首页的区分
61
- * @param fieldName
62
- * @param value
63
- */
64
- function setSystemField(fieldName: string, value: number | string): void {
65
- const systemInfo = helper.getSystemInfo();
66
- // @ts-ignore
67
- systemInfo[fieldName] = value;
68
- }
69
-
70
58
  export default {
71
59
  init,
72
60
  report,
73
61
  fastReport,
74
62
  report2,
75
63
  fastReport2,
76
- setSystemField,
64
+ setSystemField: helper.setSystemField,
77
65
  };