@tmsfe/tms-core 0.0.60 → 0.0.61
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
CHANGED
|
@@ -9,6 +9,31 @@ import clone from './clone';
|
|
|
9
9
|
|
|
10
10
|
let originalComponent: any = null;
|
|
11
11
|
|
|
12
|
+
// 劫持Component的生命周期
|
|
13
|
+
function proxyLifeMethod(componentName: string, componentOptions: any, methodName: string): void {
|
|
14
|
+
/* eslint-disable */
|
|
15
|
+
componentOptions.lifetimes = componentOptions.lifetimes || {};
|
|
16
|
+
let original = helper.emptyFunc;
|
|
17
|
+
const proxyMethod = function (...args: any[]): any {
|
|
18
|
+
// 生命周期函数先发埋点,避免次过程用户退出而丢失埋点
|
|
19
|
+
const data = clone.deepClone(this.data);
|
|
20
|
+
const eventName = `Component_${componentName}_${methodName}`;
|
|
21
|
+
helper.reportData(eventName, data);
|
|
22
|
+
// 执行原函数
|
|
23
|
+
return helper.executeFunc(this, original, args, helper.emptyFunc);
|
|
24
|
+
}
|
|
25
|
+
if (componentOptions.lifetimes[methodName]) {
|
|
26
|
+
original = componentOptions.lifetimes[methodName];
|
|
27
|
+
componentOptions.lifetimes[methodName] = proxyMethod;
|
|
28
|
+
} else if (componentOptions[methodName]) {
|
|
29
|
+
original = componentOptions[methodName];
|
|
30
|
+
componentOptions[methodName] = proxyMethod;
|
|
31
|
+
} else {
|
|
32
|
+
componentOptions.lifetimes[methodName] = proxyMethod;
|
|
33
|
+
}
|
|
34
|
+
/* eslint-enable */
|
|
35
|
+
}
|
|
36
|
+
|
|
12
37
|
// 劫持绑定事件
|
|
13
38
|
function proxyBindEvent(componentName: string, methods: any, methodName: string): void {
|
|
14
39
|
const original = methods[methodName];
|
|
@@ -30,7 +55,6 @@ function proxyBindEvent(componentName: string, methods: any, methodName: string)
|
|
|
30
55
|
|
|
31
56
|
// 劫持Page
|
|
32
57
|
function init(): void {
|
|
33
|
-
// @ts-ignore
|
|
34
58
|
originalComponent = Component;
|
|
35
59
|
// @ts-ignore
|
|
36
60
|
Component = function (options: any) {
|
|
@@ -41,6 +65,7 @@ function init(): void {
|
|
|
41
65
|
for (const name of options.tmsReportEvents) {
|
|
42
66
|
proxyBindEvent(options.tmsComponentName, methods, name);
|
|
43
67
|
}
|
|
68
|
+
proxyLifeMethod(options.tmsComponentName, options, 'ready');
|
|
44
69
|
}
|
|
45
70
|
originalComponent(options);
|
|
46
71
|
};
|
package/src/report/proxy/page.ts
CHANGED
|
@@ -101,9 +101,7 @@ function proxyBindEvent(pageOptions: any, methodName: string): void {
|
|
|
101
101
|
|
|
102
102
|
// 劫持Page
|
|
103
103
|
function proxyPage(): void {
|
|
104
|
-
// @ts-ignore
|
|
105
104
|
originalPage = Page;
|
|
106
|
-
// @ts-ignore
|
|
107
105
|
Page = function (options: any) {
|
|
108
106
|
// 只有tms的页面才需要上报
|
|
109
107
|
if (options.tmsAutoReport) {
|
|
@@ -122,9 +120,8 @@ function proxyPage(): void {
|
|
|
122
120
|
// 劫持导航api
|
|
123
121
|
function proxyNavigateApi(api: string): void {
|
|
124
122
|
// @ts-ignore
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
Object.defineProperty(owx, api, {
|
|
123
|
+
const originalApi = wx[api];
|
|
124
|
+
Object.defineProperty(wx, api, {
|
|
128
125
|
writable: true,
|
|
129
126
|
enumerable: true,
|
|
130
127
|
configurable: true,
|