fast-vue-multi-pages 1.0.18 → 1.0.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,7 +11,7 @@ import { FastVueMultiElement } from "./other/FastVueMultiElement";
11
11
  import { FastVueMultiWindow } from "./other/FastVueMultiWindow";
12
12
  import { FastVueMultiFile } from "./other/FastVueMultiFile";
13
13
  import { FastVueMultiBase64 } from "./other/FastVueMultiBase64";
14
- import { FastVueMultiWatcher } from "./other/FastVueMultiWatcher";
14
+ import { FastVueMultiEventBus } from "./other/FastVueMultiEventBus";
15
15
  /**
16
16
  * FastVueMultiTool 手机APP功能工具类
17
17
  */
@@ -77,7 +77,7 @@ export declare class FastVueMultiTool {
77
77
  */
78
78
  static Base64: typeof FastVueMultiBase64;
79
79
  /**
80
- * 监听者
80
+ * 事件传递
81
81
  */
82
- static Watcher: typeof FastVueMultiWatcher;
82
+ static EventBus: typeof FastVueMultiEventBus;
83
83
  }
@@ -15,7 +15,7 @@ const FastVueMultiElement_1 = require("./other/FastVueMultiElement");
15
15
  const FastVueMultiWindow_1 = require("./other/FastVueMultiWindow");
16
16
  const FastVueMultiFile_1 = require("./other/FastVueMultiFile");
17
17
  const FastVueMultiBase64_1 = require("./other/FastVueMultiBase64");
18
- const FastVueMultiWatcher_1 = require("./other/FastVueMultiWatcher");
18
+ const FastVueMultiEventBus_1 = require("./other/FastVueMultiEventBus");
19
19
  /**
20
20
  * FastVueMultiTool 手机APP功能工具类
21
21
  */
@@ -81,8 +81,8 @@ class FastVueMultiTool {
81
81
  */
82
82
  static Base64 = FastVueMultiBase64_1.FastVueMultiBase64;
83
83
  /**
84
- * 监听者
84
+ * 事件传递
85
85
  */
86
- static Watcher = FastVueMultiWatcher_1.FastVueMultiWatcher;
86
+ static EventBus = FastVueMultiEventBus_1.FastVueMultiEventBus;
87
87
  }
88
88
  exports.FastVueMultiTool = FastVueMultiTool;
