fast-vue-multi-pages 1.0.30 → 1.1.1

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.
@@ -15,6 +15,7 @@ import { FastVueMultiEventBus } from "./other/FastVueMultiEventBus";
15
15
  import { FastVueMultiObject } from "./other/FastVueMultiObject";
16
16
  import { FastVueMultiUUID } from "./other/FastVueMultiUUID";
17
17
  import { FastVueMultiAnimate } from "./other/FastVueMultiAnimate";
18
+ import moment from "moment";
18
19
  /**
19
20
  * FastVueMultiTool 工具类
20
21
  */
@@ -99,4 +100,8 @@ export declare class FastVueMultiTool {
99
100
  * 数值动画类
100
101
  */
101
102
  static Animate: typeof FastVueMultiAnimate;
103
+ /**
104
+ * moment工具类 http://momentjs.com/
105
+ */
106
+ static Moment: typeof moment;
102
107
  }
@@ -19,6 +19,7 @@ const FastVueMultiEventBus_1 = require("./other/FastVueMultiEventBus");
19
19
  const FastVueMultiObject_1 = require("./other/FastVueMultiObject");
20
20
  const FastVueMultiUUID_1 = require("./other/FastVueMultiUUID");
21
21
  const FastVueMultiAnimate_1 = require("./other/FastVueMultiAnimate");
22
+ const moment_1 = tslib_1.__importDefault(require("moment"));
22
23
  /**
23
24
  * FastVueMultiTool 工具类
24
25
  */
@@ -103,5 +104,9 @@ class FastVueMultiTool {
103
104
  * 数值动画类
104
105
  */
105
106
  static Animate = FastVueMultiAnimate_1.FastVueMultiAnimate;
107
+ /**
108
+ * moment工具类 http://momentjs.com/
109
+ */
110
+ static Moment = moment_1.default;
106
111
  }
107
112
  exports.FastVueMultiTool = FastVueMultiTool;
@@ -1,4 +1,5 @@
1
1
  import { FastVueMultiTool } from "./FastVueMultiTool";
2
2
  import { FastVueMultiSimpleJsonResponse } from "./http/FastVueMultiSimpleJsonResponse";
3
3
  import { FastVueMultiSimpleRequestConfig } from "./http/FastVueMultiSimpleRequestConfig";
4
- export { FastVueMultiTool, FastVueMultiSimpleJsonResponse, FastVueMultiSimpleRequestConfig };
4
+ import { FastVueNative } from "./native/FastVueNative";
5
+ export { FastVueNative, FastVueMultiTool, FastVueMultiSimpleJsonResponse, FastVueMultiSimpleRequestConfig };
package/dist/cjs/index.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FastVueMultiSimpleRequestConfig = exports.FastVueMultiSimpleJsonResponse = exports.FastVueMultiTool = void 0;
3
+ exports.FastVueMultiSimpleRequestConfig = exports.FastVueMultiSimpleJsonResponse = exports.FastVueMultiTool = exports.FastVueNative = void 0;
4
4
  const FastVueMultiTool_1 = require("./FastVueMultiTool");
5
5
  Object.defineProperty(exports, "FastVueMultiTool", { enumerable: true, get: function () { return FastVueMultiTool_1.FastVueMultiTool; } });
6
6
  const FastVueMultiSimpleJsonResponse_1 = require("./http/FastVueMultiSimpleJsonResponse");
7
7
  Object.defineProperty(exports, "FastVueMultiSimpleJsonResponse", { enumerable: true, get: function () { return FastVueMultiSimpleJsonResponse_1.FastVueMultiSimpleJsonResponse; } });
8
8
  const FastVueMultiSimpleRequestConfig_1 = require("./http/FastVueMultiSimpleRequestConfig");
9
9
  Object.defineProperty(exports, "FastVueMultiSimpleRequestConfig", { enumerable: true, get: function () { return FastVueMultiSimpleRequestConfig_1.FastVueMultiSimpleRequestConfig; } });
