@tmsfe/tms-core 0.0.128 → 0.0.130

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.128",
3
+ "version": "0.0.130",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
package/src/request.js CHANGED
@@ -51,7 +51,7 @@ const getTmsUUID = () => {
51
51
  }
52
52
 
53
53
  return uuid;
54
- }
54
+ };
55
55
 
56
56
  /**
57
57
  * 用于对request请求对象做签名
@@ -165,8 +165,9 @@ const getMycarPubOpenId = () => {
165
165
  return getMycarPubOpenIdProm;
166
166
  }
167
167
 
168
- // 优先用缓存的
169
- const key = 'tms.pubOpenId';
168
+ const { appEnv } = getApp().tms.getEnvInfo();
169
+ // 优先用缓存的,正式环境跟测试环境的不一样
170
+ const key = `tms.pubOpenId.${appEnv}`;
170
171
  const pubOpenId = wx.getStorageSync(key);
171
172
  if (pubOpenId) {
172
173
  getMycarPubOpenIdProm = Promise.resolve(pubOpenId);
@@ -1,250 +0,0 @@
1
- /**
2
- * 由于需要把tms-core从主包中移到vendor分包中使用分包异步化加载,
3
- * 但是很多分包中都会立即调用getApp().tms的接口,为了保证调用不出错,
4
- * 特地新增此代理js,用于在app.js中先挂在到app.tms下,等vendor加载完再替换掉。
5
- * 注意:tms-core有改动都要来这里确认proxy有没有问题。
6
- */
7
-
8
- import syncApi from './syncfnmanager';
9
- import AutoReport from './report/proxy/index';
10
- import md5 from './md5';
11
- import { serialize } from './objUtils';
12
- import { calCoordinateDistance, formatDistance } from './distanceUtils';
13
- import { getNavBarConfigData } from './navbarUtils';
14
- import { compareVersion } from './compareVersion';
15
- import * as uiUtil from './tmsuiUtils';
16
- import * as rpxUtil from './rpx';
17
- import * as stringUtils from './stringUtils';
18
- import * as timeUtils from './timeUtils';
19
- import * as ipxHelper from './ipxHelper';
20
- import * as storage from './storage';
21
- import * as funcUtils from './funcUtils';
22
-
23
- let app = null;
24
- let initOptions = null;
25
- let tmsPromise = null;
26
- let tms = null;
27
- let logger = null;
28
-
29
- function invoke(obj, funcName, args) {
30
- if (obj[funcName]) {
31
- return obj[funcName](...args);
32
- }
33
-
34
- // 非法调用的时候就要及时上报日志,方便解决问题
35
- if (!logger) {
36
- logger = wx.getRealtimeLogManager();
37
- }
38
- const msg = `tms-proxy: Cannot read property ${funcName}`;
39
- logger.addFilterMsg('tms-proxy');
40
- logger.error(msg);
41
- console.error(msg);
42
- return Promise.reject(msg);
43
- }
44
-
45
- function initProxy(appObj, options) {
46
- app = appObj;
47
- initOptions = options;
48
- // 如果是在app.js的onLaunch中调用,则没有getApp().tms为空
49
- const getTms = () => getApp()?.tms || wx.tms;
50
- AutoReport.init({
51
- report: (...data) => {
52
- const tms = getTms();
53
- tms.getReporter().report2(...data);
54
- },
55
- fastReport: (...data) => {
56
- const tms = getTms();
57
- tms.getReporter().fastReport2(...data);
58
- },
59
- });
60
- }
61
-
62
- function awaitTMS() {
63
- if (tmsPromise === null) {
64
- tmsPromise = new Promise((resolve) => {
65
- app.initPromise.then((res) => {
66
- tms = res;
67
- resolve(res);
68
- });
69
- });
70
- }
71
- return tmsPromise;
72
- }
73
-
74
- // 返回Promise的函数,无返回结果的也可以放这里
75
- const asyncFuncs = {};
76
- const asyncFuncNames = [
77
- // 这行是tms-ui的
78
- 'showDrawer', 'hideDrawer', 'showModal', 'hideModal',
79
- // 这行是runtime的
80
- 'getPhone', 'registerPhone', 'login', 'checkLogin', 'getLoginInfo', 'getOpenId', 'getMycarPubOpenId', 'getSinanPubOpenId',
81
- // tms-core
82
- 'setAuthInfo', 'getConfig', 'getApolloConfig', 'navigateToWebview', 'callCloudFunc', 'getEncryptUserInfo',
83
- 'setUserLocation', 'getUserLocation', 'getMpOpenId', 'getOuterOpenId',
84
- ];
85
- asyncFuncNames.forEach((funcName) => {
86
- asyncFuncs[funcName] = function (...args) {
87
- return awaitTMS().then(tms => invoke(tms, funcName, args));
88
- };
89
- });
90
-
91
- // 返回对象的函数,并且对象的所有接口都可以以promise的形式返回
92
- const objFuncs = {};
93
- const objFuncNames = [
94
- 'getLogManager', 'getRealtimeLogManager', 'getReporter', 'getEventDispatcher',
95
- ];
96
- objFuncNames.forEach((funcName) => {
97
- objFuncs[funcName] = function (...args1) {
98
- const ps = awaitTMS().then(tms => invoke(tms, funcName, args1));
99
- return new Proxy({}, {
100
- get(obj, name) {
101
- return function (...args2) {
102
- return ps.then(funcObj => invoke(funcObj, name, args2));
103
- };
104
- },
105
- });
106
- };
107
- });
108
-
109
- // runtime
110
- function getCarManager() {
111
- return {
112
- getCarInfo() {
113
- if (tms) {
114
- return tms.getCarManager().getCarInfo();
115
- }
116
- return wx.getStorageSync('currentCar') || {};
117
- },
118
- setCarInfo(param = {}) {
119
- awaitTMS().then(tms => tms.getCarManager().setCarInfo(param));
120
- },
121
- getCarList() {
122
- return awaitTMS().then(tms => tms.getCarManager().getCarList());
123
- },
124
- };
125
- }
126
-
127
- function getLocationManager() {
128
- let manager = null;
129
- const ps = awaitTMS().then((tms) => {
130
- manager = tms.getLocationManager();
131
- });
132
- let currLoc = null;
133
- const getUserLocation = () => {
134
- if (manager) {
135
- return manager.getUserLocation();
136
- }
137
- return currLoc;
138
- };
139
- const setUserLocation = (loc) => {
140
- if (manager) {
141
- manager.setUserLocation(loc);
142
- } else if (loc && (typeof loc === 'object')) {
143
- currLoc = loc;
144
- ps.then(() => manager.setUserLocation(loc));
145
- }
146
- };
147
- return new Proxy({}, {
148
- get(obj, name) {
149
- if (name === 'getUserLocation') {
150
- return getUserLocation;
151
- }
152
- if (name === 'setUserLocation') {
153
- return setUserLocation;
154
- }
155
- if (name === 'locForNoAuth') {
156
- return {
157
- province: '广东省',
158
- cityCode: '440300',
159
- cityName: '深圳市',
160
- latitude: 22.54286,
161
- longitude: 114.05956,
162
- title: '深圳市民中心',
163
- address: '广东省深圳市福田区福中三路',
164
- };
165
- }
166
- return function (...args) {
167
- return ps.then(() => invoke(manager, name, args));
168
- };
169
- },
170
- });
171
- }
172
-
173
- function createRequest(config = {}) {
174
- let request = null;
175
- const ps = awaitTMS().then((tms) => {
176
- request = tms.createRequest(config);
177
- });
178
- const makeUrl = (path) => {
179
- if (request) {
180
- return request.makeUrl(path);
181
- }
182
- if ((/^http/i).test(path)) {
183
- return path;
184
- }
185
- const host = config?.host || initOptions.defaultHost;
186
- const validHost = (/^http/i).test(host) ? host : `https://${host}`;
187
- return `${validHost}/${path}`;
188
- };
189
- return new Proxy({}, {
190
- get(obj, name) {
191
- if (name === 'makeUrl') {
192
- return makeUrl;
193
- }
194
- return function (...args) {
195
- return ps.then(() => invoke(request, name, args));
196
- };
197
- },
198
- });
199
- }
200
-
201
- function getEnvInfo() {
202
- if (tms) {
203
- return tms.getEnvInfo();
204
- }
205
- const { wxAppId, appVersion, appEnv, client } = initOptions;
206
- return { wxAppId, appVersion, appEnv, client };
207
- }
208
-
209
- function isAppPageExist(...args) {
210
- if (tms) {
211
- return tms.isAppPageExist(...args);
212
- }
213
- return true; // todo: 可能不正确
214
- }
215
-
216
- function getHomePage() {
217
- if (tms) {
218
- return tms.getHomePage();
219
- }
220
- return initOptions.homePage;
221
- }
222
-
223
- const api = {
224
- isProxy: true, // 方便定位问题时判断是否proxy
225
- initProxy,
226
- md5,
227
- getCarManager,
228
- getLocationManager,
229
- serialize,
230
- calCoordinateDistance,
231
- formatDistance,
232
- getNavBarConfigData,
233
- compareVersion,
234
- createRequest,
235
- getEnvInfo,
236
- isAppPageExist,
237
- getHomePage,
238
- storage,
239
- ...rpxUtil,
240
- ...uiUtil,
241
- ...asyncFuncs,
242
- ...objFuncs,
243
- ...syncApi,
244
- ...stringUtils,
245
- ...timeUtils,
246
- ...ipxHelper,
247
- ...funcUtils,
248
- };
249
-
250
- export default api;
@@ -1,19 +0,0 @@
1
- import tmsProxy from './index-proxy';
2
-
3
- describe('tmsProxy', () => {
4
- beforeAll(() => {
5
- tmsProxy.initProxy({
6
- initPromise: new Promise(() => {}),
7
- }, {});
8
- });
9
-
10
- it('tmsProxy.getCarManager test', () => {
11
- const car = tmsProxy.getCarManager();
12
- expect(car).toBeInstanceOf(Object);
13
- });
14
-
15
- it('tmsProxy.createRequest test', () => {
16
- const request = tmsProxy.createRequest();
17
- expect(request).toBeInstanceOf(Object);
18
- });
19
- });