@tmsfe/tms-core 0.0.10 → 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 +19 -44
- package/package.json +1 -1
- package/src/fastreport.js +13 -7
- package/src/report.js +9 -24
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);
|
|
@@ -1248,16 +1253,21 @@ const formatReportData = async (reportData, deviceData) => {
|
|
|
1248
1253
|
|
|
1249
1254
|
}; // 对部分空数据使用默认数据填充
|
|
1250
1255
|
|
|
1251
|
-
|
|
1252
|
-
|
|
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]);
|
|
1253
1264
|
}); // 所有上报数据都转换为字符串
|
|
1254
1265
|
|
|
1255
1266
|
param.forEach((reportItem, index) => {
|
|
1256
1267
|
if (reportItem && typeof reportItem !== 'string') {
|
|
1257
1268
|
param[index] = `${JSON.stringify(reportItem)}`;
|
|
1258
1269
|
} else {
|
|
1259
|
-
|
|
1260
|
-
param[index] = paramItem || paramItem === 0 ? `${paramItem}` : '';
|
|
1270
|
+
param[index] = handleDefaultData(reportItem, '');
|
|
1261
1271
|
}
|
|
1262
1272
|
});
|
|
1263
1273
|
return param.map(item => item !== null ? encodeURIComponent(item) : item);
|
|
@@ -1476,41 +1486,6 @@ const startListenApp = () => {
|
|
|
1476
1486
|
// onHide时立即上报,并清除定时器
|
|
1477
1487
|
report(true, true);
|
|
1478
1488
|
});
|
|
1479
|
-
/**
|
|
1480
|
-
* 监听小程序路由切换事件
|
|
1481
|
-
*/
|
|
1482
|
-
|
|
1483
|
-
if (!wx.onAppRoute) {
|
|
1484
|
-
cache({
|
|
1485
|
-
26: 'H',
|
|
1486
|
-
27: 'H100',
|
|
1487
|
-
40: 'notReport'
|
|
1488
|
-
}, true);
|
|
1489
|
-
wx.reportAnalytics('onapproute_not_support', {
|
|
1490
|
-
mp_version: getMiniProgramVersion()
|
|
1491
|
-
});
|
|
1492
|
-
return;
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1495
|
-
wx.onAppRoute(res => {
|
|
1496
|
-
const {
|
|
1497
|
-
path,
|
|
1498
|
-
query,
|
|
1499
|
-
openType
|
|
1500
|
-
} = res || {};
|
|
1501
|
-
cache({
|
|
1502
|
-
26: 'H',
|
|
1503
|
-
27: 'H100',
|
|
1504
|
-
38: path,
|
|
1505
|
-
39: JSON.stringify(query),
|
|
1506
|
-
40: openType
|
|
1507
|
-
});
|
|
1508
|
-
wx.reportAnalytics('page_show', {
|
|
1509
|
-
path,
|
|
1510
|
-
query: JSON.stringify(query),
|
|
1511
|
-
opentype: openType
|
|
1512
|
-
});
|
|
1513
|
-
});
|
|
1514
1489
|
};
|
|
1515
1490
|
|
|
1516
1491
|
/**
|
package/package.json
CHANGED
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/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
|
|
|
@@ -409,26 +414,6 @@ const startListenApp = () => {
|
|
|
409
414
|
// onHide时立即上报,并清除定时器
|
|
410
415
|
report(true, true);
|
|
411
416
|
});
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* 监听小程序路由切换事件
|
|
415
|
-
*/
|
|
416
|
-
if (!wx.onAppRoute) {
|
|
417
|
-
cache({ 26: 'H', 27: 'H100', 40: 'notReport' }, true);
|
|
418
|
-
wx.reportAnalytics('onapproute_not_support', {
|
|
419
|
-
mp_version: getMiniProgramVersion(),
|
|
420
|
-
});
|
|
421
|
-
return;
|
|
422
|
-
}
|
|
423
|
-
wx.onAppRoute((res) => {
|
|
424
|
-
const { path, query, openType } = res || {};
|
|
425
|
-
cache({ 26: 'H', 27: 'H100', 38: path, 39: JSON.stringify(query), 40: openType });
|
|
426
|
-
wx.reportAnalytics('page_show', {
|
|
427
|
-
path,
|
|
428
|
-
query: JSON.stringify(query),
|
|
429
|
-
opentype: openType,
|
|
430
|
-
});
|
|
431
|
-
});
|
|
432
417
|
};
|
|
433
418
|
|
|
434
419
|
export {
|