10
+ const FastVueNative_1 = require("./native/FastVueNative");
11
+ Object.defineProperty(exports, "FastVueNative", { enumerable: true, get: function () { return FastVueNative_1.FastVueNative; } });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * FastNative 调用Android或IOS原生方法工具
3
+ * @author Janesen
4
+ */
5
+ /**
6
+ * 执行本地方法核心类
7
+ */
8
+ export declare class FastVueNative {
9
+ private static methodInfos;
10
+ private static getKey;
11
+ private static showError;
12
+ /**
13
+ * 注册js函数到window对象中,以供客户端调用
14
+ * @private
15
+ */
16
+ private static injectAppJsForNativeCall;
17
+ /**
18
+ * 是否是安卓客户端
19
+ */
20
+ static isAndroid(): boolean;
21
+ /**
22
+ * 是否是ios客户端
23
+ */
24
+ static isIOS(): boolean;
25
+ /**
26
+ * 执行手机客户端原生方法
27
+ * @param methodName 方法名称
28
+ * @param methodParams 方法参数,Array格式,按照原生方法的参数顺序设置
29
+ * @param callBack 回调函数
30
+ */
31
+ static execute(methodName: string, methodParams: any, callBack?: (result: {
32
+ success: boolean;
33
+ message: string;
34
+ data: any;
35
+ }) => void): void;
36
+ /**
37
+ * 手机原生方法回执时调用
38
+ * @param key 回调函数的唯一标识
39
+ * @param result 回调结果
40
+ */
41
+ static appCallBack(key: string, result: string): void;
42
+ /**
43
+ * 递归执行回调,针对同一个浏览器下嵌入iframe问题
44
+ * @param targetWindow 目标window
45
+ * @param key
46
+ * @param result
47
+ * @private
48
+ */
49
+ private static doAppCallBack;
50
+ /**
51
+ * 手机原生方法回执时调用
52
+ * @param key 回调函数的唯一标识
53
+ * @param result 回调结果
54
+ */
55
+ private static executeAppCallBack;
56
+ /**
57
+ * 手机原生方法执行错误时调用
58
+ * @param message 错误信息
59
+ */
60
+ private static error;
61
+ /**
62
+ * 可同步或异步执行手机客户端原生方法
63
+ * @param methodName 方法名称
64
+ * @param methodParams 方法参数,Array格式,按照原生方法的参数顺序设置
65
+ * @param callBack 回调函数
66
+ */
67
+ static executeByPromise(methodName: string, methodParams: any, callBack?: (result: {
68
+ success: boolean;
69
+ message: string;
70
+ data?: any;
71
+ }) => void): Promise<{
72
+ success: boolean;
73
+ message: string;
74
+ data: any;
75
+ }>;
76
+ }
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FastVueNative = void 0;
4
+ const FastVueMultiObject_1 = require("../other/FastVueMultiObject");
5
+ const FastVueMultiBoolean_1 = require("../other/FastVueMultiBoolean");
6
+ /**
7
+ * FastNative 调用Android或IOS原生方法工具
8
+ * @author Janesen
9
+ */
10
+ /**
11
+ * 执行本地方法核心类
12
+ */
13
+ class FastVueNative {
14
+ static methodInfos = {};
15
+ static getKey() {
16
+ let d = new Date().getTime();
17
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
18
+ let r = (d + Math.random() * 16) % 16 | 0;
19
+ d = Math.floor(d / 16);
20
+ return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
21
+ });
22
+ }
23
+ static showError(message) {
24
+ alert("FastAppJs发生错误:" + message);
25
+ }
26
+ /**
27
+ * 注册js函数到window对象中,以供客户端调用
28
+ * @private
29
+ */
30
+ static injectAppJsForNativeCall() {
31
+ if (!(window["appJs"])) {
32
+ window["appJs"] = FastVueNative;
33
+ }
34
+ }
35
+ /**
36
+ * 是否是安卓客户端
37
+ */
38
+ static isAndroid() {
39
+ return navigator.userAgent.toLowerCase().indexOf('android') > -1;
40
+ }
41
+ /**
42
+ * 是否是ios客户端
43
+ */
44
+ static isIOS() {
45
+ return navigator.userAgent.toLowerCase().indexOf('iphone') > -1;
46
+ }
47
+ /**
48
+ * 执行手机客户端原生方法
49
+ * @param methodName 方法名称
50
+ * @param methodParams 方法参数,Array格式,按照原生方法的参数顺序设置
51
+ * @param callBack 回调函数
52
+ */
53
+ static execute(methodName, methodParams, callBack) {
54
+ this.injectAppJsForNativeCall();
55
+ const Base64 = require("js-base64");
56
+ const key = this.getKey();
57
+ try {
58
+ if (methodParams == null) {
59
+ methodParams = [];
60
+ }
61
+ if (callBack == null) {
62
+ callBack = function (result) { };
63
+ }
64
+ this.methodInfos[key] = { methodName: methodName, methodParams: methodParams, callBack: callBack };
65
+ methodParams.unshift(key);
66
+ methodParams.forEach(function (value, index) {
67
+ if (value == null) {
68
+ methodParams[index] = "";
69
+ return true;
70
+ }
71
+ if (!(value instanceof Array)) {
72
+ methodParams[index] = value.toString();
73
+ }
74
+ });
75
+ if (this.isAndroid()) {
76
+ if (window["app"] && window["app"].doJavaScript && typeof (window["app"]).doJavaScript === 'function') {
77
+ window["app"].doJavaScript(methodName, Base64.encode(JSON.stringify(methodParams)));
78
+ }
79
+ else {
80
+ this.executeAppCallBack(key, Base64.encode(JSON.stringify({
81
+ success: false,
82
+ message: "客户端WebView不支持调用原生功能!",
83
+ data: null
84
+ })));
85
+ }
86
+ }
87
+ else if (this.isIOS()) {
88
+ let message = 'window.app.doJavaScript(' + methodName + ',' + Base64.encode(JSON.stringify(methodParams)) + ')';
89
+ alert(message); // IOS 使用alert触发程序中的事件,并过滤执行到客户端上的方法
90
+ }
91
+ else {
92
+ this.executeAppCallBack(key, Base64.encode(JSON.stringify({
93
+ success: false,
94
+ message: "客户端WebView不支持调用原生功能!",
95
+ data: null
96
+ })));
97
+ }
98
+ }
99
+ catch (e) {
100
+ console.error(e);
101
+ this.executeAppCallBack(key, Base64.encode(JSON.stringify({
102
+ success: false,
103
+ message: FastVueMultiObject_1.FastVueMultiObject.geErrorInfo(e),
104
+ data: null
105
+ })));
106
+ }
107
+ }
108
+ /**
109
+ * 手机原生方法回执时调用
110
+ * @param key 回调函数的唯一标识
111
+ * @param result 回调结果
112
+ */
113
+ static appCallBack(key, result) {
114
+ this.doAppCallBack(window, key, result);
115
+ }
116
+ /**
117
+ * 递归执行回调,针对同一个浏览器下嵌入iframe问题
118
+ * @param targetWindow 目标window
119
+ * @param key
120
+ * @param result
121
+ * @private
122
+ */
123
+ static doAppCallBack(targetWindow, key, result) {
124
+ if (targetWindow["appJs"]) {
125
+ targetWindow["appJs"].executeAppCallBack(key, result);
126
+ }
127
+ for (let i = 0; i < targetWindow.length; i++) {
128
+ this.doAppCallBack(targetWindow[i], key, result);
129
+ }
130
+ }
131
+ /**
132
+ * 手机原生方法回执时调用
133
+ * @param key 回调函数的唯一标识
134
+ * @param result 回调结果
135
+ */
136
+ static executeAppCallBack(key, result) {
137
+ let methodInfo = this.methodInfos[key.toString()];
138
+ if (methodInfo) {
139
+ const Base64 = require("js-base64");
140
+ result = Base64.decode(result);
141
+ const jsonData = JSON.parse(result);
142
+ try {
143
+ jsonData.success = FastVueMultiBoolean_1.FastVueMultiBoolean.parse(jsonData.success);
144
+ jsonData.data = jsonData.result;
145
+ if (methodInfo.callBack && typeof methodInfo.callBack === 'function') {
146
+ methodInfo.callBack(jsonData);
147
+ }
148
+ }
149
+ catch (e) {
150
+ console.error(e);
151
+ if (methodInfo.callBack && typeof methodInfo.callBack === 'function') {
152
+ methodInfo.callBack({ success: false, message: e.message, data: null });
153
+ }
154
+ }
155
+ finally {
156
+ console.info("执行原生方法:", methodInfo.methodName, "方法参数:", methodInfo.methodParams, "执行结果:", jsonData);
157
+ }
158
+ }
159
+ }
160
+ /**
161
+ * 手机原生方法执行错误时调用
162
+ * @param message 错误信息
163
+ */
164
+ static error(message) {
165
+ alert('手机原生端发生错误:' + message);
166
+ }
167
+ /**
168
+ * 可同步或异步执行手机客户端原生方法
169
+ * @param methodName 方法名称
170
+ * @param methodParams 方法参数,Array格式,按照原生方法的参数顺序设置
171
+ * @param callBack 回调函数
172
+ */
173
+ static async executeByPromise(methodName, methodParams, callBack) {
174
+ return new Promise(function (resolved, rejected) {
175
+ FastVueNative.execute(methodName, methodParams, function (result) {
176
+ if (callBack) {
177
+ callBack(result);
178
+ }
179
+ resolved(result);
180
+ });
181
+ });
182
+ }
183
+ }
184
+ exports.FastVueNative = FastVueNative;
@@ -9,4 +9,9 @@ export declare class FastVueMultiObject {
9
9
  * @param value
10
10
  */
11
11
  static isValid(value: any): boolean;
12
+ /**
13
+ * 获取异常信息的堆栈信息
14
+ * @param event
15
+ */
16
+ static geErrorInfo(event: any): string;
12
17
  }
