@cloudcare/rum-uniapp 2.1.24 → 2.2.1
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/cjs/boot/buildEnv.js +1 -1
- package/cjs/helper/enums.js +2 -1
- package/cjs/rumEventsCollection/action/trackActions.js +29 -72
- package/cjs/rumEventsCollection/page/index.js +37 -49
- package/cjs/rumEventsCollection/setDataCollection.js +25 -56
- package/esm/boot/buildEnv.js +1 -1
- package/esm/helper/enums.js +2 -1
- package/esm/rumEventsCollection/action/trackActions.js +29 -72
- package/esm/rumEventsCollection/page/index.js +37 -49
- package/esm/rumEventsCollection/setDataCollection.js +25 -56
- package/package.json +1 -1
package/cjs/boot/buildEnv.js
CHANGED
package/cjs/helper/enums.js
CHANGED
|
@@ -9,8 +9,6 @@ var _lifeCycle = require("../../core/lifeCycle");
|
|
|
9
9
|
var _trackEventCounts = require("../trackEventCounts");
|
|
10
10
|
var _trackPageActiveites = require("../trackPageActiveites");
|
|
11
11
|
var _enums = require("../../helper/enums");
|
|
12
|
-
var _sdk = require("../../core/sdk");
|
|
13
|
-
var WHITE_METHOD = ['setup'];
|
|
14
12
|
function trackActions(lifeCycle, Vue) {
|
|
15
13
|
var action = startActionManagement(lifeCycle);
|
|
16
14
|
|
|
@@ -18,57 +16,34 @@ function trackActions(lifeCycle, Vue) {
|
|
|
18
16
|
lifeCycle.subscribe(_lifeCycle.LifeCycleEventType.VIEW_CREATED, function () {
|
|
19
17
|
action.discardCurrent();
|
|
20
18
|
});
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
var originComponent = Component;
|
|
46
|
-
Component = function Component(component) {
|
|
47
|
-
var methods = (0, _utils.getMethods)(component.methods);
|
|
48
|
-
methods.forEach(function (methodName) {
|
|
49
|
-
clickProxy(component, methodName, function (_action) {
|
|
50
|
-
action.create(_action.type, _action.name);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
return originComponent(component);
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
if (!hasComponent) {
|
|
57
|
-
var originCreatePage = _sdk.tracker.createPage;
|
|
58
|
-
_sdk.tracker.createPage = function (page) {
|
|
59
|
-
// methods 方法
|
|
60
|
-
proxyInstance(page, action, lifeCycle);
|
|
61
|
-
return originCreatePage.call(this, page);
|
|
62
|
-
};
|
|
63
|
-
var originCreateComponent = _sdk.tracker.createComponent;
|
|
64
|
-
_sdk.tracker.createComponent = function (component) {
|
|
65
|
-
proxyInstance(component, action, lifeCycle);
|
|
66
|
-
return originCreateComponent.call(this, component);
|
|
19
|
+
var hookClick = function hookClick(instance) {
|
|
20
|
+
var methods = (0, _utils.getMethods)(instance);
|
|
21
|
+
methods.forEach(function (methodName) {
|
|
22
|
+
clickProxy(instance, methodName, function (_action) {
|
|
23
|
+
action.create(_action.type, _action.name);
|
|
24
|
+
}, lifeCycle);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
var originPage = Page;
|
|
28
|
+
Page = function Page(page) {
|
|
29
|
+
try {
|
|
30
|
+
hookClick(page);
|
|
31
|
+
} catch (error) {}
|
|
32
|
+
return originPage(page);
|
|
33
|
+
};
|
|
34
|
+
var originComponent = Component;
|
|
35
|
+
Component = function Component(component) {
|
|
36
|
+
if (component.methods && component.methods.onLoad) {
|
|
37
|
+
var originOnLoad = component.methods.onLoad;
|
|
38
|
+
component.methods.onLoad = function () {
|
|
39
|
+
try {
|
|
40
|
+
hookClick(this);
|
|
41
|
+
} catch (error) {}
|
|
42
|
+
return originOnLoad.apply(this, arguments);
|
|
67
43
|
};
|
|
68
44
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
45
|
+
return originComponent(component);
|
|
46
|
+
};
|
|
72
47
|
return {
|
|
73
48
|
stop: function stop() {
|
|
74
49
|
action.discardCurrent();
|
|
@@ -77,25 +52,7 @@ function trackActions(lifeCycle, Vue) {
|
|
|
77
52
|
};
|
|
78
53
|
}
|
|
79
54
|
|
|
80
|
-
function proxyInstance(options, action, lifeCycle) {
|
|
81
|
-
// methods 方法
|
|
82
|
-
if (options.methods) {
|
|
83
|
-
var vueMethods = Object.keys(options.methods);
|
|
84
|
-
vueMethods.forEach(function (methodName) {
|
|
85
|
-
clickProxy(options.methods, methodName, function (_action) {
|
|
86
|
-
action.create(_action.type, _action.name);
|
|
87
|
-
}, lifeCycle);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
var originMethods = (0, _utils.getMethods)(options);
|
|
91
|
-
originMethods.forEach(function (methodName) {
|
|
92
|
-
clickProxy(options, methodName, function (_action) {
|
|
93
|
-
action.create(_action.type, _action.name);
|
|
94
|
-
}, lifeCycle);
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
55
|
function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
98
|
-
if (WHITE_METHOD.indexOf(methodName) > -1) return;
|
|
99
56
|
var originMethod = origin[methodName];
|
|
100
57
|
origin[methodName] = function () {
|
|
101
58
|
var result = originMethod.apply(this, arguments);
|
|
@@ -111,17 +68,17 @@ function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
|
111
68
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
112
69
|
} else if (methodName === 'onAddToFavorites') {
|
|
113
70
|
action.type = 'click';
|
|
114
|
-
action.name = '收藏 ' + '标题: ' + result.title + (result.query ? ' query: ' + result.query : '');
|
|
71
|
+
action.name = '收藏 ' + '标题: ' + (result && result.title) || '' + (result.query ? ' query: ' + result.query : '');
|
|
115
72
|
callback(action);
|
|
116
73
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
117
74
|
} else if (methodName === 'onShareAppMessage') {
|
|
118
75
|
action.type = 'click';
|
|
119
|
-
action.name = '转发 ' + '标题: ' + result.title + (result.path ? ' path: ' + result.path : '');
|
|
76
|
+
action.name = '转发 ' + '标题: ' + (result && result.title) || '' + (result.path ? ' path: ' + result.path : '');
|
|
120
77
|
callback(action);
|
|
121
78
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
122
79
|
} else if (methodName === 'onShareTimeline') {
|
|
123
80
|
action.type = 'click';
|
|
124
|
-
action.name = '分享到朋友圈 ' + '标题: ' + result.title + (result.query ? ' query: ' + result.query : '');
|
|
81
|
+
action.name = '分享到朋友圈 ' + '标题: ' + (result && result.title) || '' + (result.query ? ' query: ' + result.query : '');
|
|
125
82
|
callback(action);
|
|
126
83
|
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
127
84
|
} else if (methodName === 'onTabItemTap') {
|
|
@@ -10,58 +10,46 @@ var _trackEventCounts2 = require("../trackEventCounts");
|
|
|
10
10
|
var _lifeCycle = require("../../core/lifeCycle");
|
|
11
11
|
// 劫持原小程序App方法
|
|
12
12
|
var THROTTLE_VIEW_UPDATE_PERIOD = exports.THROTTLE_VIEW_UPDATE_PERIOD = 3000;
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
var activePage = (0, _utils.getActivePage)();
|
|
28
|
-
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
13
|
+
function rewritePage(configuration, lifeCycle, Vue) {
|
|
14
|
+
var originPage = Page;
|
|
15
|
+
var originComponent = Component;
|
|
16
|
+
var hookPage = function hookPage(pageInstance) {
|
|
17
|
+
var currentView,
|
|
18
|
+
startTime = (0, _utils.now)();
|
|
19
|
+
['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(function (methodName) {
|
|
20
|
+
var userDefinedMethod = pageInstance[methodName];
|
|
21
|
+
pageInstance[methodName] = function () {
|
|
22
|
+
if (methodName === 'onShow' || methodName === 'onLoad') {
|
|
23
|
+
if (typeof currentView === 'undefined') {
|
|
24
|
+
var activePage = (0, _utils.getActivePage)();
|
|
25
|
+
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
26
|
+
}
|
|
29
27
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
currentView && currentView.setLoadEventEnd(methodName);
|
|
29
|
+
if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
|
|
30
|
+
currentView.triggerUpdate();
|
|
31
|
+
if (methodName === 'onUnload' || methodName === 'onHide') {
|
|
32
|
+
currentView.end();
|
|
33
|
+
currentView = undefined;
|
|
34
|
+
}
|
|
37
35
|
}
|
|
38
|
-
|
|
39
|
-
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
40
|
-
};
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
function rewritePage(configuration, lifeCycle, Vue) {
|
|
44
|
-
if (Vue && Vue.extend) {
|
|
45
|
-
var originVueExtend = Vue.extend;
|
|
46
|
-
Vue.extend = function (vueOptions) {
|
|
47
|
-
proxyPage(vueOptions, lifeCycle);
|
|
48
|
-
return originVueExtend.call(this, vueOptions);
|
|
49
|
-
};
|
|
50
|
-
} else {
|
|
51
|
-
if (Page) {
|
|
52
|
-
var originPage = Page;
|
|
53
|
-
Page = function Page(pageOptions) {
|
|
54
|
-
proxyPage(pageOptions, lifeCycle);
|
|
55
|
-
return originPage.call(this, pageOptions);
|
|
56
|
-
};
|
|
57
|
-
} else {
|
|
58
|
-
var originComponent = Component;
|
|
59
|
-
Component = function Component(pageOptions) {
|
|
60
|
-
proxyPage(pageOptions.methods, lifeCycle);
|
|
61
|
-
return originComponent.call(this, pageOptions);
|
|
36
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
62
37
|
};
|
|
63
|
-
}
|
|
64
|
-
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
Component = function Component(component) {
|
|
41
|
+
try {
|
|
42
|
+
hookPage(component.methods);
|
|
43
|
+
} catch (error) {}
|
|
44
|
+
return originComponent(component);
|
|
45
|
+
};
|
|
46
|
+
Page = function Page(page) {
|
|
47
|
+
// 合并方法,插入记录脚本
|
|
48
|
+
try {
|
|
49
|
+
hookPage(page);
|
|
50
|
+
} catch (error) {}
|
|
51
|
+
return originPage(page);
|
|
52
|
+
};
|
|
65
53
|
}
|
|
66
54
|
function newView(lifeCycle, route, startTime) {
|
|
67
55
|
if (typeof startTime === 'undefined' || Number(startTime) === 0) {
|
|
@@ -5,63 +5,32 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.startSetDataColloction = startSetDataColloction;
|
|
7
7
|
var _lifeCycle = require("../core/lifeCycle");
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
8
|
+
function startSetDataColloction(lifeCycle, Vue) {
|
|
9
|
+
var originComponent = Component;
|
|
10
|
+
Component = function Component(component) {
|
|
11
|
+
var originComponentAttached;
|
|
12
|
+
function handlerOrigin() {
|
|
13
|
+
this.setUpdatePerformanceListener && this.setUpdatePerformanceListener({
|
|
14
|
+
withDataPaths: true
|
|
15
|
+
}, function (res) {
|
|
16
|
+
lifeCycle.notify(_lifeCycle.LifeCycleEventType.PAGE_SET_DATA_UPDATE, res);
|
|
17
|
+
});
|
|
18
|
+
return originComponentAttached && originComponentAttached.apply(this, arguments);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
if (typeof setData === 'function') {
|
|
29
|
-
try {
|
|
30
|
-
// 这里暂时这么处理 只读属性 会抛出错误
|
|
31
|
-
mpInstance.setData = function (data, callback) {
|
|
32
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
33
|
-
};
|
|
34
|
-
} catch (err) {
|
|
35
|
-
Object.defineProperty(mpInstance.__proto__, 'setData', {
|
|
36
|
-
configurable: false,
|
|
37
|
-
enumerable: false,
|
|
38
|
-
value: function value(data, callback) {
|
|
39
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
40
|
-
}
|
|
41
|
-
});
|
|
20
|
+
try {
|
|
21
|
+
if (component.lifetimes && component.lifetimes['attached']) {
|
|
22
|
+
originComponentAttached = component.lifetimes['attached'];
|
|
23
|
+
component.lifetimes['attached'] = handlerOrigin;
|
|
24
|
+
} else if (component['attached']) {
|
|
25
|
+
// 兼容老版本
|
|
26
|
+
originComponentAttached = component['attached'];
|
|
27
|
+
component['attached'] = handlerOrigin;
|
|
42
28
|
}
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
if (component.onLoad) {
|
|
30
|
+
originComponentAttached = component.onLoad;
|
|
31
|
+
component.onLoad = handlerOrigin;
|
|
32
|
+
}
|
|
33
|
+
} catch (err) {}
|
|
34
|
+
return originComponent(component);
|
|
45
35
|
};
|
|
46
|
-
}
|
|
47
|
-
function startSetDataColloction(lifeCycle, Vue) {
|
|
48
|
-
if (Vue && Vue.extend) {
|
|
49
|
-
var originVueExtend = Vue.extend;
|
|
50
|
-
Vue.extend = function (vueOptions) {
|
|
51
|
-
proxyPage(vueOptions, lifeCycle);
|
|
52
|
-
return originVueExtend.call(this, vueOptions);
|
|
53
|
-
};
|
|
54
|
-
} else {
|
|
55
|
-
if (!_sdk.tracker) return;
|
|
56
|
-
var originCreatePage = _sdk.tracker.createPage;
|
|
57
|
-
_sdk.tracker.createPage = function (pageOptions) {
|
|
58
|
-
proxyPage(pageOptions, lifeCycle);
|
|
59
|
-
return originCreatePage.call(this, pageOptions);
|
|
60
|
-
};
|
|
61
|
-
var originCreateComponent = _sdk.tracker.createComponent;
|
|
62
|
-
_sdk.tracker.createComponent = function (component) {
|
|
63
|
-
proxyPage(component, lifeCycle);
|
|
64
|
-
return originCreateComponent.call(this, component);
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
36
|
}
|
package/esm/boot/buildEnv.js
CHANGED
package/esm/helper/enums.js
CHANGED
|
@@ -3,8 +3,6 @@ import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
|
3
3
|
import { trackEventCounts } from '../trackEventCounts';
|
|
4
4
|
import { waitIdlePageActivity } from '../trackPageActiveites';
|
|
5
5
|
import { ActionType } from '../../helper/enums';
|
|
6
|
-
import { tracker } from '../../core/sdk';
|
|
7
|
-
var WHITE_METHOD = ['setup'];
|
|
8
6
|
export function trackActions(lifeCycle, Vue) {
|
|
9
7
|
var action = startActionManagement(lifeCycle);
|
|
10
8
|
|
|
@@ -12,57 +10,34 @@ export function trackActions(lifeCycle, Vue) {
|
|
|
12
10
|
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
|
|
13
11
|
action.discardCurrent();
|
|
14
12
|
});
|
|
15
|
-
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
var originComponent = Component;
|
|
40
|
-
Component = function Component(component) {
|
|
41
|
-
var methods = getMethods(component.methods);
|
|
42
|
-
methods.forEach(methodName => {
|
|
43
|
-
clickProxy(component, methodName, function (_action) {
|
|
44
|
-
action.create(_action.type, _action.name);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
return originComponent(component);
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if (!hasComponent) {
|
|
51
|
-
var originCreatePage = tracker.createPage;
|
|
52
|
-
tracker.createPage = function (page) {
|
|
53
|
-
// methods 方法
|
|
54
|
-
proxyInstance(page, action, lifeCycle);
|
|
55
|
-
return originCreatePage.call(this, page);
|
|
56
|
-
};
|
|
57
|
-
var originCreateComponent = tracker.createComponent;
|
|
58
|
-
tracker.createComponent = function (component) {
|
|
59
|
-
proxyInstance(component, action, lifeCycle);
|
|
60
|
-
return originCreateComponent.call(this, component);
|
|
13
|
+
var hookClick = function hookClick(instance) {
|
|
14
|
+
var methods = getMethods(instance);
|
|
15
|
+
methods.forEach(methodName => {
|
|
16
|
+
clickProxy(instance, methodName, function (_action) {
|
|
17
|
+
action.create(_action.type, _action.name);
|
|
18
|
+
}, lifeCycle);
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var originPage = Page;
|
|
22
|
+
Page = function Page(page) {
|
|
23
|
+
try {
|
|
24
|
+
hookClick(page);
|
|
25
|
+
} catch (error) {}
|
|
26
|
+
return originPage(page);
|
|
27
|
+
};
|
|
28
|
+
var originComponent = Component;
|
|
29
|
+
Component = function Component(component) {
|
|
30
|
+
if (component.methods && component.methods.onLoad) {
|
|
31
|
+
var originOnLoad = component.methods.onLoad;
|
|
32
|
+
component.methods.onLoad = function () {
|
|
33
|
+
try {
|
|
34
|
+
hookClick(this);
|
|
35
|
+
} catch (error) {}
|
|
36
|
+
return originOnLoad.apply(this, arguments);
|
|
61
37
|
};
|
|
62
38
|
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
39
|
+
return originComponent(component);
|
|
40
|
+
};
|
|
66
41
|
return {
|
|
67
42
|
stop: function stop() {
|
|
68
43
|
action.discardCurrent();
|
|
@@ -71,25 +46,7 @@ export function trackActions(lifeCycle, Vue) {
|
|
|
71
46
|
};
|
|
72
47
|
}
|
|
73
48
|
|
|
74
|
-
function proxyInstance(options, action, lifeCycle) {
|
|
75
|
-
// methods 方法
|
|
76
|
-
if (options.methods) {
|
|
77
|
-
var vueMethods = Object.keys(options.methods);
|
|
78
|
-
vueMethods.forEach(methodName => {
|
|
79
|
-
clickProxy(options.methods, methodName, function (_action) {
|
|
80
|
-
action.create(_action.type, _action.name);
|
|
81
|
-
}, lifeCycle);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
var originMethods = getMethods(options);
|
|
85
|
-
originMethods.forEach(methodName => {
|
|
86
|
-
clickProxy(options, methodName, function (_action) {
|
|
87
|
-
action.create(_action.type, _action.name);
|
|
88
|
-
}, lifeCycle);
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
49
|
function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
92
|
-
if (WHITE_METHOD.indexOf(methodName) > -1) return;
|
|
93
50
|
var originMethod = origin[methodName];
|
|
94
51
|
origin[methodName] = function () {
|
|
95
52
|
var result = originMethod.apply(this, arguments);
|
|
@@ -105,17 +62,17 @@ function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
|
105
62
|
lifeCycle.notify(LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
106
63
|
} else if (methodName === 'onAddToFavorites') {
|
|
107
64
|
action.type = 'click';
|
|
108
|
-
action.name = '收藏 ' + '标题: ' + result.title + (result.query ? ' query: ' + result.query : '');
|
|
65
|
+
action.name = '收藏 ' + '标题: ' + (result && result.title) || '' + (result.query ? ' query: ' + result.query : '');
|
|
109
66
|
callback(action);
|
|
110
67
|
lifeCycle.notify(LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
111
68
|
} else if (methodName === 'onShareAppMessage') {
|
|
112
69
|
action.type = 'click';
|
|
113
|
-
action.name = '转发 ' + '标题: ' + result.title + (result.path ? ' path: ' + result.path : '');
|
|
70
|
+
action.name = '转发 ' + '标题: ' + (result && result.title) || '' + (result.path ? ' path: ' + result.path : '');
|
|
114
71
|
callback(action);
|
|
115
72
|
lifeCycle.notify(LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
116
73
|
} else if (methodName === 'onShareTimeline') {
|
|
117
74
|
action.type = 'click';
|
|
118
|
-
action.name = '分享到朋友圈 ' + '标题: ' + result.title + (result.query ? ' query: ' + result.query : '');
|
|
75
|
+
action.name = '分享到朋友圈 ' + '标题: ' + (result && result.title) || '' + (result.query ? ' query: ' + result.query : '');
|
|
119
76
|
callback(action);
|
|
120
77
|
lifeCycle.notify(LifeCycleEventType.PAGE_ALIAS_ACTION, true);
|
|
121
78
|
} else if (methodName === 'onTabItemTap') {
|
|
@@ -4,58 +4,46 @@ import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
|
4
4
|
|
|
5
5
|
// 劫持原小程序App方法
|
|
6
6
|
export var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
|
|
7
|
-
function
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var activePage = getActivePage();
|
|
22
|
-
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
7
|
+
export function rewritePage(configuration, lifeCycle, Vue) {
|
|
8
|
+
var originPage = Page;
|
|
9
|
+
var originComponent = Component;
|
|
10
|
+
var hookPage = function hookPage(pageInstance) {
|
|
11
|
+
var currentView,
|
|
12
|
+
startTime = now();
|
|
13
|
+
['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(methodName => {
|
|
14
|
+
var userDefinedMethod = pageInstance[methodName];
|
|
15
|
+
pageInstance[methodName] = function () {
|
|
16
|
+
if (methodName === 'onShow' || methodName === 'onLoad') {
|
|
17
|
+
if (typeof currentView === 'undefined') {
|
|
18
|
+
var activePage = getActivePage();
|
|
19
|
+
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
20
|
+
}
|
|
23
21
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
currentView && currentView.setLoadEventEnd(methodName);
|
|
23
|
+
if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
|
|
24
|
+
currentView.triggerUpdate();
|
|
25
|
+
if (methodName === 'onUnload' || methodName === 'onHide') {
|
|
26
|
+
currentView.end();
|
|
27
|
+
currentView = undefined;
|
|
28
|
+
}
|
|
31
29
|
}
|
|
32
|
-
|
|
33
|
-
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
34
|
-
};
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
export function rewritePage(configuration, lifeCycle, Vue) {
|
|
38
|
-
if (Vue && Vue.extend) {
|
|
39
|
-
var originVueExtend = Vue.extend;
|
|
40
|
-
Vue.extend = function (vueOptions) {
|
|
41
|
-
proxyPage(vueOptions, lifeCycle);
|
|
42
|
-
return originVueExtend.call(this, vueOptions);
|
|
43
|
-
};
|
|
44
|
-
} else {
|
|
45
|
-
if (Page) {
|
|
46
|
-
var originPage = Page;
|
|
47
|
-
Page = function Page(pageOptions) {
|
|
48
|
-
proxyPage(pageOptions, lifeCycle);
|
|
49
|
-
return originPage.call(this, pageOptions);
|
|
50
|
-
};
|
|
51
|
-
} else {
|
|
52
|
-
var originComponent = Component;
|
|
53
|
-
Component = function Component(pageOptions) {
|
|
54
|
-
proxyPage(pageOptions.methods, lifeCycle);
|
|
55
|
-
return originComponent.call(this, pageOptions);
|
|
30
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
56
31
|
};
|
|
57
|
-
}
|
|
58
|
-
}
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Component = function Component(component) {
|
|
35
|
+
try {
|
|
36
|
+
hookPage(component.methods);
|
|
37
|
+
} catch (error) {}
|
|
38
|
+
return originComponent(component);
|
|
39
|
+
};
|
|
40
|
+
Page = function Page(page) {
|
|
41
|
+
// 合并方法,插入记录脚本
|
|
42
|
+
try {
|
|
43
|
+
hookPage(page);
|
|
44
|
+
} catch (error) {}
|
|
45
|
+
return originPage(page);
|
|
46
|
+
};
|
|
59
47
|
}
|
|
60
48
|
function newView(lifeCycle, route, startTime) {
|
|
61
49
|
if (typeof startTime === 'undefined' || Number(startTime) === 0) {
|
|
@@ -1,61 +1,30 @@
|
|
|
1
1
|
import { LifeCycleEventType } from '../core/lifeCycle';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
export function startSetDataColloction(lifeCycle, Vue) {
|
|
3
|
+
var originComponent = Component;
|
|
4
|
+
Component = function Component(component) {
|
|
5
|
+
var originComponentAttached;
|
|
6
|
+
function handlerOrigin() {
|
|
7
|
+
this.setUpdatePerformanceListener && this.setUpdatePerformanceListener({
|
|
8
|
+
withDataPaths: true
|
|
9
|
+
}, res => {
|
|
10
|
+
lifeCycle.notify(LifeCycleEventType.PAGE_SET_DATA_UPDATE, res);
|
|
11
|
+
});
|
|
12
|
+
return originComponentAttached && originComponentAttached.apply(this, arguments);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if (typeof setData === 'function') {
|
|
23
|
-
try {
|
|
24
|
-
// 这里暂时这么处理 只读属性 会抛出错误
|
|
25
|
-
mpInstance.setData = function (data, callback) {
|
|
26
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
27
|
-
};
|
|
28
|
-
} catch (err) {
|
|
29
|
-
Object.defineProperty(mpInstance.__proto__, 'setData', {
|
|
30
|
-
configurable: false,
|
|
31
|
-
enumerable: false,
|
|
32
|
-
value: function value(data, callback) {
|
|
33
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
34
|
-
}
|
|
35
|
-
});
|
|
14
|
+
try {
|
|
15
|
+
if (component.lifetimes && component.lifetimes['attached']) {
|
|
16
|
+
originComponentAttached = component.lifetimes['attached'];
|
|
17
|
+
component.lifetimes['attached'] = handlerOrigin;
|
|
18
|
+
} else if (component['attached']) {
|
|
19
|
+
// 兼容老版本
|
|
20
|
+
originComponentAttached = component['attached'];
|
|
21
|
+
component['attached'] = handlerOrigin;
|
|
36
22
|
}
|
|
37
|
-
|
|
38
|
-
|
|
23
|
+
if (component.onLoad) {
|
|
24
|
+
originComponentAttached = component.onLoad;
|
|
25
|
+
component.onLoad = handlerOrigin;
|
|
26
|
+
}
|
|
27
|
+
} catch (err) {}
|
|
28
|
+
return originComponent(component);
|
|
39
29
|
};
|
|
40
|
-
}
|
|
41
|
-
export function startSetDataColloction(lifeCycle, Vue) {
|
|
42
|
-
if (Vue && Vue.extend) {
|
|
43
|
-
var originVueExtend = Vue.extend;
|
|
44
|
-
Vue.extend = function (vueOptions) {
|
|
45
|
-
proxyPage(vueOptions, lifeCycle);
|
|
46
|
-
return originVueExtend.call(this, vueOptions);
|
|
47
|
-
};
|
|
48
|
-
} else {
|
|
49
|
-
if (!tracker) return;
|
|
50
|
-
var originCreatePage = tracker.createPage;
|
|
51
|
-
tracker.createPage = function (pageOptions) {
|
|
52
|
-
proxyPage(pageOptions, lifeCycle);
|
|
53
|
-
return originCreatePage.call(this, pageOptions);
|
|
54
|
-
};
|
|
55
|
-
var originCreateComponent = tracker.createComponent;
|
|
56
|
-
tracker.createComponent = function (component) {
|
|
57
|
-
proxyPage(component, lifeCycle);
|
|
58
|
-
return originCreateComponent.call(this, component);
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
30
|
}
|