@tmsfe/tms-core 0.0.92 → 0.0.95
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 +7 -3
- package/src/cloudService.js +7 -0
- package/src/compareVersion.js +29 -0
- package/src/config.js +5 -4
- package/src/env.js +43 -14
- package/src/eventDispatcher.js +12 -5
- package/src/index-proxy.js +5 -2
- package/src/index.js +47 -12
- package/src/ipxHelper.js +7 -4
- package/src/location/base.ts +2 -0
- package/src/location/index.ts +30 -7
- package/src/location/utils.ts +5 -1
- package/src/log.js +13 -3
- package/src/md5.js +1 -4
- package/src/mpInfo.js +7 -1
- package/src/navbarUtils.js +9 -35
- package/src/navigator.js +2 -4
- package/src/numUtils.js +9 -6
- package/src/objUtils.js +3 -2
- package/src/report/clone.ts +3 -5
- package/src/report/formatV1.ts +1 -0
- package/src/report/formatV2.ts +1 -0
- package/src/report/helper.ts +2 -1
- package/src/report/index.ts +27 -4
- package/src/report/proxy/app.ts +1 -0
- package/src/report/proxy/component.ts +1 -0
- package/src/report/proxy/helper.ts +3 -2
- package/src/report/proxy/index.ts +1 -0
- package/src/report/proxy/page.ts +1 -0
- package/src/report/proxy/types.ts +1 -0
- package/src/report/sender.ts +1 -0
- package/src/request.js +1 -1
- package/src/rpx.js +7 -3
- package/src/runtime/car.js +4 -0
- package/src/runtime/index.js +43 -23
- package/src/runtime/{login.js → login.ts} +57 -2
- package/src/storage.js +13 -9
- package/src/stringUtils.js +8 -5
- package/src/syncfnmanager.js +3 -3
- package/src/timeUtils.js +25 -31
- package/tmsdoc.config.js +12 -0
- package/tsconfig.json +29 -27
package/src/stringUtils.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @desc: 字符串处理相关函数
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
/**
|
|
2
6
|
* 字符串截断,处理时按可见字符长度进行截断
|
|
3
7
|
* 可见字符的含义是指:字母、数字、汉字、表情等均等价于一个字符
|
|
@@ -115,13 +119,12 @@ const isValidPlate = (plate) => {
|
|
|
115
119
|
* 四舍五入,并返回格式化的字符串
|
|
116
120
|
* 支持保留n位小数,n>=0,如 roundStr(1.325, 2)=1.33
|
|
117
121
|
* 支持格式化字符串时取出末尾的0,如roundStr(1.109, 2, true)=1.1
|
|
118
|
-
* @param {any} x
|
|
119
|
-
* 如果n不是合法数字或者无法转换为合法数字,roundStr结果返回''
|
|
122
|
+
* @param {any} x 原数字, 如果n不是合法数字或者无法转换为合法数字,roundStr结果返回''
|
|
120
123
|
* @param {any} n 保留几位小数,默认0
|
|
121
|
-
* 如果n不是合法数字或者无法转换为合法数字,roundStr结果返回''
|
|
122
|
-
* 如果n小于0,roundStr结果返回''
|
|
123
|
-
* 如果n的值包含小数部分,roundStr处理时只关注n的整数部分值
|
|
124
124
|
* @param {boolean} removeTrailingZero 是否移除字符串末尾的无效数字0
|
|
125
|
+
1. 如果n不是合法数字或者无法转换为合法数字,roundStr结果返回''
|
|
126
|
+
2. 如果n小于0,roundStr结果返回''
|
|
127
|
+
3. 如果n的值包含小数部分,roundStr处理时只关注n的整数部分值
|
|
125
128
|
* @returns {string} 返回四舍五入后的字符串,异常情况下返回空字符串''
|
|
126
129
|
*/
|
|
127
130
|
const roundStr = (x, n = 2, removeTrailingZero = false) => {
|
package/src/syncfnmanager.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* 本文件负责对小程序调用wx同步方法的管理
|
|
2
|
+
* @desc: 本文件负责对小程序调用wx同步方法的管理
|
|
3
3
|
*/
|
|
4
4
|
let systemInfo = null; // 系统信息。
|
|
5
5
|
let launchOptions = null; // 启动参数
|
|
@@ -25,7 +25,7 @@ const getSystemInfoSync = () => {
|
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
27
|
* 重置系统信息,仅用于单元测试
|
|
28
|
-
* @returns {
|
|
28
|
+
* @returns {void}
|
|
29
29
|
*/
|
|
30
30
|
const resetSystemInfoSync = () => {
|
|
31
31
|
systemInfo = null;
|
|
@@ -66,7 +66,7 @@ const getPlatform = () => {
|
|
|
66
66
|
};
|
|
67
67
|
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
69
|
+
* 获取字符串类型的启动参数, 同wx.getLaunchOptionsSync进行JSON.stringify
|
|
70
70
|
* @returns {String} 序列化的参数字符串
|
|
71
71
|
*/
|
|
72
72
|
const getLaunchParamOfString = () => {
|
package/src/timeUtils.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @author:
|
|
4
|
-
* Created:
|
|
5
|
-
* Description: format time.
|
|
6
|
-
* History:
|
|
7
|
-
* 2017-07-26 @davislu modify.
|
|
2
|
+
* @desc: 时间处理相关函数
|
|
3
|
+
* @author:2017-07-26 @davislu modify.
|
|
8
4
|
*/
|
|
9
5
|
|
|
10
6
|
import { round } from './numUtils';
|
|
@@ -14,17 +10,16 @@ import { roundStr } from './stringUtils';
|
|
|
14
10
|
* 将时间段进行聚合计算,得出不同时间单位的计数值,例如:3601秒 -> { hour: 1, minute: 0, second: 1 },即:1小时0分1秒
|
|
15
11
|
* @param {Number} seconds 时间段的总秒数
|
|
16
12
|
* @param {String} maxUnit 最大计数单位:second-秒,minute-分,hour-小时,day-天,month-月,year-年;默认 year
|
|
17
|
-
* 单位大小:year > Month > day > hour > month > second
|
|
18
13
|
* @param {String} minUnit 最小计数单位:second-秒,minute-分,hour-小时,day-天,month-月,year-年;默认 second
|
|
19
14
|
* @param {Number} decimal 有不足最小单位数值的情况下,保留几位小数;默认 2
|
|
20
|
-
* @returns {Object} result
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
15
|
+
* @returns {Object} result 以下是各计数单位下的数值:
|
|
16
|
+
* @returns {Number} result.year - 年; 当maxUnit < 'year' 时,此字段永远为0;此字段为-1时,表示 seconds 参数非法 或 minUnit > maxUnit等异常情况
|
|
17
|
+
* @returns {Number} result.month - 月; 当maxUnit < 'month' 时,此字段永远为0;
|
|
18
|
+
* @returns {Number} result.day - 天; 当maxUnit < 'day' 时,此字段永远为0;
|
|
19
|
+
* @returns {Number} result.hour - 小时;当maxUnit < 'hour' 时,此字段永远为0;
|
|
20
|
+
* @returns {Number} result.minute - 分钟;当maxUnit < 'minute' 时,此字段永远为0;
|
|
21
|
+
* @returns {Number} result.second - 秒;
|
|
22
|
+
* @returns {Number} result.decimal - 不足最小单位的部分,具体含义与 minUnit 参数相关;例如 minUnit = day 时,此字段表示不足1天的部分
|
|
28
23
|
*/
|
|
29
24
|
const groupTimeDuration = (seconds, maxUnit = 'year', minUnit = 'second', decimal = 2) => {
|
|
30
25
|
// 时间参数(seconds)检查
|
|
@@ -65,10 +60,9 @@ const groupTimeDuration = (seconds, maxUnit = 'year', minUnit = 'second', decima
|
|
|
65
60
|
* 将时间段进行聚合计算并格式化,得出方便人阅读的文案,例如:3601秒 -> 1小时0分1秒
|
|
66
61
|
* @param {Number} seconds 时间段的总秒数
|
|
67
62
|
* @param {String} maxUnit 最大计数单位:second-秒,minute-分,hour-小时,day-天,month-月,year-年;默认 year
|
|
68
|
-
* 单位大小:year > Month > day > hour > month > second
|
|
69
63
|
* @param {String} minUnit 最小计数单位:second-秒,minute-分,hour-小时,day-天,month-月,year-年;默认 second
|
|
70
64
|
* @param {Number} decimal 有不足最小单位数值的情况下,保留几位小数;默认 2
|
|
71
|
-
* @returns {String}
|
|
65
|
+
* @returns {String}
|
|
72
66
|
*/
|
|
73
67
|
const formatTimeDuration = (seconds, maxUnit = 'year', minUnit = 'second', decimal = 2) => {
|
|
74
68
|
const result = groupTimeDuration(seconds, maxUnit, minUnit, decimal);
|
|
@@ -89,9 +83,9 @@ const formatTimeDuration = (seconds, maxUnit = 'year', minUnit = 'second', decim
|
|
|
89
83
|
|
|
90
84
|
/**
|
|
91
85
|
* @function
|
|
92
|
-
* @description
|
|
86
|
+
* @description 格式化时间,>24小时的显示 【x天】;<1小时的显示 【x分钟】;<24小时&>1小时的显示 【x小时y分钟】
|
|
93
87
|
* @param {Number} seconds 秒数
|
|
94
|
-
* @returns {String} 格式化的时间
|
|
88
|
+
* @returns {String} 格式化的时间
|
|
95
89
|
*/
|
|
96
90
|
const formatTime = (seconds) => {
|
|
97
91
|
if (typeof seconds !== 'number') return seconds;
|
|
@@ -109,7 +103,7 @@ const formatTime = (seconds) => {
|
|
|
109
103
|
|
|
110
104
|
/**
|
|
111
105
|
* @function
|
|
112
|
-
* @description
|
|
106
|
+
* @description 将秒数格式化: 秒数多于1天显示【x天y小时z分钟】;秒数小于1小时【x分钟】;秒数介于1天和1小时之间显示【x小时y分钟】
|
|
113
107
|
* @param {Number} seconds 秒数
|
|
114
108
|
* @returns {String} 格式化后的文案
|
|
115
109
|
*/
|
|
@@ -212,17 +206,17 @@ const dateToString = (date, withTime = false, withSeconds = false, join = '-') =
|
|
|
212
206
|
/**
|
|
213
207
|
* 将时间字符串转换为Date对象
|
|
214
208
|
* @param {String} str 时间字符串,如:2022-03-24 20:02:05
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
* @returns {Date
|
|
209
|
+
1. 支持对日期完整但时间部分缺失的情况进行处理,如:
|
|
210
|
+
2. 2022-03-24 20:02 -> Date(1648123320000)
|
|
211
|
+
3. 2022-03-24 20: -> Date(1648123200000)
|
|
212
|
+
4. 2022-03-24 20 -> Date(1648123200000)
|
|
213
|
+
5. 2022-03-24 -> Date(1648051200000)
|
|
214
|
+
6. 小于10的数字可以省略0:
|
|
215
|
+
7. 2022-3-24 20:2 -> Date(1648123320000)
|
|
216
|
+
8. 支持任意分割符,如:
|
|
217
|
+
9. 2022年03月24日 20时02分 -> Date(1648123320000)
|
|
218
|
+
10. 2022/03/24 20:02:05 -> Date(1648123325000)
|
|
219
|
+
* @returns {Date} 时间对象;转换失败时返回null
|
|
226
220
|
*/
|
|
227
221
|
const parseDateTime = (str) => {
|
|
228
222
|
const arr = new RegExp(/(\d{4})[^\d]+(\d{1,2})[^\d]+(\d{1,2})(.*)/, 'g').exec(str); // 分割日期和时间
|
package/tmsdoc.config.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const path = require('path');
|
|
2
|
+
function resolve(dir) {
|
|
3
|
+
return path.resolve(__dirname, dir);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
module.exports = {
|
|
7
|
+
[resolve('dist/src')]: {
|
|
8
|
+
title: 'tms-core',
|
|
9
|
+
exclude: '/docs\\/|node_modules|\\.test\\.js|utils|tmsuiUtils/',
|
|
10
|
+
outputPath: '../../prod/tmsapidocs/docs/tmscore/api.md',
|
|
11
|
+
},
|
|
12
|
+
};
|
package/tsconfig.json
CHANGED
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"sourceMap": false,
|
|
4
|
+
"target": "esnext",
|
|
5
|
+
"module": "esnext",
|
|
6
|
+
"moduleResolution": "node",
|
|
7
|
+
"allowJs": true,
|
|
8
|
+
"strict": false,
|
|
9
|
+
"declarationMap": false,
|
|
10
|
+
"noUnusedLocals": false,
|
|
11
|
+
"experimentalDecorators": true,
|
|
12
|
+
"resolveJsonModule": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"removeComments": false,
|
|
15
|
+
"jsx": "preserve",
|
|
16
|
+
"lib": ["esnext"],
|
|
17
|
+
"rootDir": ".",
|
|
18
|
+
"types": [
|
|
19
|
+
"miniprogram-api-typings"
|
|
20
|
+
],
|
|
21
|
+
"outDir": "dist",
|
|
22
|
+
"paths": {
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"include": [
|
|
26
|
+
"src/**/*.js",
|
|
27
|
+
"src/**/*.ts"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
|