fast-vue-multi-pages 1.0.11 → 1.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -11,6 +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
15
  /**
15
16
  * FastBaseApp 手机APP功能工具类
16
17
  */
@@ -71,4 +72,8 @@ export declare class FastVueMultiTool {
71
72
  * base64相关操作
72
73
  */
73
74
  static Base64: typeof FastVueMultiBase64;
75
+ /**
76
+ * 监听者
77
+ */
78
+ static Watcher: typeof FastVueMultiWatcher;
74
79
  }
@@ -15,6 +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
19
  /**
19
20
  * FastBaseApp 手机APP功能工具类
20
21
  */
@@ -75,5 +76,9 @@ class FastVueMultiTool {
75
76
  * base64相关操作
76
77
  */
77
78
  static Base64 = FastVueMultiBase64_1.FastVueMultiBase64;
79
+ /**
80
+ * 监听者
81
+ */
82
+ static Watcher = FastVueMultiWatcher_1.FastVueMultiWatcher;
78
83
  }
79
84
  exports.FastVueMultiTool = FastVueMultiTool;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 事件监听器
3
+ */
4
+ export declare class FastVueMultiWatcher {
5
+ private static getWatcherConfig;
6
+ private static getWatcherTimer;
7
+ private static setWatcherTimer;
8
+ private static stopWatcherTimer;
9
+ private static startTimer;
10
+ /**
11
+ * 启动一个事件监听器
12
+ * @param eventName 事件名称 string|array
13
+ * @param callback 事件触发的回调 function(eventName,eventParams){}
14
+ */
15
+ static startWatcher(eventName: any, callback: any): void;
16
+ /**
17
+ * 通知事件监听者
18
+ * @param eventName 事件名称 string|array
19
+ * @param eventParams 携带参数 any
20
+ */
21
+ static notifyWatcher(eventName: any, eventParams?: any): void;
22
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FastVueMultiWatcher = 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 FastVueMultiWatcher {
11
+ static getWatcherConfig() {
12
+ if (!window["__watcherConfig"]) {
13
+ window["__watcherConfig"] = {};
14
+ }
15
+ return window["__watcherConfig"];
16
+ }
17
+ static getWatcherTimer() {
18
+ return window["__watcherTimer"];
19
+ }
20
+ static setWatcherTimer(timer) {
21
+ window["__watcherTimer"] = 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 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);
43
+ }
44
+ config.timestamp = timestamp;
45
+ config.callback(eventName, params);
46
+ }
47
+ }
48
+ }
49
+ this.startTimer();
50
+ }, 500));
51
+ }
52
+ /**
53
+ * 启动一个事件监听器
54
+ * @param eventName 事件名称 string|array
55
+ * @param callback 事件触发的回调 function(eventName,eventParams){}
56
+ */
57
+ static startWatcher(eventName, callback) {
58
+ if (!window["__watchCookieTimestamp"]) {
59
+ window["__watchCookieTimestamp"] = {};
60
+ }
61
+ if (!callback || lodash_1.default.isEmpty(eventName)) {
62
+ //未携带回调函数的监听者,认为是无效监听
63
+ return;
64
+ }
65
+ 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
+ };
71
+ }
72
+ }
73
+ else {
74
+ this.getWatcherConfig()[eventName] = {
75
+ timestamp: new Date().getTime(),
76
+ callback: callback,
77
+ };
78
+ }
79
+ this.startTimer();
80
+ }
81
+ /**
82
+ * 通知事件监听者
83
+ * @param eventName 事件名称 string|array
84
+ * @param eventParams 携带参数 any
85
+ */
86
+ static notifyWatcher(eventName, eventParams) {
87
+ if (lodash_1.default.isEmpty(eventName)) {
88
+ return;
89
+ }
90
+ if (lodash_1.default.isArray(eventName)) {
91
+ for (let cookieNameElement of eventName) {
92
+ js_cookie_1.default.set("EVENT@" + cookieNameElement, (new Date().getTime()).toString());
93
+ if (eventParams) {
94
+ js_cookie_1.default.set("EVENT@PARMAS@" + cookieNameElement, JSON.stringify(eventParams));
95
+ }
96
+ }
97
+ }
98
+ else {
99
+ js_cookie_1.default.set("EVENT@" + eventName, (new Date().getTime()).toString());
100
+ if (eventParams) {
101
+ js_cookie_1.default.set("EVENT@PARMAS@" + eventName, JSON.stringify(eventParams));
102
+ }
103
+ }
104
+ }
105
+ }
106
+ exports.FastVueMultiWatcher = FastVueMultiWatcher;
@@ -11,6 +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
15
  /**
15
16
  * FastBaseApp 手机APP功能工具类
16
17
  */
@@ -71,4 +72,8 @@ export declare class FastVueMultiTool {
71
72
  * base64相关操作
72
73
  */
73
74
  static Base64: typeof FastVueMultiBase64;
75
+ /**
76
+ * 监听者
77
+ */
78
+ static Watcher: typeof FastVueMultiWatcher;
74
79
  }