@@ -91,7 +91,7 @@ export declare namespace FastVueMultiHttp {
91
91
  */
92
92
  static setFinalHeader(key: string, value: string): void;
93
93
  /**
94
- * 获取接口的全局参数,同步获取了原生APP的全局参数
94
+ * 获取接口的全局参数
95
95
  */
96
96
  static getFinalParams(): any;
97
97
  /**
@@ -128,7 +128,15 @@ var FastVueMultiHttp;
128
128
  else {
129
129
  for (let paramKey in param) {
130
130
  if (param.hasOwnProperty(paramKey)) {
131
- newParams.append(paramKey, param[paramKey]);
131
+ let value = param[paramKey];
132
+ if (lodash_1.default.isArray(value)) {
133
+ for (let valueElement of value) {
134
+ newParams.append(paramKey, valueElement);
135
+ }
136
+ }
137
+ else {
138
+ newParams.append(paramKey, param[paramKey]);
139
+ }
132
140
  }
133
141
  }
134
142
  }
@@ -271,7 +279,7 @@ var FastVueMultiHttp;
271
279
  }
272
280
  }
273
281
  /**
274
- * 获取接口的全局参数,同步获取了原生APP的全局参数
282
+ * 获取接口的全局参数
275
283
  */
276
284
  static getFinalParams() {
277
285
  let justFinalParams = {};
@@ -76,31 +76,31 @@ class FastVueMultiDate {
76
76
  let nice = true;
77
77
  if (time / month >= 1) {
78
78
  if (level >= 5) {
79
- return parseInt(String(time / month)) + "个月前";
79
+ return parseInt((time / month).toString()) + "个月前";
80
80
  }
81
81
  nice = false;
82
82
  }
83
83
  if (nice && time / week >= 1) {
84
84
  if (level >= 4) {
85
- return parseInt(String(time / week)) + "周前";
85
+ return parseInt((time / week).toString()) + "周前";
86
86
  }
87
87
  nice = false;
88
88
  }
89
89
  if (nice && time / day >= 1) {
90
90
  if (level >= 3) {
91
- return parseInt(String(time / day)) + "天前";
91
+ return parseInt((time / day).toString()) + "天前";
92
92
  }
93
93
  nice = false;
94
94
  }
95
95
  if (nice && time / hour >= 1) {
96
96
  if (level >= 2) {
97
- return parseInt(String(time / hour)) + "小时前";
97
+ return parseInt((time / hour).toString()) + "小时前";
98
98
  }
99
99
  nice = false;
100
100
  }
101
101
  if (nice && time / minute >= 1) {
102
102
  if (level >= 1) {
103
- return parseInt(String(time / minute)) + "分钟前";
103
+ return parseInt((time / minute).toString()) + "分钟前";
104
104
  }
105
105
  }
106
106
  return this.format(sourceDate, "yyyy-MM-DD HH:mm");
@@ -121,13 +121,13 @@ class FastVueMultiDate {
121
121
  return descriptions.join("");
122
122
  }
123
123
  else if (timestamp < minuteUnit) {
124
- descriptions.push(lodash_1.default.padStart(String(timestamp / seconds), 2, "0") + (chinese ? '秒' : ''));
124
+ descriptions.push(lodash_1.default.padStart((timestamp / seconds).toString(), 2, "0") + (chinese ? '秒' : ''));
125
125
  return descriptions.join("");
126
126
  }
127
127
  if (timestamp < hourUnit) {
128
- let minute = parseInt(String(timestamp / minuteUnit));
129
- descriptions.push(lodash_1.default.padStart(String(minute), 2, "0") + (chinese ? '分' : ':'));
130
- let nextTimestamp = timestamp - parseInt(String(minute * minuteUnit));
128
+ let minute = parseInt((timestamp / minuteUnit).toString());
129
+ descriptions.push(lodash_1.default.padStart(minute.toString(), 2, "0") + (chinese ? '分' : ':'));
130
+ let nextTimestamp = timestamp - parseInt((minute * minuteUnit).toString());
131
131
  if (nextTimestamp === 0) {
132
132
  descriptions.push("00" + (chinese ? '秒' : ''));
133
133
  }
@@ -137,9 +137,9 @@ class FastVueMultiDate {
137
137
  return descriptions.join("");
138
138
  }
139
139
  if (timestamp < dayUnit) {
140
- let hour = parseInt(String(timestamp / hourUnit));
141
- descriptions.push(lodash_1.default.padStart(String(hour), 2, "0") + (chinese ? '时' : ':'));
142
- let nextTimestamp = timestamp - parseInt(String(hour * hourUnit));
140
+ let hour = parseInt((timestamp / hourUnit).toString());
141
+ descriptions.push(lodash_1.default.padStart((hour).toString(), 2, "0") + (chinese ? '时' : ':'));
142
+ let nextTimestamp = timestamp - parseInt((hour * hourUnit).toString());
143
143
  if (nextTimestamp === 0) {
144
144
  descriptions.push("00" + (chinese ? '分' : ':'));
145
145
  descriptions.push("00" + (chinese ? '秒' : ''));
@@ -149,9 +149,9 @@ class FastVueMultiDate {
149
149
  }
150
150
  return descriptions.join("");
151
151
  }
152
- let day = parseInt(String(timestamp / dayUnit));
152
+ let day = parseInt((timestamp / dayUnit).toString());
153
153
  descriptions.push(day + (chinese ? '天' : 'day '));
154
- let nextTimestamp = timestamp - parseInt(String(day * dayUnit));
154
+ let nextTimestamp = timestamp - parseInt((day * dayUnit).toString());
155
155
  if (nextTimestamp === 0) {
156
156
  descriptions.push("00" + (chinese ? '时' : ':'));
157
157
  descriptions.push("00" + (chinese ? '分' : ':'));
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 事件监听器
3
+ */
4
+ export declare class FastVueMultiEventBus {
5
+ private static getWatcherConfig;
6
+ private static getWatcherTimer;
7
+ private static setWatcherTimer;
8
+ private static stopWatcherTimer;
9
+ private static startTimer;
10
+ private static pushWatcher;
11
+ /**
12
+ * 启动一个事件监听器
13
+ * @param eventName 事件名称 string|array
14
+ * @param callback 事件触发的回调 function(eventName,eventParams){}
15
+ */
16
+ static on(eventName: any, callback: any): void;
17
+ /**
18
+ * 通知事件监听者
19
+ * @param eventName 事件名称 string|array
20
+ * @param eventParams 携带参数 any
21
+ */
22
+ static emit(eventName: any, eventParams?: any): void;
23
+ }
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FastVueMultiEventBus = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
6
+ const js_cookie_1 = tslib_1.__importDefault(require("js-cookie"));
7
+ /**
8
+ * 事件监听器
9
+ */
10
+ class FastVueMultiEventBus {
11
+ static getWatcherConfig() {
12
+ if (!window["__WATCHER_CONFIG"]) {
13
+ window["__WATCHER_CONFIG"] = {};
14
+ }
15
+ return window["__WATCHER_CONFIG"];
16
+ }
17
+ static getWatcherTimer() {
18
+ return window["__WATCHER_TIMER"];
19
+ }
20
+ static setWatcherTimer(timer) {
21
+ window["__WATCHER_TIMER"] = timer;
22
+ }
23
+ static stopWatcherTimer() {
24
+ if (this.getWatcherTimer()) {
25
+ clearTimeout(this.getWatcherTimer());
26
+ }
27
+ }
28
+ static startTimer() {
29
+ this.stopWatcherTimer();
30
+ this.setWatcherTimer(setTimeout(() => {
31
+ for (let eventName in this.getWatcherConfig()) {
32
+ let watchValue = js_cookie_1.default.get("EVENT@" + eventName);
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);
47
+ }
48
+ }
49
+ }
50
+ }
51
+ this.startTimer();
52
+ }, 500));
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
+ }
69
+ /**
70
+ * 启动一个事件监听器
71
+ * @param eventName 事件名称 string|array
72
+ * @param callback 事件触发的回调 function(eventName,eventParams){}
73
+ */
74
+ static on(eventName, callback) {
75
+ if (!callback || lodash_1.default.isEmpty(eventName)) {
76
+ //未携带回调函数的监听者,认为是无效监听
77
+ return;
78
+ }
79
+ if (lodash_1.default.isArray(eventName)) {
80
+ for (let eventNameElement of eventName) {
81
+ this.pushWatcher(eventNameElement, callback);
82
+ }
83
+ }
84
+ else {
85
+ this.pushWatcher(eventName, callback);
86
+ }
87
+ this.startTimer();
88
+ }
89
+ /**
90
+ * 通知事件监听者
91
+ * @param eventName 事件名称 string|array
92
+ * @param eventParams 携带参数 any
93
+ */
94
+ static emit(eventName, eventParams) {
95
+ if (lodash_1.default.isEmpty(eventName)) {
96
+ return;
97
+ }
98
+ if (lodash_1.default.isArray(eventName)) {
99
+ for (let eventNameElement of eventName) {
100
+ js_cookie_1.default.set("EVENT@" + eventNameElement, (new Date().getTime()).toString());
101
+ if (eventParams) {
102
+ js_cookie_1.default.set("EVENT@PARMAS@" + eventNameElement, JSON.stringify(eventParams));
103
+ }
104
+ }
105
+ }
106
+ else {
107
+ js_cookie_1.default.set("EVENT@" + eventName, (new Date().getTime()).toString());
108
+ if (eventParams) {
109
+ js_cookie_1.default.set("EVENT@PARMAS@" + eventName, JSON.stringify(eventParams));
110
+ }
111
+ }
112
+ }
113
+ }
114
+ exports.FastVueMultiEventBus = FastVueMultiEventBus;
@@ -11,7 +11,7 @@ import { FastVueMultiElement } from "./other/FastVueMultiElement";
11
11
  import { FastVueMultiWindow } from "./other/FastVueMultiWindow";
12
12
  import { FastVueMultiFile } from "./other/FastVueMultiFile";
13
13
  import { FastVueMultiBase64 } from "./other/FastVueMultiBase64";
14
- import { FastVueMultiWatcher } from "./other/FastVueMultiWatcher";
14
+ import { FastVueMultiEventBus } from "./other/FastVueMultiEventBus";
15
15
  /**
16
16
  * FastVueMultiTool 手机APP功能工具类
17
17
  */
@@ -77,7 +77,7 @@ export declare class FastVueMultiTool {
77
77
  */
78
78
  static Base64: typeof FastVueMultiBase64;
79
79
  /**
80
- * 监听者
80
+ * 事件传递
81
81
  */
82
- static Watcher: typeof FastVueMultiWatcher;
82
+ static EventBus: typeof FastVueMultiEventBus;
83
83
  }
@@ -1,4 +1,4 @@
1
- define(["require", "exports", "tslib", "lodash", "./http/FastVueMultiHttp", "./other/FastVueMultiStore", "./vue/FastVueMultiConfig", "./http/FastVueMultiCookie", "./other/FastVueMultiClipboard", "./other/FastVueMultiDate", "./other/FastVueMultiBoolean", "./other/FastVueMultiFunction", "./other/FastVueMultiElement", "./other/FastVueMultiWindow", "./other/FastVueMultiFile", "./other/FastVueMultiBase64", "./other/FastVueMultiWatcher"], function (require, exports, tslib_1, lodash_1, FastVueMultiHttp_1, FastVueMultiStore_1, FastVueMultiConfig_1, FastVueMultiCookie_1, FastVueMultiClipboard_1, FastVueMultiDate_1, FastVueMultiBoolean_1, FastVueMultiFunction_1, FastVueMultiElement_1, FastVueMultiWindow_1, FastVueMultiFile_1, FastVueMultiBase64_1, FastVueMultiWatcher_1) {
1
+ define(["require", "exports", "tslib", "lodash", "./http/FastVueMultiHttp", "./other/FastVueMultiStore", "./vue/FastVueMultiConfig", "./http/FastVueMultiCookie", "./other/FastVueMultiClipboard", "./other/FastVueMultiDate", "./other/FastVueMultiBoolean", "./other/FastVueMultiFunction", "./other/FastVueMultiElement", "./other/FastVueMultiWindow", "./other/FastVueMultiFile", "./other/FastVueMultiBase64", "./other/FastVueMultiEventBus"], function (require, exports, tslib_1, lodash_1, FastVueMultiHttp_1, FastVueMultiStore_1, FastVueMultiConfig_1, FastVueMultiCookie_1, FastVueMultiClipboard_1, FastVueMultiDate_1, FastVueMultiBoolean_1, FastVueMultiFunction_1, FastVueMultiElement_1, FastVueMultiWindow_1, FastVueMultiFile_1, FastVueMultiBase64_1, FastVueMultiEventBus_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.FastVueMultiTool = void 0;
@@ -70,9 +70,9 @@ define(["require", "exports", "tslib", "lodash", "./http/FastVueMultiHttp", "./o
70
70
  */
71
71
  FastVueMultiTool.Base64 = FastVueMultiBase64_1.FastVueMultiBase64;
72
72
  /**
73
- * 监听者
73
+ * 事件传递
74
74
  */
75
- FastVueMultiTool.Watcher = FastVueMultiWatcher_1.FastVueMultiWatcher;
75
+ FastVueMultiTool.EventBus = FastVueMultiEventBus_1.FastVueMultiEventBus;
76
76
  return FastVueMultiTool;
77
77
  }());
78
78
  exports.FastVueMultiTool = FastVueMultiTool;
@@ -91,7 +91,7 @@ export declare namespace FastVueMultiHttp {
91
91
  */
92
92
  static setFinalHeader(key: string, value: string): void;
93
93
  /**
94
- * 获取接口的全局参数,同步获取了原生APP的全局参数
94
+ * 获取接口的全局参数
95
95
  */
96
96
  static getFinalParams(): any;
97
97
  /**
@@ -130,7 +130,16 @@ define(["require", "exports", "tslib", "axios", "lodash", "../vue/FastVueMultiCo
130
130
  else {
131
131
  for (var paramKey in param) {
132
132
  if (param.hasOwnProperty(paramKey)) {
133
- newParams.append(paramKey, param[paramKey]);
133
+ var value = param[paramKey];
134
+ if (lodash_1.default.isArray(value)) {
135
+ for (var _i = 0, value_1 = value; _i < value_1.length; _i++) {
136
+ var valueElement = value_1[_i];
137
+ newParams.append(paramKey, valueElement);
138
+ }
139
+ }
140
+ else {
141
+ newParams.append(paramKey, param[paramKey]);
142
+ }
134
143
  }
135
144
  }
136
145
  }
@@ -277,7 +286,7 @@ define(["require", "exports", "tslib", "axios", "lodash", "../vue/FastVueMultiCo
277
286
  }
278
287
  };
279
288
  /**
280
- * 获取接口的全局参数,同步获取了原生APP的全局参数
289
+ * 获取接口的全局参数
281
290
  */
282
291
  Base.getFinalParams = function () {
283
292
  var justFinalParams = {};
@@ -78,31 +78,31 @@ define(["require", "exports", "tslib", "moment", "lodash"], function (require, e
78
78
  var nice = true;
79
79
  if (time / month >= 1) {
80
80
  if (level >= 5) {
81
- return parseInt(String(time / month)) + "个月前";
81
+ return parseInt((time / month).toString()) + "个月前";
82
82
  }
83
83
  nice = false;
84
84
  }
85
85
  if (nice && time / week >= 1) {
86
86
  if (level >= 4) {
87
- return parseInt(String(time / week)) + "周前";
87
+ return parseInt((time / week).toString()) + "周前";
88
88
  }
89
89
  nice = false;
90
90
  }
91
91
  if (nice && time / day >= 1) {
92
92
  if (level >= 3) {
93
- return parseInt(String(time / day)) + "天前";
93
+ return parseInt((time / day).toString()) + "天前";
94
94
  }
95
95
  nice = false;
96
96
  }
97
97
  if (nice && time / hour >= 1) {
98
98
  if (level >= 2) {
99
- return parseInt(String(time / hour)) + "小时前";
99
+ return parseInt((time / hour).toString()) + "小时前";
100
100
  }
101
101
  nice = false;
102
102
  }
103
103
  if (nice && time / minute >= 1) {
104
104
  if (level >= 1) {
105
- return parseInt(String(time / minute)) + "分钟前";
105
+ return parseInt((time / minute).toString()) + "分钟前";
106
106
  }
107
107
  }
108
108
  return this.format(sourceDate, "yyyy-MM-DD HH:mm");
@@ -123,13 +123,13 @@ define(["require", "exports", "tslib", "moment", "lodash"], function (require, e
123
123
  return descriptions.join("");
124
124
  }
125
125
  else if (timestamp < minuteUnit) {
126
- descriptions.push(lodash_1.default.padStart(String(timestamp / seconds), 2, "0") + (chinese ? '秒' : ''));
126
+ descriptions.push(lodash_1.default.padStart((timestamp / seconds).toString(), 2, "0") + (chinese ? '秒' : ''));
127
127
  return descriptions.join("");
128
128
  }
129
129
  if (timestamp < hourUnit) {
130
- var minute = parseInt(String(timestamp / minuteUnit));
131
- descriptions.push(lodash_1.default.padStart(String(minute), 2, "0") + (chinese ? '分' : ':'));
132
- var nextTimestamp_1 = timestamp - parseInt(String(minute * minuteUnit));
130
+ var minute = parseInt((timestamp / minuteUnit).toString());
131
+ descriptions.push(lodash_1.default.padStart(minute.toString(), 2, "0") + (chinese ? '分' : ':'));
132
+ var nextTimestamp_1 = timestamp - parseInt((minute * minuteUnit).toString());
133
133
  if (nextTimestamp_1 === 0) {
134
134
  descriptions.push("00" + (chinese ? '秒' : ''));
135
135
  }
@@ -139,9 +139,9 @@ define(["require", "exports", "tslib", "moment", "lodash"], function (require, e
139
139
  return descriptions.join("");
140
140
  }
141
141
  if (timestamp < dayUnit) {
142
- var hour = parseInt(String(timestamp / hourUnit));
143
- descriptions.push(lodash_1.default.padStart(String(hour), 2, "0") + (chinese ? '时' : ':'));
144
- var nextTimestamp_2 = timestamp - parseInt(String(hour * hourUnit));
142
+ var hour = parseInt((timestamp / hourUnit).toString());
143
+ descriptions.push(lodash_1.default.padStart((hour).toString(), 2, "0") + (chinese ? '时' : ':'));
144
+ var nextTimestamp_2 = timestamp - parseInt((hour * hourUnit).toString());
145
145
  if (nextTimestamp_2 === 0) {
146
146
  descriptions.push("00" + (chinese ? '分' : ':'));
147
147
  descriptions.push("00" + (chinese ? '秒' : ''));
@@ -151,9 +151,9 @@ define(["require", "exports", "tslib", "moment", "lodash"], function (require, e
151
151
  }
152
152
  return descriptions.join("");
153
153
  }
154
- var day = parseInt(String(timestamp / dayUnit));
154
+ var day = parseInt((timestamp / dayUnit).toString());
155
155
  descriptions.push(day + (chinese ? '天' : 'day '));
156
- var nextTimestamp = timestamp - parseInt(String(day * dayUnit));
156
+ var nextTimestamp = timestamp - parseInt((day * dayUnit).toString());
157
157
  if (nextTimestamp === 0) {
158
158
  descriptions.push("00" + (chinese ? '时' : ':'));
159
159
  descriptions.push("00" + (chinese ? '分' : ':'));
@@ -0,0 +1,23 @@
1
+ /**
2
+ * 事件监听器
3
+ */
4
+ export declare class FastVueMultiEventBus {
5
+ private static getWatcherConfig;
6
+ private static getWatcherTimer;
7
+ private static setWatcherTimer;
8
+ private static stopWatcherTimer;
9
+ private static startTimer;
10
+ private static pushWatcher;
11
+ /**
12
+ * 启动一个事件监听器
13
+ * @param eventName 事件名称 string|array
14
+ * @param callback 事件触发的回调 function(eventName,eventParams){}
15
+ */
16
+ static on(eventName: any, callback: any): void;
17
+ /**
18
+ * 通知事件监听者
19
+ * @param eventName 事件名称 string|array
20
+ * @param eventParams 携带参数 any
21
+ */
22
+ static emit(eventName: any, eventParams?: any): void;
23
+ }
@@ -0,0 +1,122 @@
1
+ define(["require", "exports", "tslib", "lodash", "js-cookie"], function (require, exports, tslib_1, lodash_1, js_cookie_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.FastVueMultiEventBus = void 0;
5
+ lodash_1 = tslib_1.__importDefault(lodash_1);
6
+ js_cookie_1 = tslib_1.__importDefault(js_cookie_1);
7
+ /**
8
+ * 事件监听器
9
+ */
10
+ var FastVueMultiEventBus = /** @class */ (function () {
11
+ function FastVueMultiEventBus() {
12
+ }
13
+ FastVueMultiEventBus.getWatcherConfig = function () {
14
+ if (!window["__WATCHER_CONFIG"]) {
15
+ window["__WATCHER_CONFIG"] = {};
16
+ }
17
+ return window["__WATCHER_CONFIG"];
18
+ };
19
+ FastVueMultiEventBus.getWatcherTimer = function () {
20
+ return window["__WATCHER_TIMER"];
21
+ };
22
+ FastVueMultiEventBus.setWatcherTimer = function (timer) {
23
+ window["__WATCHER_TIMER"] = timer;
24
+ };
25
+ FastVueMultiEventBus.stopWatcherTimer = function () {
26
+ if (this.getWatcherTimer()) {
27
+ clearTimeout(this.getWatcherTimer());
28
+ }
29
+ };
30
+ FastVueMultiEventBus.startTimer = function () {
31
+ var _this = this;
32
+ this.stopWatcherTimer();
33
+ this.setWatcherTimer(setTimeout(function () {
34
+ for (var eventName in _this.getWatcherConfig()) {
35
+ var watchValue = js_cookie_1.default.get("EVENT@" + eventName);
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);
51
+ }
52
+ }
53
+ }
54
+ }
55
+ _this.startTimer();
56
+ }, 500));
57
+ };
58
+ FastVueMultiEventBus.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
+ };
73
+ /**
74
+ * 启动一个事件监听器
75
+ * @param eventName 事件名称 string|array
76
+ * @param callback 事件触发的回调 function(eventName,eventParams){}
77
+ */
78
+ FastVueMultiEventBus.on = function (eventName, callback) {
79
+ if (!callback || lodash_1.default.isEmpty(eventName)) {
80
+ //未携带回调函数的监听者,认为是无效监听
81
+ return;
82
+ }
83
+ if (lodash_1.default.isArray(eventName)) {
84
+ for (var _i = 0, eventName_1 = eventName; _i < eventName_1.length; _i++) {
85
+ var eventNameElement = eventName_1[_i];
86
+ this.pushWatcher(eventNameElement, callback);
87
+ }
88
+ }
89
+ else {
90
+ this.pushWatcher(eventName, callback);
91
+ }
92
+ this.startTimer();
93
+ };
94
+ /**
95
+ * 通知事件监听者
96
+ * @param eventName 事件名称 string|array
97
+ * @param eventParams 携带参数 any
98
+ */
99
+ FastVueMultiEventBus.emit = function (eventName, eventParams) {
100
+ if (lodash_1.default.isEmpty(eventName)) {
101
+ return;
102
+ }
103
+ if (lodash_1.default.isArray(eventName)) {
104
+ for (var _i = 0, eventName_2 = eventName; _i < eventName_2.length; _i++) {
105
+ var eventNameElement = eventName_2[_i];
106
+ js_cookie_1.default.set("EVENT@" + eventNameElement, (new Date().getTime()).toString());
107
+ if (eventParams) {
108
+ js_cookie_1.default.set("EVENT@PARMAS@" + eventNameElement, JSON.stringify(eventParams));
109
+ }
110
+ }
111
+ }
112
+ else {
113
+ js_cookie_1.default.set("EVENT@" + eventName, (new Date().getTime()).toString());
114
+ if (eventParams) {
115
+ js_cookie_1.default.set("EVENT@PARMAS@" + eventName, JSON.stringify(eventParams));
116
+ }
117
+ }
118
+ };
119
+ return FastVueMultiEventBus;
120
+ }());
121
+ exports.FastVueMultiEventBus = FastVueMultiEventBus;
122
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-vue-multi-pages",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "author": "janesen",
5
5
  "description": "快速搭建VUE项目工具类的基本库,主要用于每个功能页面独立生成html",
6
6
  "main": "./dist/cjs/index.js",