fast-vue-multi-pages 1.0.12 → 1.0.14
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/other/FastVueMultiWatcher.d.ts +1 -0
- package/dist/cjs/other/FastVueMultiWatcher.js +40 -32
- package/dist/cjs/vue/FastVueMultiConfig.js +3 -3
- package/dist/esm/other/FastVueMultiWatcher.d.ts +1 -0
- package/dist/esm/other/FastVueMultiWatcher.js +41 -32
- package/dist/esm/vue/FastVueMultiConfig.js +3 -3
- package/package.json +1 -1
- package/vue/FastVueMultiConfig.js +3 -3
@@ -9,16 +9,16 @@ const js_cookie_1 = tslib_1.__importDefault(require("js-cookie"));
|
|
9
9
|
*/
|
10
10
|
class FastVueMultiWatcher {
|
11
11
|
static getWatcherConfig() {
|
12
|
-
if (!window["
|
13
|
-
window["
|
12
|
+
if (!window["__WATCHER_CONFIG"]) {
|
13
|
+
window["__WATCHER_CONFIG"] = {};
|
14
14
|
}
|
15
|
-
return window["
|
15
|
+
return window["__WATCHER_CONFIG"];
|
16
16
|
}
|
17
17
|
static getWatcherTimer() {
|
18
|
-
return window["
|
18
|
+
return window["__WATCHER_TIMER"];
|
19
19
|
}
|
20
20
|
static setWatcherTimer(timer) {
|
21
|
-
window["
|
21
|
+
window["__WATCHER_TIMER"] = timer;
|
22
22
|
}
|
23
23
|
static stopWatcherTimer() {
|
24
24
|
if (this.getWatcherTimer()) {
|
@@ -30,51 +30,59 @@ class FastVueMultiWatcher {
|
|
30
30
|
this.setWatcherTimer(setTimeout(() => {
|
31
31
|
for (let eventName in this.getWatcherConfig()) {
|
32
32
|
let watchValue = js_cookie_1.default.get("EVENT@" + eventName);
|
33
|
-
let
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
33
|
+
let configs = this.getWatcherConfig()[eventName];
|
34
|
+
for (let config of configs) {
|
35
|
+
if (watchValue !== null && watchValue !== undefined && watchValue !== "null" && watchValue !== "undefined") {
|
36
|
+
let timestamp = parseInt(watchValue);
|
37
|
+
if (isNaN(timestamp)) {
|
38
|
+
continue;
|
39
|
+
}
|
40
|
+
if (config.timestamp < timestamp) {
|
41
|
+
let params = js_cookie_1.default.get("EVENT@PARMAS@" + eventName);
|
42
|
+
if (params) {
|
43
|
+
params = JSON.parse(params);
|
44
|
+
}
|
45
|
+
config.timestamp = timestamp;
|
46
|
+
config.callback(eventName, params);
|
43
47
|
}
|
44
|
-
config.timestamp = timestamp;
|
45
|
-
config.callback(eventName, params);
|
46
48
|
}
|
47
49
|
}
|
48
50
|
}
|
49
51
|
this.startTimer();
|
50
52
|
}, 500));
|
51
53
|
}
|
54
|
+
static pushWatcher(eventName, callback) {
|
55
|
+
let lastConfigs = this.getWatcherConfig()[eventName];
|
56
|
+
if (lastConfigs) {
|
57
|
+
lastConfigs.push({
|
58
|
+
timestamp: new Date().getTime(),
|
59
|
+
callback: callback,
|
60
|
+
});
|
61
|
+
}
|
62
|
+
else {
|
63
|
+
this.getWatcherConfig()[eventName] = [{
|
64
|
+
timestamp: new Date().getTime(),
|
65
|
+
callback: callback,
|
66
|
+
}];
|
67
|
+
}
|
68
|
+
}
|
52
69
|
/**
|
53
70
|
* 启动一个事件监听器
|
54
71
|
* @param eventName 事件名称 string|array
|
55
72
|
* @param callback 事件触发的回调 function(eventName,eventParams){}
|
56
73
|
*/
|
57
74
|
static startWatcher(eventName, callback) {
|
58
|
-
if (!window["__watchCookieTimestamp"]) {
|
59
|
-
window["__watchCookieTimestamp"] = {};
|
60
|
-
}
|
61
75
|
if (!callback || lodash_1.default.isEmpty(eventName)) {
|
62
76
|
//未携带回调函数的监听者,认为是无效监听
|
63
77
|
return;
|
64
78
|
}
|
65
79
|
if (lodash_1.default.isArray(eventName)) {
|
66
|
-
for (let
|
67
|
-
this.
|
68
|
-
timestamp: new Date().getTime(),
|
69
|
-
callback: callback,
|
70
|
-
};
|
80
|
+
for (let eventNameElement of eventName) {
|
81
|
+
this.pushWatcher(eventNameElement, callback);
|
71
82
|
}
|
72
83
|
}
|
73
84
|
else {
|
74
|
-
this.
|
75
|
-
timestamp: new Date().getTime(),
|
76
|
-
callback: callback,
|
77
|
-
};
|
85
|
+
this.pushWatcher(eventName, callback);
|
78
86
|
}
|
79
87
|
this.startTimer();
|
80
88
|
}
|
@@ -88,10 +96,10 @@ class FastVueMultiWatcher {
|
|
88
96
|
return;
|
89
97
|
}
|
90
98
|
if (lodash_1.default.isArray(eventName)) {
|
91
|
-
for (let
|
92
|
-
js_cookie_1.default.set("EVENT@" +
|
99
|
+
for (let eventNameElement of eventName) {
|
100
|
+
js_cookie_1.default.set("EVENT@" + eventNameElement, (new Date().getTime()).toString());
|
93
101
|
if (eventParams) {
|
94
|
-
js_cookie_1.default.set("EVENT@PARMAS@" +
|
102
|
+
js_cookie_1.default.set("EVENT@PARMAS@" + eventNameElement, JSON.stringify(eventParams));
|
95
103
|
}
|
96
104
|
}
|
97
105
|
}
|
@@ -4,13 +4,13 @@ exports.FastVueMultiConfig = void 0;
|
|
4
4
|
class FastVueMultiConfig {
|
5
5
|
static getGlobalConfigObj() {
|
6
6
|
// @ts-ignore
|
7
|
-
if (!window["
|
7
|
+
if (!window["__SYSTEM_GLOBAL_CONFIG"]) {
|
8
8
|
//注意:此处变量 SystemGlobalConfig 在 webpack.DefinePlugin 编译后会替换成原始值,所以需要用window对象存储一下
|
9
9
|
// @ts-ignore
|
10
|
-
window["
|
10
|
+
window["__SYSTEM_GLOBAL_CONFIG"] = SystemGlobalConfig;
|
11
11
|
}
|
12
12
|
// @ts-ignore
|
13
|
-
return window["
|
13
|
+
return window["__SYSTEM_GLOBAL_CONFIG"];
|
14
14
|
}
|
15
15
|
/**
|
16
16
|
* 获取系统全局变量值
|
@@ -11,16 +11,16 @@ define(["require", "exports", "tslib", "lodash", "js-cookie"], function (require
|
|
11
11
|
function FastVueMultiWatcher() {
|
12
12
|
}
|
13
13
|
FastVueMultiWatcher.getWatcherConfig = function () {
|
14
|
-
if (!window["
|
15
|
-
window["
|
14
|
+
if (!window["__WATCHER_CONFIG"]) {
|
15
|
+
window["__WATCHER_CONFIG"] = {};
|
16
16
|
}
|
17
|
-
return window["
|
17
|
+
return window["__WATCHER_CONFIG"];
|
18
18
|
};
|
19
19
|
FastVueMultiWatcher.getWatcherTimer = function () {
|
20
|
-
return window["
|
20
|
+
return window["__WATCHER_TIMER"];
|
21
21
|
};
|
22
22
|
FastVueMultiWatcher.setWatcherTimer = function (timer) {
|
23
|
-
window["
|
23
|
+
window["__WATCHER_TIMER"] = timer;
|
24
24
|
};
|
25
25
|
FastVueMultiWatcher.stopWatcherTimer = function () {
|
26
26
|
if (this.getWatcherTimer()) {
|
@@ -33,52 +33,61 @@ define(["require", "exports", "tslib", "lodash", "js-cookie"], function (require
|
|
33
33
|
this.setWatcherTimer(setTimeout(function () {
|
34
34
|
for (var eventName in _this.getWatcherConfig()) {
|
35
35
|
var watchValue = js_cookie_1.default.get("EVENT@" + eventName);
|
36
|
-
var
|
37
|
-
|
38
|
-
var
|
39
|
-
if (
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
if (
|
45
|
-
params =
|
36
|
+
var configs = _this.getWatcherConfig()[eventName];
|
37
|
+
for (var _i = 0, configs_1 = configs; _i < configs_1.length; _i++) {
|
38
|
+
var config = configs_1[_i];
|
39
|
+
if (watchValue !== null && watchValue !== undefined && watchValue !== "null" && watchValue !== "undefined") {
|
40
|
+
var timestamp = parseInt(watchValue);
|
41
|
+
if (isNaN(timestamp)) {
|
42
|
+
continue;
|
43
|
+
}
|
44
|
+
if (config.timestamp < timestamp) {
|
45
|
+
var params = js_cookie_1.default.get("EVENT@PARMAS@" + eventName);
|
46
|
+
if (params) {
|
47
|
+
params = JSON.parse(params);
|
48
|
+
}
|
49
|
+
config.timestamp = timestamp;
|
50
|
+
config.callback(eventName, params);
|
46
51
|
}
|
47
|
-
config.timestamp = timestamp;
|
48
|
-
config.callback(eventName, params);
|
49
52
|
}
|
50
53
|
}
|
51
54
|
}
|
52
55
|
_this.startTimer();
|
53
56
|
}, 500));
|
54
57
|
};
|
58
|
+
FastVueMultiWatcher.pushWatcher = function (eventName, callback) {
|
59
|
+
var lastConfigs = this.getWatcherConfig()[eventName];
|
60
|
+
if (lastConfigs) {
|
61
|
+
lastConfigs.push({
|
62
|
+
timestamp: new Date().getTime(),
|
63
|
+
callback: callback,
|
64
|
+
});
|
65
|
+
}
|
66
|
+
else {
|
67
|
+
this.getWatcherConfig()[eventName] = [{
|
68
|
+
timestamp: new Date().getTime(),
|
69
|
+
callback: callback,
|
70
|
+
}];
|
71
|
+
}
|
72
|
+
};
|
55
73
|
/**
|
56
74
|
* 启动一个事件监听器
|
57
75
|
* @param eventName 事件名称 string|array
|
58
76
|
* @param callback 事件触发的回调 function(eventName,eventParams){}
|
59
77
|
*/
|
60
78
|
FastVueMultiWatcher.startWatcher = function (eventName, callback) {
|
61
|
-
if (!window["__watchCookieTimestamp"]) {
|
62
|
-
window["__watchCookieTimestamp"] = {};
|
63
|
-
}
|
64
79
|
if (!callback || lodash_1.default.isEmpty(eventName)) {
|
65
80
|
//未携带回调函数的监听者,认为是无效监听
|
66
81
|
return;
|
67
82
|
}
|
68
83
|
if (lodash_1.default.isArray(eventName)) {
|
69
84
|
for (var _i = 0, eventName_1 = eventName; _i < eventName_1.length; _i++) {
|
70
|
-
var
|
71
|
-
this.
|
72
|
-
timestamp: new Date().getTime(),
|
73
|
-
callback: callback,
|
74
|
-
};
|
85
|
+
var eventNameElement = eventName_1[_i];
|
86
|
+
this.pushWatcher(eventNameElement, callback);
|
75
87
|
}
|
76
88
|
}
|
77
89
|
else {
|
78
|
-
this.
|
79
|
-
timestamp: new Date().getTime(),
|
80
|
-
callback: callback,
|
81
|
-
};
|
90
|
+
this.pushWatcher(eventName, callback);
|
82
91
|
}
|
83
92
|
this.startTimer();
|
84
93
|
};
|
@@ -93,10 +102,10 @@ define(["require", "exports", "tslib", "lodash", "js-cookie"], function (require
|
|
93
102
|
}
|
94
103
|
if (lodash_1.default.isArray(eventName)) {
|
95
104
|
for (var _i = 0, eventName_2 = eventName; _i < eventName_2.length; _i++) {
|
96
|
-
var
|
97
|
-
js_cookie_1.default.set("EVENT@" +
|
105
|
+
var eventNameElement = eventName_2[_i];
|
106
|
+
js_cookie_1.default.set("EVENT@" + eventNameElement, (new Date().getTime()).toString());
|
98
107
|
if (eventParams) {
|
99
|
-
js_cookie_1.default.set("EVENT@PARMAS@" +
|
108
|
+
js_cookie_1.default.set("EVENT@PARMAS@" + eventNameElement, JSON.stringify(eventParams));
|
100
109
|
}
|
101
110
|
}
|
102
111
|
}
|
@@ -7,13 +7,13 @@ define(["require", "exports"], function (require, exports) {
|
|
7
7
|
}
|
8
8
|
FastVueMultiConfig.getGlobalConfigObj = function () {
|
9
9
|
// @ts-ignore
|
10
|
-
if (!window["
|
10
|
+
if (!window["__SYSTEM_GLOBAL_CONFIG"]) {
|
11
11
|
//注意:此处变量 SystemGlobalConfig 在 webpack.DefinePlugin 编译后会替换成原始值,所以需要用window对象存储一下
|
12
12
|
// @ts-ignore
|
13
|
-
window["
|
13
|
+
window["__SYSTEM_GLOBAL_CONFIG"] = SystemGlobalConfig;
|
14
14
|
}
|
15
15
|
// @ts-ignore
|
16
|
-
return window["
|
16
|
+
return window["__SYSTEM_GLOBAL_CONFIG"];
|
17
17
|
};
|
18
18
|
/**
|
19
19
|
* 获取系统全局变量值
|
package/package.json
CHANGED
@@ -4,13 +4,13 @@ exports.FastVueMultiConfig = void 0;
|
|
4
4
|
class FastVueMultiConfig {
|
5
5
|
static getGlobalConfigObj() {
|
6
6
|
// @ts-ignore
|
7
|
-
if (!window["
|
7
|
+
if (!window["__SYSTEM_GLOBAL_CONFIG"]) {
|
8
8
|
//注意:此处变量 SystemGlobalConfig 在 webpack.DefinePlugin 编译后会替换成原始值,所以需要用window对象存储一下
|
9
9
|
// @ts-ignore
|
10
|
-
window["
|
10
|
+
window["__SYSTEM_GLOBAL_CONFIG"] = SystemGlobalConfig;
|
11
11
|
}
|
12
12
|
// @ts-ignore
|
13
|
-
return window["
|
13
|
+
return window["__SYSTEM_GLOBAL_CONFIG"];
|
14
14
|
}
|
15
15
|
/**
|
16
16
|
* 获取系统全局变量值
|