@@ -39,5 +39,27 @@ class FastVueMultiObject {
39
39
  }
40
40
  return true;
41
41
  }
42
+ /**
43
+ * 获取异常信息的堆栈信息
44
+ * @param event
45
+ */
46
+ static geErrorInfo(event) {
47
+ if (event) {
48
+ if (event.error && event.error.stack) {
49
+ return event.error.stack;
50
+ }
51
+ else if (event.stack) {
52
+ return event.stack;
53
+ }
54
+ else if (event.message) {
55
+ return event.message;
56
+ }
57
+ else if (event.reason) {
58
+ return event.reason;
59
+ }
60
+ return event.toString();
61
+ }
62
+ return "";
63
+ }
42
64
  }
43
65
  exports.FastVueMultiObject = FastVueMultiObject;
@@ -15,6 +15,7 @@ import { FastVueMultiEventBus } from "./other/FastVueMultiEventBus";
15
15
  import { FastVueMultiObject } from "./other/FastVueMultiObject";
16
16
  import { FastVueMultiUUID } from "./other/FastVueMultiUUID";
17
17
  import { FastVueMultiAnimate } from "./other/FastVueMultiAnimate";
18
+ import moment from "moment";
18
19
  /**
19
20
  * FastVueMultiTool 工具类
20
21
  */
