fast-vue-multi-pages 1.0.12 → 1.0.13
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/dist/cjs/other/FastVueMultiWatcher.d.ts +1 -0
- package/dist/cjs/other/FastVueMultiWatcher.js +37 -32
- package/dist/cjs/vue/FastVueMultiConfig.js +3 -3
- package/dist/esm/other/FastVueMultiWatcher.d.ts +1 -0
- package/dist/esm/other/FastVueMultiWatcher.js +38 -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,56 @@ 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(callback);
|
58
|
+
}
|
59
|
+
else {
|
60
|
+
this.getWatcherConfig()[eventName] = [{
|
61
|
+
timestamp: new Date().getTime(),
|
62
|
+
callback: callback,
|
63
|
+
}];
|
64
|
+
}
|
65
|
+
}
|
52
66
|
/**
|
53
67
|
* 启动一个事件监听器
|
54
68
|
* @param eventName 事件名称 string|array
|
55
69
|
* @param callback 事件触发的回调 function(eventName,eventParams){}
|
56
70
|
*/
|
57
71
|
static startWatcher(eventName, callback) {
|
58
|
-
if (!window["__watchCookieTimestamp"]) {
|
59
|
-
window["__watchCookieTimestamp"] = {};
|
60
|
-
}
|
61
72
|
if (!callback || lodash_1.default.isEmpty(eventName)) {
|
62
73
|
//未携带回调函数的监听者,认为是无效监听
|
63
74
|
return;
|
64
75
|
}
|
65
76
|
if (lodash_1.default.isArray(eventName)) {
|
66
|
-
for (let
|
67
|
-
this.
|
68
|
-
timestamp: new Date().getTime(),
|
69
|
-
callback: callback,
|
70
|
-
};
|
77
|
+
for (let eventNameElement of eventName) {
|
78
|
+
this.pushWatcher(eventNameElement, callback);
|
71
79
|
}
|
72
80
|
}
|
73
81
|
else {
|
74
|
-
this.
|
75
|
-
timestamp: new Date().getTime(),
|
76
|
-
callback: callback,
|
77
|
-
};
|
82
|
+
this.pushWatcher(eventName, callback);
|
78
83
|
}
|
79
84
|
this.startTimer();
|
80
85
|
}
|
@@ -88,10 +93,10 @@ class FastVueMultiWatcher {
|
|
88
93
|
return;
|
89
94
|
}
|
90
95
|
if (lodash_1.default.isArray(eventName)) {
|
91
|
-
for (let
|
92
|
-
js_cookie_1.default.set("EVENT@" +
|
96
|
+
for (let eventNameElement of eventName) {
|
97
|
+
js_cookie_1.default.set("EVENT@" + eventNameElement, (new Date().getTime()).toString());
|
93
98
|
if (eventParams) {
|
94
|
-
js_cookie_1.default.set("EVENT@PARMAS@" +
|
99
|
+
js_cookie_1.default.set("EVENT@PARMAS@" + eventNameElement, JSON.stringify(eventParams));
|
95
100
|
}
|
96
101
|
}
|
97
102
|
}
|
@@ -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,58 @@ 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(callback);
|
62
|
+
}
|
63
|
+
else {
|
64
|
+
this.getWatcherConfig()[eventName] = [{
|
65
|
+
timestamp: new Date().getTime(),
|
66
|
+
callback: callback,
|
67
|
+
}];
|
68
|
+
}
|
69
|
+
};
|
55
70
|
/**
|
56
71
|
* 启动一个事件监听器
|
57
72
|
* @param eventName 事件名称 string|array
|
58
73
|
* @param callback 事件触发的回调 function(eventName,eventParams){}
|
59
74
|
*/
|
60
75
|
FastVueMultiWatcher.startWatcher = function (eventName, callback) {
|
61
|
-
if (!window["__watchCookieTimestamp"]) {
|
62
|
-
window["__watchCookieTimestamp"] = {};
|
63
|
-
}
|
64
76
|
if (!callback || lodash_1.default.isEmpty(eventName)) {
|
65
77
|
//未携带回调函数的监听者,认为是无效监听
|
66
78
|
return;
|
67
79
|
}
|
68
80
|
if (lodash_1.default.isArray(eventName)) {
|
69
81
|
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
|
-
};
|
82
|
+
var eventNameElement = eventName_1[_i];
|
83
|
+
this.pushWatcher(eventNameElement, callback);
|
75
84
|
}
|
76
85
|
}
|
77
86
|
else {
|
78
|
-
this.
|
79
|
-
timestamp: new Date().getTime(),
|
80
|
-
callback: callback,
|
81
|
-
};
|
87
|
+
this.pushWatcher(eventName, callback);
|
82
88
|
}
|
83
89
|
this.startTimer();
|
84
90
|
};
|
@@ -93,10 +99,10 @@ define(["require", "exports", "tslib", "lodash", "js-cookie"], function (require
|
|
93
99
|
}
|
94
100
|
if (lodash_1.default.isArray(eventName)) {
|
95
101
|
for (var _i = 0, eventName_2 = eventName; _i < eventName_2.length; _i++) {
|
96
|
-
var
|
97
|
-
js_cookie_1.default.set("EVENT@" +
|
102
|
+
var eventNameElement = eventName_2[_i];
|
103
|
+
js_cookie_1.default.set("EVENT@" + eventNameElement, (new Date().getTime()).toString());
|
98
104
|
if (eventParams) {
|
99
|
-
js_cookie_1.default.set("EVENT@PARMAS@" +
|
105
|
+
js_cookie_1.default.set("EVENT@PARMAS@" + eventNameElement, JSON.stringify(eventParams));
|
100
106
|
}
|
101
107
|
}
|
102
108
|
}
|
@@ -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
|
* 获取系统全局变量值
|