fast-vue-multi-pages 1.0.12 → 1.0.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@ export declare class FastVueMultiWatcher {
7
7
  private static setWatcherTimer;
8
8
  private static stopWatcherTimer;
9
9
  private static startTimer;
10
+ private static pushWatcher;
10
11
  /**
11
12
  * 启动一个事件监听器
12
13
  * @param eventName 事件名称 string|array
@@ -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["__watcherConfig"]) {
13
- window["__watcherConfig"] = {};
12
+ if (!window["__WATCHER_CONFIG"]) {
13
+ window["__WATCHER_CONFIG"] = {};
14
14
  }
15
- return window["__watcherConfig"];
15
+ return window["__WATCHER_CONFIG"];
16
16
  }
17
17
  static getWatcherTimer() {
18
- return window["__watcherTimer"];
18
+ return window["__WATCHER_TIMER"];
19
19
  }
20
20
  static setWatcherTimer(timer) {
21
- window["__watcherTimer"] = timer;
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 config = this.getWatcherConfig()[eventName];
34
- if (watchValue !== null && watchValue !== undefined && watchValue !== "null" && watchValue !== "undefined") {
35
- let timestamp = parseInt(watchValue);
36
- if (isNaN(timestamp)) {
37
- continue;
38
- }
39
- if (config.timestamp < timestamp) {
40
- let params = js_cookie_1.default.get("EVENT@PARMAS@" + eventName);
41
- if (params) {
42
- params = JSON.parse(params);
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 cookieNameElement of eventName) {
67
- this.getWatcherConfig()[cookieNameElement] = {
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.getWatcherConfig()[eventName] = {
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 cookieNameElement of eventName) {
92
- js_cookie_1.default.set("EVENT@" + cookieNameElement, (new Date().getTime()).toString());
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@" + cookieNameElement, JSON.stringify(eventParams));
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["__SystemGlobalConfig"]) {
7
+ if (!window["__SYSTEM_GLOBAL_CONFIG"]) {
8
8
  //注意:此处变量 SystemGlobalConfig 在 webpack.DefinePlugin 编译后会替换成原始值,所以需要用window对象存储一下
9
9
  // @ts-ignore
10
- window["__SystemGlobalConfig"] = SystemGlobalConfig;
10
+ window["__SYSTEM_GLOBAL_CONFIG"] = SystemGlobalConfig;
11
11
  }
12
12
  // @ts-ignore
13
- return window["__SystemGlobalConfig"];
13
+ return window["__SYSTEM_GLOBAL_CONFIG"];
14
14
  }
15
15
  /**
16
16
  * 获取系统全局变量值
@@ -7,6 +7,7 @@ export declare class FastVueMultiWatcher {
7
7
  private static setWatcherTimer;
8
8
  private static stopWatcherTimer;
9
9
  private static startTimer;
10
+ private static pushWatcher;
10
11
  /**
11
12
  * 启动一个事件监听器
12
13
  * @param eventName 事件名称 string|array
@@ -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["__watcherConfig"]) {
15
- window["__watcherConfig"] = {};
14
+ if (!window["__WATCHER_CONFIG"]) {
15
+ window["__WATCHER_CONFIG"] = {};
16
16
  }
17
- return window["__watcherConfig"];
17
+ return window["__WATCHER_CONFIG"];
18
18
  };
19
19
  FastVueMultiWatcher.getWatcherTimer = function () {
20
- return window["__watcherTimer"];
20
+ return window["__WATCHER_TIMER"];
21
21
  };
22
22
  FastVueMultiWatcher.setWatcherTimer = function (timer) {
23
- window["__watcherTimer"] = timer;
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 config = _this.getWatcherConfig()[eventName];
37
- if (watchValue !== null && watchValue !== undefined && watchValue !== "null" && watchValue !== "undefined") {
38
- var timestamp = parseInt(watchValue);
39
- if (isNaN(timestamp)) {
40
- continue;
41
- }
42
- if (config.timestamp < timestamp) {
43
- var params = js_cookie_1.default.get("EVENT@PARMAS@" + eventName);
44
- if (params) {
45
- params = JSON.parse(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 cookieNameElement = eventName_1[_i];
71
- this.getWatcherConfig()[cookieNameElement] = {
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.getWatcherConfig()[eventName] = {
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 cookieNameElement = eventName_2[_i];
97
- js_cookie_1.default.set("EVENT@" + cookieNameElement, (new Date().getTime()).toString());
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@" + cookieNameElement, JSON.stringify(eventParams));
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["__SystemGlobalConfig"]) {
10
+ if (!window["__SYSTEM_GLOBAL_CONFIG"]) {
11
11
  //注意:此处变量 SystemGlobalConfig 在 webpack.DefinePlugin 编译后会替换成原始值,所以需要用window对象存储一下
12
12
  // @ts-ignore
13
- window["__SystemGlobalConfig"] = SystemGlobalConfig;
13
+ window["__SYSTEM_GLOBAL_CONFIG"] = SystemGlobalConfig;
14
14
  }
15
15
  // @ts-ignore
16
- return window["__SystemGlobalConfig"];
16
+ return window["__SYSTEM_GLOBAL_CONFIG"];
17
17
  };
18
18
  /**
19
19
  * 获取系统全局变量值
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-vue-multi-pages",
3
- "version": "1.0.12",
3
+ "version": "1.0.13",
4
4
  "author": "janesen",
5
5
  "description": "快速搭建VUE项目工具类的基本库,主要用于每个功能页面独立生成html",
6
6
  "main": "./dist/cjs/index.js",
@@ -4,13 +4,13 @@ exports.FastVueMultiConfig = void 0;
4
4
  class FastVueMultiConfig {
5
5
  static getGlobalConfigObj() {
6
6
  // @ts-ignore
7
- if (!window["__SystemGlobalConfig"]) {
7
+ if (!window["__SYSTEM_GLOBAL_CONFIG"]) {
8
8
  //注意:此处变量 SystemGlobalConfig 在 webpack.DefinePlugin 编译后会替换成原始值,所以需要用window对象存储一下
9
9
  // @ts-ignore
10
- window["__SystemGlobalConfig"] = SystemGlobalConfig;
10
+ window["__SYSTEM_GLOBAL_CONFIG"] = SystemGlobalConfig;
11
11
  }
12
12
  // @ts-ignore
13
- return window["__SystemGlobalConfig"];
13
+ return window["__SYSTEM_GLOBAL_CONFIG"];
14
14
  }
15
15
  /**
16
16
  * 获取系统全局变量值