@@ -99,4 +100,8 @@ export declare class FastVueMultiTool {
99
100
  * 数值动画类
100
101
  */
101
102
  static Animate: typeof FastVueMultiAnimate;
103
+ /**
104
+ * moment工具类 http://momentjs.com/
105
+ */
106
+ static Moment: typeof moment;
102
107
  }
@@ -1,8 +1,9 @@
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", "./other/FastVueMultiObject", "./other/FastVueMultiUUID", "./other/FastVueMultiAnimate"], 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, FastVueMultiObject_1, FastVueMultiUUID_1, FastVueMultiAnimate_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", "./other/FastVueMultiObject", "./other/FastVueMultiUUID", "./other/FastVueMultiAnimate", "moment"], 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, FastVueMultiObject_1, FastVueMultiUUID_1, FastVueMultiAnimate_1, moment_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.FastVueMultiTool = void 0;
5
5
  lodash_1 = tslib_1.__importDefault(lodash_1);
6
+ moment_1 = tslib_1.__importDefault(moment_1);
6
7
  /**
7
8
  * FastVueMultiTool 工具类
8
9
  */
@@ -89,6 +90,10 @@ define(["require", "exports", "tslib", "lodash", "./http/FastVueMultiHttp", "./o
89
90
  * 数值动画类
90
91
  */
91
92
  FastVueMultiTool.Animate = FastVueMultiAnimate_1.FastVueMultiAnimate;
93
+ /**
94
+ * moment工具类 http://momentjs.com/
95
+ */
96
+ FastVueMultiTool.Moment = moment_1.default;
92
97
  return FastVueMultiTool;
93
98
  }());
