@tmsfe/tms-core 0.0.13 → 0.0.14
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.js +23 -19
- package/package.json +2 -4
- package/src/fastreport.js +13 -7
- package/src/location/base.ts +4 -11
- package/src/report.js +9 -4
package/dist/index.js
CHANGED
|
@@ -28,6 +28,15 @@ const getSystemInfo$1 = () => {
|
|
|
28
28
|
host
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
+
|
|
32
|
+
const handleParamOfDifferentType = param => {
|
|
33
|
+
const data = new Array(41);
|
|
34
|
+
Object.keys(param).forEach(key => {
|
|
35
|
+
const valType = typeof param[key];
|
|
36
|
+
if (valType === 'string') data[key] = param[key];else if (valType === 'object') data[key] = JSON.stringify(param[key]);else data[key] = String(param[key]);
|
|
37
|
+
});
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
31
40
|
/**
|
|
32
41
|
* @class FastReport
|
|
33
42
|
* @classdesc 快速上报模块,不依赖用户标识和位置
|
|
@@ -49,12 +58,8 @@ class FastReport {
|
|
|
49
58
|
var _data$;
|
|
50
59
|
|
|
51
60
|
if (!(param !== null && param !== void 0 && param[27])) return Promise.reject('invalid report param');
|
|
52
|
-
const data = new Array(41);
|
|
53
61
|
const env = getEnvInfo();
|
|
54
|
-
|
|
55
|
-
const valType = typeof param[key];
|
|
56
|
-
if (valType === 'string') data[key] = param[key];else if (valType === 'object') data[key] = JSON.stringify(param[key]);else data[key] = String(param[key]);
|
|
57
|
-
});
|
|
62
|
+
const data = handleParamOfDifferentType(param);
|
|
58
63
|
data[9] = '2';
|
|
59
64
|
data[33] = encodeURIComponent(JSON.stringify(getSystemInfo$1()));
|
|
60
65
|
appVer && !data[10] && (data[10] = env.appVersion);
|
|
@@ -543,8 +548,6 @@ function getWxLocation(type = defaultLocationType) {
|
|
|
543
548
|
});
|
|
544
549
|
});
|
|
545
550
|
}
|
|
546
|
-
// 是否开启监听位置变更
|
|
547
|
-
let isListenerLocation = false;
|
|
548
551
|
/**
|
|
549
552
|
* @class Location
|
|
550
553
|
* @classdesc 基于微信api,封装location相关的接口。 包括监听位置变化, 获取用户位置信息
|
|
@@ -552,14 +555,11 @@ let isListenerLocation = false;
|
|
|
552
555
|
*/
|
|
553
556
|
class LocationBase {
|
|
554
557
|
/**
|
|
555
|
-
* @private
|
|
558
|
+
* @private 构造函数
|
|
556
559
|
*/
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
wx.onLocationChange(this.subscribeLocationChnage);
|
|
561
|
-
wx.startLocationUpdate({});
|
|
562
|
-
}
|
|
560
|
+
constructor() {
|
|
561
|
+
wx.onLocationChange(this.subscribeLocationChnage);
|
|
562
|
+
wx.startLocationUpdate({});
|
|
563
563
|
}
|
|
564
564
|
/**
|
|
565
565
|
* 获取用户当前位置(经纬度)
|
|
@@ -609,7 +609,6 @@ class LocationBase {
|
|
|
609
609
|
getWxLocationPromise(showModalWhenCloseAuth, type, content = '', showCancel = true) {
|
|
610
610
|
return new Promise((resolve, reject) => {
|
|
611
611
|
getWxLocation(type).then((res) => {
|
|
612
|
-
this.listenerLocation();
|
|
613
612
|
userLocationCache$1 = res;
|
|
614
613
|
// 更新用户状态 -- todo
|
|
615
614
|
updateLocStatus(true);
|
|
@@ -1254,16 +1253,21 @@ const formatReportData = async (reportData, deviceData) => {
|
|
|
1254
1253
|
|
|
1255
1254
|
}; // 对部分空数据使用默认数据填充
|
|
1256
1255
|
|
|
1257
|
-
|
|
1258
|
-
|
|
1256
|
+
const handleDefaultData = (paramItem, defaultData) => {
|
|
1257
|
+
const arr = [paramItem, paramItem === 0, paramItem === false];
|
|
1258
|
+
return arr.some(item => !!item) ? paramItem : defaultData || '';
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1261
|
+
Object.keys(defaultReportData).forEach(index => {
|
|
1262
|
+
const paramItem = param[index];
|
|
1263
|
+
param[index] = handleDefaultData(paramItem, defaultReportData[index]);
|
|
1259
1264
|
}); // 所有上报数据都转换为字符串
|
|
1260
1265
|
|
|
1261
1266
|
param.forEach((reportItem, index) => {
|
|
1262
1267
|
if (reportItem && typeof reportItem !== 'string') {
|
|
1263
1268
|
param[index] = `${JSON.stringify(reportItem)}`;
|
|
1264
1269
|
} else {
|
|
1265
|
-
|
|
1266
|
-
param[index] = paramItem || paramItem === 0 ? `${paramItem}` : '';
|
|
1270
|
+
param[index] = handleDefaultData(reportItem, '');
|
|
1267
1271
|
}
|
|
1268
1272
|
});
|
|
1269
1273
|
return param.map(item => item !== null ? encodeURIComponent(item) : item);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tmsfe/tms-core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.14",
|
|
4
4
|
"description": "tms运行时框架",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -34,9 +34,7 @@
|
|
|
34
34
|
"rollup": "^2.6.1",
|
|
35
35
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
36
36
|
"rollup-plugin-terser": "^6.1.0",
|
|
37
|
-
"rollup-plugin-typescript2": "0.27.0"
|
|
38
|
-
"rollup-plugin-replace": "^2.2.0",
|
|
39
|
-
"typescript": "^4.5.2"
|
|
37
|
+
"rollup-plugin-typescript2": "0.27.0"
|
|
40
38
|
},
|
|
41
39
|
"author": "tms·web",
|
|
42
40
|
"gitHead": "72bf52451594b49a1c9f78edbad5956d414a66ca"
|
package/src/fastreport.js
CHANGED
|
@@ -16,6 +16,18 @@ const getSystemInfo = () => {
|
|
|
16
16
|
return { model, wxVersion, platform, SDKVersion, host };
|
|
17
17
|
};
|
|
18
18
|
|
|
19
|
+
const handleParamOfDifferentType = (param) => {
|
|
20
|
+
const data = new Array(41);
|
|
21
|
+
Object.keys(param).forEach((key) => {
|
|
22
|
+
const valType = typeof param[key];
|
|
23
|
+
if (valType === 'string') data[key] = param[key];
|
|
24
|
+
else if (valType === 'object') data[key] = JSON.stringify(param[key]);
|
|
25
|
+
else data[key] = String(param[key]);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return data;
|
|
29
|
+
};
|
|
30
|
+
|
|
19
31
|
/**
|
|
20
32
|
* @class FastReport
|
|
21
33
|
* @classdesc 快速上报模块,不依赖用户标识和位置
|
|
@@ -33,14 +45,8 @@ export default class FastReport {
|
|
|
33
45
|
*/
|
|
34
46
|
static report(param, simulatedUserId = true, simulatedUserIdIndex = 40, reportShowScene = true, appVer = true) {
|
|
35
47
|
if (!param?.[27]) return Promise.reject('invalid report param');
|
|
36
|
-
const data = new Array(41);
|
|
37
48
|
const env = getEnvInfo();
|
|
38
|
-
|
|
39
|
-
const valType = typeof param[key];
|
|
40
|
-
if (valType === 'string') data[key] = param[key];
|
|
41
|
-
else if (valType === 'object') data[key] = JSON.stringify(param[key]);
|
|
42
|
-
else data[key] = String(param[key]);
|
|
43
|
-
});
|
|
49
|
+
const data = handleParamOfDifferentType(param);
|
|
44
50
|
data[9] = '2';
|
|
45
51
|
data[33] = encodeURIComponent(JSON.stringify(getSystemInfo()));
|
|
46
52
|
appVer && !data[10] && (data[10] = env.appVersion);
|
package/src/location/base.ts
CHANGED
|
@@ -29,9 +29,6 @@ function getWxLocation(type: string = defaultLocationType): Promise<WxPostionTyp
|
|
|
29
29
|
});
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
// 是否开启监听位置变更
|
|
33
|
-
let isListenerLocation = false;
|
|
34
|
-
|
|
35
32
|
/**
|
|
36
33
|
* @class Location
|
|
37
34
|
* @classdesc 基于微信api,封装location相关的接口。 包括监听位置变化, 获取用户位置信息
|
|
@@ -39,14 +36,11 @@ let isListenerLocation = false;
|
|
|
39
36
|
*/
|
|
40
37
|
class LocationBase {
|
|
41
38
|
/**
|
|
42
|
-
* @private
|
|
39
|
+
* @private 构造函数
|
|
43
40
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
wx.onLocationChange(this.subscribeLocationChnage);
|
|
48
|
-
wx.startLocationUpdate({});
|
|
49
|
-
}
|
|
41
|
+
constructor() {
|
|
42
|
+
wx.onLocationChange(this.subscribeLocationChnage);
|
|
43
|
+
wx.startLocationUpdate({});
|
|
50
44
|
}
|
|
51
45
|
|
|
52
46
|
/**
|
|
@@ -101,7 +95,6 @@ class LocationBase {
|
|
|
101
95
|
public getWxLocationPromise(showModalWhenCloseAuth: boolean, type: string, content = '', showCancel = true) {
|
|
102
96
|
return new Promise((resolve, reject) => {
|
|
103
97
|
getWxLocation(type).then((res: WxPostionType) => {
|
|
104
|
-
this.listenerLocation();
|
|
105
98
|
userLocationCache = res;
|
|
106
99
|
// 更新用户状态 -- todo
|
|
107
100
|
updateLocStatus(true);
|
package/src/report.js
CHANGED
|
@@ -212,8 +212,14 @@ const formatReportData = async (reportData, deviceData) => {
|
|
|
212
212
|
36: getAppShowOptions(), // 打开小程序的场景值及参数
|
|
213
213
|
};
|
|
214
214
|
// 对部分空数据使用默认数据填充
|
|
215
|
-
|
|
216
|
-
|
|
215
|
+
const handleDefaultData = (paramItem, defaultData) => {
|
|
216
|
+
const arr = [paramItem, paramItem === 0, paramItem === false];
|
|
217
|
+
return (arr.some(item => !!item)) ? paramItem : (defaultData || '');
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
Object.keys(defaultReportData).forEach((index) => {
|
|
221
|
+
const paramItem = param[index];
|
|
222
|
+
param[index] = handleDefaultData(paramItem, defaultReportData[index]);
|
|
217
223
|
});
|
|
218
224
|
|
|
219
225
|
// 所有上报数据都转换为字符串
|
|
@@ -221,8 +227,7 @@ const formatReportData = async (reportData, deviceData) => {
|
|
|
221
227
|
if (reportItem && typeof reportItem !== 'string') {
|
|
222
228
|
param[index] = `${JSON.stringify(reportItem)}`;
|
|
223
229
|
} else {
|
|
224
|
-
|
|
225
|
-
param[index] = (paramItem || paramItem === 0) ? `${paramItem}` : '';
|
|
230
|
+
param[index] = handleDefaultData(reportItem, '');
|
|
226
231
|
}
|
|
227
232
|
});
|
|
228
233
|
|