@@ -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"], 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) {
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) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.FastVueMultiTool = void 0;
@@ -65,6 +65,10 @@ define(["require", "exports", "tslib", "lodash", "./http/FastVueMultiHttp", "./o
65
65
  * base64相关操作
66
66
  */
67
67
  FastVueMultiTool.Base64 = FastVueMultiBase64_1.FastVueMultiBase64;
68
+ /**
69
+ * 监听者
70
+ */
71
+ FastVueMultiTool.Watcher = FastVueMultiWatcher_1.FastVueMultiWatcher;
68
72
  return FastVueMultiTool;
69
73
  }());
70
74
  exports.FastVueMultiTool = FastVueMultiTool;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 事件监听器
3
+ */
4
+ export declare class FastVueMultiWatcher {
5
+ private static getWatcherConfig;
6
+ private static getWatcherTimer;
7
+ private static setWatcherTimer;
8
+ private static stopWatcherTimer;
9
+ private static startTimer;
10
+ /**
11
+ * 启动一个事件监听器
12
+ * @param eventName 事件名称 string|array
13
+ * @param callback 事件触发的回调 function(eventName,eventParams){}
14
+ */
15
+ static startWatcher(eventName: any, callback: any): void;
16
+ /**
17
+ * 通知事件监听者
18
+ * @param eventName 事件名称 string|array
19
+ * @param eventParams 携带参数 any
20
+ */
21
+ static notifyWatcher(eventName: any, eventParams?: any): void;
22
+ }
@@ -0,0 +1,113 @@
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.FastVueMultiWatcher = 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 FastVueMultiWatcher = /** @class */ (function () {
11
+ function FastVueMultiWatcher() {
12
+ }
13
+ FastVueMultiWatcher.getWatcherConfig = function () {
14
+ if (!window["__watcherConfig"]) {
15
+ window["__watcherConfig"] = {};
16
+ }
17
+ return window["__watcherConfig"];
18
+ };
19
+ FastVueMultiWatcher.getWatcherTimer = function () {
20
+ return window["__watcherTimer"];
21
+ };
22
+ FastVueMultiWatcher.setWatcherTimer = function (timer) {
23
+ window["__watcherTimer"] = timer;
24
+ };
25
+ FastVueMultiWatcher.stopWatcherTimer = function () {
26
+ if (this.getWatcherTimer()) {
27
+ clearTimeout(this.getWatcherTimer());
28
+ }
29
+ };
30
+ FastVueMultiWatcher.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 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);
46
+ }
47
+ config.timestamp = timestamp;
48
+ config.callback(eventName, params);
49
+ }
50
+ }
51
+ }
52
+ _this.startTimer();
53
+ }, 500));
54
+ };
55
+ /**
56
+ * 启动一个事件监听器
57
+ * @param eventName 事件名称 string|array
58
+ * @param callback 事件触发的回调 function(eventName,eventParams){}
59
+ */
60
+ FastVueMultiWatcher.startWatcher = function (eventName, callback) {
61
+ if (!window["__watchCookieTimestamp"]) {
62
+ window["__watchCookieTimestamp"] = {};
63
+ }
64
+ if (!callback || lodash_1.default.isEmpty(eventName)) {
65
+ //未携带回调函数的监听者,认为是无效监听
66
+ return;
67
+ }
68
+ if (lodash_1.default.isArray(eventName)) {
69
+ 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
+ };
75
+ }
76
+ }
77
+ else {
78
+ this.getWatcherConfig()[eventName] = {
79
+ timestamp: new Date().getTime(),
80
+ callback: callback,
81
+ };
82
+ }
83
+ this.startTimer();
84
+ };
85
+ /**
86
+ * 通知事件监听者
87
+ * @param eventName 事件名称 string|array
88
+ * @param eventParams 携带参数 any
89
+ */
90
+ FastVueMultiWatcher.notifyWatcher = function (eventName, eventParams) {
91
+ if (lodash_1.default.isEmpty(eventName)) {
92
+ return;
93
+ }
94
+ if (lodash_1.default.isArray(eventName)) {
95
+ 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());
98
+ if (eventParams) {
99
+ js_cookie_1.default.set("EVENT@PARMAS@" + cookieNameElement, JSON.stringify(eventParams));
100
+ }
101
+ }
102
+ }
103
+ else {
104
+ js_cookie_1.default.set("EVENT@" + eventName, (new Date().getTime()).toString());
105
+ if (eventParams) {
106
+ js_cookie_1.default.set("EVENT@PARMAS@" + eventName, JSON.stringify(eventParams));
107
+ }
108
+ }
109
+ };
110
+ return FastVueMultiWatcher;
111
+ }());
112
+ exports.FastVueMultiWatcher = FastVueMultiWatcher;
113
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-vue-multi-pages",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "author": "janesen",
5
5
  "description": "快速搭建VUE项目工具类的基本库,主要用于每个功能页面独立生成html",
6
6
  "main": "./dist/cjs/index.js",