94
99
  exports.FastVueMultiTool = FastVueMultiTool;
@@ -1,4 +1,5 @@
1
1
  import { FastVueMultiTool } from "./FastVueMultiTool";
2
2
  import { FastVueMultiSimpleJsonResponse } from "./http/FastVueMultiSimpleJsonResponse";
3
3
  import { FastVueMultiSimpleRequestConfig } from "./http/FastVueMultiSimpleRequestConfig";
4
- export { FastVueMultiTool, FastVueMultiSimpleJsonResponse, FastVueMultiSimpleRequestConfig };
4
+ import { FastVueNative } from "./native/FastVueNative";
5
+ export { FastVueNative, FastVueMultiTool, FastVueMultiSimpleJsonResponse, FastVueMultiSimpleRequestConfig };
package/dist/esm/index.js CHANGED
@@ -1,8 +1,9 @@
1
- define(["require", "exports", "./FastVueMultiTool", "./http/FastVueMultiSimpleJsonResponse", "./http/FastVueMultiSimpleRequestConfig"], function (require, exports, FastVueMultiTool_1, FastVueMultiSimpleJsonResponse_1, FastVueMultiSimpleRequestConfig_1) {
1
+ define(["require", "exports", "./FastVueMultiTool", "./http/FastVueMultiSimpleJsonResponse", "./http/FastVueMultiSimpleRequestConfig", "./native/FastVueNative"], function (require, exports, FastVueMultiTool_1, FastVueMultiSimpleJsonResponse_1, FastVueMultiSimpleRequestConfig_1, FastVueNative_1) {
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.FastVueMultiSimpleRequestConfig = exports.FastVueMultiSimpleJsonResponse = exports.FastVueMultiTool = void 0;
4
+ exports.FastVueMultiSimpleRequestConfig = exports.FastVueMultiSimpleJsonResponse = exports.FastVueMultiTool = exports.FastVueNative = void 0;
5
5
  Object.defineProperty(exports, "FastVueMultiTool", { enumerable: true, get: function () { return FastVueMultiTool_1.FastVueMultiTool; } });
6
6
  Object.defineProperty(exports, "FastVueMultiSimpleJsonResponse", { enumerable: true, get: function () { return FastVueMultiSimpleJsonResponse_1.FastVueMultiSimpleJsonResponse; } });
7
7
  Object.defineProperty(exports, "FastVueMultiSimpleRequestConfig", { enumerable: true, get: function () { return FastVueMultiSimpleRequestConfig_1.FastVueMultiSimpleRequestConfig; } });
8
+ Object.defineProperty(exports, "FastVueNative", { enumerable: true, get: function () { return FastVueNative_1.FastVueNative; } });
8
9
  });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * FastNative 调用Android或IOS原生方法工具
3
+ * @author Janesen
4
+ */
5
+ /**
6
+ * 执行本地方法核心类
7
+ */
8
+ export declare class FastVueNative {
9
+ private static methodInfos;
10
+ private static getKey;
11
+ private static showError;
12
+ /**
13
+ * 注册js函数到window对象中,以供客户端调用
14
+ * @private
15
+ */
16
+ private static injectAppJsForNativeCall;
17
+ /**
18
+ * 是否是安卓客户端
19
+ */
20
+ static isAndroid(): boolean;
21
+ /**
22
+ * 是否是ios客户端
23
+ */
24
+ static isIOS(): boolean;
25
+ /**
26
+ * 执行手机客户端原生方法
27
+ * @param methodName 方法名称
28
+ * @param methodParams 方法参数,Array格式,按照原生方法的参数顺序设置
29
+ * @param callBack 回调函数
30
+ */
31
+ static execute(methodName: string, methodParams: any, callBack?: (result: {
32
+ success: boolean;
33
+ message: string;
34
+ data: any;
35
+ }) => void): void;
36
+ /**
37
+ * 手机原生方法回执时调用
38
+ * @param key 回调函数的唯一标识
39
+ * @param result 回调结果
40
+ */
41
+ static appCallBack(key: string, result: string): void;
42
+ /**
43
+ * 递归执行回调,针对同一个浏览器下嵌入iframe问题
44
+ * @param targetWindow 目标window
45
+ * @param key
46
+ * @param result
47
+ * @private
48
+ */
49
+ private static doAppCallBack;
50
+ /**
51
+ * 手机原生方法回执时调用
52
+ * @param key 回调函数的唯一标识
53
+ * @param result 回调结果
54
+ */
55
+ private static executeAppCallBack;
56
+ /**
57
+ * 手机原生方法执行错误时调用
58
+ * @param message 错误信息
59
+ */
60
+ private static error;
61
+ /**
62
+ * 可同步或异步执行手机客户端原生方法
63
+ * @param methodName 方法名称
64
+ * @param methodParams 方法参数,Array格式,按照原生方法的参数顺序设置
65
+ * @param callBack 回调函数
66
+ */
67
+ static executeByPromise(methodName: string, methodParams: any, callBack?: (result: {
68
+ success: boolean;
69
+ message: string;
70
+ data?: any;
71
+ }) => void): Promise<{
72
+ success: boolean;
73
+ message: string;
74
+ data: any;
75
+ }>;
76
+ }
@@ -0,0 +1,191 @@
1
+ define(["require", "exports", "tslib", "../other/FastVueMultiObject", "../other/FastVueMultiBoolean"], function (require, exports, tslib_1, FastVueMultiObject_1, FastVueMultiBoolean_1) {
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.FastVueNative = void 0;
5
+ /**
6
+ * FastNative 调用Android或IOS原生方法工具
7
+ * @author Janesen
8
+ */
9
+ /**
10
+ * 执行本地方法核心类
11
+ */
12
+ var FastVueNative = /** @class */ (function () {
13
+ function FastVueNative() {
14
+ }
15
+ FastVueNative.getKey = function () {
16
+ var d = new Date().getTime();
17
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
18
+ var r = (d + Math.random() * 16) % 16 | 0;
19
+ d = Math.floor(d / 16);
20
+ return (c == 'x' ? r : (r & 0x3 | 0x8)).toString(16);
21
+ });
22
+ };
23
+ FastVueNative.showError = function (message) {
24
+ alert("FastAppJs发生错误:" + message);
25
+ };
26
+ /**
27
+ * 注册js函数到window对象中,以供客户端调用
28
+ * @private
29
+ */
30
+ FastVueNative.injectAppJsForNativeCall = function () {
31
+ if (!(window["appJs"])) {
32
+ window["appJs"] = FastVueNative;
33
+ }
34
+ };
35
+ /**
36
+ * 是否是安卓客户端
37
+ */
38
+ FastVueNative.isAndroid = function () {
39
+ return navigator.userAgent.toLowerCase().indexOf('android') > -1;
40
+ };
41
+ /**
42
+ * 是否是ios客户端
43
+ */
44
+ FastVueNative.isIOS = function () {
45
+ return navigator.userAgent.toLowerCase().indexOf('iphone') > -1;
46
+ };
47
+ /**
48
+ * 执行手机客户端原生方法
49
+ * @param methodName 方法名称
50
+ * @param methodParams 方法参数,Array格式,按照原生方法的参数顺序设置
51
+ * @param callBack 回调函数
52
+ */
53
+ FastVueNative.execute = function (methodName, methodParams, callBack) {
54
+ this.injectAppJsForNativeCall();
55
+ var Base64 = require("js-base64");
56
+ var key = this.getKey();
57
+ try {
58
+ if (methodParams == null) {
59
+ methodParams = [];
60
+ }
61
+ if (callBack == null) {
62
+ callBack = function (result) { };
63
+ }
64
+ this.methodInfos[key] = { methodName: methodName, methodParams: methodParams, callBack: callBack };
65
+ methodParams.unshift(key);
66
+ methodParams.forEach(function (value, index) {
67
+ if (value == null) {
68
+ methodParams[index] = "";
69
+ return true;
70
+ }
71
+ if (!(value instanceof Array)) {
72
+ methodParams[index] = value.toString();
73
+ }
74
+ });
75
+ if (this.isAndroid()) {
76
+ if (window["app"] && window["app"].doJavaScript && typeof (window["app"]).doJavaScript === 'function') {
77
+ window["app"].doJavaScript(methodName, Base64.encode(JSON.stringify(methodParams)));
78
+ }
79
+ else {
80
+ this.executeAppCallBack(key, Base64.encode(JSON.stringify({
81
+ success: false,
82
+ message: "客户端WebView不支持调用原生功能!",
83
+ data: null
84
+ })));
85
+ }
86
+ }
87
+ else if (this.isIOS()) {
88
+ var message = 'window.app.doJavaScript(' + methodName + ',' + Base64.encode(JSON.stringify(methodParams)) + ')';
89
+ alert(message); // IOS 使用alert触发程序中的事件,并过滤执行到客户端上的方法
90
+ }
91
+ else {
92
+ this.executeAppCallBack(key, Base64.encode(JSON.stringify({
93
+ success: false,
94
+ message: "客户端WebView不支持调用原生功能!",
95
+ data: null
96
+ })));
97
+ }
98
+ }
99
+ catch (e) {
100
+ console.error(e);
101
+ this.executeAppCallBack(key, Base64.encode(JSON.stringify({
102
+ success: false,
103
+ message: FastVueMultiObject_1.FastVueMultiObject.geErrorInfo(e),
104
+ data: null
105
+ })));
106
+ }
107
+ };
108
+ /**
109
+ * 手机原生方法回执时调用
110
+ * @param key 回调函数的唯一标识
111
+ * @param result 回调结果
112
+ */
113
+ FastVueNative.appCallBack = function (key, result) {
114
+ this.doAppCallBack(window, key, result);
115
+ };
116
+ /**
117
+ * 递归执行回调,针对同一个浏览器下嵌入iframe问题
118
+ * @param targetWindow 目标window
119
+ * @param key
120
+ * @param result
121
+ * @private
122
+ */
123
+ FastVueNative.doAppCallBack = function (targetWindow, key, result) {
124
+ if (targetWindow["appJs"]) {
125
+ targetWindow["appJs"].executeAppCallBack(key, result);
126
+ }
127
+ for (var i = 0; i < targetWindow.length; i++) {
128
+ this.doAppCallBack(targetWindow[i], key, result);
129
+ }
130
+ };
131
+ /**
132
+ * 手机原生方法回执时调用
133
+ * @param key 回调函数的唯一标识
134
+ * @param result 回调结果
135
+ */
136
+ FastVueNative.executeAppCallBack = function (key, result) {
137
+ var methodInfo = this.methodInfos[key.toString()];
138
+ if (methodInfo) {
139
+ var Base64 = require("js-base64");
140
+ result = Base64.decode(result);
141
+ var jsonData = JSON.parse(result);
142
+ try {
143
+ jsonData.success = FastVueMultiBoolean_1.FastVueMultiBoolean.parse(jsonData.success);
144
+ jsonData.data = jsonData.result;
145
+ if (methodInfo.callBack && typeof methodInfo.callBack === 'function') {
146
+ methodInfo.callBack(jsonData);
147
+ }
148
+ }
149
+ catch (e) {
150
+ console.error(e);
151
+ if (methodInfo.callBack && typeof methodInfo.callBack === 'function') {
152
+ methodInfo.callBack({ success: false, message: e.message, data: null });
153
+ }
154
+ }
155
+ finally {
156
+ console.info("执行原生方法:", methodInfo.methodName, "方法参数:", methodInfo.methodParams, "执行结果:", jsonData);
157
+ }
158
+ }
159
+ };
160
+ /**
161
+ * 手机原生方法执行错误时调用
162
+ * @param message 错误信息
163
+ */
164
+ FastVueNative.error = function (message) {
165
+ alert('手机原生端发生错误:' + message);
166
+ };
167
+ /**
168
+ * 可同步或异步执行手机客户端原生方法
169
+ * @param methodName 方法名称
170
+ * @param methodParams 方法参数,Array格式,按照原生方法的参数顺序设置
171
+ * @param callBack 回调函数
172
+ */
173
+ FastVueNative.executeByPromise = function (methodName, methodParams, callBack) {
174
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
175
+ return tslib_1.__generator(this, function (_a) {
176
+ return [2 /*return*/, new Promise(function (resolved, rejected) {
177
+ FastVueNative.execute(methodName, methodParams, function (result) {
178
+ if (callBack) {
179
+ callBack(result);
180
+ }
181
+ resolved(result);
182
+ });
183
+ })];
184
+ });
185
+ });
186
+ };
187
+ FastVueNative.methodInfos = {};
188
+ return FastVueNative;
189
+ }());
190
+ exports.FastVueNative = FastVueNative;
191
+ });
@@ -9,4 +9,9 @@ export declare class FastVueMultiObject {
9
9
  * @param value
10
10
  */
11
11
  static isValid(value: any): boolean;
12
+ /**
13
+ * 获取异常信息的堆栈信息
14
+ * @param event
15
+ */
16
+ static geErrorInfo(event: any): string;
12
17
  }
@@ -41,6 +41,28 @@ define(["require", "exports", "tslib", "lodash"], function (require, exports, ts
41
41
  }
42
42
  return true;
43
43
  };
44
+ /**
45
+ * 获取异常信息的堆栈信息
46
+ * @param event
47
+ */
48
+ FastVueMultiObject.geErrorInfo = function (event) {
49
+ if (event) {
50
+ if (event.error && event.error.stack) {
51
+ return event.error.stack;
52
+ }
53
+ else if (event.stack) {
54
+ return event.stack;
55
+ }
56
+ else if (event.message) {
57
+ return event.message;
58
+ }
59
+ else if (event.reason) {
60
+ return event.reason;
61
+ }
62
+ return event.toString();
63
+ }
64
+ return "";
65
+ };
44
66
  return FastVueMultiObject;
45
67
  }());
46
68
  exports.FastVueMultiObject = FastVueMultiObject;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fast-vue-multi-pages",
3
- "version": "1.0.30",
3
+ "version": "1.1.1",
4
4
  "author": "janesen",
5
5
  "description": "快速搭建VUE项目工具类的基本库,主要用于每个功能页面独立生成html",
6
6
  "main": "./dist/cjs/index.js",