@tmsfe/tms-core 0.0.78 → 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.78",
3
+ "version": "0.0.81",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -11,6 +11,7 @@ import md5 from './md5';
11
11
  import { serialize } from './objUtils';
12
12
  import { calCoordinateDistance, formatDistance } from './distanceUtils';
13
13
  import { getNavBarConfigData } from './navbarUtils';
14
+ import * as uiUtil from './tmsuiUtils';
14
15
  import * as rpxUtil from './rpx';
15
16
  import * as stringUtils from './stringUtils';
16
17
  import * as timeUtils from './timeUtils';
@@ -221,6 +222,7 @@ const api = {
221
222
  getHomePage,
222
223
  storage,
223
224
  ...rpxUtil,
225
+ ...uiUtil,
224
226
  ...asyncFuncs,
225
227
  ...objFuncs,
226
228
  ...syncApi,
package/src/index.js CHANGED
@@ -45,6 +45,7 @@ import getLocInstance from './location/index';
45
45
  import LocationBase from './location/base';
46
46
  import { getMpOpenId, getOuterOpenId, getEncryptUserInfo } from './mpInfo';
47
47
  import * as storage from './storage';
48
+ import * as uiUtil from './tmsuiUtils';
48
49
  import { throttle, debounce } from './funcUtils';
49
50
 
50
51
  /**
@@ -200,6 +201,7 @@ const api = {
200
201
  storage,
201
202
 
202
203
  ...syncApi,
204
+ ...uiUtil,
203
205
  throttle,
204
206
  debounce,
205
207
  };
@@ -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
  };
@@ -163,7 +163,7 @@ function proxySubscribeMessage(): void {
163
163
  // eslint-disable-next-line
164
164
  options.fail = function(err: any) {
165
165
  helper.reportData('wx_requestSubscribeMessage_fail', tmplIds, err.errMsg);
166
- originalFail.fail(this, err);
166
+ originalFail.call(this, err);
167
167
  };
168
168
  originalApi.call(this, options);
169
169
  },
@@ -0,0 +1,68 @@
1
+
2
+ /**
3
+ * 从当前页面中选定组件
4
+ * @param {String} selector 元素选择器
5
+ * @returns {Element} 组件
6
+ */
7
+ const selectCompFromCurPage = (selector) => {
8
+ const pages = getCurrentPages();
9
+ if (pages.length === 0) {
10
+ throw new Error('Empty page container found');
11
+ }
12
+
13
+ const context = pages[pages.length - 1];
14
+ const comp = context.selectComponent(selector);
15
+ if (!comp) {
16
+ throw new Error(`No component found with selector <${selector}>`);
17
+ }
18
+ return comp;
19
+ };
20
+
21
+ /* eslint-disable */
22
+ const showDrawer = (options = {}, selectComp = selectCompFromCurPage) => {
23
+ const { selector = '#drawer' } = options;
24
+ const comp = selectComp(selector);
25
+ comp?.show(options);
26
+ };
27
+ const hideDrawer = (options = {}, selectComp = selectCompFromCurPage) => {
28
+ const { selector = '#drawer' } = options;
29
+ const comp = selectComp(selector);
30
+ comp?.hide(options);
31
+ };
32
+ /* eslint-disable */
33
+
34
+ /**
35
+ * 显示或隐藏Modal
36
+ * @param {Boolean} display 展示/隐藏
37
+ * @param {Object} options Modal参数
38
+ * @param {Function} selectComp 选择组件的方法
39
+ * @returns {void}
40
+ */
41
+ const toggleModal = (display = true, options = {}, selectComp) => {
42
+ const { selector = '#modal' } = options;
43
+ try {
44
+ const comp = selectComp(selector);
45
+ if (display) {
46
+ comp.show(options);
47
+ } else {
48
+ comp.hide(options);
49
+ }
50
+ } catch (e) {
51
+ if (typeof options.fail === 'function') {
52
+ options.fail({ errMsg: e.toString() });
53
+ } else {
54
+ throw e;
55
+ }
56
+ if (typeof options.complete === 'function') {
57
+ options.complete({ success: false, errMsg: e.toString() });
58
+ }
59
+ }
60
+ };
61
+
62
+ const showModal = (options, selectComp = selectCompFromCurPage) => toggleModal(true, options, selectComp);
63
+ const hideModal = (options, selectComp = selectCompFromCurPage) => toggleModal(false,options, selectComp);
64
+
65
+ module.exports = {
66
+ showDrawer, hideDrawer,
67
+ showModal, hideModal,
68
+ };