@tmsfe/tms-core 0.0.16 → 0.0.20
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/dist/index-proxy.js +2 -2
- package/dist/index.js +48 -5
- package/dist/ipxHelper-c5ab3693.js +543 -0
- package/dist/objUtils-154b94db.js +244 -0
- package/dist/request-f350158c.js +543 -0
- package/dist/request-f8a4745b.js +543 -0
- package/dist/request.js +2 -2
- package/package.json +1 -1
- package/src/index.js +6 -0
- package/src/location/index.ts +44 -0
- package/src/numUtils.js +16 -0
- package/src/objUtils.js +21 -2
- package/src/report.js +2 -2
- package/src/request.js +13 -6
- package/src/stringUtils.js +2 -2
package/src/request.js
CHANGED
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
import md5 from './md5';
|
|
12
12
|
import { getLogManager } from './log';
|
|
13
13
|
import { getEnvInfo, getAuthInfo } from './env';
|
|
14
|
+
import { safeJsonParse } from './objUtils';
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* 用于序列化需要签名的参数
|
|
@@ -20,13 +21,9 @@ import { getEnvInfo, getAuthInfo } from './env';
|
|
|
20
21
|
*/
|
|
21
22
|
const seriesParam = (param) => {
|
|
22
23
|
const keys = Object.keys(param)
|
|
23
|
-
.filter(key => typeof param[key] !== 'undefined')
|
|
24
24
|
.sort();
|
|
25
25
|
const series = keys.map((key) => {
|
|
26
26
|
const val = param[key];
|
|
27
|
-
if (typeof val === 'number' && isNaN(val)) {
|
|
28
|
-
return `${key}null`;
|
|
29
|
-
}
|
|
30
27
|
return `${key}${typeof val === 'object' ? JSON.stringify(val) : val}`;
|
|
31
28
|
});
|
|
32
29
|
return series.join('');
|
|
@@ -76,6 +73,16 @@ const composeParam = async (param = {}, withAuth = true, baseParam = {}) => {
|
|
|
76
73
|
{ ...baseParam },
|
|
77
74
|
{ ...paramsWithAuth },
|
|
78
75
|
);
|
|
76
|
+
// 清理undefined和NaN的参数
|
|
77
|
+
Object.keys(combinedParam)
|
|
78
|
+
.forEach((key) => {
|
|
79
|
+
if (typeof combinedParam[key] === 'number' && isNaN(combinedParam[key])) {
|
|
80
|
+
delete combinedParam[key];
|
|
81
|
+
}
|
|
82
|
+
if (typeof combinedParam[key] === 'undefined') {
|
|
83
|
+
delete combinedParam[key];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
79
86
|
return combinedParam;
|
|
80
87
|
};
|
|
81
88
|
|
|
@@ -248,7 +255,7 @@ export default class Request {
|
|
|
248
255
|
});
|
|
249
256
|
|
|
250
257
|
if (typeof res?.data === 'string') {
|
|
251
|
-
return
|
|
258
|
+
return safeJsonParse(res?.data);
|
|
252
259
|
}
|
|
253
260
|
return res?.data;
|
|
254
261
|
}
|
|
@@ -265,7 +272,7 @@ export default class Request {
|
|
|
265
272
|
const res = await this.createRequestTask(path, param, method, header);
|
|
266
273
|
|
|
267
274
|
if (typeof res?.data === 'string') {
|
|
268
|
-
return
|
|
275
|
+
return safeJsonParse(res?.data);
|
|
269
276
|
}
|
|
270
277
|
|
|
271
278
|
return res?.data;
|
package/src/stringUtils.js
CHANGED
|
@@ -113,8 +113,8 @@ const isValidPlate = (plate) => {
|
|
|
113
113
|
|
|
114
114
|
/**
|
|
115
115
|
* 四舍五入,并返回格式化的字符串
|
|
116
|
-
* 支持保留n位小数,n>=0,如
|
|
117
|
-
* 支持格式化字符串时取出末尾的0,如
|
|
116
|
+
* 支持保留n位小数,n>=0,如 roundStr(1.325, 2)=1.33
|
|
117
|
+
* 支持格式化字符串时取出末尾的0,如roundStr(1.109, 2, true)=1.1
|
|
118
118
|
* @param {any} x 原数字
|
|
119
119
|
* 如果n不是合法数字或者无法转换为合法数字,roundStr结果返回''
|
|
120
120
|
* @param {any} n 保留几位小数,默认0
|