@tmsfe/tms-core 0.0.126 → 0.0.128
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/report/formatV2.ts +3 -1
- package/src/report/helper.ts +27 -1
- package/src/runtime/index.js +10 -4
- package/src/runtime/login.ts +23 -3
package/package.json
CHANGED
package/src/report/formatV2.ts
CHANGED
|
@@ -64,7 +64,9 @@ function getBaseData(page: IPage, deviceData: IDeviceData): { arr: DataItem[], n
|
|
|
64
64
|
arr[25] = page.depth;
|
|
65
65
|
// 26: f26,一次小程序生命周期中的埋点统一标记
|
|
66
66
|
arr[26] = helper.getLifeReportKey();
|
|
67
|
-
// 27
|
|
67
|
+
// 27: f27,生成用户唯一id,方便追踪未登录接口
|
|
68
|
+
arr[27] = helper.getTmsUUID();
|
|
69
|
+
// 28 ~ 30: 预留字段给后续扩展使用
|
|
68
70
|
// 31 ~ 40: 提供给开发自定义
|
|
69
71
|
// --------------------------字段列表--------------------------
|
|
70
72
|
return { arr, nextIndex: 31 };
|
package/src/report/helper.ts
CHANGED
|
@@ -103,6 +103,31 @@ function getNowString(): string {
|
|
|
103
103
|
return `${year}${month}${day}${hours}${minutes}${seconds}${ms}`;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
let uuid = '';
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 生成用户唯一id,方便追踪未登录接口
|
|
110
|
+
*/
|
|
111
|
+
function getTmsUUID(): string {
|
|
112
|
+
if (uuid) {
|
|
113
|
+
return uuid;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const key = 'tms.user.uuid';
|
|
117
|
+
uuid = wx.getStorageSync(key);
|
|
118
|
+
if (!uuid) {
|
|
119
|
+
const str = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx';
|
|
120
|
+
uuid = str.replace(/[xy]/g, (c) => {
|
|
121
|
+
const r = (Math.random() * 16) | 0;
|
|
122
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
123
|
+
return v.toString(16);
|
|
124
|
+
});
|
|
125
|
+
wx.setStorageSync(key, uuid);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return uuid;
|
|
129
|
+
}
|
|
130
|
+
|
|
106
131
|
let lifeReportKey = '';
|
|
107
132
|
|
|
108
133
|
/**
|
|
@@ -181,7 +206,7 @@ function getAppScene(): number {
|
|
|
181
206
|
let isCrawler: boolean | null = null;
|
|
182
207
|
|
|
183
208
|
/**
|
|
184
|
-
*
|
|
209
|
+
* 判断当前是否需要发埋点(爬虫和插自动化测试下打开的不发)
|
|
185
210
|
*/
|
|
186
211
|
function canReport(): boolean {
|
|
187
212
|
if (isCrawler === null) {
|
|
@@ -271,6 +296,7 @@ function post(api: string, params: any): Promise<{ errCode: number, errMsg: stri
|
|
|
271
296
|
export default {
|
|
272
297
|
init,
|
|
273
298
|
post,
|
|
299
|
+
getTmsUUID,
|
|
274
300
|
getClientName,
|
|
275
301
|
getAppVersion,
|
|
276
302
|
getSystemInfo,
|
package/src/runtime/index.js
CHANGED
|
@@ -96,7 +96,10 @@ const login = async () => {
|
|
|
96
96
|
*/
|
|
97
97
|
async function setPaypointAuth(param = {}) {
|
|
98
98
|
const request = getRequestInstnce();
|
|
99
|
-
const userInfo = await
|
|
99
|
+
const [userInfo, mycarPubOpenId] = await Promise.all([
|
|
100
|
+
getLoginInfo(),
|
|
101
|
+
getMycarPubOpenId(),
|
|
102
|
+
]);
|
|
100
103
|
|
|
101
104
|
const req = {
|
|
102
105
|
traceSource: param.traceSource || 1, // 请求类型
|
|
@@ -106,7 +109,7 @@ async function setPaypointAuth(param = {}) {
|
|
|
106
109
|
subAppId: param.appId || 'wx735359beafd78b9f', // 默认使用我的车的小程序号发布号发布
|
|
107
110
|
appId: param.wechaId || 'wx29d15d946a7f2351', // 默认使用我的车的公众号id
|
|
108
111
|
...userInfo,
|
|
109
|
-
openId:
|
|
112
|
+
openId: mycarPubOpenId,
|
|
110
113
|
};
|
|
111
114
|
|
|
112
115
|
const res = await request.post('paypoint/setpayauth', req);
|
|
@@ -173,7 +176,10 @@ async function getPermissionList(param = {}) {
|
|
|
173
176
|
*/
|
|
174
177
|
async function terminatePaypointPermisson(param = {}) {
|
|
175
178
|
const request = getRequestInstnce();
|
|
176
|
-
const userInfo = await
|
|
179
|
+
const [userInfo, mycarPubOpenId] = await Promise.all([
|
|
180
|
+
getLoginInfo(),
|
|
181
|
+
getMycarPubOpenId(),
|
|
182
|
+
]);
|
|
177
183
|
|
|
178
184
|
const data = {
|
|
179
185
|
traceSource: param.traceSource || 1, // 请求来源
|
|
@@ -185,7 +191,7 @@ async function terminatePaypointPermisson(param = {}) {
|
|
|
185
191
|
reason: param.reason || '其他',
|
|
186
192
|
serviceId: param.serviceId,
|
|
187
193
|
...userInfo,
|
|
188
|
-
openId:
|
|
194
|
+
openId: mycarPubOpenId,
|
|
189
195
|
};
|
|
190
196
|
|
|
191
197
|
const res = await request.post('paypoint/terminatePaypointPermisson', data);
|
package/src/runtime/login.ts
CHANGED
|
@@ -82,7 +82,12 @@ async function login() {
|
|
|
82
82
|
// @ts-ignore
|
|
83
83
|
const { trafficEntrence: registerSource, scene: sceneId } = getOpenAppTrafficData();
|
|
84
84
|
|
|
85
|
-
userData = await getApp().tms.createRequest({ withAuth: false }).post('user/login', {
|
|
85
|
+
userData = await getApp().tms.createRequest({ withAuth: false }).post('user/login', {
|
|
86
|
+
code,
|
|
87
|
+
sceneId,
|
|
88
|
+
registerSource,
|
|
89
|
+
apiVer: 1, // 1表示不需要再去请求mycarPubOpenId,能快100ms
|
|
90
|
+
});
|
|
86
91
|
} catch (e) {
|
|
87
92
|
console.error(e); // eslint-disable-line
|
|
88
93
|
}
|
|
@@ -156,12 +161,27 @@ let getMycarPubOpenIdProm;
|
|
|
156
161
|
* 获取失败时,返回rejected Promise,rejected数据为错误对象
|
|
157
162
|
*/
|
|
158
163
|
const getMycarPubOpenId = () => {
|
|
159
|
-
if (getMycarPubOpenIdProm) {
|
|
164
|
+
if (getMycarPubOpenIdProm) {
|
|
165
|
+
return getMycarPubOpenIdProm;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// 优先用缓存的
|
|
169
|
+
const key = 'tms.pubOpenId';
|
|
170
|
+
const pubOpenId = wx.getStorageSync(key);
|
|
171
|
+
if (pubOpenId) {
|
|
172
|
+
getMycarPubOpenIdProm = Promise.resolve(pubOpenId);
|
|
160
173
|
return getMycarPubOpenIdProm;
|
|
161
174
|
}
|
|
162
175
|
|
|
176
|
+
// 从接口请求
|
|
163
177
|
getMycarPubOpenIdProm = getOaPubOpenId('mycar')
|
|
164
|
-
.then(
|
|
178
|
+
.then((pubOpenId) => {
|
|
179
|
+
if (pubOpenId) {
|
|
180
|
+
wx.setStorageSync(key, pubOpenId);
|
|
181
|
+
return pubOpenId;
|
|
182
|
+
}
|
|
183
|
+
return Promise.reject(new Error('No mycarPubOpenId found'));
|
|
184
|
+
})
|
|
165
185
|
.catch((e) => {
|
|
166
186
|
getMycarPubOpenIdProm = null;
|
|
167
187
|
return Promise.reject(e);
|