@tmsfe/tms-core 0.0.111 → 0.0.113
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 +1 -1
- package/src/location/index.ts +41 -41
- package/src/request.js +50 -40
package/package.json
CHANGED
package/src/location/index.ts
CHANGED
|
@@ -55,19 +55,19 @@ let ipLocationPromise: null | Promise<IpLocationType> = null; // ip定位请求
|
|
|
55
55
|
*/
|
|
56
56
|
class Location extends LocationBase {
|
|
57
57
|
/**
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
58
|
+
* @desc 默认位置信息
|
|
59
|
+
* @property {object} locForNoAuth 默认的位置信息
|
|
60
|
+
* @property {string} locForNoAuth.privince 省份信息
|
|
61
|
+
* @property {string} locForNoAuth.cityCode 城市编码
|
|
62
|
+
* @property {string} locForNoAuth.cityName 城市名称
|
|
63
|
+
* @property {string} locForNoAuth.district 地区名称
|
|
64
|
+
* @property {string} locForNoAuth.latitude 维度
|
|
65
|
+
* @property {string} locForNoAuth.longitude 经度
|
|
66
|
+
* @example
|
|
67
|
+
* const app = getApp({ allowDefault: true });
|
|
68
|
+
* const locationManager = app.tms.getLocationManager(); // 获取位置管理器
|
|
69
|
+
* console.log(locationManager.locForNoAuth) // 获取默认位置
|
|
70
|
+
*/
|
|
71
71
|
public locForNoAuth = {
|
|
72
72
|
province: '广东省',
|
|
73
73
|
cityCode: '440300',
|
|
@@ -133,7 +133,7 @@ class Location extends LocationBase {
|
|
|
133
133
|
|
|
134
134
|
return Promise.reject(res);
|
|
135
135
|
})
|
|
136
|
-
|
|
136
|
+
.catch(err => Promise.reject(err));
|
|
137
137
|
|
|
138
138
|
return userLocationCache[cacheName];
|
|
139
139
|
}
|
|
@@ -175,13 +175,13 @@ class Location extends LocationBase {
|
|
|
175
175
|
*/
|
|
176
176
|
getLocationDetail(showModalWhenCloseAuth = false, type = LocationType, content = '', getPoi = 0) {
|
|
177
177
|
return this.getLocation(showModalWhenCloseAuth, type, content)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
178
|
+
.then(async (res: WxPostionType) => {
|
|
179
|
+
const res2 = await this.getPoiInfo(res.latitude, res.longitude, getPoi);
|
|
180
|
+
// @ts-ignore
|
|
181
|
+
res2.accuracy = res.accuracy;
|
|
182
|
+
return res2;
|
|
183
|
+
})
|
|
184
|
+
.catch(err => Promise.reject(err));
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
/**
|
|
@@ -216,13 +216,13 @@ class Location extends LocationBase {
|
|
|
216
216
|
*/
|
|
217
217
|
getLocationDetailSilent(getPoi = 0, type = 'gcj02') {
|
|
218
218
|
return this.getLocationSilent(type)
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
219
|
+
.then(async (res: WxPostionType) => {
|
|
220
|
+
const res2 = await this.getPoiInfo(res.latitude, res.longitude, getPoi);
|
|
221
|
+
// @ts-ignore
|
|
222
|
+
res2.accuracy = res.accuracy;
|
|
223
|
+
return res2;
|
|
224
|
+
})
|
|
225
|
+
.catch(err => Promise.reject(err));
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
/**
|
|
@@ -239,7 +239,7 @@ class Location extends LocationBase {
|
|
|
239
239
|
* longitude: 116.2545454,
|
|
240
240
|
* adCode: 1212144,
|
|
241
241
|
* }
|
|
242
|
-
|
|
242
|
+
*/
|
|
243
243
|
getUserLocation(): PostionType | undefined {
|
|
244
244
|
return userLocation;
|
|
245
245
|
}
|
|
@@ -337,18 +337,18 @@ class Location extends LocationBase {
|
|
|
337
337
|
if (ipLocationPromise === null || force) {
|
|
338
338
|
ipLocationPromise = new Promise((resolve, reject) => {
|
|
339
339
|
request.post('basic/lbs/decodeip')
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
340
|
+
.then((res) => {
|
|
341
|
+
if (res.errCode === 0) {
|
|
342
|
+
resolve(res.resData as IpLocationType);
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
reject({ erMsg: res.errMsg });
|
|
346
|
+
ipLocationPromise = null;
|
|
347
|
+
})
|
|
348
|
+
.catch((e) => {
|
|
349
|
+
reject(e);
|
|
350
|
+
ipLocationPromise = null;
|
|
351
|
+
});
|
|
352
352
|
});
|
|
353
353
|
}
|
|
354
354
|
return ipLocationPromise;
|
package/src/request.js
CHANGED
|
@@ -22,7 +22,7 @@ const logger = wx.getLogManager({});
|
|
|
22
22
|
*/
|
|
23
23
|
const seriesParam = (param) => {
|
|
24
24
|
const keys = Object.keys(param)
|
|
25
|
-
|
|
25
|
+
.sort();
|
|
26
26
|
const series = keys.map((key) => {
|
|
27
27
|
const val = param[key];
|
|
28
28
|
return `${key}${typeof val === 'object' ? JSON.stringify(val) : val}`;
|
|
@@ -53,12 +53,12 @@ const composeParam = async (param = {}, withAuth = true, baseParam = {}) => {
|
|
|
53
53
|
const version = '1.0';
|
|
54
54
|
const { appVersion, wxAppId, client } = getEnvInfo();
|
|
55
55
|
const nonce = Math.random()
|
|
56
|
-
|
|
57
|
-
|
|
56
|
+
.toString(36)
|
|
57
|
+
.substr(2, 10);
|
|
58
58
|
const timestamp = Date.now();
|
|
59
59
|
const random = Math.random()
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
.toString()
|
|
61
|
+
.slice(2, 7);
|
|
62
62
|
const sourceId = ['', 'sinan', 'mycar'].indexOf(client) + 7; // 6 未知 7 云函数 8 出行 9 我的车
|
|
63
63
|
const seqId = `${timestamp}${sourceId}${random}`;
|
|
64
64
|
const paramsWithAuth = await modifyAuthParam(param, withAuth);
|
|
@@ -76,14 +76,14 @@ const composeParam = async (param = {}, withAuth = true, baseParam = {}) => {
|
|
|
76
76
|
);
|
|
77
77
|
// 清理undefined和NaN的参数
|
|
78
78
|
Object.keys(combinedParam)
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
79
|
+
.forEach((key) => {
|
|
80
|
+
if (typeof combinedParam[key] === 'number' && isNaN(combinedParam[key])) {
|
|
81
|
+
delete combinedParam[key];
|
|
82
|
+
}
|
|
83
|
+
if (typeof combinedParam[key] === 'undefined') {
|
|
84
|
+
delete combinedParam[key];
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
87
|
return combinedParam;
|
|
88
88
|
};
|
|
89
89
|
|
|
@@ -312,42 +312,52 @@ export default class Request {
|
|
|
312
312
|
const requestParam = await composeParam(param, this.withAuth, this.baseParam);
|
|
313
313
|
const data = sign(requestParam);
|
|
314
314
|
return new Promise((resolve, reject) => {
|
|
315
|
+
|
|
316
|
+
const requestTime = Date.now();
|
|
317
|
+
const printLog = (isSuccess, res) => {
|
|
318
|
+
// 埋点已经单独打日志了,接口请求数据日志太长影响分析
|
|
319
|
+
if (path.indexOf('basic/event/upload') !== -1) {
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
let result = JSON.stringify(res);
|
|
324
|
+
// 打车日志不截断,方便用于回放
|
|
325
|
+
if (isSuccess && path.indexOf('/takecar/') === -1 && result.length > 500) {
|
|
326
|
+
result = `${result.substring(0, 500)} 内容太长被截断`;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
const obj = {
|
|
330
|
+
path,
|
|
331
|
+
method,
|
|
332
|
+
header: JSON.stringify(header),
|
|
333
|
+
params: JSON.stringify(data),
|
|
334
|
+
duration: Date.now() - requestTime,
|
|
335
|
+
};
|
|
336
|
+
if (isSuccess) {
|
|
337
|
+
obj.res = result;
|
|
338
|
+
} else {
|
|
339
|
+
obj.err = result;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
const str = JSON.stringify(obj, null, ' ').replace(/\\"/ig, '\'');
|
|
343
|
+
if (isSuccess) {
|
|
344
|
+
logger.log(`接口请求成功:\n${str}`);
|
|
345
|
+
} else {
|
|
346
|
+
logger.warn(`接口请求失败:\n${str}`);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
|
|
315
350
|
wx.request({
|
|
316
351
|
url: this.makeUrl(path),
|
|
317
352
|
header,
|
|
318
353
|
method,
|
|
319
354
|
data,
|
|
320
355
|
success: (res) => {
|
|
321
|
-
|
|
322
|
-
if (path.indexOf('basic/event/upload') === -1) {
|
|
323
|
-
let result = JSON.stringify(res?.data);
|
|
324
|
-
if (result.length > 500) {
|
|
325
|
-
result = `${result.substring(0, 500)} 内容太长被截断`;
|
|
326
|
-
}
|
|
327
|
-
const obj = {
|
|
328
|
-
path,
|
|
329
|
-
method,
|
|
330
|
-
header: JSON.stringify(header),
|
|
331
|
-
params: JSON.stringify(data),
|
|
332
|
-
res: result,
|
|
333
|
-
};
|
|
334
|
-
const str = JSON.stringify(obj, null, ' ').replace(/\\"/ig, '\'');
|
|
335
|
-
logger.log(`接口请求成功:\n${str}`);
|
|
336
|
-
}
|
|
337
|
-
|
|
356
|
+
printLog(true, res.data);
|
|
338
357
|
resolve(res);
|
|
339
358
|
},
|
|
340
359
|
fail: (err) => {
|
|
341
|
-
|
|
342
|
-
path,
|
|
343
|
-
method,
|
|
344
|
-
header: JSON.stringify(header),
|
|
345
|
-
params: JSON.stringify(data),
|
|
346
|
-
err: JSON.stringify(err),
|
|
347
|
-
};
|
|
348
|
-
const str = JSON.stringify(obj, null, ' ').replace(/\\"/ig, '\'');
|
|
349
|
-
logger.warn(`接口请求失败:\n${str}`);
|
|
350
|
-
|
|
360
|
+
printLog(false, err);
|
|
351
361
|
reject(err);
|
|
352
362
|
},
|
|
353
363
|
});
|