@tmsfe/tms-core 0.0.29 → 0.0.30
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 +1 -1
- package/src/cloudReport.ts +15 -11
- package/src/fastreport.js +17 -56
package/package.json
CHANGED
package/src/cloudReport.ts
CHANGED
|
@@ -37,6 +37,17 @@ function getSystemInfoString(): string {
|
|
|
37
37
|
return encodeURIComponent(JSON.stringify(info));
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
+
function convert2String(value: any): string {
|
|
41
|
+
const type = typeof value;
|
|
42
|
+
if (type === 'string') {
|
|
43
|
+
return value;
|
|
44
|
+
}
|
|
45
|
+
if (type === 'object') {
|
|
46
|
+
return JSON.stringify(value);
|
|
47
|
+
}
|
|
48
|
+
return String(value);
|
|
49
|
+
}
|
|
50
|
+
|
|
40
51
|
function getSeqInfo(): { timestamp: number, seqId: string } {
|
|
41
52
|
const timestamp = Date.now();
|
|
42
53
|
const random = Math.random().toString();
|
|
@@ -123,16 +134,7 @@ function formatData(page: IPage, seqId: string, data: any[]): DataType[] {
|
|
|
123
134
|
console.error(data);
|
|
124
135
|
throw new Error('埋点参数个数超出上限');
|
|
125
136
|
}
|
|
126
|
-
|
|
127
|
-
let value: string;
|
|
128
|
-
if (type === 'string') {
|
|
129
|
-
value = item;
|
|
130
|
-
} else if (type === 'object') {
|
|
131
|
-
value = JSON.stringify(item);
|
|
132
|
-
} else {
|
|
133
|
-
value = String(item);
|
|
134
|
-
}
|
|
135
|
-
arr[index] = value;
|
|
137
|
+
arr[index] = convert2String(item);
|
|
136
138
|
index += 1;
|
|
137
139
|
}
|
|
138
140
|
return arr;
|
|
@@ -185,11 +187,13 @@ function doCallCloudFunc(arr: DataType[], timestamp: number, seqId: string, open
|
|
|
185
187
|
*/
|
|
186
188
|
function callCloudFunc(arr: string[]): void {
|
|
187
189
|
const { timestamp, seqId } = getSeqInfo();
|
|
188
|
-
doCallCloudFunc(arr, timestamp, seqId,
|
|
190
|
+
doCallCloudFunc(arr, timestamp, seqId, openidIndex);
|
|
189
191
|
}
|
|
190
192
|
|
|
191
193
|
export default {
|
|
192
194
|
init,
|
|
193
195
|
report,
|
|
194
196
|
callCloudFunc,
|
|
197
|
+
convert2String,
|
|
198
|
+
getSystemInfoString,
|
|
195
199
|
};
|
package/src/fastreport.js
CHANGED
|
@@ -3,28 +3,14 @@
|
|
|
3
3
|
* @author Fenggang.Sun <fenggangsun@tencent.com>
|
|
4
4
|
* @file 快速上报数据,不处理过多逻辑,保证快速上报
|
|
5
5
|
*/
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import Sync from './syncfnmanager';
|
|
9
|
-
|
|
10
|
-
let simulatedUserIdCache; // 模拟用户id在内存里的缓存
|
|
11
|
-
|
|
12
|
-
const getSystemInfo = () => {
|
|
13
|
-
const system = Sync.getSystemInfoSync();
|
|
14
|
-
const { model = '', version: wxVersion = '', platform = '', SDKVersion = '', host = '' } = system;
|
|
15
|
-
|
|
16
|
-
return { model, wxVersion, platform, SDKVersion, host };
|
|
17
|
-
};
|
|
6
|
+
import { getEnvInfo, getAuthInfo } from './env';
|
|
7
|
+
import CloudReport from './cloudReport';
|
|
18
8
|
|
|
19
9
|
const handleParamOfDifferentType = (param) => {
|
|
20
10
|
const data = new Array(41);
|
|
21
11
|
Object.keys(param).forEach((key) => {
|
|
22
|
-
|
|
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]);
|
|
12
|
+
data[key] = CloudReport.convert2String(param[key]);
|
|
26
13
|
});
|
|
27
|
-
|
|
28
14
|
return data;
|
|
29
15
|
};
|
|
30
16
|
|
|
@@ -39,52 +25,27 @@ export default class FastReport {
|
|
|
39
25
|
* @memberof FastReport
|
|
40
26
|
* @description 快速上报
|
|
41
27
|
* @param {Object} param 埋点数据
|
|
42
|
-
* @param {Boolean} simulatedUserId 是否上报模拟用户Id
|
|
43
|
-
* @param {Number} simulatedUserIdIndex 上报模拟用户ID时放在哪个字段
|
|
44
|
-
* @param {Boolean} reportShowScene 是否上报小程序onShow场景值
|
|
45
|
-
* @param {Boolean} appVer 是否上报小程序版本
|
|
46
|
-
* @returns {Promsie} 返回上报结果
|
|
47
28
|
*/
|
|
48
|
-
static report(param = {}
|
|
49
|
-
if (!param[27])
|
|
29
|
+
static report(param = {}) {
|
|
30
|
+
if (!param[27]) {
|
|
31
|
+
return Promise.reject('invalid report param');
|
|
32
|
+
}
|
|
50
33
|
const env = getEnvInfo();
|
|
51
34
|
const data = handleParamOfDifferentType(param);
|
|
52
35
|
data[9] = '2';
|
|
53
|
-
data[
|
|
54
|
-
if (appVer) {
|
|
55
|
-
data[10] = defAssign(data[10], env.appVersion);
|
|
56
|
-
}
|
|
36
|
+
data[10] = defAssign(data[10], env.appVersion);
|
|
57
37
|
data[26] = defAssign(data[26], data[27]?.[0]);
|
|
58
38
|
data[28] = env.client;
|
|
59
|
-
if (
|
|
39
|
+
if (!data[29]) {
|
|
60
40
|
const appShowScene = wx.getStorageSync('appShowScene');
|
|
61
|
-
if (appShowScene)
|
|
41
|
+
if (appShowScene) {
|
|
42
|
+
data[29] = String(appShowScene);
|
|
43
|
+
}
|
|
62
44
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.catch(() => null);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @memberof FastReport
|
|
73
|
-
* @description 获取模拟的用户身份标识
|
|
74
|
-
* @returns {String} 用户的临时标识
|
|
75
|
-
*/
|
|
76
|
-
static getSimulatedUserId() {
|
|
77
|
-
// 优先使用内存级缓存
|
|
78
|
-
if (simulatedUserIdCache) return simulatedUserIdCache;
|
|
79
|
-
const key = 'SimulatedUserKey';
|
|
80
|
-
// 读取本地缓存记录的值
|
|
81
|
-
simulatedUserIdCache = wx.getStorageSync(key);
|
|
82
|
-
if (simulatedUserIdCache) return simulatedUserIdCache;
|
|
83
|
-
// 生成新的值
|
|
84
|
-
const nonce = Math.random().toString(36)
|
|
85
|
-
.substr(2, 10);
|
|
86
|
-
simulatedUserIdCache = `${Date.now()}_${nonce}`;
|
|
87
|
-
wx.setStorage({ key, data: simulatedUserIdCache });
|
|
88
|
-
return simulatedUserIdCache;
|
|
45
|
+
data[33] = CloudReport.getSystemInfoString();
|
|
46
|
+
getAuthInfo().then((user) => {
|
|
47
|
+
data[5] = user.uid;
|
|
48
|
+
CloudReport.callCloudFunc(data);
|
|
49
|
+
});
|
|
89
50
|
}
|
|
90
51
|
};
|