@tmsfe/tms-core 0.0.19 → 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 +19 -3
- package/dist/ipxHelper-c5ab3693.js +543 -0
- package/dist/objUtils-154b94db.js +244 -0
- package/dist/request-f8a4745b.js +543 -0
- package/dist/request.js +2 -2
- package/package.json +1 -1
package/dist/index-proxy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { m as md5 } from './
|
|
1
|
+
import { o as rpxToPx, s as syncApi, p as stringUtils, t as timeUtils, q as ipxHelper } from './ipxHelper-c5ab3693.js';
|
|
2
|
+
import { m as md5, s as serialize } from './objUtils-154b94db.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 由于需要把tms-core、tms-runtime从主包中移到vendor分包中使用分包异步化加载,
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { R as Request, g as getLogManager, a as getRealtimeLogManager } from './request-
|
|
1
|
+
import { R as Request, g as getLogManager, a as getRealtimeLogManager } from './request-f8a4745b.js';
|
|
2
2
|
import { g as getEnvInfo, a as getAuthInfo, s as setAuthInfo, i as isAppPageExist, b as getHomePage, c as setEnvInfo, d as setAppPagePaths } from './env-c7da70e1.js';
|
|
3
|
-
import { s as syncApi, f as formatPlate, a as subStr, h as hidePhoneCenter, i as isValidPhone, b as isValidPlate, c as isValidAuthCode,
|
|
4
|
-
import { m as md5 } from './
|
|
3
|
+
import { s as syncApi, r as roundStr, f as formatPlate, a as subStr, h as hidePhoneCenter, i as isValidPhone, b as isValidPlate, c as isValidAuthCode, d as formatTime, e as formatTimeStr, g as formatTimeWithDetails, j as dateToString, k as ipxInit, l as isIPX, m as getIpxClass, n as getIpxConfig, o as rpxToPx } from './ipxHelper-c5ab3693.js';
|
|
4
|
+
import { m as md5, s as serialize } from './objUtils-154b94db.js';
|
|
5
5
|
import { callCloudFunc } from './cloudService.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1532,6 +1532,19 @@ const startListenApp = () => {
|
|
|
1532
1532
|
});
|
|
1533
1533
|
};
|
|
1534
1534
|
|
|
1535
|
+
/**
|
|
1536
|
+
* 四舍五入(支持保留n位小数,n>=0)
|
|
1537
|
+
* @param {any} x 原数字
|
|
1538
|
+
* 如果n不是合法数字或者无法转换为合法数字,round结果返回NaN
|
|
1539
|
+
* @param {any} n 保留几位小数,默认0
|
|
1540
|
+
* 如果n不是合法数字或者无法转换为合法数字,round结果返回NaN
|
|
1541
|
+
* 如果n小于0,round结果返回NaN
|
|
1542
|
+
* 如果n的值包含小数部分,round处理时只关注n的整数部分值
|
|
1543
|
+
* @return {number} 返回一个保留n位小数的数字,异常情况下可能是NaN
|
|
1544
|
+
*/
|
|
1545
|
+
|
|
1546
|
+
const round = (x, n = 0) => parseFloat(roundStr(x, n, false));
|
|
1547
|
+
|
|
1535
1548
|
/**
|
|
1536
1549
|
* 支持服务接入相关接口
|
|
1537
1550
|
*/
|
|
@@ -1719,6 +1732,9 @@ const api = {
|
|
|
1719
1732
|
isValidAuthCode,
|
|
1720
1733
|
roundStr,
|
|
1721
1734
|
|
|
1735
|
+
/* 数字方法 */
|
|
1736
|
+
round,
|
|
1737
|
+
|
|
1722
1738
|
/* 时间方法 */
|
|
1723
1739
|
formatTime,
|
|
1724
1740
|
formatTimeStr,
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 本文件负责对小程序调用wx同步方法的管理
|
|
3
|
+
*/
|
|
4
|
+
let systemInfo = null; // 系统信息。
|
|
5
|
+
|
|
6
|
+
let launchOptions = null; // 启动参数
|
|
7
|
+
|
|
8
|
+
let accountInfo = null; // 小程序账号信息
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 获取系统信息。同wx.getSystemInfoSync
|
|
12
|
+
* @returns {Object} 系统信息
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const getSystemInfoSync = () => {
|
|
16
|
+
if (systemInfo) {
|
|
17
|
+
return systemInfo;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
systemInfo = wx.getSystemInfoSync();
|
|
22
|
+
return systemInfo;
|
|
23
|
+
} catch (_) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* 重置系统信息,仅用于单元测试
|
|
29
|
+
* @returns {undefined}
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
const resetSystemInfoSync = () => {
|
|
34
|
+
systemInfo = null;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* 获取启动参数。同wx.getLaunchOptionsSync
|
|
38
|
+
* @returns {Object} 启动参数
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
const getLaunchOptionsSync = () => {
|
|
43
|
+
if (launchOptions) {
|
|
44
|
+
return launchOptions;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
try {
|
|
48
|
+
launchOptions = wx.getLaunchOptionsSync();
|
|
49
|
+
return launchOptions;
|
|
50
|
+
} catch (_) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* 获取客户端平台。同wx.getSystemInfoSync().platform
|
|
56
|
+
* @returns {String} 平台名称
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
const getPlatform = () => {
|
|
61
|
+
const UNKNOWN = 'unknown';
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const systemInfo = getSystemInfoSync();
|
|
65
|
+
const {
|
|
66
|
+
platform
|
|
67
|
+
} = systemInfo;
|
|
68
|
+
return platform || UNKNOWN;
|
|
69
|
+
} catch (_) {
|
|
70
|
+
return UNKNOWN;
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* 获取字符串类型的启动参数
|
|
75
|
+
* @returns {String} 序列化的参数字符串
|
|
76
|
+
*/
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
const getLaunchParamOfString = () => {
|
|
80
|
+
try {
|
|
81
|
+
const options = getLaunchOptionsSync() || {};
|
|
82
|
+
return JSON.stringify(options);
|
|
83
|
+
} catch (_) {
|
|
84
|
+
return '';
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* @description 获取小程序账号信息
|
|
89
|
+
* @returns {Object} 小程序账号信息,返回内容同wx.getAccountInfoSync()
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
const getAccountInfoSync = () => {
|
|
94
|
+
if (accountInfo) {
|
|
95
|
+
return accountInfo;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
accountInfo = wx.getAccountInfoSync();
|
|
100
|
+
return accountInfo;
|
|
101
|
+
} catch (_) {
|
|
102
|
+
return {};
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
const obj = {
|
|
106
|
+
getPlatform,
|
|
107
|
+
getSystemInfoSync,
|
|
108
|
+
getLaunchOptionsSync,
|
|
109
|
+
getLaunchParamOfString,
|
|
110
|
+
resetSystemInfoSync,
|
|
111
|
+
getAccountInfoSync
|
|
112
|
+
};
|
|
113
|
+
var syncApi = obj;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @description rpx to px
|
|
117
|
+
* @param {Number} rpx 需要转换的rpx数值
|
|
118
|
+
* @returns {Number} 转换后的rpx数值
|
|
119
|
+
*/
|
|
120
|
+
|
|
121
|
+
const rpxToPx = rpx => {
|
|
122
|
+
const sys = syncApi.getSystemInfoSync();
|
|
123
|
+
const ww = sys.windowWidth;
|
|
124
|
+
const ratio = ww / 750;
|
|
125
|
+
return rpx * ratio;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* 字符串截断,处理时按可见字符长度进行截断
|
|
130
|
+
* 可见字符的含义是指:字母、数字、汉字、表情等均等价于一个字符
|
|
131
|
+
* @param {String} str - 原始字符串
|
|
132
|
+
* @param {Number} maxLen - 字符串截断后的最大长度
|
|
133
|
+
* @returns {String} 截断后的字符串;如果确实进行了截断,在最后面加'...';
|
|
134
|
+
*/
|
|
135
|
+
const subStr = (str, maxLen) => {
|
|
136
|
+
// 按照码点(codePoint),把原始字符串的前maxLen+1个字符放到chars数组中
|
|
137
|
+
const chars = [];
|
|
138
|
+
|
|
139
|
+
for (const codePoint of str) {
|
|
140
|
+
// eslint-disable-line
|
|
141
|
+
chars.push(codePoint);
|
|
142
|
+
if (chars.length > maxLen) break;
|
|
143
|
+
} // 如果可见字符数量小于等于字符串截断后的最大长度,无需截断,返回原始字符串
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
if (chars.length <= maxLen) {
|
|
147
|
+
return str;
|
|
148
|
+
} // 可见字符数量多于字符串截断后的最大长度,需要截断,并在末尾添加...
|
|
149
|
+
// 注意,此时返回的字符串是 maxLen-2个可见字符 + ...(maxLen-2是因为...占用2个汉字字符位置)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
return `${chars.splice(0, maxLen - 2).join('')}...`;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* 手机号处理,隐藏中间部分位数
|
|
156
|
+
* 隐藏规则:假设隐藏部分位数后,手机号由ABC构成,其中A、C是可见部分,B是隐藏部分
|
|
157
|
+
* 1. 隐藏部分(B)占手机号总位数的1/3,且隐藏部分的位数向上取整
|
|
158
|
+
* 2. 不被隐藏的部分(A、C)要均匀分布在隐藏部分(B)的两侧,即尽量使AC等长
|
|
159
|
+
* 3. 如果不隐藏部分(A、C)长度无法等长,则使C多显示一位
|
|
160
|
+
* @param {String} phone 手机号
|
|
161
|
+
* @returns {String} 隐藏后的手机号
|
|
162
|
+
*/
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
const hidePhoneCenter = phone => {
|
|
166
|
+
const len = phone && phone.length;
|
|
167
|
+
|
|
168
|
+
if (!len) {
|
|
169
|
+
return '';
|
|
170
|
+
} // 各部分位数
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
const center = Math.ceil(len / 3);
|
|
174
|
+
const left = Math.floor((len - center) / 2);
|
|
175
|
+
const right = len - center - left; // 各部分字符串
|
|
176
|
+
|
|
177
|
+
const centerStr = phone.substr(left, center).replace(/./g, '*');
|
|
178
|
+
const leftStr = phone.substr(0, left);
|
|
179
|
+
const rightStr = phone.substr(-right);
|
|
180
|
+
return `${leftStr}${centerStr}${rightStr}`;
|
|
181
|
+
};
|
|
182
|
+
/**
|
|
183
|
+
* 格式化车牌
|
|
184
|
+
* 例如:京A12345 -> 京A·12345
|
|
185
|
+
* @param {String} plate 车牌号
|
|
186
|
+
* @returns {String} 格式化后的车牌号
|
|
187
|
+
*/
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
const formatPlate = plate => {
|
|
191
|
+
if (!plate || typeof plate !== 'string') {
|
|
192
|
+
return '';
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (plate.length <= 2 || /·/.test(plate)) {
|
|
196
|
+
return plate;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return `${plate.substring(0, 2)}·${plate.substring(2)}`;
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* 检查手机号是否合法
|
|
203
|
+
* @param {String} phone 手机号
|
|
204
|
+
* @returns {Boolean} 手机号是否合法
|
|
205
|
+
*/
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
const isValidPhone = phone => /^1[\d]{10}$/.test(phone);
|
|
209
|
+
/**
|
|
210
|
+
* 检查验证码是否合法
|
|
211
|
+
* @param {String} code 验证码
|
|
212
|
+
* @returns {Boolean} 验证码是否合法
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
const isValidAuthCode = code => /^[\d]{6}$/.test(code);
|
|
217
|
+
|
|
218
|
+
const validPlateFirstLetters = ['京', '津', '冀', '晋', '蒙', '辽', '吉', '黑', '沪', '苏', '浙', '皖', '闽', '赣', '鲁', '豫', '鄂', '湘', '粤', '桂', '琼', '渝', '川', '贵', '云', '藏', '陕', '甘', '青', '宁', '新', '使', '领'];
|
|
219
|
+
/**
|
|
220
|
+
* 检查车牌是否合法
|
|
221
|
+
* @param {String} plate 车牌
|
|
222
|
+
* @returns {Boolean} 车牌是否合法
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
const isValidPlate = plate => {
|
|
226
|
+
if (!plate || typeof plate !== 'string') {
|
|
227
|
+
return false;
|
|
228
|
+
} // 检查首位是否是合法的汉字
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
const [firstLetter] = plate;
|
|
232
|
+
|
|
233
|
+
if (validPlateFirstLetters.indexOf(firstLetter) === -1) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
if (!/[使领警学]/.test(plate)) {
|
|
238
|
+
// 普通车牌
|
|
239
|
+
const number = plate.substring(1);
|
|
240
|
+
return /^[a-zA-Z][0-9a-zA-Z]{5}$/.test(number) // 第一位是字母,后面5位是字母或数字
|
|
241
|
+
|| /^[a-zA-Z][a-zA-Z][0-9a-zA-Z]{5}$/.test(number) // 第一位是字母,第二位是字母,后面再跟5位字母或数字(新能源小车)
|
|
242
|
+
|| /^[a-zA-Z][0-9a-zA-Z]{5}[a-zA-Z]$/.test(number) // 第一位是字母,最后一位是字母,中间5位字母或数字(新能源大车)
|
|
243
|
+
|| /^粤Z[0-9a-zA-Z]{4,5}[港澳]{1}/.test(plate); // 广东港澳两地车牌
|
|
244
|
+
} // return /^[^使领警学]{1}[a-zA-Z][0-9a-zA-Z]{3,4}[使领警学]{1}$/.test(plate) || // 使/领/警/学车牌
|
|
245
|
+
// /^[使领]{1}[0-9a-zA-Z]{5}$/.test(plate); // 使馆领事馆特殊车牌
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
return false;
|
|
249
|
+
};
|
|
250
|
+
/**
|
|
251
|
+
* 四舍五入,并返回格式化的字符串
|
|
252
|
+
* 支持保留n位小数,n>=0,如 roundStr(1.325, 2)=1.33
|
|
253
|
+
* 支持格式化字符串时取出末尾的0,如roundStr(1.109, 2, true)=1.1
|
|
254
|
+
* @param {any} x 原数字
|
|
255
|
+
* 如果n不是合法数字或者无法转换为合法数字,roundStr结果返回''
|
|
256
|
+
* @param {any} n 保留几位小数,默认0
|
|
257
|
+
* 如果n不是合法数字或者无法转换为合法数字,roundStr结果返回''
|
|
258
|
+
* 如果n小于0,roundStr结果返回''
|
|
259
|
+
* 如果n的值包含小数部分,roundStr处理时只关注n的整数部分值
|
|
260
|
+
* @param {boolean} removeTrailingZero 是否移除字符串末尾的无效数字0
|
|
261
|
+
* @returns {string} 返回四舍五入后的字符串,异常情况下返回空字符串''
|
|
262
|
+
*/
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
const roundStr = (x, n = 2, removeTrailingZero = false) => {
|
|
266
|
+
let xNum = Number(x); // x转换为数字
|
|
267
|
+
|
|
268
|
+
const nNum = Math.floor(Number(n)); // n转换为数字,且只保留整数部分
|
|
269
|
+
// 异常情况,返回''
|
|
270
|
+
|
|
271
|
+
if (isNaN(xNum) || isNaN(nNum) || nNum < 0) return ''; // 仅保留整数的情况
|
|
272
|
+
|
|
273
|
+
if (nNum === 0) return Math.round(xNum); // 保留n位小数的情况
|
|
274
|
+
|
|
275
|
+
const xStr = xNum.toString();
|
|
276
|
+
const rexExp = new RegExp(`\\.\\d{${nNum}}5`); // 1. 大部分情况下,四舍五入使用Number.toFixed即可
|
|
277
|
+
// 2. 然而,Number.toFixed方法在某些情况下对第n+1位是5的四舍五入存在问题,如1.325保留2小数时结果为1.32(期望为1.33)
|
|
278
|
+
// 对此种情况下,有两种处理方式:
|
|
279
|
+
// 2.1 先扩大10^n倍,舍掉小数部分取整数部分,然后加1,最后缩小10^n倍
|
|
280
|
+
// 但此种情况下,不能处理过大的数字,也不能处理保留小数位数过多的情况,会可能导致数字超过Infinity
|
|
281
|
+
// 2.2 Number.toFixed是四舍6入,对于第n+1位是5的情况,增加2*10^(-n-1),保证满足第n+1位>6
|
|
282
|
+
// 增加2*10^(-n-1)而不是增加1*10^(-n-1)是因为后者不能保证第n+1位>=6,例如1.325+0.001=1.32599999...第n+1位仍然为5
|
|
283
|
+
// 此处,采用2.2方式,解决Number.toFixed的问题,又能避免2.1方式中数字超过Infinity的问题
|
|
284
|
+
|
|
285
|
+
if (rexExp.test(xStr)) {
|
|
286
|
+
// 情况2,处理方式2.1:如果小数部分第n+1位是5,增加2*10^(-n-1)
|
|
287
|
+
xNum += 2 * 10 ** (-nNum - 1);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
const str = xNum.toFixed(nNum);
|
|
291
|
+
if (!removeTrailingZero) return str; // 去除末尾的0
|
|
292
|
+
|
|
293
|
+
if (/^\d+\.0*$/.test(str)) {
|
|
294
|
+
// 小数部分全是0
|
|
295
|
+
return str.replace(/^(\d+)(\.0*)$/, (_m, s1) => s1);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return str.replace(/^(\d+\.\d*[1-9]{1})(0*)$/, (_m, s1) => s1);
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
var stringUtils = /*#__PURE__*/Object.freeze({
|
|
302
|
+
__proto__: null,
|
|
303
|
+
formatPlate: formatPlate,
|
|
304
|
+
subStr: subStr,
|
|
305
|
+
hidePhoneCenter: hidePhoneCenter,
|
|
306
|
+
isValidPhone: isValidPhone,
|
|
307
|
+
isValidPlate: isValidPlate,
|
|
308
|
+
isValidAuthCode: isValidAuthCode,
|
|
309
|
+
roundStr: roundStr
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Tencent Inc. All Rights Reserved.
|
|
314
|
+
* @author:
|
|
315
|
+
* Created:
|
|
316
|
+
* Description: format time.
|
|
317
|
+
* History:
|
|
318
|
+
* 2017-07-26 @davislu modify.
|
|
319
|
+
*/
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* @function
|
|
323
|
+
* @description 格式化时间
|
|
324
|
+
* @param {Number} seconds 秒数
|
|
325
|
+
* @returns {String} 格式化的时间 -> 2小时47分钟或者12天
|
|
326
|
+
*/
|
|
327
|
+
const formatTime = seconds => {
|
|
328
|
+
if (typeof seconds !== 'number') return seconds;
|
|
329
|
+
const PER_MINUTE = 60 * 1;
|
|
330
|
+
const PER_HOUR = 60 * PER_MINUTE;
|
|
331
|
+
const PRE_DAY = 24 * PER_HOUR;
|
|
332
|
+
let cost = ''; // >24小时的显示 【x天】
|
|
333
|
+
|
|
334
|
+
if (seconds >= PRE_DAY) {
|
|
335
|
+
cost = `${Math.floor(seconds / PRE_DAY)}天`; // <1小时的显示 【x分钟】 ,x取整数上限,最低为1分钟。
|
|
336
|
+
} else if (seconds < PER_HOUR) {
|
|
337
|
+
cost = `${Math.ceil(seconds / PER_MINUTE)}分钟`; // <24小时&>1小时的显示 【x小时y分钟】 ,分钟取整数上限
|
|
338
|
+
} else {
|
|
339
|
+
cost = `${Math.floor(seconds / PER_HOUR)}小时`;
|
|
340
|
+
const s = seconds % PER_HOUR;
|
|
341
|
+
|
|
342
|
+
if (s > 0) {
|
|
343
|
+
cost += `${Math.ceil(s / PER_MINUTE)}分钟`;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return cost;
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* @function
|
|
351
|
+
* @description 将秒数格式化为x天y小时z分钟
|
|
352
|
+
* @param {Number} oriSeconds 秒数
|
|
353
|
+
* @returns {String} 格式化后的文案
|
|
354
|
+
*/
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
const formatTimeWithDetails = oriSeconds => {
|
|
358
|
+
let seconds = oriSeconds; // 非Number类型,直接返回,不进行处理
|
|
359
|
+
|
|
360
|
+
if (typeof seconds !== 'number') return seconds; // 参数为NaN类型,直接抛出异常
|
|
361
|
+
|
|
362
|
+
if (isNaN(seconds)) throw new Error(`formatTimeWithDetails方法的参数seconds必须时一个非NaN数字,现在的值为${seconds}`); // 定义一些常量
|
|
363
|
+
// 1分钟包含的秒数
|
|
364
|
+
|
|
365
|
+
const PER_MINUTE = 60 * 1; // 1小时包含的秒数
|
|
366
|
+
|
|
367
|
+
const PER_HOUR = 60 * PER_MINUTE; // 1天包含的秒数
|
|
368
|
+
|
|
369
|
+
const PRE_DAY = 24 * PER_HOUR;
|
|
370
|
+
let cost = ''; // 秒数多于1天
|
|
371
|
+
|
|
372
|
+
if (seconds >= PRE_DAY) {
|
|
373
|
+
cost = `${Math.floor(seconds / PRE_DAY)}天`;
|
|
374
|
+
seconds %= PRE_DAY;
|
|
375
|
+
} // 秒数小于1小时
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
if (seconds < PER_HOUR) {
|
|
379
|
+
if (cost) {
|
|
380
|
+
cost += '0小时';
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
cost += `${Math.ceil(seconds / PER_MINUTE)}分钟`;
|
|
384
|
+
} else {
|
|
385
|
+
// 秒数介于1天和1分钟之间
|
|
386
|
+
cost += `${Math.floor(seconds / PER_HOUR)}小时`;
|
|
387
|
+
const s = seconds % PER_HOUR;
|
|
388
|
+
|
|
389
|
+
if (s > 0) {
|
|
390
|
+
cost += `${Math.ceil(s / PER_MINUTE)}分钟`;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
return cost;
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* @function
|
|
398
|
+
* @description 对原有时间字符串进行格式化
|
|
399
|
+
* @param {String} str - 原字符串
|
|
400
|
+
* @param {String} dateSeprator - 日期分隔符
|
|
401
|
+
* @param {Boolean} keepSeconds - 是否保留秒数
|
|
402
|
+
* @returns {String} 格式化后的文案
|
|
403
|
+
*/
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
const formatTimeStr = (str = '', dateSeprator = '.', keepSeconds = false) => {
|
|
407
|
+
if (typeof str !== 'string' || str === '') {
|
|
408
|
+
return '';
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
let s = str.replace(/-/g, dateSeprator).replace(/:/g, ':'); // 不保留秒的时候,如果有两个冒号,截取第二个冒号之前的部分
|
|
412
|
+
|
|
413
|
+
if (!keepSeconds && /[^:]*:[^:]*:/.test(s)) {
|
|
414
|
+
const firstIndex = s.indexOf(':');
|
|
415
|
+
const secondIndex = s.indexOf(':', firstIndex + 1);
|
|
416
|
+
|
|
417
|
+
if (secondIndex > -1) {
|
|
418
|
+
s = s.substring(0, secondIndex);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
return s;
|
|
423
|
+
};
|
|
424
|
+
/**
|
|
425
|
+
* @description 格式化时间戳为 yyyy-mm-dd, yyyy-mm-dd HH:MM, yyyy-mm-dd HH:MM:SS
|
|
426
|
+
* @param {Date} date 日期
|
|
427
|
+
* @param {Boolean} withTime 是否带时间
|
|
428
|
+
* @param {Boolean} withSeconds 是否带秒数
|
|
429
|
+
* @param {String} join 连字符
|
|
430
|
+
* @returns {String} 格式化后的字符串,如 2021-03-18 或者 2021-03-18 10:11
|
|
431
|
+
*/
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
const dateToString = (date, withTime = false, withSeconds = false, join = '-') => {
|
|
435
|
+
const DATE = date ? new Date(date) : new Date(); // 为兼容ios,android平台的差异,故而不使用toLocaleDateString方法
|
|
436
|
+
|
|
437
|
+
const year = DATE.getFullYear();
|
|
438
|
+
const month = DATE.getMonth() + 1;
|
|
439
|
+
const day = DATE.getDate();
|
|
440
|
+
const time = DATE.toTimeString().slice(0, 8);
|
|
441
|
+
let dateStr = year + join + month + join + day;
|
|
442
|
+
|
|
443
|
+
if (!withTime) {
|
|
444
|
+
return dateStr.replace(/\b\d\b/g, '0$&');
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
dateStr = `${dateStr} ${time}`.replace(/\b\d\b/g, '0$&');
|
|
448
|
+
|
|
449
|
+
if (!withSeconds) {
|
|
450
|
+
dateStr = dateStr.slice(0, -3);
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
return dateStr;
|
|
454
|
+
};
|
|
455
|
+
|
|
456
|
+
var timeUtils = /*#__PURE__*/Object.freeze({
|
|
457
|
+
__proto__: null,
|
|
458
|
+
formatTime: formatTime,
|
|
459
|
+
formatTimeStr: formatTimeStr,
|
|
460
|
+
formatTimeWithDetails: formatTimeWithDetails,
|
|
461
|
+
dateToString: dateToString
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
/**
|
|
465
|
+
* Tencent Inc. All Rights Reserved.
|
|
466
|
+
* @author: petegao@tencent.com
|
|
467
|
+
* Created: 2019-01-14.
|
|
468
|
+
*
|
|
469
|
+
*/
|
|
470
|
+
let isInit = false;
|
|
471
|
+
let isIPXSign = false;
|
|
472
|
+
let ipxClass = '';
|
|
473
|
+
/**
|
|
474
|
+
* @returns {undefined}
|
|
475
|
+
*/
|
|
476
|
+
|
|
477
|
+
function init() {
|
|
478
|
+
if (isInit) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
isInit = true;
|
|
483
|
+
const sysInfo = syncApi.getSystemInfoSync();
|
|
484
|
+
const {
|
|
485
|
+
model,
|
|
486
|
+
platform: pl
|
|
487
|
+
} = sysInfo;
|
|
488
|
+
|
|
489
|
+
if (pl !== 'ios') {
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
if (model.search('iPhone X') > -1 || model.search('iPhone 11') > -1) {
|
|
494
|
+
isIPXSign = true;
|
|
495
|
+
ipxClass = 'view__ipx';
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
/**
|
|
499
|
+
* @returns {Boolean} 判断是否是 iPhoneX
|
|
500
|
+
*/
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
function isIPX() {
|
|
504
|
+
init();
|
|
505
|
+
return isIPXSign;
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* @returns {String} 返回 ipxClass
|
|
509
|
+
*/
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
function getIpxClass() {
|
|
513
|
+
init();
|
|
514
|
+
return ipxClass;
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* @param {Object} config 用户需要合并的IPX的配置
|
|
518
|
+
* @returns {Object} 合并后的IPX的配置
|
|
519
|
+
*/
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
function getIpxConfig(config) {
|
|
523
|
+
init();
|
|
524
|
+
return { ...config,
|
|
525
|
+
data: { ...config.data,
|
|
526
|
+
isIPX: isIPXSign,
|
|
527
|
+
ipxClass
|
|
528
|
+
}
|
|
529
|
+
};
|
|
530
|
+
} // 兼容旧接口,已经没什么用了
|
|
531
|
+
|
|
532
|
+
|
|
533
|
+
function ipxInit() {}
|
|
534
|
+
|
|
535
|
+
var ipxHelper = /*#__PURE__*/Object.freeze({
|
|
536
|
+
__proto__: null,
|
|
537
|
+
ipxInit: ipxInit,
|
|
538
|
+
isIPX: isIPX,
|
|
539
|
+
getIpxClass: getIpxClass,
|
|
540
|
+
getIpxConfig: getIpxConfig
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
export { subStr as a, isValidPlate as b, isValidAuthCode as c, formatTime as d, formatTimeStr as e, formatPlate as f, formatTimeWithDetails as g, hidePhoneCenter as h, isValidPhone as i, dateToString as j, ipxInit as k, isIPX as l, getIpxClass as m, getIpxConfig as n, rpxToPx as o, stringUtils as p, ipxHelper as q, roundStr as r, syncApi as s, timeUtils as t };
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2017-present, Tencent, Inc. All rights reserved.
|
|
3
|
+
* @author Davis.Lu <davislu@tencent.com>
|
|
4
|
+
*
|
|
5
|
+
* @file crypto tools.
|
|
6
|
+
*
|
|
7
|
+
**/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @public
|
|
11
|
+
* @description 基于md5算法对源字符串进行hash,生成hash字符串
|
|
12
|
+
* @param {String} str 源字符串
|
|
13
|
+
* @returns {String} 源字符串的md5 hash值
|
|
14
|
+
*/
|
|
15
|
+
const md5 = function (str) {
|
|
16
|
+
/**
|
|
17
|
+
* 将unicode编码成utf-8
|
|
18
|
+
* @private
|
|
19
|
+
* @param {string} encoedStr unicode字符
|
|
20
|
+
* @returns {string} utf8格式的字符串
|
|
21
|
+
*/
|
|
22
|
+
const encodeUtf8 = encoedStr => {
|
|
23
|
+
const string = encoedStr.replace(/\r\n/g, '\n');
|
|
24
|
+
/**
|
|
25
|
+
* @private
|
|
26
|
+
* @param {string} c unicode字符
|
|
27
|
+
* @returns {string} 字符串
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
const charCode = c => String.fromCharCode(c);
|
|
31
|
+
|
|
32
|
+
const utftextArr = [];
|
|
33
|
+
|
|
34
|
+
for (let n = 0; n < string.length; n += 1) {
|
|
35
|
+
let c = string.charCodeAt(n);
|
|
36
|
+
|
|
37
|
+
if (c < 128) {
|
|
38
|
+
utftextArr.push(charCode(c));
|
|
39
|
+
} else if (c < 2048) {
|
|
40
|
+
utftextArr.push(charCode(c >> 6 | 192), charCode(c & 63 | 128));
|
|
41
|
+
} else if (c < 55296 || c >= 57344) {
|
|
42
|
+
utftextArr.push(charCode(c >> 12 | 224), charCode(c >> 6 & 63 | 128), charCode(c & 63 | 128));
|
|
43
|
+
} else {
|
|
44
|
+
c = 65536 + ((c & 1023) << 10 | string.charCodeAt(n += 1) & 1023);
|
|
45
|
+
utftextArr.push(charCode(c >> 18 | 240), charCode(c >> 12 & 63 | 128), charCode(c >> 6 & 63 | 128), charCode(c & 63 | 128));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return utftextArr.join('');
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* @private
|
|
53
|
+
* @param {string} string 字符串
|
|
54
|
+
* @returns {array} 字符串分组
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
const convertToWordArray = string => {
|
|
59
|
+
const msgLen = string.length;
|
|
60
|
+
const lNumberOfWords = ((msgLen + 8 - (msgLen + 8) % 64) / 64 + 1) * 16;
|
|
61
|
+
const lWordArray = Array(lNumberOfWords - 1);
|
|
62
|
+
let lByteCount = 0;
|
|
63
|
+
|
|
64
|
+
while (lByteCount <= msgLen) {
|
|
65
|
+
const wordCount = (lByteCount - lByteCount % 4) / 4;
|
|
66
|
+
const lBytePosition = lByteCount % 4 * 8;
|
|
67
|
+
const byteWord = lByteCount === msgLen ? 0x80 : string.charCodeAt(lByteCount);
|
|
68
|
+
lWordArray[wordCount] |= byteWord << lBytePosition;
|
|
69
|
+
lByteCount += 1;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
lWordArray[lNumberOfWords - 2] = msgLen << 3;
|
|
73
|
+
lWordArray[lNumberOfWords - 1] = msgLen >>> 29;
|
|
74
|
+
return lWordArray;
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* @private
|
|
78
|
+
* @param {string} lValue 字符串
|
|
79
|
+
* @param {number} iShiftBits 移动位数
|
|
80
|
+
* @returns {string} 字符串
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
const rotateLeft = (lValue, iShiftBits) => lValue << iShiftBits | lValue >>> 32 - iShiftBits;
|
|
85
|
+
/**
|
|
86
|
+
* @private
|
|
87
|
+
* @param {string} lX 字符串
|
|
88
|
+
* @param {string} lY 字符串
|
|
89
|
+
* @returns {string} 字符串
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
const addUnsigned = (lX, lY) => {
|
|
94
|
+
const lX8 = lX & 0x80000000;
|
|
95
|
+
const lY8 = lY & 0x80000000;
|
|
96
|
+
const lX4 = lX & 0x40000000;
|
|
97
|
+
const lY4 = lY & 0x40000000;
|
|
98
|
+
const lResult = (lX & 0x3FFFFFFF) + (lY & 0x3FFFFFFF);
|
|
99
|
+
if (lX4 & lY4) return lResult ^ 0x80000000 ^ lX8 ^ lY8;
|
|
100
|
+
if (!(lX4 | lY4)) return lResult ^ lX8 ^ lY8;
|
|
101
|
+
return lResult & 0x40000000 ? lResult ^ 0xC0000000 ^ lX8 ^ lY8 : lResult ^ 0x40000000 ^ lX8 ^ lY8;
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* @private
|
|
105
|
+
* @param {object} recycleData 对象
|
|
106
|
+
* @returns {string} 字符串
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
const addRecycling = recycleData => {
|
|
111
|
+
const {
|
|
112
|
+
FN,
|
|
113
|
+
a,
|
|
114
|
+
b,
|
|
115
|
+
c,
|
|
116
|
+
d,
|
|
117
|
+
x,
|
|
118
|
+
s,
|
|
119
|
+
ac
|
|
120
|
+
} = recycleData;
|
|
121
|
+
const aa = addUnsigned(a, addUnsigned(addUnsigned(FN(b, c, d), x), ac));
|
|
122
|
+
return addUnsigned(rotateLeft(aa, s), b);
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* @private
|
|
126
|
+
* @param {string} lValue 字符串
|
|
127
|
+
* @returns {string} 字符串
|
|
128
|
+
*/
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
const wordToHex = lValue => {
|
|
132
|
+
let WordToHexValue = '';
|
|
133
|
+
|
|
134
|
+
for (let lCount = 0; lCount <= 3; lCount += 1) {
|
|
135
|
+
const lByte = lValue >>> lCount * 8 & 255;
|
|
136
|
+
const WordToHexValueTemp = `0${lByte.toString(16)}`;
|
|
137
|
+
WordToHexValue += WordToHexValueTemp.substr(WordToHexValueTemp.length - 2, 2);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return WordToHexValue;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
let [a, b, c, d] = [0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476];
|
|
144
|
+
const sArr = [[7, 12, 17, 22], [5, 9, 14, 20], [4, 11, 16, 23], [6, 10, 15, 21]];
|
|
145
|
+
const kiArr = '16b05af49e38d27c58be147ad0369cf207e5c3a18f6d4b29'.split('').map(n => parseInt(n, 16));
|
|
146
|
+
const hxArr = [0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE, 0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501, 0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE, 0x6B901122, 0xFD987193, 0xA679438E, 0x49B40821, 0xF61E2562, 0xC040B340, 0x265E5A51, 0xE9B6C7AA, 0xD62F105D, 0x2441453, 0xD8A1E681, 0xE7D3FBC8, 0x21E1CDE6, 0xC33707D6, 0xF4D50D87, 0x455A14ED, 0xA9E3E905, 0xFCEFA3F8, 0x676F02D9, 0x8D2A4C8A, 0xFFFA3942, 0x8771F681, 0x6D9D6122, 0xFDE5380C, 0xA4BEEA44, 0x4BDECFA9, 0xF6BB4B60, 0xBEBFBC70, 0x289B7EC6, 0xEAA127FA, 0xD4EF3085, 0x4881D05, 0xD9D4D039, 0xE6DB99E5, 0x1FA27CF8, 0xC4AC5665, 0xF4292244, 0x432AFF97, 0xAB9423A7, 0xFC93A039, 0x655B59C3, 0x8F0CCC92, 0xFFEFF47D, 0x85845DD1, 0x6FA87E4F, 0xFE2CE6E0, 0xA3014314, 0x4E0811A1, 0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391]; // eslint-disable-next-line require-jsdoc
|
|
147
|
+
|
|
148
|
+
const cyc = (i, r = 0) => (i + r) % 4; // 4组处理位操作函数
|
|
149
|
+
// eslint-disable-next-line require-jsdoc
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
const md5F = (x, y, z) => x & y | ~x & z; // eslint-disable-next-line require-jsdoc
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
const md5G = (x, y, z) => x & z | y & ~z; // eslint-disable-next-line require-jsdoc
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
const md5H = (x, y, z) => x ^ y ^ z; // eslint-disable-next-line require-jsdoc
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
const md5I = (x, y, z) => y ^ (x | ~z);
|
|
162
|
+
|
|
163
|
+
const string = encodeUtf8(str);
|
|
164
|
+
const x = convertToWordArray(string);
|
|
165
|
+
|
|
166
|
+
for (let k = 0; k < x.length; k += 16) {
|
|
167
|
+
const AA = a;
|
|
168
|
+
const BB = b;
|
|
169
|
+
const CC = c;
|
|
170
|
+
const DD = d;
|
|
171
|
+
const arr = [a, d, c, b];
|
|
172
|
+
hxArr.forEach((hx, m) => {
|
|
173
|
+
const i = m % 16;
|
|
174
|
+
const g = m / 16 << 0;
|
|
175
|
+
const ki = m < 16 ? m : kiArr[m - 16];
|
|
176
|
+
const FN = [md5F, md5G, md5H, md5I][g];
|
|
177
|
+
arr[cyc(i)] = addRecycling({
|
|
178
|
+
FN,
|
|
179
|
+
a: arr[cyc(i)],
|
|
180
|
+
b: arr[cyc(i, 3)],
|
|
181
|
+
c: arr[cyc(i, 2)],
|
|
182
|
+
d: arr[cyc(i, 1)],
|
|
183
|
+
x: x[k + ki],
|
|
184
|
+
s: sArr[g][i % 4],
|
|
185
|
+
ac: hx
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
a = addUnsigned(arr[0], AA);
|
|
189
|
+
b = addUnsigned(arr[3], BB);
|
|
190
|
+
c = addUnsigned(arr[2], CC);
|
|
191
|
+
d = addUnsigned(arr[1], DD);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return (wordToHex(a) + wordToHex(b) + wordToHex(c) + wordToHex(d)).toLowerCase();
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
var md5$1 = md5;
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Tencent Inc. All Rights Reserved.
|
|
201
|
+
* Description: Some Functions for Obejct.
|
|
202
|
+
*/
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* @function
|
|
206
|
+
* @description 把对象拼接成 a=b&c=d 形式的字符串
|
|
207
|
+
* @param {Object} queryObj 需要进行序列化的对象
|
|
208
|
+
* @returns {String} 拼接后的字符串
|
|
209
|
+
*/
|
|
210
|
+
const serialize = (queryObj = {}) => {
|
|
211
|
+
if (!queryObj) {
|
|
212
|
+
return '';
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const queryArray = [];
|
|
216
|
+
Object.keys(queryObj).forEach(key => {
|
|
217
|
+
queryArray.push(`${key}=${queryObj[key]}`);
|
|
218
|
+
});
|
|
219
|
+
return queryArray.join('&');
|
|
220
|
+
};
|
|
221
|
+
class JsonParseError extends Error {
|
|
222
|
+
constructor(text, data) {
|
|
223
|
+
super(text);
|
|
224
|
+
this.data = data;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* 安全的JSON.parse
|
|
230
|
+
*/
|
|
231
|
+
|
|
232
|
+
function safeJsonParse(data, throwErrIfParseFail = false) {
|
|
233
|
+
try {
|
|
234
|
+
return JSON.parse(data);
|
|
235
|
+
} catch (e) {
|
|
236
|
+
if (throwErrIfParseFail) {
|
|
237
|
+
throw new JsonParseError('JSON.parse error', data);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return data;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
export { safeJsonParse as a, md5$1 as m, serialize as s };
|
|
@@ -0,0 +1,543 @@
|
|
|
1
|
+
import { a as safeJsonParse, m as md5 } from './objUtils-154b94db.js';
|
|
2
|
+
import { a as getAuthInfo, g as getEnvInfo } from './env-c7da70e1.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 本文件主要负责在小程序中日志打印功能,包含本地日志及实时日志. 主要做了两件事:
|
|
6
|
+
* 1、参数序列化处理;支持传递任意多个参数,并对类型为对象的参数进行字符串序列化处理(避免打印出来是'[Object Object]'的格式);
|
|
7
|
+
* 2、低版本兼容;
|
|
8
|
+
*/
|
|
9
|
+
// 低版本不支持getLogManager或者getRealtimeLogManager时,用ManagerForLowerVersionLib来兼容
|
|
10
|
+
const ManagerForLowerVersionLib = {
|
|
11
|
+
debug: () => {},
|
|
12
|
+
info: () => {},
|
|
13
|
+
log: () => {},
|
|
14
|
+
warn: () => {},
|
|
15
|
+
error: () => {},
|
|
16
|
+
addFilterMsg: () => {},
|
|
17
|
+
setFilterMsg: () => {}
|
|
18
|
+
}; // 小程序基础库2.7.1版本以上支持,所以需要兼容性处理
|
|
19
|
+
|
|
20
|
+
let logInstance = null;
|
|
21
|
+
let rtLogInstance = null;
|
|
22
|
+
|
|
23
|
+
function getLogInstance() {
|
|
24
|
+
if (logInstance === null) {
|
|
25
|
+
logInstance = wx.getLogManager ? wx.getLogManager() : ManagerForLowerVersionLib;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return logInstance;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function getRTLogInstance() {
|
|
32
|
+
if (rtLogInstance === null) {
|
|
33
|
+
rtLogInstance = wx.getRealtimeLogManager ? wx.getRealtimeLogManager() : ManagerForLowerVersionLib;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return rtLogInstance;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 参数中有对象类型的,将其转换为字符串类型,以便查看
|
|
40
|
+
* @param {Array<Any>} params 需要格式化的数据
|
|
41
|
+
* @returns {Array<String>} 字符串序列化后的数据
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
const format = params => params.map(param => typeof param === 'string' ? param : JSON.stringify(param));
|
|
46
|
+
/**
|
|
47
|
+
* @namespace LOG
|
|
48
|
+
* @description 普通日志管理器,将日志记录在小程序日志文件中,用户上传后,可以在小程序后台-反馈管理中看到
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
const LOG = {
|
|
53
|
+
/**
|
|
54
|
+
* @description 写debug日志
|
|
55
|
+
* @param {...Any} params 需要打印的数据,支持任意多个
|
|
56
|
+
* @returns {Void} 无返回值
|
|
57
|
+
*/
|
|
58
|
+
debug(...params) {
|
|
59
|
+
getLogInstance().debug(...format(params));
|
|
60
|
+
},
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @description 写info日志
|
|
64
|
+
* @param {...Any} params 需要打印的数据,支持任意多个
|
|
65
|
+
* @returns {Void} 无返回值
|
|
66
|
+
*/
|
|
67
|
+
info(...params) {
|
|
68
|
+
getLogInstance().info(...format(params));
|
|
69
|
+
},
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* @description 写log日志
|
|
73
|
+
* @param {...Any} params 需要打印的数据,支持任意多个
|
|
74
|
+
* @returns {Void} 无返回值
|
|
75
|
+
*/
|
|
76
|
+
log(...params) {
|
|
77
|
+
getLogInstance().log(...format(params));
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @description 写warn日志
|
|
82
|
+
* @param {...Any} params 需要打印的数据,支持任意多个
|
|
83
|
+
* @returns {Void} 无返回值
|
|
84
|
+
*/
|
|
85
|
+
warn(...params) {
|
|
86
|
+
getLogInstance().warn(...format(params));
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* @description 写warn日志. LogManager并没有error方法,为了兼容旧代码,所以声明一个error方法
|
|
91
|
+
* @param {...Any} params 需要打印的数据,支持任意多个
|
|
92
|
+
* @returns {Void} 无返回值
|
|
93
|
+
*/
|
|
94
|
+
error(...params) {
|
|
95
|
+
LOG.warn(...params);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* @namespace RTLOG
|
|
101
|
+
* @description 实时日志,将日志实时上传至小程序后台-开发-运维中心-实时日志,方便快速排查漏洞,定位问题
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
const RTLOG = {
|
|
105
|
+
/**
|
|
106
|
+
* @description 写info日志
|
|
107
|
+
* @param {...Any} params 需要打印的数据,支持任意多个
|
|
108
|
+
* @returns {Void} 无返回值
|
|
109
|
+
*/
|
|
110
|
+
info(...params) {
|
|
111
|
+
getRTLogInstance().info(...format(params));
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* @description 写warn日志
|
|
116
|
+
* @param {...Any} params 需要打印的数据,支持任意多个
|
|
117
|
+
* @returns {Void} 无返回值
|
|
118
|
+
*/
|
|
119
|
+
warn(...params) {
|
|
120
|
+
getRTLogInstance().warn(...format(params));
|
|
121
|
+
},
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* @description 写error日志
|
|
125
|
+
* @param {...Any} params 需要打印的数据,支持任意多个
|
|
126
|
+
* @returns {Void} 无返回值
|
|
127
|
+
*/
|
|
128
|
+
error(...params) {
|
|
129
|
+
getRTLogInstance().error(...format(params));
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @description 添加过滤关键字
|
|
134
|
+
* @param {String} msg 关键字
|
|
135
|
+
* @returns {Void} 无返回值
|
|
136
|
+
*/
|
|
137
|
+
addFilterMsg(msg) {
|
|
138
|
+
getRTLogInstance().addFilterMsg(msg);
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @description 设置过滤关键字
|
|
143
|
+
* @param {String} msg 关键字
|
|
144
|
+
* @returns {Void} 无返回值
|
|
145
|
+
*/
|
|
146
|
+
setFilterMsg(msg) {
|
|
147
|
+
getRTLogInstance().setFilterMsg(msg);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* @description 获取日志管理器对象,该对象提供的方法同wx.getLogManager()提供的方法,详见微信文档
|
|
153
|
+
* @returns {Object} [LOG](#namespace-log)
|
|
154
|
+
* @example
|
|
155
|
+
* const logger = getLogManager();
|
|
156
|
+
* logger.log(1, 'str', { a: 1 }, ...);
|
|
157
|
+
* logger.info(1, 'str', { a: 1 }, ...);
|
|
158
|
+
* logger.debug(1, 'str', { a: 1 }, ...);
|
|
159
|
+
* logger.awrn(1, 'str', { a: 1 }, ...);
|
|
160
|
+
*/
|
|
161
|
+
|
|
162
|
+
const getLogManager = () => LOG;
|
|
163
|
+
/**
|
|
164
|
+
* @description 获取实时日志管理器对象,该对象提供的方法同wx.getRealtimeLogManager()提供的方法,详见微信文档
|
|
165
|
+
* @returns {Object} [RTLOG](#namespace-rtlog)
|
|
166
|
+
* @example
|
|
167
|
+
* const logger = getRealtimeLogManager();
|
|
168
|
+
* logger.info(1, 'str', { a: 1 }, ...);
|
|
169
|
+
* logger.warn(1, 'str', { a: 1 }, ...);
|
|
170
|
+
* logger.error(1, 'str', { a: 1 }, ...);
|
|
171
|
+
*/
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
const getRealtimeLogManager = () => RTLOG;
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @copyright 2021-present, Tencent, Inc. All rights reserved.
|
|
178
|
+
* @brief request.js用于发起网络请求.
|
|
179
|
+
* request模块作为基于 tms-core & tms-runtime 的应用的公共请求模块。
|
|
180
|
+
* 目前支持在出行服务小程序或基于出行服务的小程序中调用。在后续tms-runtime支持公众号H5后,
|
|
181
|
+
* 将支持在H5中调用。
|
|
182
|
+
*
|
|
183
|
+
* 考虑到对不同运行环境的支持,强依赖运行环境的依赖,比如 wx.request,应通过注入的形式提供。
|
|
184
|
+
* 框架判断在不同的运行环境,切换调用不同运行环境提供的方法。
|
|
185
|
+
*/
|
|
186
|
+
/**
|
|
187
|
+
* 用于序列化需要签名的参数
|
|
188
|
+
* @private
|
|
189
|
+
* @param {object} param 需要序列化的参数
|
|
190
|
+
* @returns {string} 序列化之后的参数字符串
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
const seriesParam = param => {
|
|
194
|
+
const keys = Object.keys(param).sort();
|
|
195
|
+
const series = keys.map(key => {
|
|
196
|
+
const val = param[key];
|
|
197
|
+
return `${key}${typeof val === 'object' ? JSON.stringify(val) : val}`;
|
|
198
|
+
});
|
|
199
|
+
return series.join('');
|
|
200
|
+
};
|
|
201
|
+
/**
|
|
202
|
+
* 用于对request请求对象做签名
|
|
203
|
+
* @private
|
|
204
|
+
* @param {object} param 需要做签名的参数
|
|
205
|
+
* @returns {object} 签名后的参数对象
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
const sign = (param = {}) => {
|
|
210
|
+
const token = '';
|
|
211
|
+
const signture = md5(seriesParam(param) + token);
|
|
212
|
+
return { ...param,
|
|
213
|
+
sign: signture
|
|
214
|
+
};
|
|
215
|
+
};
|
|
216
|
+
/**
|
|
217
|
+
* 用于对request请求对象添加系统参数
|
|
218
|
+
* @private
|
|
219
|
+
* @param {object} param 接口调用传入的参数
|
|
220
|
+
* @param {Boolean} withAuth 是否需要登录参数
|
|
221
|
+
* @param {object} baseParam request实例定义的基础参数
|
|
222
|
+
* @returns {object} 全部参数对象
|
|
223
|
+
*/
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
const composeParam = async (param = {}, withAuth = true, baseParam = {}) => {
|
|
227
|
+
const version = '1.0';
|
|
228
|
+
const {
|
|
229
|
+
appVersion,
|
|
230
|
+
wxAppId,
|
|
231
|
+
client
|
|
232
|
+
} = getEnvInfo();
|
|
233
|
+
const nonce = Math.random().toString(36).substr(2, 10);
|
|
234
|
+
const timestamp = Date.now();
|
|
235
|
+
const random = Math.random().toString().slice(2, 7);
|
|
236
|
+
const sourceId = ['', 'sinan', 'mycar'].indexOf(client) + 7; // 6 未知 7 云函数 8 出行 9 我的车
|
|
237
|
+
|
|
238
|
+
const seqId = `${timestamp}${sourceId}${random}`;
|
|
239
|
+
const paramsWithAuth = await modifyAuthParam(param, withAuth);
|
|
240
|
+
const combinedParam = Object.assign({
|
|
241
|
+
version,
|
|
242
|
+
appVersion,
|
|
243
|
+
nonce,
|
|
244
|
+
timestamp,
|
|
245
|
+
seqId,
|
|
246
|
+
wxAppId
|
|
247
|
+
}, { ...baseParam
|
|
248
|
+
}, { ...paramsWithAuth
|
|
249
|
+
}); // 清理undefined和NaN的参数
|
|
250
|
+
|
|
251
|
+
Object.keys(combinedParam).forEach(key => {
|
|
252
|
+
if (typeof combinedParam[key] === 'number' && isNaN(combinedParam[key])) {
|
|
253
|
+
delete combinedParam[key];
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
if (typeof combinedParam[key] === 'undefined') {
|
|
257
|
+
delete combinedParam[key];
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
return combinedParam;
|
|
261
|
+
};
|
|
262
|
+
/**
|
|
263
|
+
* 用于保证业务参数的登录态参数,
|
|
264
|
+
* 若接口不依赖登录态 如 user/login,则保证参数中不包括userId & token,
|
|
265
|
+
* 若接口依赖登录态,则保证参数中填充userId & token,
|
|
266
|
+
* @private
|
|
267
|
+
* @param {object} param 要校验登录态的业务参数
|
|
268
|
+
* @param {boolean} withAuth 是否要校验登录态
|
|
269
|
+
* @returns {object} 增加登录态后的参数
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
const modifyAuthParam = async (param, withAuth) => {
|
|
274
|
+
const requestParam = { ...param
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
if (withAuth) {
|
|
278
|
+
const {
|
|
279
|
+
userId,
|
|
280
|
+
token
|
|
281
|
+
} = await getAuthInfo();
|
|
282
|
+
requestParam.userId = userId;
|
|
283
|
+
requestParam.token = token;
|
|
284
|
+
return requestParam;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
delete requestParam.userId;
|
|
288
|
+
delete requestParam.userid;
|
|
289
|
+
delete requestParam.token;
|
|
290
|
+
return requestParam;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* @public
|
|
294
|
+
* @class Request
|
|
295
|
+
* @classdesc 网络请求类,对签名、鉴权等逻辑进行封装处理,用于向腾讯出行服务平台后台发送网络请求
|
|
296
|
+
*/
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
class Request {
|
|
300
|
+
/**
|
|
301
|
+
* 默认的request host域名
|
|
302
|
+
* defaultHost 在tms-runtime初始化时进行设置,为出行服务接入层域名
|
|
303
|
+
* 具体业务模块 new Request() 使用时,不指定自定义 host ,将使用defaultHost
|
|
304
|
+
*/
|
|
305
|
+
static defaultHost = '';
|
|
306
|
+
host = '';
|
|
307
|
+
withAuth = true;
|
|
308
|
+
baseParam = {};
|
|
309
|
+
/**
|
|
310
|
+
* Request 构造函数
|
|
311
|
+
* @param {Object} config 构造参数
|
|
312
|
+
* @param {Object} config.withAuth 是否填充登录态参数
|
|
313
|
+
* @param {Object} config.host 自定义的host域名
|
|
314
|
+
* @param {Object} config.baseParam 默认携带的参数
|
|
315
|
+
*/
|
|
316
|
+
|
|
317
|
+
constructor(config = {
|
|
318
|
+
withAuth: true
|
|
319
|
+
}) {
|
|
320
|
+
if (config.host) {
|
|
321
|
+
this.host = config.host;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (typeof config.withAuth !== 'undefined') {
|
|
325
|
+
this.withAuth = !!config.withAuth;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
this.baseParam = config.baseParam || {};
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* 格式化接口路径
|
|
332
|
+
* @private
|
|
333
|
+
* @param {string} path 需要格式化的接口路径
|
|
334
|
+
* @returns {string} 格式化后的接口路径
|
|
335
|
+
*/
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
makeUrl(path) {
|
|
339
|
+
if (/^http/i.test(path)) return path;
|
|
340
|
+
const host = this.host || Request.defaultHost;
|
|
341
|
+
const validHost = /^http/i.test(host) ? host : `https://${host}`;
|
|
342
|
+
return `${validHost}/${path}`;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* @public
|
|
347
|
+
* @memberof Request
|
|
348
|
+
* @param {String} path 请求接口路径
|
|
349
|
+
* @param {Object} [param] 请求参数
|
|
350
|
+
* @param {Object} [header] 自定义请求头
|
|
351
|
+
* @returns {Promise} 接口响应
|
|
352
|
+
* @example
|
|
353
|
+
* const $ = getApp().tms.createRequest();
|
|
354
|
+
* $.get(apiPath)
|
|
355
|
+
* .then((data) => {
|
|
356
|
+
* // data {Object} 响应数据
|
|
357
|
+
* // {
|
|
358
|
+
* // errCode {Number} 接口响应状态码
|
|
359
|
+
* // errMsg {String} 接口响应状态信息
|
|
360
|
+
* // resData {Object} 接口返回数据
|
|
361
|
+
* // }
|
|
362
|
+
* })
|
|
363
|
+
* .catch((e) => {
|
|
364
|
+
* // e {Object} 错误信息
|
|
365
|
+
* });
|
|
366
|
+
*/
|
|
367
|
+
get(path, param, header) {
|
|
368
|
+
return this.doRequest(path, param, 'GET', header);
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* @public
|
|
372
|
+
* @memberof Request
|
|
373
|
+
* @param {String} path 请求接口路径
|
|
374
|
+
* @param {Object} [param] 请求参数
|
|
375
|
+
* @param {Object} [header] 自定义请求头
|
|
376
|
+
* @returns {Promise} 接口响应
|
|
377
|
+
* @example
|
|
378
|
+
* const $ = getApp().tms.createRequest();
|
|
379
|
+
* $.post(apiPath)
|
|
380
|
+
* .then((data) => {
|
|
381
|
+
* // data {Object} 响应数据
|
|
382
|
+
* // {
|
|
383
|
+
* // errCode {Number} 接口响应状态码
|
|
384
|
+
* // errMsg {String} 接口响应状态信息
|
|
385
|
+
* // resData {Object} 接口返回数据
|
|
386
|
+
* // }
|
|
387
|
+
* })
|
|
388
|
+
* .catch((e) => {
|
|
389
|
+
* // e {Object} 错误信息
|
|
390
|
+
* });
|
|
391
|
+
*/
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
post(path, param, header) {
|
|
395
|
+
return this.doRequest(path, param, 'POST', header);
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* 发送get方式的请求,该方法会返回wx.request全量的返回值(含data,header,cookies,statusCode)
|
|
399
|
+
* @memberof Request
|
|
400
|
+
* @param {string} path 请求接口路径
|
|
401
|
+
* @param {object} param 业务参数
|
|
402
|
+
* @param {object} header 自定义请求头
|
|
403
|
+
* @returns {promise} 接口请求promise
|
|
404
|
+
*/
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
execGet(path, param, header) {
|
|
408
|
+
return this.createRequestTask(path, param, 'GET', header);
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* 发送post方式的请求,该方法会返回wx.request全量的返回值(含data,header,cookies,statusCode等)
|
|
412
|
+
* @memberof Request
|
|
413
|
+
* @param {string} path 请求接口路径
|
|
414
|
+
* @param {object} param 业务参数
|
|
415
|
+
* @param {object} header 自定义请求头
|
|
416
|
+
* @returns {promise} 接口请求promise
|
|
417
|
+
*/
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
execPost(path, param, header) {
|
|
421
|
+
return this.createRequestTask(path, param, 'POST', header);
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* @memberof Request
|
|
425
|
+
* @param {String} path 请求接口路径
|
|
426
|
+
* @param {String} filePath 上传文件的本地路径
|
|
427
|
+
* @param {Object} param 需要携带的其他参数
|
|
428
|
+
* @param {Object} header 自定义的请求头
|
|
429
|
+
* @returns {Object} 接口返回结果
|
|
430
|
+
*/
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
async upload(path, filePath, param, header) {
|
|
434
|
+
const requestParam = await composeParam(param, this.withAuth, this.baseParam);
|
|
435
|
+
const res = await new Promise((resolve, reject) => {
|
|
436
|
+
wx.uploadFile({
|
|
437
|
+
name: 'content',
|
|
438
|
+
url: this.makeUrl(path),
|
|
439
|
+
filePath,
|
|
440
|
+
formData: sign(requestParam),
|
|
441
|
+
header,
|
|
442
|
+
success: resolve,
|
|
443
|
+
fail: reject
|
|
444
|
+
});
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
if (typeof (res === null || res === void 0 ? void 0 : res.data) === 'string') {
|
|
448
|
+
return safeJsonParse(res === null || res === void 0 ? void 0 : res.data);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
return res === null || res === void 0 ? void 0 : res.data;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* @memberof Request
|
|
455
|
+
* @param {string} path 请求接口路径
|
|
456
|
+
* @param {string} param 业务参数
|
|
457
|
+
* @param {string} method 请求方法 get/post
|
|
458
|
+
* @param {object} header 自定义的请求头
|
|
459
|
+
* @returns {object} 接口返回结果
|
|
460
|
+
*/
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
async doRequest(path, param = {}, method = 'POST', header = {}) {
|
|
464
|
+
const res = await this.createRequestTask(path, param, method, header);
|
|
465
|
+
|
|
466
|
+
if (typeof (res === null || res === void 0 ? void 0 : res.data) === 'string') {
|
|
467
|
+
return safeJsonParse(res === null || res === void 0 ? void 0 : res.data);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
return res === null || res === void 0 ? void 0 : res.data;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* 序列化一个 get 请求地址
|
|
474
|
+
* @memberof Request
|
|
475
|
+
* @param {string} path 请求接口路径
|
|
476
|
+
* @param {object} data 业务参数
|
|
477
|
+
* @returns {Promise} 返回序列化之后的 get 请求地址
|
|
478
|
+
*/
|
|
479
|
+
|
|
480
|
+
|
|
481
|
+
async serialize(path, data = {}) {
|
|
482
|
+
let url = this.makeUrl(path);
|
|
483
|
+
const signData = await composeParam(data, this.withAuth, this.baseParam);
|
|
484
|
+
const signture = sign(signData);
|
|
485
|
+
const params = [];
|
|
486
|
+
Object.keys(signture).forEach(key => {
|
|
487
|
+
const val = encodeURIComponent(signture[key]);
|
|
488
|
+
params.push(`${key}=${val}`);
|
|
489
|
+
});
|
|
490
|
+
if (params.length) url += (/\?/.test(url) ? '&' : '?') + params.join('&');
|
|
491
|
+
return Promise.resolve({
|
|
492
|
+
url
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
/**
|
|
496
|
+
* 创建发送请求任务
|
|
497
|
+
* @memberof Request
|
|
498
|
+
* @param {string} path 请求接口路径
|
|
499
|
+
* @param {string} param 业务参数
|
|
500
|
+
* @param {string} method 请求方法 get/post
|
|
501
|
+
* @param {object} header 自定义的请求头
|
|
502
|
+
* @returns {Promise} 接口返回结果
|
|
503
|
+
*/
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
async createRequestTask(path, param = {}, method = 'POST', header = {}) {
|
|
507
|
+
const requestParam = await composeParam(param, this.withAuth, this.baseParam);
|
|
508
|
+
const data = sign(requestParam);
|
|
509
|
+
const logger = getLogManager();
|
|
510
|
+
const res = await new Promise((resolve, reject) => {
|
|
511
|
+
wx.request({
|
|
512
|
+
url: this.makeUrl(path),
|
|
513
|
+
header,
|
|
514
|
+
method,
|
|
515
|
+
data,
|
|
516
|
+
success: res => {
|
|
517
|
+
resolve(res);
|
|
518
|
+
logger.log({
|
|
519
|
+
path,
|
|
520
|
+
header,
|
|
521
|
+
method,
|
|
522
|
+
param: data,
|
|
523
|
+
res: res === null || res === void 0 ? void 0 : res.data
|
|
524
|
+
});
|
|
525
|
+
},
|
|
526
|
+
fail: err => {
|
|
527
|
+
reject(err);
|
|
528
|
+
logger.log({
|
|
529
|
+
path,
|
|
530
|
+
header,
|
|
531
|
+
method,
|
|
532
|
+
param: data,
|
|
533
|
+
err
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
});
|
|
538
|
+
return res;
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
export { Request as R, getRealtimeLogManager as a, getLogManager as g };
|
package/dist/request.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import './
|
|
2
|
-
export { R as default } from './request-
|
|
1
|
+
import './objUtils-154b94db.js';
|
|
2
|
+
export { R as default } from './request-f8a4745b.js';
|
|
3
3
|
import './env-c7da70e1.js';
|