@cloudcare/rum-uniapp 2.1.3 → 2.1.6
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/boot/rum.entry.js +3 -0
- package/cjs/core/configuration.js +2 -1
- package/cjs/rumEventsCollection/action/trackActions.js +52 -48
- package/cjs/rumEventsCollection/page/index.js +48 -35
- package/cjs/rumEventsCollection/setDataCollection.js +47 -25
- package/esm/boot/buildEnv.js +1 -1
- package/esm/boot/rum.entry.js +3 -0
- package/esm/core/configuration.js +2 -1
- package/esm/rumEventsCollection/action/trackActions.js +50 -48
- package/esm/rumEventsCollection/page/index.js +51 -36
- package/esm/rumEventsCollection/setDataCollection.js +46 -25
- package/package.json +1 -1
package/cjs/boot/buildEnv.js
CHANGED
package/cjs/boot/rum.entry.js
CHANGED
|
@@ -45,6 +45,9 @@ var makeRum = function makeRum(startRumImpl) {
|
|
|
45
45
|
addActionStrategy = _startRumImpl.addAction;
|
|
46
46
|
isAlreadyInitialized = true;
|
|
47
47
|
},
|
|
48
|
+
initVue3: function initVue3(userConfiguration) {
|
|
49
|
+
this.init({}, userConfiguration);
|
|
50
|
+
},
|
|
48
51
|
getInternalContext: function getInternalContext(startTime) {
|
|
49
52
|
return _getInternalContext(startTime);
|
|
50
53
|
},
|
|
@@ -97,5 +97,6 @@ var haveSameOrigin = function haveSameOrigin(url1, url2) {
|
|
|
97
97
|
};
|
|
98
98
|
|
|
99
99
|
function isIntakeRequest(url, configuration) {
|
|
100
|
-
return haveSameOrigin(url, configuration.datakitUrl)
|
|
100
|
+
// return haveSameOrigin(url, configuration.datakitUrl)
|
|
101
|
+
return url.indexOf(configuration.datakitUrl) === 0;
|
|
101
102
|
}
|
|
@@ -15,57 +15,41 @@ var _trackPageActiveites = require("../trackPageActiveites");
|
|
|
15
15
|
|
|
16
16
|
var _enums = require("../../helper/enums");
|
|
17
17
|
|
|
18
|
+
var _sdk = require("../../core/sdk");
|
|
19
|
+
|
|
20
|
+
var WHITE_METHOD = ['setup'];
|
|
21
|
+
|
|
18
22
|
function trackActions(lifeCycle, Vue) {
|
|
19
23
|
var action = startActionManagement(lifeCycle); // New views trigger the discard of the current pending Action
|
|
20
24
|
|
|
21
25
|
lifeCycle.subscribe(_lifeCycle.LifeCycleEventType.VIEW_CREATED, function () {
|
|
22
26
|
action.discardCurrent();
|
|
23
27
|
});
|
|
24
|
-
var originVueExtend = Vue.extend;
|
|
25
|
-
|
|
26
|
-
Vue.extend = function (vueOptions) {
|
|
27
|
-
// methods 方法
|
|
28
|
-
if (vueOptions.methods) {
|
|
29
|
-
var vueMethods = Object.keys(vueOptions.methods);
|
|
30
|
-
vueMethods.forEach(function (methodName) {
|
|
31
|
-
clickProxy(vueOptions.methods, methodName, function (_action) {
|
|
32
|
-
action.create(_action.type, _action.name);
|
|
33
|
-
}, lifeCycle);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
28
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
//
|
|
61
|
-
// const methods = getMethods(component)
|
|
62
|
-
// methods.forEach((methodName) => {
|
|
63
|
-
// clickProxy(component, methodName, function (_action) {
|
|
64
|
-
// action.create(_action.type, _action.name)
|
|
65
|
-
// })
|
|
66
|
-
// })
|
|
67
|
-
// return originComponent(component)
|
|
68
|
-
// }
|
|
29
|
+
if (Vue && Vue.extend) {
|
|
30
|
+
var originVueExtend = Vue.extend;
|
|
31
|
+
|
|
32
|
+
Vue.extend = function (vueOptions) {
|
|
33
|
+
proxyInstance(vueOptions, action, lifeCycle);
|
|
34
|
+
return originVueExtend.call(this, vueOptions);
|
|
35
|
+
};
|
|
36
|
+
} else {
|
|
37
|
+
if (!_sdk.tracker) return;
|
|
38
|
+
var originCreatePage = _sdk.tracker.createPage;
|
|
39
|
+
|
|
40
|
+
_sdk.tracker.createPage = function (page) {
|
|
41
|
+
// methods 方法
|
|
42
|
+
proxyInstance(page, action, lifeCycle);
|
|
43
|
+
return originCreatePage.call(this, page);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
var originCreateComponent = _sdk.tracker.createComponent;
|
|
47
|
+
|
|
48
|
+
_sdk.tracker.createComponent = function (component) {
|
|
49
|
+
proxyInstance(component, action, lifeCycle);
|
|
50
|
+
return originCreateComponent.call(this, component);
|
|
51
|
+
};
|
|
52
|
+
} // var originVueExtend = Vue.extend
|
|
69
53
|
|
|
70
54
|
|
|
71
55
|
return {
|
|
@@ -75,11 +59,31 @@ function trackActions(lifeCycle, Vue) {
|
|
|
75
59
|
};
|
|
76
60
|
}
|
|
77
61
|
|
|
78
|
-
function
|
|
79
|
-
|
|
62
|
+
function proxyInstance(options, action, lifeCycle) {
|
|
63
|
+
// methods 方法
|
|
64
|
+
if (options.methods) {
|
|
65
|
+
var vueMethods = Object.keys(options.methods);
|
|
66
|
+
vueMethods.forEach(function (methodName) {
|
|
67
|
+
clickProxy(options.methods, methodName, function (_action) {
|
|
68
|
+
action.create(_action.type, _action.name);
|
|
69
|
+
}, lifeCycle);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var originMethods = (0, _utils.getMethods)(options);
|
|
74
|
+
originMethods.forEach(function (methodName) {
|
|
75
|
+
clickProxy(options, methodName, function (_action) {
|
|
76
|
+
action.create(_action.type, _action.name);
|
|
77
|
+
}, lifeCycle);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
82
|
+
if (WHITE_METHOD.indexOf(methodName) > -1) return;
|
|
83
|
+
var originMethod = origin[methodName];
|
|
80
84
|
|
|
81
|
-
|
|
82
|
-
var result =
|
|
85
|
+
origin[methodName] = function () {
|
|
86
|
+
var result = originMethod.apply(this, arguments);
|
|
83
87
|
var action = {};
|
|
84
88
|
|
|
85
89
|
if ((0, _utils.isObject)(arguments[0])) {
|
|
@@ -12,51 +12,64 @@ var _trackEventCounts2 = require("../trackEventCounts");
|
|
|
12
12
|
|
|
13
13
|
var _lifeCycle = require("../../core/lifeCycle");
|
|
14
14
|
|
|
15
|
-
var _sdk = require("../../core/sdk");
|
|
16
|
-
|
|
17
15
|
// 劫持原小程序App方法
|
|
18
16
|
var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
|
|
19
17
|
exports.THROTTLE_VIEW_UPDATE_PERIOD = THROTTLE_VIEW_UPDATE_PERIOD;
|
|
20
18
|
|
|
21
|
-
function
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
var
|
|
27
|
-
|
|
28
|
-
[
|
|
29
|
-
var
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
41
|
-
}
|
|
19
|
+
function proxyPage(pageOptions, lifeCycle) {
|
|
20
|
+
// 合并方法,插入记录脚本
|
|
21
|
+
var currentView,
|
|
22
|
+
startTime = (0, _utils.now)();
|
|
23
|
+
['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(function (methodName) {
|
|
24
|
+
var userDefinedMethod = pageOptions[methodName];
|
|
25
|
+
|
|
26
|
+
pageOptions[methodName] = function () {
|
|
27
|
+
var mpType = this.mpType || this.$vm.mpType;
|
|
28
|
+
|
|
29
|
+
if (mpType !== 'page') {
|
|
30
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
31
|
+
} // 只处理page类型
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if (methodName === 'onShow' || methodName === 'onLoad') {
|
|
35
|
+
if (typeof currentView === 'undefined') {
|
|
36
|
+
var activePage = (0, _utils.getActivePage)();
|
|
37
|
+
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
42
38
|
}
|
|
39
|
+
}
|
|
43
40
|
|
|
44
|
-
|
|
41
|
+
currentView && currentView.setLoadEventEnd(methodName);
|
|
45
42
|
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
|
|
44
|
+
currentView.triggerUpdate();
|
|
48
45
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
46
|
+
if (methodName === 'onUnload' || methodName === 'onHide') {
|
|
47
|
+
currentView.end();
|
|
48
|
+
currentView = undefined;
|
|
53
49
|
}
|
|
50
|
+
}
|
|
54
51
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
53
|
+
};
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function rewritePage(configuration, lifeCycle, Vue) {
|
|
58
|
+
if (Vue && Vue.extend) {
|
|
59
|
+
var originVueExtend = Vue.extend;
|
|
60
|
+
|
|
61
|
+
Vue.extend = function (vueOptions) {
|
|
62
|
+
proxyPage(vueOptions, lifeCycle);
|
|
63
|
+
return originVueExtend.call(this, vueOptions);
|
|
64
|
+
};
|
|
65
|
+
} else {
|
|
66
|
+
var originComponent = Component;
|
|
67
|
+
|
|
68
|
+
Component = function Component(pageOptions) {
|
|
69
|
+
proxyPage(pageOptions.methods, lifeCycle);
|
|
70
|
+
return originComponent.call(this, pageOptions);
|
|
71
|
+
};
|
|
72
|
+
}
|
|
60
73
|
}
|
|
61
74
|
|
|
62
75
|
function newView(lifeCycle, route, startTime) {
|
|
@@ -9,6 +9,8 @@ var _lifeCycle = require("../core/lifeCycle");
|
|
|
9
9
|
|
|
10
10
|
var _utils = require("../helper/utils");
|
|
11
11
|
|
|
12
|
+
var _sdk = require("../core/sdk");
|
|
13
|
+
|
|
12
14
|
function resetSetData(data, callback, lifeCycle, mpInstance) {
|
|
13
15
|
var pendingStartTimestamp = (0, _utils.now)();
|
|
14
16
|
|
|
@@ -26,36 +28,56 @@ function resetSetData(data, callback, lifeCycle, mpInstance) {
|
|
|
26
28
|
return _callback;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
function
|
|
30
|
-
var
|
|
31
|
-
|
|
32
|
-
Vue.extend = function (vueOptions) {
|
|
33
|
-
var userDefinedMethod = vueOptions['onLoad'];
|
|
31
|
+
function proxyPage(pageOptions, lifeCycle) {
|
|
32
|
+
var userDefinedMethod = pageOptions['onLoad'];
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
pageOptions['onLoad'] = function () {
|
|
35
|
+
var mpInstance = this.$scope;
|
|
36
|
+
var setData = mpInstance.setData;
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
if (typeof setData === 'function') {
|
|
39
|
+
try {
|
|
40
|
+
// 这里暂时这么处理 只读属性 会抛出错误
|
|
41
|
+
mpInstance.setData = function (data, callback) {
|
|
42
|
+
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
43
|
+
};
|
|
44
|
+
} catch (err) {
|
|
45
|
+
Object.defineProperty(mpInstance.__proto__, 'setData', {
|
|
46
|
+
configurable: false,
|
|
47
|
+
enumerable: false,
|
|
48
|
+
value: function value(data, callback) {
|
|
43
49
|
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
Object.defineProperty(mpInstance.__proto__, 'setData', {
|
|
47
|
-
configurable: false,
|
|
48
|
-
enumerable: false,
|
|
49
|
-
value: function value(data, callback) {
|
|
50
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
}
|
|
50
|
+
}
|
|
51
|
+
});
|
|
54
52
|
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
56
|
+
};
|
|
57
|
+
}
|
|
55
58
|
|
|
56
|
-
|
|
59
|
+
function startSetDataColloction(lifeCycle, Vue) {
|
|
60
|
+
if (Vue && Vue.extend) {
|
|
61
|
+
var originVueExtend = Vue.extend;
|
|
62
|
+
|
|
63
|
+
Vue.extend = function (vueOptions) {
|
|
64
|
+
proxyPage(vueOptions, lifeCycle);
|
|
65
|
+
return originVueExtend.call(this, vueOptions);
|
|
57
66
|
};
|
|
67
|
+
} else {
|
|
68
|
+
if (!_sdk.tracker) return;
|
|
69
|
+
var originCreatePage = _sdk.tracker.createPage;
|
|
58
70
|
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
_sdk.tracker.createPage = function (pageOptions) {
|
|
72
|
+
proxyPage(pageOptions, lifeCycle);
|
|
73
|
+
return originCreatePage.call(this, pageOptions);
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
var originCreateComponent = _sdk.tracker.createComponent;
|
|
77
|
+
|
|
78
|
+
_sdk.tracker.createComponent = function (component) {
|
|
79
|
+
proxyPage(component, lifeCycle);
|
|
80
|
+
return originCreateComponent.call(this, component);
|
|
81
|
+
};
|
|
82
|
+
}
|
|
61
83
|
}
|
package/esm/boot/buildEnv.js
CHANGED
package/esm/boot/rum.entry.js
CHANGED
|
@@ -33,6 +33,9 @@ export var makeRum = function makeRum(startRumImpl) {
|
|
|
33
33
|
addActionStrategy = _startRumImpl.addAction;
|
|
34
34
|
isAlreadyInitialized = true;
|
|
35
35
|
},
|
|
36
|
+
initVue3: function initVue3(userConfiguration) {
|
|
37
|
+
this.init({}, userConfiguration);
|
|
38
|
+
},
|
|
36
39
|
getInternalContext: function getInternalContext(startTime) {
|
|
37
40
|
return _getInternalContext(startTime);
|
|
38
41
|
},
|
|
@@ -85,5 +85,6 @@ var haveSameOrigin = function haveSameOrigin(url1, url2) {
|
|
|
85
85
|
};
|
|
86
86
|
|
|
87
87
|
export function isIntakeRequest(url, configuration) {
|
|
88
|
-
return haveSameOrigin(url, configuration.datakitUrl)
|
|
88
|
+
// return haveSameOrigin(url, configuration.datakitUrl)
|
|
89
|
+
return url.indexOf(configuration.datakitUrl) === 0;
|
|
89
90
|
}
|
|
@@ -3,57 +3,39 @@ 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'];
|
|
6
8
|
export function trackActions(lifeCycle, Vue) {
|
|
7
9
|
var action = startActionManagement(lifeCycle); // New views trigger the discard of the current pending Action
|
|
8
10
|
|
|
9
11
|
lifeCycle.subscribe(LifeCycleEventType.VIEW_CREATED, function () {
|
|
10
12
|
action.discardCurrent();
|
|
11
13
|
});
|
|
12
|
-
var originVueExtend = Vue.extend;
|
|
13
|
-
|
|
14
|
-
Vue.extend = function (vueOptions) {
|
|
15
|
-
// methods 方法
|
|
16
|
-
if (vueOptions.methods) {
|
|
17
|
-
var vueMethods = Object.keys(vueOptions.methods);
|
|
18
|
-
vueMethods.forEach(methodName => {
|
|
19
|
-
clickProxy(vueOptions.methods, methodName, function (_action) {
|
|
20
|
-
action.create(_action.type, _action.name);
|
|
21
|
-
}, lifeCycle);
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
14
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
//
|
|
49
|
-
// const methods = getMethods(component)
|
|
50
|
-
// methods.forEach((methodName) => {
|
|
51
|
-
// clickProxy(component, methodName, function (_action) {
|
|
52
|
-
// action.create(_action.type, _action.name)
|
|
53
|
-
// })
|
|
54
|
-
// })
|
|
55
|
-
// return originComponent(component)
|
|
56
|
-
// }
|
|
15
|
+
if (Vue && Vue.extend) {
|
|
16
|
+
var originVueExtend = Vue.extend;
|
|
17
|
+
|
|
18
|
+
Vue.extend = function (vueOptions) {
|
|
19
|
+
proxyInstance(vueOptions, action, lifeCycle);
|
|
20
|
+
return originVueExtend.call(this, vueOptions);
|
|
21
|
+
};
|
|
22
|
+
} else {
|
|
23
|
+
if (!tracker) return;
|
|
24
|
+
var originCreatePage = tracker.createPage;
|
|
25
|
+
|
|
26
|
+
tracker.createPage = function (page) {
|
|
27
|
+
// methods 方法
|
|
28
|
+
proxyInstance(page, action, lifeCycle);
|
|
29
|
+
return originCreatePage.call(this, page);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
var originCreateComponent = tracker.createComponent;
|
|
33
|
+
|
|
34
|
+
tracker.createComponent = function (component) {
|
|
35
|
+
proxyInstance(component, action, lifeCycle);
|
|
36
|
+
return originCreateComponent.call(this, component);
|
|
37
|
+
};
|
|
38
|
+
} // var originVueExtend = Vue.extend
|
|
57
39
|
|
|
58
40
|
|
|
59
41
|
return {
|
|
@@ -63,11 +45,31 @@ export function trackActions(lifeCycle, Vue) {
|
|
|
63
45
|
};
|
|
64
46
|
}
|
|
65
47
|
|
|
66
|
-
function
|
|
67
|
-
|
|
48
|
+
function proxyInstance(options, action, lifeCycle) {
|
|
49
|
+
// methods 方法
|
|
50
|
+
if (options.methods) {
|
|
51
|
+
var vueMethods = Object.keys(options.methods);
|
|
52
|
+
vueMethods.forEach(methodName => {
|
|
53
|
+
clickProxy(options.methods, methodName, function (_action) {
|
|
54
|
+
action.create(_action.type, _action.name);
|
|
55
|
+
}, lifeCycle);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var originMethods = getMethods(options);
|
|
60
|
+
originMethods.forEach(methodName => {
|
|
61
|
+
clickProxy(options, methodName, function (_action) {
|
|
62
|
+
action.create(_action.type, _action.name);
|
|
63
|
+
}, lifeCycle);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function clickProxy(origin, methodName, callback, lifeCycle) {
|
|
68
|
+
if (WHITE_METHOD.indexOf(methodName) > -1) return;
|
|
69
|
+
var originMethod = origin[methodName];
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
var result =
|
|
71
|
+
origin[methodName] = function () {
|
|
72
|
+
var result = originMethod.apply(this, arguments);
|
|
71
73
|
var action = {};
|
|
72
74
|
|
|
73
75
|
if (isObject(arguments[0])) {
|
|
@@ -1,48 +1,63 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type, now, throttle, UUID, isNumber, getActivePage } from '../../helper/utils';
|
|
2
2
|
import { trackEventCounts } from '../trackEventCounts';
|
|
3
|
-
import { LifeCycleEventType } from '../../core/lifeCycle';
|
|
4
|
-
import { sdk } from '../../core/sdk'; // 劫持原小程序App方法
|
|
3
|
+
import { LifeCycleEventType } from '../../core/lifeCycle'; // 劫持原小程序App方法
|
|
5
4
|
|
|
6
5
|
export var THROTTLE_VIEW_UPDATE_PERIOD = 3000;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
6
|
+
|
|
7
|
+
function proxyPage(pageOptions, lifeCycle) {
|
|
8
|
+
// 合并方法,插入记录脚本
|
|
9
|
+
var currentView,
|
|
10
|
+
startTime = now();
|
|
11
|
+
['onReady', 'onShow', 'onLoad', 'onUnload', 'onHide'].forEach(methodName => {
|
|
12
|
+
var userDefinedMethod = pageOptions[methodName];
|
|
13
|
+
|
|
14
|
+
pageOptions[methodName] = function () {
|
|
15
|
+
var mpType = this.mpType || this.$vm.mpType;
|
|
16
|
+
|
|
17
|
+
if (mpType !== 'page') {
|
|
18
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
19
|
+
} // 只处理page类型
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if (methodName === 'onShow' || methodName === 'onLoad') {
|
|
23
|
+
if (typeof currentView === 'undefined') {
|
|
24
|
+
var activePage = getActivePage();
|
|
25
|
+
currentView = newView(lifeCycle, activePage && activePage.route, startTime);
|
|
28
26
|
}
|
|
27
|
+
}
|
|
29
28
|
|
|
30
|
-
|
|
29
|
+
currentView && currentView.setLoadEventEnd(methodName);
|
|
31
30
|
|
|
32
|
-
|
|
33
|
-
|
|
31
|
+
if ((methodName === 'onUnload' || methodName === 'onHide' || methodName === 'onShow') && currentView) {
|
|
32
|
+
currentView.triggerUpdate();
|
|
34
33
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
34
|
+
if (methodName === 'onUnload' || methodName === 'onHide') {
|
|
35
|
+
currentView.end();
|
|
36
|
+
currentView = undefined;
|
|
39
37
|
}
|
|
38
|
+
}
|
|
40
39
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function rewritePage(configuration, lifeCycle, Vue) {
|
|
46
|
+
if (Vue && Vue.extend) {
|
|
47
|
+
var originVueExtend = Vue.extend;
|
|
48
|
+
|
|
49
|
+
Vue.extend = function (vueOptions) {
|
|
50
|
+
proxyPage(vueOptions, lifeCycle);
|
|
51
|
+
return originVueExtend.call(this, vueOptions);
|
|
52
|
+
};
|
|
53
|
+
} else {
|
|
54
|
+
var originComponent = Component;
|
|
55
|
+
|
|
56
|
+
Component = function Component(pageOptions) {
|
|
57
|
+
proxyPage(pageOptions.methods, lifeCycle);
|
|
58
|
+
return originComponent.call(this, pageOptions);
|
|
59
|
+
};
|
|
60
|
+
}
|
|
46
61
|
}
|
|
47
62
|
|
|
48
63
|
function newView(lifeCycle, route, startTime) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { LifeCycleEventType } from '../core/lifeCycle';
|
|
2
2
|
import { now } from '../helper/utils';
|
|
3
|
+
import { tracker } from '../core/sdk';
|
|
3
4
|
|
|
4
5
|
function resetSetData(data, callback, lifeCycle, mpInstance) {
|
|
5
6
|
var pendingStartTimestamp = now();
|
|
@@ -18,36 +19,56 @@ function resetSetData(data, callback, lifeCycle, mpInstance) {
|
|
|
18
19
|
return _callback;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
Vue.extend = function (vueOptions) {
|
|
25
|
-
var userDefinedMethod = vueOptions['onLoad'];
|
|
22
|
+
function proxyPage(pageOptions, lifeCycle) {
|
|
23
|
+
var userDefinedMethod = pageOptions['onLoad'];
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
pageOptions['onLoad'] = function () {
|
|
26
|
+
var mpInstance = this.$scope;
|
|
27
|
+
var setData = mpInstance.setData;
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
if (typeof setData === 'function') {
|
|
30
|
+
try {
|
|
31
|
+
// 这里暂时这么处理 只读属性 会抛出错误
|
|
32
|
+
mpInstance.setData = function (data, callback) {
|
|
33
|
+
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
34
|
+
};
|
|
35
|
+
} catch (err) {
|
|
36
|
+
Object.defineProperty(mpInstance.__proto__, 'setData', {
|
|
37
|
+
configurable: false,
|
|
38
|
+
enumerable: false,
|
|
39
|
+
value: function value(data, callback) {
|
|
35
40
|
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
Object.defineProperty(mpInstance.__proto__, 'setData', {
|
|
39
|
-
configurable: false,
|
|
40
|
-
enumerable: false,
|
|
41
|
-
value: function value(data, callback) {
|
|
42
|
-
return setData.call(mpInstance, data, resetSetData(data, callback, lifeCycle, mpInstance));
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
}
|
|
41
|
+
}
|
|
42
|
+
});
|
|
46
43
|
}
|
|
44
|
+
}
|
|
47
45
|
|
|
48
|
-
|
|
46
|
+
return userDefinedMethod && userDefinedMethod.apply(this, arguments);
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function startSetDataColloction(lifeCycle, Vue) {
|
|
51
|
+
if (Vue && Vue.extend) {
|
|
52
|
+
var originVueExtend = Vue.extend;
|
|
53
|
+
|
|
54
|
+
Vue.extend = function (vueOptions) {
|
|
55
|
+
proxyPage(vueOptions, lifeCycle);
|
|
56
|
+
return originVueExtend.call(this, vueOptions);
|
|
49
57
|
};
|
|
58
|
+
} else {
|
|
59
|
+
if (!tracker) return;
|
|
60
|
+
var originCreatePage = tracker.createPage;
|
|
50
61
|
|
|
51
|
-
|
|
52
|
-
|
|
62
|
+
tracker.createPage = function (pageOptions) {
|
|
63
|
+
proxyPage(pageOptions, lifeCycle);
|
|
64
|
+
return originCreatePage.call(this, pageOptions);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
var originCreateComponent = tracker.createComponent;
|
|
68
|
+
|
|
69
|
+
tracker.createComponent = function (component) {
|
|
70
|
+
proxyPage(component, lifeCycle);
|
|
71
|
+
return originCreateComponent.call(this, component);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
53
74
|
}
|