@tmsfe/tms-core 0.0.98 → 0.0.100
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/index-proxy.js +1 -1
- package/src/report/proxy/component.ts +40 -6
- package/src/report/proxy/page.ts +33 -6
- package/src/request.js +1 -1
- package/src/runtime/index.js +11 -1
- package/tsconfig.json +0 -30
package/package.json
CHANGED
package/src/index-proxy.js
CHANGED
|
@@ -66,7 +66,7 @@ const asyncFuncNames = [
|
|
|
66
66
|
// 这行是tms-ui的
|
|
67
67
|
'showDrawer', 'hideDrawer', 'showModal', 'hideModal',
|
|
68
68
|
// 这行是runtime的
|
|
69
|
-
'getPhone', 'registerPhone', 'login', 'getLoginInfo', 'getOpenId', 'getMycarPubOpenId', 'getSinanPubOpenId',
|
|
69
|
+
'getPhone', 'registerPhone', 'login', 'checkLogin', 'getLoginInfo', 'getOpenId', 'getMycarPubOpenId', 'getSinanPubOpenId',
|
|
70
70
|
// tms-core
|
|
71
71
|
'setAuthInfo', 'getConfig', 'getApolloConfig', 'navigateToWebview', 'callCloudFunc', 'getEncryptUserInfo',
|
|
72
72
|
'setUserLocation', 'getUserLocation', 'getMpOpenId', 'getOuterOpenId',
|
|
@@ -5,11 +5,12 @@
|
|
|
5
5
|
|
|
6
6
|
// / <reference path='./types.ts'/>
|
|
7
7
|
|
|
8
|
+
// uniapp转换工具执行之后会打开这句注释
|
|
9
|
+
// import Vue from 'vue';
|
|
10
|
+
|
|
8
11
|
import clone from '../clone';
|
|
9
12
|
import helper from './helper';
|
|
10
13
|
|
|
11
|
-
let originalComponent: any = null;
|
|
12
|
-
|
|
13
14
|
// 劫持Component的生命周期
|
|
14
15
|
function proxyLifeMethod(componentName: string, componentOptions: any, methodName: string): void {
|
|
15
16
|
/* eslint-disable */
|
|
@@ -21,7 +22,9 @@ function proxyLifeMethod(componentName: string, componentOptions: any, methodNam
|
|
|
21
22
|
obj[methodName] = function (...args: any[]): any {
|
|
22
23
|
// 生命周期函数先发埋点,避免次过程用户退出而丢失埋点
|
|
23
24
|
const data = clone.deepClone(this.data);
|
|
24
|
-
|
|
25
|
+
// vue下组件ready事件名是mounted,这里统一改为跟小程序一样用ready
|
|
26
|
+
const funcName = methodName === 'mounted' ? 'ready' : methodName;
|
|
27
|
+
const eventName = `Component_${componentName}_${funcName}`;
|
|
25
28
|
helper.reportData(eventName, data);
|
|
26
29
|
// 执行原函数
|
|
27
30
|
return helper.executeFunc(this, original, args, helper.emptyFunc);
|
|
@@ -48,9 +51,9 @@ function proxyBindEvent(componentName: string, methods: any, methodName: string,
|
|
|
48
51
|
};
|
|
49
52
|
}
|
|
50
53
|
|
|
51
|
-
//
|
|
52
|
-
function
|
|
53
|
-
originalComponent = Component;
|
|
54
|
+
// 劫持小程序的Component
|
|
55
|
+
function proxyMpComponent(): void {
|
|
56
|
+
const originalComponent = Component;
|
|
54
57
|
// @ts-ignore
|
|
55
58
|
Component = function (options: any) {
|
|
56
59
|
// 只有tms的页面才需要上报
|
|
@@ -67,6 +70,37 @@ function init(): void {
|
|
|
67
70
|
};
|
|
68
71
|
}
|
|
69
72
|
|
|
73
|
+
// 劫持vue的Component
|
|
74
|
+
function proxyVueComponent(): void {
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
Vue.mixin({
|
|
77
|
+
beforeCreate() {
|
|
78
|
+
const options = this.$options;
|
|
79
|
+
// 有组件名则不是页面
|
|
80
|
+
if (!options.tmsAutoReport || !options.tmsComponentName) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const { methods } = options;
|
|
85
|
+
for (const event of options.tmsReportEvents) {
|
|
86
|
+
const { name, type } = event;
|
|
87
|
+
proxyBindEvent(options.tmsComponentName, methods, name, type);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
proxyLifeMethod(options.tmsComponentName, options, 'mounted');
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 劫持Page
|
|
96
|
+
function init(): void {
|
|
97
|
+
if (wx.isH5) {
|
|
98
|
+
proxyVueComponent();
|
|
99
|
+
} else {
|
|
100
|
+
proxyMpComponent();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
70
104
|
export default {
|
|
71
105
|
init,
|
|
72
106
|
};
|
package/src/report/proxy/page.ts
CHANGED
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
// / <reference path='./types.ts'/>
|
|
7
7
|
|
|
8
|
+
// uniapp转换工具执行之后会打开这句注释
|
|
9
|
+
// import Vue from 'vue';
|
|
10
|
+
|
|
8
11
|
import clone from '../clone';
|
|
9
12
|
import helper from './helper';
|
|
10
13
|
|
|
@@ -19,8 +22,6 @@ const maybeLifeMethods = [
|
|
|
19
22
|
];
|
|
20
23
|
const lifeMethods = mustLifeMethods.concat(maybeLifeMethods);
|
|
21
24
|
|
|
22
|
-
let originalPage: any = null;
|
|
23
|
-
|
|
24
25
|
// 劫持Page的生命周期
|
|
25
26
|
function proxyLifeMethod(pageOptions: any, methodName: string): void {
|
|
26
27
|
if (!pageOptions[methodName] && !mustLifeMethods.includes(methodName)) {
|
|
@@ -104,9 +105,9 @@ function proxyBindEvent(pageOptions: any, methodName: string, bindType: string):
|
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
//
|
|
108
|
-
function
|
|
109
|
-
originalPage = Page;
|
|
108
|
+
// 劫持小程序的Page
|
|
109
|
+
function proxyMpPage(): void {
|
|
110
|
+
const originalPage = Page;
|
|
110
111
|
Page = function (options: any) {
|
|
111
112
|
// 只有tms的页面才需要上报
|
|
112
113
|
if (options.tmsAutoReport) {
|
|
@@ -123,9 +124,35 @@ function proxyPage(): void {
|
|
|
123
124
|
};
|
|
124
125
|
}
|
|
125
126
|
|
|
127
|
+
// 劫持vue的Page
|
|
128
|
+
function proxyVuePage(): void {
|
|
129
|
+
// @ts-ignore
|
|
130
|
+
Vue.mixin({
|
|
131
|
+
beforeCreate() {
|
|
132
|
+
const options = this.$options;
|
|
133
|
+
// 有组件名则不是页面
|
|
134
|
+
if (!options.tmsAutoReport || options.tmsComponentName) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
for (const methodName of lifeMethods) {
|
|
139
|
+
proxyLifeMethod(options, methodName);
|
|
140
|
+
}
|
|
141
|
+
for (const event of options.tmsReportEvents) {
|
|
142
|
+
const { name, type } = event;
|
|
143
|
+
proxyBindEvent(options.methods, name, type);
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
|
|
126
149
|
// 劫持Page
|
|
127
150
|
function init(): void {
|
|
128
|
-
|
|
151
|
+
if (wx.isH5) {
|
|
152
|
+
proxyVuePage();
|
|
153
|
+
} else {
|
|
154
|
+
proxyMpPage();
|
|
155
|
+
}
|
|
129
156
|
}
|
|
130
157
|
|
|
131
158
|
export default {
|
package/src/request.js
CHANGED
|
@@ -264,7 +264,7 @@ export default class Request {
|
|
|
264
264
|
/**
|
|
265
265
|
* @memberof Request
|
|
266
266
|
* @param {string} path 请求接口路径
|
|
267
|
-
* @param {
|
|
267
|
+
* @param {object} param 业务参数
|
|
268
268
|
* @param {string} method 请求方法 get/post
|
|
269
269
|
* @param {object} header 自定义的请求头
|
|
270
270
|
* @returns {object} 接口返回结果
|
package/src/runtime/index.js
CHANGED
|
@@ -47,6 +47,15 @@ const loginInfoPromise = new Promise(resolver => __resolver__.getLoginInfo = res
|
|
|
47
47
|
*/
|
|
48
48
|
const getLoginInfo = () => loginInfoPromise;
|
|
49
49
|
|
|
50
|
+
/**
|
|
51
|
+
* @public
|
|
52
|
+
* @description 获取用户userId等登录信息
|
|
53
|
+
* @param autoLogin 未登录时是否自动登录(小程序中启动时就已登录,该参数用于uniapp的h5页面)
|
|
54
|
+
*/
|
|
55
|
+
function checkLogin(autoLogin = false) {
|
|
56
|
+
// uniapp的h5会覆盖checkLogin函数实现检查和自动登录功能
|
|
57
|
+
return getLoginInfo().then(() => true);
|
|
58
|
+
}
|
|
50
59
|
|
|
51
60
|
/**
|
|
52
61
|
* tms.getCarManager 用户获取小程序统一维护的车信息管理器
|
|
@@ -62,7 +71,7 @@ const getCarManager = () => Car;
|
|
|
62
71
|
* 返回数据示意
|
|
63
72
|
* {
|
|
64
73
|
* userId: "1135608",
|
|
65
|
-
* token: "
|
|
74
|
+
* token: "xxxxxx",
|
|
66
75
|
* firstLogin: 0,
|
|
67
76
|
* },
|
|
68
77
|
*/
|
|
@@ -226,6 +235,7 @@ const api = {
|
|
|
226
235
|
getPhone,
|
|
227
236
|
registerPhone,
|
|
228
237
|
login,
|
|
238
|
+
checkLogin,
|
|
229
239
|
getLoginInfo,
|
|
230
240
|
getOpenId,
|
|
231
241
|
getMycarPubOpenId,
|
package/tsconfig.json
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
{
|
|
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
|
-
|