@bud-fe/h5-native-bridge 1.0.4 → 1.0.6
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/README.md +35 -40
- package/dist/native-bridge.es.js +694 -274
- package/dist/native-bridge.es.js.map +1 -1
- package/dist/native-bridge.umd.js +1 -1
- package/dist/native-bridge.umd.js.map +1 -1
- package/dist/src/core/index.d.ts +9 -8
- package/dist/src/plugins/media.d.ts +29 -0
- package/dist/src/plugins/navigate.d.ts +20 -0
- package/dist/src/plugins/toast.d.ts +3 -2
- package/package.json +13 -8
package/dist/native-bridge.es.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
-
var __publicField = (obj, key, value) => {
|
|
4
|
-
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
return value;
|
|
6
|
-
};
|
|
7
1
|
var BridgeErrorCode = /* @__PURE__ */ ((BridgeErrorCode2) => {
|
|
8
2
|
BridgeErrorCode2[BridgeErrorCode2["SUCCESS"] = 0] = "SUCCESS";
|
|
9
3
|
BridgeErrorCode2[BridgeErrorCode2["JSON_ERROR"] = 1] = "JSON_ERROR";
|
|
@@ -19,27 +13,61 @@ const createBridgeError = (code, message, details) => {
|
|
|
19
13
|
error.details = details;
|
|
20
14
|
return error;
|
|
21
15
|
};
|
|
22
|
-
|
|
16
|
+
var __defProp$b = Object.defineProperty;
|
|
17
|
+
var __defNormalProp$b = (obj, key, value) => key in obj ? __defProp$b(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
18
|
+
var __publicField$b = (obj, key, value) => {
|
|
19
|
+
__defNormalProp$b(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
20
|
+
return value;
|
|
21
|
+
};
|
|
22
|
+
let AbortControllerPolyfill;
|
|
23
|
+
if (typeof AbortController === "undefined") {
|
|
24
|
+
AbortControllerPolyfill = class {
|
|
25
|
+
constructor() {
|
|
26
|
+
__publicField$b(this, "signal");
|
|
27
|
+
this.signal = {
|
|
28
|
+
aborted: false,
|
|
29
|
+
_listeners: [],
|
|
30
|
+
addEventListener: function(event, callback) {
|
|
31
|
+
this._listeners.push(callback);
|
|
32
|
+
},
|
|
33
|
+
removeEventListener: function(event, callback) {
|
|
34
|
+
const index = this._listeners.indexOf(callback);
|
|
35
|
+
if (index !== -1) {
|
|
36
|
+
this._listeners.splice(index, 1);
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
dispatchEvent: function(event) {
|
|
40
|
+
this._listeners.forEach((listener) => listener(event));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
abort() {
|
|
45
|
+
this.signal.aborted = true;
|
|
46
|
+
this.signal.dispatchEvent({ type: "abort" });
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
} else {
|
|
50
|
+
AbortControllerPolyfill = AbortController;
|
|
51
|
+
}
|
|
52
|
+
const _NativeBridgeCore = class _NativeBridgeCore2 {
|
|
23
53
|
/**
|
|
24
54
|
* 私有构造函数(单例模式)
|
|
25
55
|
*/
|
|
26
56
|
constructor(options = {}) {
|
|
27
|
-
__publicField(this, "callbackMap");
|
|
28
|
-
__publicField(this, "callbackId");
|
|
29
|
-
__publicField(this, "isReady");
|
|
30
|
-
__publicField(this, "readyCallbacks");
|
|
31
|
-
__publicField(this, "debugMode");
|
|
32
|
-
__publicField(this, "defaultTimeout");
|
|
33
|
-
__publicField(this, "plugins");
|
|
34
|
-
__publicField(this, "pendingCalls");
|
|
35
|
-
__publicField(this, "errorHandler");
|
|
36
|
-
__publicField(this, "eventListeners", /* @__PURE__ */ new Map());
|
|
37
|
-
__publicField(this, "nativeEventHandlers", /* @__PURE__ */ new Map());
|
|
38
|
-
|
|
39
|
-
__publicField(this, "
|
|
40
|
-
__publicField(this, "
|
|
41
|
-
// 新增方法注册机制
|
|
42
|
-
__publicField(this, "methodRegistry", /* @__PURE__ */ new Map());
|
|
57
|
+
__publicField$b(this, "callbackMap");
|
|
58
|
+
__publicField$b(this, "callbackId");
|
|
59
|
+
__publicField$b(this, "isReady");
|
|
60
|
+
__publicField$b(this, "readyCallbacks");
|
|
61
|
+
__publicField$b(this, "debugMode");
|
|
62
|
+
__publicField$b(this, "defaultTimeout");
|
|
63
|
+
__publicField$b(this, "plugins");
|
|
64
|
+
__publicField$b(this, "pendingCalls");
|
|
65
|
+
__publicField$b(this, "errorHandler");
|
|
66
|
+
__publicField$b(this, "eventListeners", /* @__PURE__ */ new Map());
|
|
67
|
+
__publicField$b(this, "nativeEventHandlers", /* @__PURE__ */ new Map());
|
|
68
|
+
__publicField$b(this, "VERSION", "1.0.0");
|
|
69
|
+
__publicField$b(this, "API_VERSION", "1");
|
|
70
|
+
__publicField$b(this, "methodRegistry", /* @__PURE__ */ new Map());
|
|
43
71
|
this.callbackMap = /* @__PURE__ */ new Map();
|
|
44
72
|
this.callbackId = 1;
|
|
45
73
|
this.isReady = false;
|
|
@@ -58,14 +86,14 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
58
86
|
* 获取NativeBridge单例
|
|
59
87
|
*/
|
|
60
88
|
static getInstance(options = {}) {
|
|
61
|
-
if (!
|
|
62
|
-
|
|
89
|
+
if (!_NativeBridgeCore2.instance) {
|
|
90
|
+
_NativeBridgeCore2.instance = new _NativeBridgeCore2(options);
|
|
63
91
|
} else if (options.plugins && options.plugins.length > 0) {
|
|
64
92
|
options.plugins.forEach((plugin) => {
|
|
65
|
-
|
|
93
|
+
_NativeBridgeCore2.instance.use(plugin);
|
|
66
94
|
});
|
|
67
95
|
}
|
|
68
|
-
return
|
|
96
|
+
return _NativeBridgeCore2.instance;
|
|
69
97
|
}
|
|
70
98
|
/**
|
|
71
99
|
* 注册原生事件监听
|
|
@@ -248,7 +276,7 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
248
276
|
if (callbacks) {
|
|
249
277
|
this.callbackMap.set(callbackId, callbacks);
|
|
250
278
|
if (timeout > 0) {
|
|
251
|
-
const controller = new
|
|
279
|
+
const controller = new AbortControllerPolyfill();
|
|
252
280
|
const timeoutId = setTimeout(() => {
|
|
253
281
|
var _a2, _b;
|
|
254
282
|
if (controller.signal.aborted)
|
|
@@ -309,6 +337,9 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
309
337
|
}
|
|
310
338
|
return callbackId;
|
|
311
339
|
}
|
|
340
|
+
isIOS() {
|
|
341
|
+
return /iPhone|iPad|iPod/i.test(navigator.userAgent);
|
|
342
|
+
}
|
|
312
343
|
/**
|
|
313
344
|
* 同步调用原生方法
|
|
314
345
|
*
|
|
@@ -321,15 +352,15 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
321
352
|
* @throws 当发送消息到原生App失败时抛出错误
|
|
322
353
|
*/
|
|
323
354
|
callNativeSync(action, params, callbacks) {
|
|
324
|
-
var _a, _b, _c, _d
|
|
355
|
+
var _a, _b, _c, _d;
|
|
325
356
|
let data = void 0;
|
|
326
357
|
try {
|
|
327
358
|
const messageString = JSON.stringify({ action, params });
|
|
328
359
|
const win = typeof window !== "undefined" ? window : void 0;
|
|
329
|
-
if ((
|
|
360
|
+
if (this.isIOS()) {
|
|
330
361
|
this.log(`发送消息到 iOS WKWebView: ${messageString}`);
|
|
331
|
-
data =
|
|
332
|
-
} else if ((
|
|
362
|
+
data = prompt(messageString);
|
|
363
|
+
} else if ((_a = win == null ? void 0 : win.AndroidBridge) == null ? void 0 : _a.postSyncMessage) {
|
|
333
364
|
this.log(`发送消息到安卓原生App: ${messageString}`);
|
|
334
365
|
data = win.AndroidBridge.postSyncMessage(messageString);
|
|
335
366
|
} else if (win) {
|
|
@@ -345,7 +376,7 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
345
376
|
}, 0);
|
|
346
377
|
return void 0;
|
|
347
378
|
} catch (iframeError) {
|
|
348
|
-
(
|
|
379
|
+
(_b = callbacks == null ? void 0 : callbacks.fail) == null ? void 0 : _b.call(callbacks, iframeError);
|
|
349
380
|
throw createBridgeError(
|
|
350
381
|
BridgeErrorCode.SYSTEM_ERROR,
|
|
351
382
|
`创建 iframe 失败: ${iframeError.message}`
|
|
@@ -353,7 +384,7 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
353
384
|
}
|
|
354
385
|
}
|
|
355
386
|
} catch (error) {
|
|
356
|
-
(
|
|
387
|
+
(_c = callbacks == null ? void 0 : callbacks.fail) == null ? void 0 : _c.call(callbacks, error);
|
|
357
388
|
throw createBridgeError(
|
|
358
389
|
BridgeErrorCode.SYSTEM_ERROR,
|
|
359
390
|
`发送消息到原生App失败: ${error.message}`
|
|
@@ -362,7 +393,7 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
362
393
|
if (this.debugMode) {
|
|
363
394
|
this.log(`收到原生回调: success`, data);
|
|
364
395
|
}
|
|
365
|
-
(
|
|
396
|
+
(_d = callbacks == null ? void 0 : callbacks.success) == null ? void 0 : _d.call(callbacks, processJsonValue(data));
|
|
366
397
|
return processJsonValue(data);
|
|
367
398
|
}
|
|
368
399
|
/**
|
|
@@ -455,21 +486,36 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
455
486
|
}, 100);
|
|
456
487
|
break;
|
|
457
488
|
default:
|
|
458
|
-
|
|
489
|
+
const entries = Array.from(this.plugins.entries());
|
|
490
|
+
for (let i = 0; i < entries.length; i++) {
|
|
491
|
+
const [plugin] = entries[i];
|
|
459
492
|
if (plugin.mockAction && typeof plugin.mockAction === "function") {
|
|
460
493
|
if (plugin.mockAction(message)) {
|
|
461
494
|
return;
|
|
462
495
|
}
|
|
463
496
|
}
|
|
464
497
|
}
|
|
465
|
-
|
|
498
|
+
setTimeout(() => {
|
|
499
|
+
this.handleNativeCallback(
|
|
500
|
+
message.callbackId,
|
|
501
|
+
"success",
|
|
502
|
+
{ message: "Mock成功", data: null }
|
|
503
|
+
);
|
|
504
|
+
}, 100);
|
|
466
505
|
}
|
|
467
506
|
}
|
|
468
507
|
/**
|
|
469
|
-
*
|
|
508
|
+
* 释放回调资源
|
|
470
509
|
*/
|
|
471
510
|
releaseCallback(callbackId) {
|
|
511
|
+
var _a, _b;
|
|
472
512
|
if (this.callbackMap.has(callbackId)) {
|
|
513
|
+
const callbacks = this.callbackMap.get(callbackId);
|
|
514
|
+
(_a = callbacks == null ? void 0 : callbacks.fail) == null ? void 0 : _a.call(
|
|
515
|
+
callbacks,
|
|
516
|
+
createBridgeError(BridgeErrorCode.SYSTEM_ERROR, "调用原生方法失败")
|
|
517
|
+
);
|
|
518
|
+
(_b = callbacks == null ? void 0 : callbacks.complete) == null ? void 0 : _b.call(callbacks);
|
|
473
519
|
this.callbackMap.delete(callbackId);
|
|
474
520
|
}
|
|
475
521
|
if (this.pendingCalls.has(callbackId)) {
|
|
@@ -508,37 +554,27 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
508
554
|
return this.debugMode;
|
|
509
555
|
}
|
|
510
556
|
/**
|
|
511
|
-
*
|
|
557
|
+
* 日志输出
|
|
512
558
|
*/
|
|
513
|
-
log(message, ...
|
|
514
|
-
if (message.includes("调试模式已")) {
|
|
515
|
-
console.log(`[NativeBridge] 📢 ${message}`, ...args);
|
|
516
|
-
return;
|
|
517
|
-
}
|
|
559
|
+
log(message, ...optionalParams) {
|
|
518
560
|
if (this.debugMode) {
|
|
519
|
-
console.log(`[NativeBridge] ${message}`, ...
|
|
561
|
+
console.log(`[NativeBridge] ${message}`, ...optionalParams);
|
|
520
562
|
}
|
|
521
563
|
}
|
|
522
564
|
/**
|
|
523
|
-
*
|
|
565
|
+
* 错误日志输出
|
|
524
566
|
*/
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
567
|
+
error(message, error) {
|
|
568
|
+
console.error(`[NativeBridge Error] ${message}`, error);
|
|
569
|
+
if (this.errorHandler && error) {
|
|
570
|
+
this.errorHandler(error, message);
|
|
528
571
|
}
|
|
529
572
|
}
|
|
530
573
|
/**
|
|
531
|
-
*
|
|
574
|
+
* 警告日志输出
|
|
532
575
|
*/
|
|
533
|
-
|
|
534
|
-
console.
|
|
535
|
-
if (this.errorHandler) {
|
|
536
|
-
try {
|
|
537
|
-
this.errorHandler(error, source);
|
|
538
|
-
} catch (handlerError) {
|
|
539
|
-
console.error("[NativeBridge] 错误处理器执行失败:", handlerError);
|
|
540
|
-
}
|
|
541
|
-
}
|
|
576
|
+
warn(message) {
|
|
577
|
+
console.warn(`[NativeBridge Warn] ${message}`);
|
|
542
578
|
}
|
|
543
579
|
/**
|
|
544
580
|
* 获取回调映射表
|
|
@@ -547,7 +583,7 @@ const _NativeBridgeCore = class _NativeBridgeCore {
|
|
|
547
583
|
return this.callbackMap;
|
|
548
584
|
}
|
|
549
585
|
};
|
|
550
|
-
__publicField(_NativeBridgeCore, "instance");
|
|
586
|
+
__publicField$b(_NativeBridgeCore, "instance");
|
|
551
587
|
let NativeBridgeCore = _NativeBridgeCore;
|
|
552
588
|
function processJsonValue(value) {
|
|
553
589
|
if (value === void 0 || value === null) {
|
|
@@ -574,11 +610,34 @@ const createNativeBridge = (options) => {
|
|
|
574
610
|
return NativeBridgeCore.getInstance(options);
|
|
575
611
|
};
|
|
576
612
|
NativeBridgeCore.getInstance();
|
|
613
|
+
var __defProp$a = Object.defineProperty;
|
|
614
|
+
var __defProps$1 = Object.defineProperties;
|
|
615
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
616
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
617
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
618
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
619
|
+
var __defNormalProp$a = (obj, key, value) => key in obj ? __defProp$a(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
620
|
+
var __spreadValues$4 = (a, b) => {
|
|
621
|
+
for (var prop in b || (b = {}))
|
|
622
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
623
|
+
__defNormalProp$a(a, prop, b[prop]);
|
|
624
|
+
if (__getOwnPropSymbols$4)
|
|
625
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
626
|
+
if (__propIsEnum$4.call(b, prop))
|
|
627
|
+
__defNormalProp$a(a, prop, b[prop]);
|
|
628
|
+
}
|
|
629
|
+
return a;
|
|
630
|
+
};
|
|
631
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
632
|
+
var __publicField$a = (obj, key, value) => {
|
|
633
|
+
__defNormalProp$a(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
634
|
+
return value;
|
|
635
|
+
};
|
|
577
636
|
class LocationPlugin {
|
|
578
637
|
constructor() {
|
|
579
|
-
__publicField(this, "name", "location");
|
|
580
|
-
__publicField(this, "version", "1.0.0");
|
|
581
|
-
__publicField(this, "context");
|
|
638
|
+
__publicField$a(this, "name", "location");
|
|
639
|
+
__publicField$a(this, "version", "1.0.0");
|
|
640
|
+
__publicField$a(this, "context");
|
|
582
641
|
}
|
|
583
642
|
install(context) {
|
|
584
643
|
this.context = context;
|
|
@@ -587,7 +646,6 @@ class LocationPlugin {
|
|
|
587
646
|
this.getLocationSync.bind(this)
|
|
588
647
|
);
|
|
589
648
|
context.bridge.registerMethod("getLocation", this.getLocation.bind(this));
|
|
590
|
-
context.bridge.log(`位置服务插件 v${this.version} 已安装`);
|
|
591
649
|
}
|
|
592
650
|
/**
|
|
593
651
|
* 获取当前位置信息
|
|
@@ -604,15 +662,15 @@ class LocationPlugin {
|
|
|
604
662
|
withReGeocode: true,
|
|
605
663
|
useCache: true
|
|
606
664
|
}) {
|
|
607
|
-
|
|
665
|
+
var _a;
|
|
666
|
+
options.useCache = (_a = options.useCache) != null ? _a : true;
|
|
608
667
|
return new Promise((resolve, reject) => {
|
|
609
|
-
this.getLocationSync({
|
|
610
|
-
...options,
|
|
668
|
+
this.getLocationSync(__spreadProps$1(__spreadValues$4({}, options), {
|
|
611
669
|
success: (location) => {
|
|
612
670
|
resolve(location);
|
|
613
671
|
},
|
|
614
672
|
fail: (error) => reject(error)
|
|
615
|
-
});
|
|
673
|
+
}));
|
|
616
674
|
});
|
|
617
675
|
}
|
|
618
676
|
getLocationSync(options = {
|
|
@@ -621,6 +679,7 @@ class LocationPlugin {
|
|
|
621
679
|
withReGeocode: true,
|
|
622
680
|
useCache: true
|
|
623
681
|
}) {
|
|
682
|
+
var _a;
|
|
624
683
|
if (!this.context) {
|
|
625
684
|
throw createBridgeError(
|
|
626
685
|
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
@@ -651,15 +710,15 @@ class LocationPlugin {
|
|
|
651
710
|
"useCache参数格式错误"
|
|
652
711
|
);
|
|
653
712
|
}
|
|
654
|
-
options.useCache = options.useCache
|
|
713
|
+
options.useCache = (_a = options.useCache) != null ? _a : true;
|
|
655
714
|
const callbacks = {
|
|
656
715
|
success: options.success,
|
|
657
716
|
fail: options.fail,
|
|
658
717
|
complete: options.complete
|
|
659
718
|
};
|
|
660
719
|
this.context.bridge.ready(() => {
|
|
661
|
-
var
|
|
662
|
-
(
|
|
720
|
+
var _a2;
|
|
721
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
663
722
|
{
|
|
664
723
|
action: "getLocation",
|
|
665
724
|
params: options
|
|
@@ -670,11 +729,31 @@ class LocationPlugin {
|
|
|
670
729
|
}
|
|
671
730
|
}
|
|
672
731
|
const locationPlugin = new LocationPlugin();
|
|
732
|
+
var __defProp$9 = Object.defineProperty;
|
|
733
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
734
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
735
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
736
|
+
var __defNormalProp$9 = (obj, key, value) => key in obj ? __defProp$9(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
737
|
+
var __spreadValues$3 = (a, b) => {
|
|
738
|
+
for (var prop in b || (b = {}))
|
|
739
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
740
|
+
__defNormalProp$9(a, prop, b[prop]);
|
|
741
|
+
if (__getOwnPropSymbols$3)
|
|
742
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
743
|
+
if (__propIsEnum$3.call(b, prop))
|
|
744
|
+
__defNormalProp$9(a, prop, b[prop]);
|
|
745
|
+
}
|
|
746
|
+
return a;
|
|
747
|
+
};
|
|
748
|
+
var __publicField$9 = (obj, key, value) => {
|
|
749
|
+
__defNormalProp$9(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
750
|
+
return value;
|
|
751
|
+
};
|
|
673
752
|
class DevicePlugin {
|
|
674
753
|
constructor() {
|
|
675
|
-
__publicField(this, "name", "device");
|
|
676
|
-
__publicField(this, "version", "1.0.0");
|
|
677
|
-
__publicField(this, "context");
|
|
754
|
+
__publicField$9(this, "name", "device");
|
|
755
|
+
__publicField$9(this, "version", "1.0.0");
|
|
756
|
+
__publicField$9(this, "context");
|
|
678
757
|
}
|
|
679
758
|
/**
|
|
680
759
|
* 安装插件
|
|
@@ -689,7 +768,6 @@ class DevicePlugin {
|
|
|
689
768
|
"setKeepScreenOn",
|
|
690
769
|
this.setKeepScreenOn.bind(this)
|
|
691
770
|
);
|
|
692
|
-
context.bridge.log(`设备信息插件 v${this.version} 已安装`);
|
|
693
771
|
}
|
|
694
772
|
/**
|
|
695
773
|
* 设置屏幕常亮状态
|
|
@@ -852,7 +930,7 @@ class DevicePlugin {
|
|
|
852
930
|
(_a = this.context) == null ? void 0 : _a.bridge.callNative(
|
|
853
931
|
{
|
|
854
932
|
action: "getWifiList",
|
|
855
|
-
params: {
|
|
933
|
+
params: __spreadValues$3({}, options)
|
|
856
934
|
},
|
|
857
935
|
callbacks
|
|
858
936
|
);
|
|
@@ -894,12 +972,32 @@ class DevicePlugin {
|
|
|
894
972
|
}
|
|
895
973
|
}
|
|
896
974
|
const devicePlugin = new DevicePlugin();
|
|
975
|
+
var __defProp$8 = Object.defineProperty;
|
|
976
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
977
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
978
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
979
|
+
var __defNormalProp$8 = (obj, key, value) => key in obj ? __defProp$8(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
980
|
+
var __spreadValues$2 = (a, b) => {
|
|
981
|
+
for (var prop in b || (b = {}))
|
|
982
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
983
|
+
__defNormalProp$8(a, prop, b[prop]);
|
|
984
|
+
if (__getOwnPropSymbols$2)
|
|
985
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
986
|
+
if (__propIsEnum$2.call(b, prop))
|
|
987
|
+
__defNormalProp$8(a, prop, b[prop]);
|
|
988
|
+
}
|
|
989
|
+
return a;
|
|
990
|
+
};
|
|
991
|
+
var __publicField$8 = (obj, key, value) => {
|
|
992
|
+
__defNormalProp$8(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
993
|
+
return value;
|
|
994
|
+
};
|
|
897
995
|
const MAX_VIDEO_DURATION = 60;
|
|
898
996
|
class MediaPlugin {
|
|
899
997
|
constructor() {
|
|
900
|
-
__publicField(this, "name", "media");
|
|
901
|
-
__publicField(this, "version", "1.0.0");
|
|
902
|
-
__publicField(this, "context");
|
|
998
|
+
__publicField$8(this, "name", "media");
|
|
999
|
+
__publicField$8(this, "version", "1.0.0");
|
|
1000
|
+
__publicField$8(this, "context");
|
|
903
1001
|
}
|
|
904
1002
|
/**
|
|
905
1003
|
* 安装插件
|
|
@@ -911,8 +1009,9 @@ class MediaPlugin {
|
|
|
911
1009
|
context.bridge.registerMethod("chooseImage", this.chooseImage.bind(this));
|
|
912
1010
|
context.bridge.registerMethod("previewImage", this.previewImage.bind(this));
|
|
913
1011
|
context.bridge.registerMethod("compressImage", this.compressImage.bind(this));
|
|
1012
|
+
context.bridge.registerMethod("compressVideo", this.compressVideo.bind(this));
|
|
914
1013
|
context.bridge.registerMethod("chooseVideo", this.chooseVideo.bind(this));
|
|
915
|
-
context.bridge.
|
|
1014
|
+
context.bridge.registerMethod("onUploadProgress", this.onUploadProgress.bind(this));
|
|
916
1015
|
}
|
|
917
1016
|
/**
|
|
918
1017
|
* 执行扫码功能
|
|
@@ -931,6 +1030,7 @@ class MediaPlugin {
|
|
|
931
1030
|
*/
|
|
932
1031
|
scan(options) {
|
|
933
1032
|
return new Promise((resolve, reject) => {
|
|
1033
|
+
var _a;
|
|
934
1034
|
if (!this.context) {
|
|
935
1035
|
throw createBridgeError(
|
|
936
1036
|
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
@@ -950,7 +1050,7 @@ class MediaPlugin {
|
|
|
950
1050
|
);
|
|
951
1051
|
}
|
|
952
1052
|
options.key = options.key || "qr";
|
|
953
|
-
options.isSupportAlbum = options.isSupportAlbum
|
|
1053
|
+
options.isSupportAlbum = (_a = options.isSupportAlbum) != null ? _a : true;
|
|
954
1054
|
const callbacks = {
|
|
955
1055
|
success: (res) => {
|
|
956
1056
|
resolve(res);
|
|
@@ -961,16 +1061,16 @@ class MediaPlugin {
|
|
|
961
1061
|
);
|
|
962
1062
|
},
|
|
963
1063
|
complete: () => {
|
|
964
|
-
var
|
|
965
|
-
(
|
|
1064
|
+
var _a2;
|
|
1065
|
+
(_a2 = options.complete) == null ? void 0 : _a2.call(options);
|
|
966
1066
|
}
|
|
967
1067
|
};
|
|
968
1068
|
this.context.bridge.ready(() => {
|
|
969
|
-
var
|
|
970
|
-
(
|
|
1069
|
+
var _a2;
|
|
1070
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
971
1071
|
{
|
|
972
1072
|
action: "scan",
|
|
973
|
-
params: {
|
|
1073
|
+
params: __spreadValues$2({}, options)
|
|
974
1074
|
},
|
|
975
1075
|
callbacks
|
|
976
1076
|
);
|
|
@@ -1148,6 +1248,7 @@ class MediaPlugin {
|
|
|
1148
1248
|
*/
|
|
1149
1249
|
compressImage(options) {
|
|
1150
1250
|
return new Promise((resolve, reject) => {
|
|
1251
|
+
var _a;
|
|
1151
1252
|
if (!this.context) {
|
|
1152
1253
|
throw createBridgeError(
|
|
1153
1254
|
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
@@ -1166,7 +1267,7 @@ class MediaPlugin {
|
|
|
1166
1267
|
"compressLevel参数格式不正确"
|
|
1167
1268
|
);
|
|
1168
1269
|
}
|
|
1169
|
-
options.compressLevel = options.compressLevel
|
|
1270
|
+
options.compressLevel = (_a = options.compressLevel) != null ? _a : 4;
|
|
1170
1271
|
const callbacks = {
|
|
1171
1272
|
success: (res) => {
|
|
1172
1273
|
resolve(res || { filePaths: "" });
|
|
@@ -1179,8 +1280,8 @@ class MediaPlugin {
|
|
|
1179
1280
|
}
|
|
1180
1281
|
};
|
|
1181
1282
|
this.context.bridge.ready(() => {
|
|
1182
|
-
var
|
|
1183
|
-
(
|
|
1283
|
+
var _a2;
|
|
1284
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
1184
1285
|
{
|
|
1185
1286
|
action: "compressImage",
|
|
1186
1287
|
params: options
|
|
@@ -1190,11 +1291,62 @@ class MediaPlugin {
|
|
|
1190
1291
|
});
|
|
1191
1292
|
});
|
|
1192
1293
|
}
|
|
1294
|
+
/**
|
|
1295
|
+
* 压缩视频
|
|
1296
|
+
* @param options 压缩视频的配置选项
|
|
1297
|
+
* @returns 返回一个Promise,解析为压缩后的视频响应数据
|
|
1298
|
+
*/
|
|
1299
|
+
compressVideo(options) {
|
|
1300
|
+
return new Promise((resolve, reject) => {
|
|
1301
|
+
var _a;
|
|
1302
|
+
if (!this.context) {
|
|
1303
|
+
throw createBridgeError(
|
|
1304
|
+
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
1305
|
+
"插件未正确初始化"
|
|
1306
|
+
);
|
|
1307
|
+
}
|
|
1308
|
+
if (!options.filePath || typeof options.filePath !== "string" || !options.filePath.trim()) {
|
|
1309
|
+
throw createBridgeError(
|
|
1310
|
+
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
1311
|
+
"filePath参数格式不正确"
|
|
1312
|
+
);
|
|
1313
|
+
}
|
|
1314
|
+
if (options.compressLevel !== void 0 && (typeof options.compressLevel !== "number" || options.compressLevel < 0 || options.compressLevel > 3 || !Number.isInteger(options.compressLevel))) {
|
|
1315
|
+
throw createBridgeError(
|
|
1316
|
+
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
1317
|
+
"compressLevel参数格式不正确"
|
|
1318
|
+
);
|
|
1319
|
+
}
|
|
1320
|
+
options.compressLevel = (_a = options.compressLevel) != null ? _a : 3;
|
|
1321
|
+
const callbacks = {
|
|
1322
|
+
success: (res) => {
|
|
1323
|
+
resolve(res || { filePath: "" });
|
|
1324
|
+
},
|
|
1325
|
+
fail: (err) => {
|
|
1326
|
+
console.error("压缩视频失败:", err);
|
|
1327
|
+
reject(err);
|
|
1328
|
+
},
|
|
1329
|
+
complete: () => {
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
this.context.bridge.ready(() => {
|
|
1333
|
+
var _a2;
|
|
1334
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
1335
|
+
{
|
|
1336
|
+
action: "compressVideo",
|
|
1337
|
+
params: options
|
|
1338
|
+
},
|
|
1339
|
+
callbacks
|
|
1340
|
+
);
|
|
1341
|
+
});
|
|
1342
|
+
});
|
|
1343
|
+
}
|
|
1193
1344
|
/**
|
|
1194
1345
|
* 选择视频文件
|
|
1195
1346
|
* @param options 选择视频的配置选项,包含以下属性:
|
|
1196
1347
|
* @param options.sourceType 视频来源类型,默认同时支持相册和相机['album','camera']
|
|
1197
1348
|
* @param options.maxDuration 视频最大时长(秒),默认60秒
|
|
1349
|
+
* @param options.compressLevel?: number; //压缩级别,支持 0 ~ 3 的整数,默认 3, (0:低质量, 1:中等质量,2:高质量,3:不压缩)
|
|
1198
1350
|
* @returns Promise<ChooseVideoResponse> 返回包含视频信息的Promise对象
|
|
1199
1351
|
* @returns ChooseVideoResponse.filePath 视频临时文件路径
|
|
1200
1352
|
* @returns ChooseVideoResponse.duration 视频时长(秒)
|
|
@@ -1204,6 +1356,7 @@ class MediaPlugin {
|
|
|
1204
1356
|
*/
|
|
1205
1357
|
chooseVideo(options = {}) {
|
|
1206
1358
|
return new Promise((resolve, reject) => {
|
|
1359
|
+
var _a, _b;
|
|
1207
1360
|
if (!this.context) {
|
|
1208
1361
|
throw createBridgeError(
|
|
1209
1362
|
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
@@ -1234,8 +1387,15 @@ class MediaPlugin {
|
|
|
1234
1387
|
"maxDuration参数格式不正确"
|
|
1235
1388
|
);
|
|
1236
1389
|
}
|
|
1390
|
+
if (options.compressLevel !== void 0 && (typeof options.compressLevel !== "number" || options.compressLevel < 0 || options.compressLevel > 3 || !Number.isInteger(options.compressLevel))) {
|
|
1391
|
+
throw createBridgeError(
|
|
1392
|
+
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
1393
|
+
"compressLevel参数格式不正确"
|
|
1394
|
+
);
|
|
1395
|
+
}
|
|
1237
1396
|
options.sourceType = options.sourceType || ["album", "camera"];
|
|
1238
|
-
options.maxDuration = options.maxDuration
|
|
1397
|
+
options.maxDuration = (_a = options.maxDuration) != null ? _a : MAX_VIDEO_DURATION;
|
|
1398
|
+
options.compressLevel = (_b = options.compressLevel) != null ? _b : 3;
|
|
1239
1399
|
const callbacks = {
|
|
1240
1400
|
success: (res) => {
|
|
1241
1401
|
resolve(res || { filePath: "", duration: 0, size: 0, height: 0, width: 0 });
|
|
@@ -1248,8 +1408,8 @@ class MediaPlugin {
|
|
|
1248
1408
|
}
|
|
1249
1409
|
};
|
|
1250
1410
|
this.context.bridge.ready(() => {
|
|
1251
|
-
var
|
|
1252
|
-
(
|
|
1411
|
+
var _a2;
|
|
1412
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
1253
1413
|
{
|
|
1254
1414
|
action: "chooseVideo",
|
|
1255
1415
|
params: options
|
|
@@ -1259,13 +1419,77 @@ class MediaPlugin {
|
|
|
1259
1419
|
});
|
|
1260
1420
|
});
|
|
1261
1421
|
}
|
|
1422
|
+
/**
|
|
1423
|
+
* 上传文件进度回调
|
|
1424
|
+
* @param options 上传进度信息
|
|
1425
|
+
* @param options.progress 上传进度,0-100
|
|
1426
|
+
* @param options.status 上传状态,0: 正在上传、1: 上传成功、2: 失败
|
|
1427
|
+
* @returns void
|
|
1428
|
+
*/
|
|
1429
|
+
onUploadProgress(callback) {
|
|
1430
|
+
if (!this.context) {
|
|
1431
|
+
throw createBridgeError(
|
|
1432
|
+
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
1433
|
+
"插件未正确初始化"
|
|
1434
|
+
);
|
|
1435
|
+
}
|
|
1436
|
+
this.context.bridge.ready(() => {
|
|
1437
|
+
var _a;
|
|
1438
|
+
(_a = this.context) == null ? void 0 : _a.bridge.onNativeEvent(
|
|
1439
|
+
"onUploadProgress",
|
|
1440
|
+
(event) => {
|
|
1441
|
+
callback(event.data ? JSON.parse(event.data) : {});
|
|
1442
|
+
}
|
|
1443
|
+
);
|
|
1444
|
+
});
|
|
1445
|
+
}
|
|
1262
1446
|
}
|
|
1263
1447
|
const mediaPlugin = new MediaPlugin();
|
|
1448
|
+
var __defProp$7 = Object.defineProperty;
|
|
1449
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
1450
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
1451
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
1452
|
+
var __defNormalProp$7 = (obj, key, value) => key in obj ? __defProp$7(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1453
|
+
var __spreadValues$1 = (a, b) => {
|
|
1454
|
+
for (var prop in b || (b = {}))
|
|
1455
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
1456
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
1457
|
+
if (__getOwnPropSymbols$1)
|
|
1458
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
1459
|
+
if (__propIsEnum$1.call(b, prop))
|
|
1460
|
+
__defNormalProp$7(a, prop, b[prop]);
|
|
1461
|
+
}
|
|
1462
|
+
return a;
|
|
1463
|
+
};
|
|
1464
|
+
var __publicField$7 = (obj, key, value) => {
|
|
1465
|
+
__defNormalProp$7(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1466
|
+
return value;
|
|
1467
|
+
};
|
|
1468
|
+
var __async$2 = (__this, __arguments, generator) => {
|
|
1469
|
+
return new Promise((resolve, reject) => {
|
|
1470
|
+
var fulfilled = (value) => {
|
|
1471
|
+
try {
|
|
1472
|
+
step(generator.next(value));
|
|
1473
|
+
} catch (e) {
|
|
1474
|
+
reject(e);
|
|
1475
|
+
}
|
|
1476
|
+
};
|
|
1477
|
+
var rejected = (value) => {
|
|
1478
|
+
try {
|
|
1479
|
+
step(generator.throw(value));
|
|
1480
|
+
} catch (e) {
|
|
1481
|
+
reject(e);
|
|
1482
|
+
}
|
|
1483
|
+
};
|
|
1484
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
1485
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
1486
|
+
});
|
|
1487
|
+
};
|
|
1264
1488
|
class NavigatePlugin {
|
|
1265
1489
|
constructor() {
|
|
1266
|
-
__publicField(this, "name", "navigate");
|
|
1267
|
-
__publicField(this, "version", "1.0.0");
|
|
1268
|
-
__publicField(this, "context");
|
|
1490
|
+
__publicField$7(this, "name", "navigate");
|
|
1491
|
+
__publicField$7(this, "version", "1.0.0");
|
|
1492
|
+
__publicField$7(this, "context");
|
|
1269
1493
|
}
|
|
1270
1494
|
install(context) {
|
|
1271
1495
|
this.context = context;
|
|
@@ -1278,10 +1502,12 @@ class NavigatePlugin {
|
|
|
1278
1502
|
this.setNavigationBar.bind(this)
|
|
1279
1503
|
);
|
|
1280
1504
|
context.bridge.registerMethod("openLink", this.openLink.bind(this));
|
|
1281
|
-
context.bridge.
|
|
1505
|
+
context.bridge.registerMethod("navigateToNativePage", this.navigateToNativePage.bind(this));
|
|
1506
|
+
context.bridge.registerMethod("closeCurrentPage", this.closeCurrentPage.bind(this));
|
|
1282
1507
|
}
|
|
1283
1508
|
setNavigationBar(options) {
|
|
1284
1509
|
return new Promise((resolve, reject) => {
|
|
1510
|
+
var _a;
|
|
1285
1511
|
if (!this.context) {
|
|
1286
1512
|
throw createBridgeError(
|
|
1287
1513
|
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
@@ -1312,7 +1538,7 @@ class NavigatePlugin {
|
|
|
1312
1538
|
"reset参数格式不正确"
|
|
1313
1539
|
);
|
|
1314
1540
|
}
|
|
1315
|
-
options.isShowBar = options.isShowBar
|
|
1541
|
+
options.isShowBar = (_a = options.isShowBar) != null ? _a : true;
|
|
1316
1542
|
const callbacks = {
|
|
1317
1543
|
success: () => {
|
|
1318
1544
|
resolve();
|
|
@@ -1330,11 +1556,11 @@ class NavigatePlugin {
|
|
|
1330
1556
|
}
|
|
1331
1557
|
};
|
|
1332
1558
|
this.context.bridge.ready(() => {
|
|
1333
|
-
var
|
|
1334
|
-
(
|
|
1559
|
+
var _a2;
|
|
1560
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
1335
1561
|
{
|
|
1336
1562
|
action: "setNavigationBar",
|
|
1337
|
-
params: {
|
|
1563
|
+
params: __spreadValues$1({}, options)
|
|
1338
1564
|
},
|
|
1339
1565
|
callbacks
|
|
1340
1566
|
);
|
|
@@ -1390,7 +1616,7 @@ class NavigatePlugin {
|
|
|
1390
1616
|
(_a = this.context) == null ? void 0 : _a.bridge.callNative(
|
|
1391
1617
|
{
|
|
1392
1618
|
action: type || "navigateTo",
|
|
1393
|
-
params: {
|
|
1619
|
+
params: __spreadValues$1({}, options)
|
|
1394
1620
|
},
|
|
1395
1621
|
callbacks
|
|
1396
1622
|
);
|
|
@@ -1407,6 +1633,7 @@ class NavigatePlugin {
|
|
|
1407
1633
|
this.navigate(options, "reLaunch");
|
|
1408
1634
|
}
|
|
1409
1635
|
navigateBack(options) {
|
|
1636
|
+
var _a;
|
|
1410
1637
|
if (!this.context) {
|
|
1411
1638
|
throw createBridgeError(
|
|
1412
1639
|
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
@@ -1419,35 +1646,35 @@ class NavigatePlugin {
|
|
|
1419
1646
|
"delta参数格式不正确"
|
|
1420
1647
|
);
|
|
1421
1648
|
}
|
|
1422
|
-
options.delta = options.delta
|
|
1649
|
+
options.delta = (_a = options.delta) != null ? _a : 1;
|
|
1423
1650
|
const callbacks = {
|
|
1424
1651
|
success: (res) => {
|
|
1425
|
-
var
|
|
1652
|
+
var _a2;
|
|
1426
1653
|
const resp = {
|
|
1427
1654
|
code: BridgeErrorCode.SUCCESS,
|
|
1428
1655
|
message: "跳转成功",
|
|
1429
1656
|
data: res
|
|
1430
1657
|
};
|
|
1431
|
-
(
|
|
1658
|
+
(_a2 = options.success) == null ? void 0 : _a2.call(options, resp);
|
|
1432
1659
|
},
|
|
1433
1660
|
fail: (err) => {
|
|
1434
|
-
var
|
|
1661
|
+
var _a2;
|
|
1435
1662
|
const resp = {
|
|
1436
1663
|
code: BridgeErrorCode.SYSTEM_ERROR,
|
|
1437
1664
|
message: "跳转失败",
|
|
1438
1665
|
details: err,
|
|
1439
1666
|
name: ""
|
|
1440
1667
|
};
|
|
1441
|
-
(
|
|
1668
|
+
(_a2 = options.fail) == null ? void 0 : _a2.call(options, resp);
|
|
1442
1669
|
},
|
|
1443
1670
|
complete: () => {
|
|
1444
|
-
var
|
|
1445
|
-
(
|
|
1671
|
+
var _a2;
|
|
1672
|
+
(_a2 = options.complete) == null ? void 0 : _a2.call(options);
|
|
1446
1673
|
}
|
|
1447
1674
|
};
|
|
1448
1675
|
this.context.bridge.ready(() => {
|
|
1449
|
-
var
|
|
1450
|
-
(
|
|
1676
|
+
var _a2;
|
|
1677
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
1451
1678
|
{
|
|
1452
1679
|
action: "navigateBack",
|
|
1453
1680
|
params: options
|
|
@@ -1461,7 +1688,69 @@ class NavigatePlugin {
|
|
|
1461
1688
|
* @param options 链接选项
|
|
1462
1689
|
* @returns Promise对象,解析为打开链接的响应
|
|
1463
1690
|
*/
|
|
1464
|
-
|
|
1691
|
+
openLink(options) {
|
|
1692
|
+
return __async$2(this, null, function* () {
|
|
1693
|
+
return new Promise((resolve, reject) => {
|
|
1694
|
+
if (!this.context) {
|
|
1695
|
+
throw createBridgeError(
|
|
1696
|
+
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
1697
|
+
"插件未正确初始化"
|
|
1698
|
+
);
|
|
1699
|
+
}
|
|
1700
|
+
if (!options.url) {
|
|
1701
|
+
throw createBridgeError(
|
|
1702
|
+
BridgeErrorCode.INVALID_ACTION,
|
|
1703
|
+
"缺少必需的参数: url"
|
|
1704
|
+
);
|
|
1705
|
+
}
|
|
1706
|
+
if (typeof options.url !== "string" || !options.url.trim()) {
|
|
1707
|
+
throw createBridgeError(
|
|
1708
|
+
BridgeErrorCode.INVALID_ACTION,
|
|
1709
|
+
"url参数格式错误"
|
|
1710
|
+
);
|
|
1711
|
+
}
|
|
1712
|
+
if (options.enableShare !== void 0 && typeof options.enableShare !== "boolean") {
|
|
1713
|
+
throw createBridgeError(
|
|
1714
|
+
BridgeErrorCode.INVALID_ACTION,
|
|
1715
|
+
"enableShare参数格式不正确"
|
|
1716
|
+
);
|
|
1717
|
+
}
|
|
1718
|
+
options.enableShare = options.enableShare || false;
|
|
1719
|
+
const callbacks = {
|
|
1720
|
+
success: () => {
|
|
1721
|
+
resolve();
|
|
1722
|
+
},
|
|
1723
|
+
fail: (err) => {
|
|
1724
|
+
reject(
|
|
1725
|
+
createBridgeError(
|
|
1726
|
+
BridgeErrorCode.SYSTEM_ERROR,
|
|
1727
|
+
"打开链接失败",
|
|
1728
|
+
err
|
|
1729
|
+
)
|
|
1730
|
+
);
|
|
1731
|
+
},
|
|
1732
|
+
complete: () => {
|
|
1733
|
+
}
|
|
1734
|
+
};
|
|
1735
|
+
this.context.bridge.ready(() => {
|
|
1736
|
+
var _a;
|
|
1737
|
+
(_a = this.context) == null ? void 0 : _a.bridge.callNative(
|
|
1738
|
+
{
|
|
1739
|
+
action: "openLink",
|
|
1740
|
+
params: __spreadValues$1({}, options)
|
|
1741
|
+
},
|
|
1742
|
+
callbacks
|
|
1743
|
+
);
|
|
1744
|
+
});
|
|
1745
|
+
});
|
|
1746
|
+
});
|
|
1747
|
+
}
|
|
1748
|
+
/**
|
|
1749
|
+
* 跳转原生设置页面
|
|
1750
|
+
* @param url 要跳转的原生页面URL
|
|
1751
|
+
* @returns Promise<void>
|
|
1752
|
+
*/
|
|
1753
|
+
navigateToNativePage(url) {
|
|
1465
1754
|
return new Promise((resolve, reject) => {
|
|
1466
1755
|
if (!this.context) {
|
|
1467
1756
|
throw createBridgeError(
|
|
@@ -1469,25 +1758,52 @@ class NavigatePlugin {
|
|
|
1469
1758
|
"插件未正确初始化"
|
|
1470
1759
|
);
|
|
1471
1760
|
}
|
|
1472
|
-
if (!
|
|
1761
|
+
if (!url || typeof url !== "string" || !url.trim()) {
|
|
1473
1762
|
throw createBridgeError(
|
|
1474
1763
|
BridgeErrorCode.INVALID_ACTION,
|
|
1475
|
-
"
|
|
1764
|
+
"url参数格式不正确"
|
|
1476
1765
|
);
|
|
1477
1766
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1767
|
+
const callbacks = {
|
|
1768
|
+
success: () => {
|
|
1769
|
+
resolve();
|
|
1770
|
+
},
|
|
1771
|
+
fail: (err) => {
|
|
1772
|
+
reject(
|
|
1773
|
+
createBridgeError(
|
|
1774
|
+
BridgeErrorCode.SYSTEM_ERROR,
|
|
1775
|
+
"跳转原生页面失败",
|
|
1776
|
+
err
|
|
1777
|
+
)
|
|
1778
|
+
);
|
|
1779
|
+
},
|
|
1780
|
+
complete: () => {
|
|
1781
|
+
}
|
|
1782
|
+
};
|
|
1783
|
+
this.context.bridge.ready(() => {
|
|
1784
|
+
var _a;
|
|
1785
|
+
(_a = this.context) == null ? void 0 : _a.bridge.callNative(
|
|
1786
|
+
{
|
|
1787
|
+
action: "navigateToNativePage",
|
|
1788
|
+
params: { url }
|
|
1789
|
+
},
|
|
1790
|
+
callbacks
|
|
1482
1791
|
);
|
|
1483
|
-
}
|
|
1484
|
-
|
|
1792
|
+
});
|
|
1793
|
+
});
|
|
1794
|
+
}
|
|
1795
|
+
/**
|
|
1796
|
+
* 关闭当前WebView页面
|
|
1797
|
+
* @returns Promise<void>
|
|
1798
|
+
*/
|
|
1799
|
+
closeCurrentPage() {
|
|
1800
|
+
return new Promise((resolve, reject) => {
|
|
1801
|
+
if (!this.context) {
|
|
1485
1802
|
throw createBridgeError(
|
|
1486
|
-
BridgeErrorCode.
|
|
1487
|
-
"
|
|
1803
|
+
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
1804
|
+
"插件未正确初始化"
|
|
1488
1805
|
);
|
|
1489
1806
|
}
|
|
1490
|
-
options.enableShare = options.enableShare || false;
|
|
1491
1807
|
const callbacks = {
|
|
1492
1808
|
success: () => {
|
|
1493
1809
|
resolve();
|
|
@@ -1496,7 +1812,7 @@ class NavigatePlugin {
|
|
|
1496
1812
|
reject(
|
|
1497
1813
|
createBridgeError(
|
|
1498
1814
|
BridgeErrorCode.SYSTEM_ERROR,
|
|
1499
|
-
"
|
|
1815
|
+
"关闭页面失败",
|
|
1500
1816
|
err
|
|
1501
1817
|
)
|
|
1502
1818
|
);
|
|
@@ -1508,8 +1824,8 @@ class NavigatePlugin {
|
|
|
1508
1824
|
var _a;
|
|
1509
1825
|
(_a = this.context) == null ? void 0 : _a.bridge.callNative(
|
|
1510
1826
|
{
|
|
1511
|
-
action: "
|
|
1512
|
-
params: {
|
|
1827
|
+
action: "closeCurrentPage",
|
|
1828
|
+
params: {}
|
|
1513
1829
|
},
|
|
1514
1830
|
callbacks
|
|
1515
1831
|
);
|
|
@@ -1518,11 +1834,17 @@ class NavigatePlugin {
|
|
|
1518
1834
|
}
|
|
1519
1835
|
}
|
|
1520
1836
|
const navigatePlugin = new NavigatePlugin();
|
|
1837
|
+
var __defProp$6 = Object.defineProperty;
|
|
1838
|
+
var __defNormalProp$6 = (obj, key, value) => key in obj ? __defProp$6(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1839
|
+
var __publicField$6 = (obj, key, value) => {
|
|
1840
|
+
__defNormalProp$6(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1841
|
+
return value;
|
|
1842
|
+
};
|
|
1521
1843
|
class ToastPlugin {
|
|
1522
1844
|
constructor() {
|
|
1523
|
-
__publicField(this, "name", "toast");
|
|
1524
|
-
__publicField(this, "version", "1.0.0");
|
|
1525
|
-
__publicField(this, "context");
|
|
1845
|
+
__publicField$6(this, "name", "toast");
|
|
1846
|
+
__publicField$6(this, "version", "1.0.0");
|
|
1847
|
+
__publicField$6(this, "context");
|
|
1526
1848
|
}
|
|
1527
1849
|
install(context) {
|
|
1528
1850
|
this.context = context;
|
|
@@ -1530,7 +1852,6 @@ class ToastPlugin {
|
|
|
1530
1852
|
context.bridge.registerMethod("hideToast", this.hideToast.bind(this));
|
|
1531
1853
|
context.bridge.registerMethod("showLoading", this.showLoading.bind(this));
|
|
1532
1854
|
context.bridge.registerMethod("hideLoading", this.hideLoading.bind(this));
|
|
1533
|
-
context.bridge.log(`导航插件 v${this.version} 已安装`);
|
|
1534
1855
|
}
|
|
1535
1856
|
hideLoading() {
|
|
1536
1857
|
return new Promise((resolve, reject) => {
|
|
@@ -1624,7 +1945,7 @@ class ToastPlugin {
|
|
|
1624
1945
|
"插件未正确初始化"
|
|
1625
1946
|
);
|
|
1626
1947
|
}
|
|
1627
|
-
if (options.type !== void 0 && typeof options.type !== "string" || options.type !== void 0 && !["none", "success", "fail", "exception"].includes(options.type)) {
|
|
1948
|
+
if (options.type !== void 0 && typeof options.type !== "string" || options.type !== void 0 && !["none", "success", "fail", "exception", "normal"].includes(options.type)) {
|
|
1628
1949
|
throw createBridgeError(
|
|
1629
1950
|
BridgeErrorCode.INVALID_ACTION,
|
|
1630
1951
|
"type参数格式不正确"
|
|
@@ -1648,7 +1969,13 @@ class ToastPlugin {
|
|
|
1648
1969
|
"duration参数格式不正确"
|
|
1649
1970
|
);
|
|
1650
1971
|
}
|
|
1651
|
-
|
|
1972
|
+
if (options.position !== void 0 && typeof options.position !== "string" || options.position !== void 0 && !["top", "bottom", "center"].includes(options.position)) {
|
|
1973
|
+
throw createBridgeError(
|
|
1974
|
+
BridgeErrorCode.INVALID_ACTION,
|
|
1975
|
+
"position参数格式不正确"
|
|
1976
|
+
);
|
|
1977
|
+
}
|
|
1978
|
+
const { type, content, duration, position } = options;
|
|
1652
1979
|
const callbacks = {
|
|
1653
1980
|
success: (obj) => {
|
|
1654
1981
|
resolve(obj);
|
|
@@ -1673,7 +2000,8 @@ class ToastPlugin {
|
|
|
1673
2000
|
params: {
|
|
1674
2001
|
type: type || "none",
|
|
1675
2002
|
content,
|
|
1676
|
-
duration: duration || 2e3
|
|
2003
|
+
duration: duration || 2e3,
|
|
2004
|
+
position: position || "center"
|
|
1677
2005
|
}
|
|
1678
2006
|
},
|
|
1679
2007
|
callbacks
|
|
@@ -1724,16 +2052,21 @@ class ToastPlugin {
|
|
|
1724
2052
|
}
|
|
1725
2053
|
}
|
|
1726
2054
|
const toastPlugin = new ToastPlugin();
|
|
2055
|
+
var __defProp$5 = Object.defineProperty;
|
|
2056
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2057
|
+
var __publicField$5 = (obj, key, value) => {
|
|
2058
|
+
__defNormalProp$5(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2059
|
+
return value;
|
|
2060
|
+
};
|
|
1727
2061
|
class UserInfoPlugin {
|
|
1728
2062
|
constructor() {
|
|
1729
|
-
__publicField(this, "name", "UserInfo");
|
|
1730
|
-
__publicField(this, "version", "1.0.0");
|
|
1731
|
-
__publicField(this, "context");
|
|
2063
|
+
__publicField$5(this, "name", "UserInfo");
|
|
2064
|
+
__publicField$5(this, "version", "1.0.0");
|
|
2065
|
+
__publicField$5(this, "context");
|
|
1732
2066
|
}
|
|
1733
2067
|
install(context) {
|
|
1734
2068
|
this.context = context;
|
|
1735
2069
|
context.bridge.registerMethod("getUserInfo", this.getUserInfo.bind(this));
|
|
1736
|
-
context.bridge.log(`导航插件 v${this.version} 已安装`);
|
|
1737
2070
|
}
|
|
1738
2071
|
getUserInfo() {
|
|
1739
2072
|
return new Promise((resolve, reject) => {
|
|
@@ -1773,11 +2106,17 @@ class UserInfoPlugin {
|
|
|
1773
2106
|
}
|
|
1774
2107
|
}
|
|
1775
2108
|
const userinfoPlugin = new UserInfoPlugin();
|
|
2109
|
+
var __defProp$4 = Object.defineProperty;
|
|
2110
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2111
|
+
var __publicField$4 = (obj, key, value) => {
|
|
2112
|
+
__defNormalProp$4(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2113
|
+
return value;
|
|
2114
|
+
};
|
|
1776
2115
|
class BluetoothPlugin {
|
|
1777
2116
|
constructor() {
|
|
1778
|
-
__publicField(this, "name", "bluetooth");
|
|
1779
|
-
__publicField(this, "version", "1.0.0");
|
|
1780
|
-
__publicField(this, "context");
|
|
2117
|
+
__publicField$4(this, "name", "bluetooth");
|
|
2118
|
+
__publicField$4(this, "version", "1.0.0");
|
|
2119
|
+
__publicField$4(this, "context");
|
|
1781
2120
|
}
|
|
1782
2121
|
install(context) {
|
|
1783
2122
|
this.context = context;
|
|
@@ -1845,7 +2184,6 @@ class BluetoothPlugin {
|
|
|
1845
2184
|
"offBLEConnectionStateChanged",
|
|
1846
2185
|
this.offBLEConnectionStateChanged.bind(this)
|
|
1847
2186
|
);
|
|
1848
|
-
context.bridge.log(`蓝牙插件 v${this.version} 已安装`);
|
|
1849
2187
|
}
|
|
1850
2188
|
//BLE蓝牙:---------------------------------------------------------------
|
|
1851
2189
|
/**
|
|
@@ -2075,7 +2413,7 @@ class BluetoothPlugin {
|
|
|
2075
2413
|
"characteristicId参数格式错误"
|
|
2076
2414
|
);
|
|
2077
2415
|
}
|
|
2078
|
-
if (typeof options.value !== "string" || !/^[0-9A-Fa-f]+$/.test(options.value) || ((_a = options.value) == null ? void 0 : _a.length) >
|
|
2416
|
+
if (typeof options.value !== "string" || !/^[0-9A-Fa-f]+$/.test(options.value) || ((_a = options.value) == null ? void 0 : _a.length) > 200) {
|
|
2079
2417
|
throw createBridgeError(
|
|
2080
2418
|
BridgeErrorCode.JSON_ERROR,
|
|
2081
2419
|
"value参数格式错误"
|
|
@@ -2526,6 +2864,7 @@ class BluetoothPlugin {
|
|
|
2526
2864
|
* @example
|
|
2527
2865
|
*/
|
|
2528
2866
|
openBluetoothAdapter(options = {}) {
|
|
2867
|
+
var _a;
|
|
2529
2868
|
if (!this.context) {
|
|
2530
2869
|
throw createBridgeError(
|
|
2531
2870
|
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
@@ -2538,15 +2877,15 @@ class BluetoothPlugin {
|
|
|
2538
2877
|
"autoClose参数格式不正确"
|
|
2539
2878
|
);
|
|
2540
2879
|
}
|
|
2541
|
-
options.autoClose = options.autoClose
|
|
2880
|
+
options.autoClose = (_a = options.autoClose) != null ? _a : true;
|
|
2542
2881
|
const callbacks = {
|
|
2543
2882
|
success: options.success,
|
|
2544
2883
|
fail: options.fail,
|
|
2545
2884
|
complete: options.complete
|
|
2546
2885
|
};
|
|
2547
2886
|
this.context.bridge.ready(() => {
|
|
2548
|
-
var
|
|
2549
|
-
(
|
|
2887
|
+
var _a2;
|
|
2888
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
2550
2889
|
{
|
|
2551
2890
|
action: "openBluetoothAdapter",
|
|
2552
2891
|
params: options
|
|
@@ -2582,11 +2921,54 @@ class BluetoothPlugin {
|
|
|
2582
2921
|
}
|
|
2583
2922
|
}
|
|
2584
2923
|
const bluetooth = new BluetoothPlugin();
|
|
2924
|
+
var __defProp$3 = Object.defineProperty;
|
|
2925
|
+
var __defProps = Object.defineProperties;
|
|
2926
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2927
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
2928
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
2929
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
2930
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
2931
|
+
var __spreadValues = (a, b) => {
|
|
2932
|
+
for (var prop in b || (b = {}))
|
|
2933
|
+
if (__hasOwnProp.call(b, prop))
|
|
2934
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
2935
|
+
if (__getOwnPropSymbols)
|
|
2936
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
2937
|
+
if (__propIsEnum.call(b, prop))
|
|
2938
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
2939
|
+
}
|
|
2940
|
+
return a;
|
|
2941
|
+
};
|
|
2942
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
2943
|
+
var __publicField$3 = (obj, key, value) => {
|
|
2944
|
+
__defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
2945
|
+
return value;
|
|
2946
|
+
};
|
|
2947
|
+
var __async$1 = (__this, __arguments, generator) => {
|
|
2948
|
+
return new Promise((resolve, reject) => {
|
|
2949
|
+
var fulfilled = (value) => {
|
|
2950
|
+
try {
|
|
2951
|
+
step(generator.next(value));
|
|
2952
|
+
} catch (e) {
|
|
2953
|
+
reject(e);
|
|
2954
|
+
}
|
|
2955
|
+
};
|
|
2956
|
+
var rejected = (value) => {
|
|
2957
|
+
try {
|
|
2958
|
+
step(generator.throw(value));
|
|
2959
|
+
} catch (e) {
|
|
2960
|
+
reject(e);
|
|
2961
|
+
}
|
|
2962
|
+
};
|
|
2963
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
2964
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
2965
|
+
});
|
|
2966
|
+
};
|
|
2585
2967
|
class StoragePlugin {
|
|
2586
2968
|
constructor() {
|
|
2587
|
-
__publicField(this, "context");
|
|
2588
|
-
__publicField(this, "name", "storage");
|
|
2589
|
-
__publicField(this, "version", "1.0.0");
|
|
2969
|
+
__publicField$3(this, "context");
|
|
2970
|
+
__publicField$3(this, "name", "storage");
|
|
2971
|
+
__publicField$3(this, "version", "1.0.0");
|
|
2590
2972
|
}
|
|
2591
2973
|
install(context) {
|
|
2592
2974
|
this.context = context;
|
|
@@ -2595,7 +2977,6 @@ class StoragePlugin {
|
|
|
2595
2977
|
context.bridge.registerMethod("getStorage", this.getStorage.bind(this));
|
|
2596
2978
|
context.bridge.registerMethod("getStorageSync", this.getStorageSync.bind(this));
|
|
2597
2979
|
context.bridge.registerMethod("removeStorage", this.removeStorage.bind(this));
|
|
2598
|
-
context.bridge.log(`本地存储插件 v${this.version} 已安装`);
|
|
2599
2980
|
}
|
|
2600
2981
|
_createCallbacks(options) {
|
|
2601
2982
|
return {
|
|
@@ -2604,38 +2985,39 @@ class StoragePlugin {
|
|
|
2604
2985
|
complete: options.complete
|
|
2605
2986
|
};
|
|
2606
2987
|
}
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
-
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
|
|
2616
|
-
|
|
2617
|
-
|
|
2618
|
-
|
|
2619
|
-
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
{
|
|
2624
|
-
...callbacks,
|
|
2625
|
-
success: (response) => {
|
|
2626
|
-
if (callbacks.success) {
|
|
2627
|
-
callbacks.success(response);
|
|
2628
|
-
}
|
|
2629
|
-
resolve(response);
|
|
2988
|
+
_callNativeMethod(action, params, callbacks) {
|
|
2989
|
+
return __async$1(this, null, function* () {
|
|
2990
|
+
if (!this.context) {
|
|
2991
|
+
throw createBridgeError(
|
|
2992
|
+
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
2993
|
+
"插件未正确初始化"
|
|
2994
|
+
);
|
|
2995
|
+
}
|
|
2996
|
+
return new Promise((resolve, reject) => {
|
|
2997
|
+
var _a;
|
|
2998
|
+
(_a = this.context) == null ? void 0 : _a.bridge.ready(() => {
|
|
2999
|
+
var _a2;
|
|
3000
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
3001
|
+
{
|
|
3002
|
+
action,
|
|
3003
|
+
params
|
|
2630
3004
|
},
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
callbacks.
|
|
3005
|
+
__spreadProps(__spreadValues({}, callbacks), {
|
|
3006
|
+
success: (response) => {
|
|
3007
|
+
if (callbacks.success) {
|
|
3008
|
+
callbacks.success(response);
|
|
3009
|
+
}
|
|
3010
|
+
resolve(response);
|
|
3011
|
+
},
|
|
3012
|
+
fail: (error) => {
|
|
3013
|
+
if (callbacks.fail) {
|
|
3014
|
+
callbacks.fail(error);
|
|
3015
|
+
}
|
|
3016
|
+
reject(error);
|
|
2634
3017
|
}
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
);
|
|
3018
|
+
})
|
|
3019
|
+
);
|
|
3020
|
+
});
|
|
2639
3021
|
});
|
|
2640
3022
|
});
|
|
2641
3023
|
}
|
|
@@ -2681,25 +3063,27 @@ class StoragePlugin {
|
|
|
2681
3063
|
);
|
|
2682
3064
|
});
|
|
2683
3065
|
}
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
3066
|
+
setStorage(options) {
|
|
3067
|
+
return __async$1(this, null, function* () {
|
|
3068
|
+
const key = options.key;
|
|
3069
|
+
if (!key) {
|
|
3070
|
+
throw createBridgeError(BridgeErrorCode.PLUGIN_NOT_INITIALIZED, "缺少必需的参数: key");
|
|
3071
|
+
}
|
|
3072
|
+
if (!options.data) {
|
|
3073
|
+
throw createBridgeError(BridgeErrorCode.INVALID_ACTION, "缺少必需的参数: data");
|
|
3074
|
+
}
|
|
3075
|
+
if (typeof key !== "string") {
|
|
3076
|
+
throw createBridgeError(BridgeErrorCode.INVALID_ACTION, "key参数格式不正确");
|
|
3077
|
+
}
|
|
3078
|
+
if (typeof options.data !== "object" && typeof options.data !== "string") {
|
|
3079
|
+
throw createBridgeError(BridgeErrorCode.INVALID_ACTION, "data参数格式不正确");
|
|
3080
|
+
}
|
|
3081
|
+
if (typeof options.data === "object" && Object.keys(options.data).length === 0) {
|
|
3082
|
+
throw createBridgeError(BridgeErrorCode.INVALID_ACTION, "data参数格式不正确");
|
|
3083
|
+
}
|
|
3084
|
+
const callbacks = this._createCallbacks(options);
|
|
3085
|
+
return this._callNativeMethod("setStorage", { key: options.key, data: options.data }, callbacks);
|
|
3086
|
+
});
|
|
2703
3087
|
}
|
|
2704
3088
|
getStorageSync(options) {
|
|
2705
3089
|
var _a;
|
|
@@ -2719,44 +3103,53 @@ class StoragePlugin {
|
|
|
2719
3103
|
const callbacks = this._createCallbacks(options);
|
|
2720
3104
|
return (_a = this.context) == null ? void 0 : _a.bridge.callNativeSync("getStorageSync", options, callbacks);
|
|
2721
3105
|
}
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
3106
|
+
getStorage(options) {
|
|
3107
|
+
return __async$1(this, null, function* () {
|
|
3108
|
+
const key = options.key;
|
|
3109
|
+
if (!key) {
|
|
3110
|
+
throw createBridgeError(BridgeErrorCode.PLUGIN_NOT_INITIALIZED, "缺少必需的参数: key");
|
|
3111
|
+
}
|
|
3112
|
+
if (typeof key !== "string") {
|
|
3113
|
+
throw createBridgeError(BridgeErrorCode.INVALID_ACTION, "key参数格式不正确");
|
|
3114
|
+
}
|
|
3115
|
+
const callbacks = this._createCallbacks(options);
|
|
3116
|
+
return this._callNativeMethod("getStorage", { key: options.key }, callbacks);
|
|
3117
|
+
});
|
|
2732
3118
|
}
|
|
2733
3119
|
/**
|
|
2734
3120
|
* 移除指定的存储数据(异步)
|
|
2735
3121
|
* @param options 存储选项,包含键值
|
|
2736
3122
|
* @returns 存储响应
|
|
2737
3123
|
*/
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
3124
|
+
removeStorage(options) {
|
|
3125
|
+
return __async$1(this, null, function* () {
|
|
3126
|
+
const key = options.key;
|
|
3127
|
+
if (!key) {
|
|
3128
|
+
throw createBridgeError(BridgeErrorCode.PLUGIN_NOT_INITIALIZED, "缺少必需的参数: key");
|
|
3129
|
+
}
|
|
3130
|
+
if (typeof key !== "string") {
|
|
3131
|
+
throw createBridgeError(BridgeErrorCode.INVALID_ACTION, "key参数格式不正确");
|
|
3132
|
+
}
|
|
3133
|
+
const callbacks = this._createCallbacks(options);
|
|
3134
|
+
return this._callNativeMethod("removeStorage", { key }, callbacks);
|
|
3135
|
+
});
|
|
2748
3136
|
}
|
|
2749
3137
|
}
|
|
2750
3138
|
const storagePlugin = new StoragePlugin();
|
|
3139
|
+
var __defProp$2 = Object.defineProperty;
|
|
3140
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3141
|
+
var __publicField$2 = (obj, key, value) => {
|
|
3142
|
+
__defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3143
|
+
return value;
|
|
3144
|
+
};
|
|
2751
3145
|
class AuthenticationPlugin {
|
|
2752
3146
|
constructor() {
|
|
2753
|
-
__publicField(this, "context");
|
|
2754
|
-
__publicField(this, "name", "authentication");
|
|
2755
|
-
__publicField(this, "version", "1.0.0");
|
|
3147
|
+
__publicField$2(this, "context");
|
|
3148
|
+
__publicField$2(this, "name", "authentication");
|
|
3149
|
+
__publicField$2(this, "version", "1.0.0");
|
|
2756
3150
|
}
|
|
2757
3151
|
install(context) {
|
|
2758
3152
|
this.context = context;
|
|
2759
|
-
context.bridge.log(`实人认证插件 v${this.version} 已安装`);
|
|
2760
3153
|
context.bridge.registerMethod(
|
|
2761
3154
|
"exclusiveLiveCheck",
|
|
2762
3155
|
this.exclusiveLiveCheck.bind(this)
|
|
@@ -2802,11 +3195,17 @@ class AuthenticationPlugin {
|
|
|
2802
3195
|
}
|
|
2803
3196
|
}
|
|
2804
3197
|
const authenticationPlugin = new AuthenticationPlugin();
|
|
3198
|
+
var __defProp$1 = Object.defineProperty;
|
|
3199
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3200
|
+
var __publicField$1 = (obj, key, value) => {
|
|
3201
|
+
__defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3202
|
+
return value;
|
|
3203
|
+
};
|
|
2805
3204
|
class RequestPlugin {
|
|
2806
3205
|
constructor() {
|
|
2807
|
-
__publicField(this, "name", "request");
|
|
2808
|
-
__publicField(this, "version", "1.0.0");
|
|
2809
|
-
__publicField(this, "context");
|
|
3206
|
+
__publicField$1(this, "name", "request");
|
|
3207
|
+
__publicField$1(this, "version", "1.0.0");
|
|
3208
|
+
__publicField$1(this, "context");
|
|
2810
3209
|
}
|
|
2811
3210
|
/**
|
|
2812
3211
|
* 安装插件
|
|
@@ -2817,7 +3216,6 @@ class RequestPlugin {
|
|
|
2817
3216
|
context.bridge.registerMethod("httpRequestSync", this.httpRequestSync.bind(this));
|
|
2818
3217
|
context.bridge.registerMethod("uploadFile", this.uploadFile.bind(this));
|
|
2819
3218
|
context.bridge.registerMethod("downloadFile", this.downloadFile.bind(this));
|
|
2820
|
-
context.bridge.log(`网络请求插件 v${this.version} 已安装`);
|
|
2821
3219
|
}
|
|
2822
3220
|
/**
|
|
2823
3221
|
* 执行HTTP请求
|
|
@@ -2880,18 +3278,12 @@ class RequestPlugin {
|
|
|
2880
3278
|
options.cacheModel = options.cacheModel || "noStore";
|
|
2881
3279
|
const callbacks = {
|
|
2882
3280
|
success: (res) => {
|
|
2883
|
-
var _a;
|
|
2884
|
-
(_a = options == null ? void 0 : options.success) == null ? void 0 : _a.call(options, res);
|
|
2885
3281
|
resolve(res);
|
|
2886
3282
|
},
|
|
2887
3283
|
fail: (err) => {
|
|
2888
|
-
var _a;
|
|
2889
|
-
(_a = options.fail) == null ? void 0 : _a.call(options, err);
|
|
2890
3284
|
reject(err);
|
|
2891
3285
|
},
|
|
2892
3286
|
complete: () => {
|
|
2893
|
-
var _a;
|
|
2894
|
-
(_a = options.complete) == null ? void 0 : _a.call(options);
|
|
2895
3287
|
}
|
|
2896
3288
|
};
|
|
2897
3289
|
this.context.bridge.ready(() => {
|
|
@@ -2908,7 +3300,7 @@ class RequestPlugin {
|
|
|
2908
3300
|
});
|
|
2909
3301
|
}
|
|
2910
3302
|
/**
|
|
2911
|
-
*
|
|
3303
|
+
*
|
|
2912
3304
|
*/
|
|
2913
3305
|
httpRequestSync(options) {
|
|
2914
3306
|
if (!this.context) {
|
|
@@ -3085,6 +3477,32 @@ class RequestPlugin {
|
|
|
3085
3477
|
}
|
|
3086
3478
|
}
|
|
3087
3479
|
const requestPlugin = new RequestPlugin();
|
|
3480
|
+
var __defProp = Object.defineProperty;
|
|
3481
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3482
|
+
var __publicField = (obj, key, value) => {
|
|
3483
|
+
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
3484
|
+
return value;
|
|
3485
|
+
};
|
|
3486
|
+
var __async = (__this, __arguments, generator) => {
|
|
3487
|
+
return new Promise((resolve, reject) => {
|
|
3488
|
+
var fulfilled = (value) => {
|
|
3489
|
+
try {
|
|
3490
|
+
step(generator.next(value));
|
|
3491
|
+
} catch (e) {
|
|
3492
|
+
reject(e);
|
|
3493
|
+
}
|
|
3494
|
+
};
|
|
3495
|
+
var rejected = (value) => {
|
|
3496
|
+
try {
|
|
3497
|
+
step(generator.throw(value));
|
|
3498
|
+
} catch (e) {
|
|
3499
|
+
reject(e);
|
|
3500
|
+
}
|
|
3501
|
+
};
|
|
3502
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
3503
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
3504
|
+
});
|
|
3505
|
+
};
|
|
3088
3506
|
class WifiPlugin {
|
|
3089
3507
|
constructor() {
|
|
3090
3508
|
__publicField(this, "context");
|
|
@@ -3097,7 +3515,6 @@ class WifiPlugin {
|
|
|
3097
3515
|
context.bridge.registerMethod("stopWifi", this.stopWifi.bind(this));
|
|
3098
3516
|
context.bridge.registerMethod("connectWifi", this.connectWifi.bind(this));
|
|
3099
3517
|
context.bridge.registerMethod("getScanWifiListAsync", this.getScanWifiListAsync.bind(this));
|
|
3100
|
-
context.bridge.log(`Wi-Fi 插件 v${this.version} 已安装`);
|
|
3101
3518
|
}
|
|
3102
3519
|
/**
|
|
3103
3520
|
* 初始化 Wi-Fi 模块
|
|
@@ -3171,6 +3588,7 @@ class WifiPlugin {
|
|
|
3171
3588
|
*/
|
|
3172
3589
|
connectWifi(options) {
|
|
3173
3590
|
return new Promise((resolve, reject) => {
|
|
3591
|
+
var _a;
|
|
3174
3592
|
if (!this.context) {
|
|
3175
3593
|
throw createBridgeError(
|
|
3176
3594
|
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
@@ -3207,7 +3625,7 @@ class WifiPlugin {
|
|
|
3207
3625
|
"isWEP参数格式错误"
|
|
3208
3626
|
);
|
|
3209
3627
|
}
|
|
3210
|
-
options.isWEP = options.isWEP
|
|
3628
|
+
options.isWEP = (_a = options.isWEP) != null ? _a : false;
|
|
3211
3629
|
const callbacks = {
|
|
3212
3630
|
success: (res) => {
|
|
3213
3631
|
resolve(res);
|
|
@@ -3218,8 +3636,8 @@ class WifiPlugin {
|
|
|
3218
3636
|
complete: options.complete
|
|
3219
3637
|
};
|
|
3220
3638
|
this.context.bridge.ready(() => {
|
|
3221
|
-
var
|
|
3222
|
-
(
|
|
3639
|
+
var _a2;
|
|
3640
|
+
(_a2 = this.context) == null ? void 0 : _a2.bridge.callNative(
|
|
3223
3641
|
{
|
|
3224
3642
|
action: "connectWifi",
|
|
3225
3643
|
params: options
|
|
@@ -3234,45 +3652,47 @@ class WifiPlugin {
|
|
|
3234
3652
|
* @param options 获取 Wi-Fi 列表的选项
|
|
3235
3653
|
* @returns 返回一个 Promise,解析为 Wi-Fi 列表响应数据
|
|
3236
3654
|
*/
|
|
3237
|
-
|
|
3238
|
-
return
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
|
|
3254
|
-
|
|
3255
|
-
|
|
3256
|
-
|
|
3257
|
-
|
|
3258
|
-
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
fail: (err) => {
|
|
3262
|
-
reject(err);
|
|
3263
|
-
},
|
|
3264
|
-
complete: options.complete
|
|
3265
|
-
};
|
|
3266
|
-
this.context.bridge.ready(() => {
|
|
3267
|
-
var _a;
|
|
3268
|
-
(_a = this.context) == null ? void 0 : _a.bridge.callNative(
|
|
3269
|
-
{
|
|
3270
|
-
action: "getScanWifiListAsync",
|
|
3271
|
-
params: options,
|
|
3272
|
-
timeout: options.timeout
|
|
3655
|
+
getScanWifiListAsync(options) {
|
|
3656
|
+
return __async(this, null, function* () {
|
|
3657
|
+
return new Promise((resolve, reject) => {
|
|
3658
|
+
if (!this.context) {
|
|
3659
|
+
throw createBridgeError(
|
|
3660
|
+
BridgeErrorCode.PLUGIN_NOT_INITIALIZED,
|
|
3661
|
+
"插件未正确初始化"
|
|
3662
|
+
);
|
|
3663
|
+
}
|
|
3664
|
+
if (typeof options.timeout !== "number") {
|
|
3665
|
+
throw createBridgeError(
|
|
3666
|
+
BridgeErrorCode.INVALID_ACTION,
|
|
3667
|
+
"timeout参数格式错误"
|
|
3668
|
+
);
|
|
3669
|
+
}
|
|
3670
|
+
if (typeof options.cacheTime !== "number") {
|
|
3671
|
+
throw createBridgeError(
|
|
3672
|
+
BridgeErrorCode.INVALID_ACTION,
|
|
3673
|
+
"cacheTime参数格式错误"
|
|
3674
|
+
);
|
|
3675
|
+
}
|
|
3676
|
+
const callbacks = {
|
|
3677
|
+
success: (res) => {
|
|
3678
|
+
resolve(res);
|
|
3273
3679
|
},
|
|
3274
|
-
|
|
3275
|
-
|
|
3680
|
+
fail: (err) => {
|
|
3681
|
+
reject(err);
|
|
3682
|
+
},
|
|
3683
|
+
complete: options.complete
|
|
3684
|
+
};
|
|
3685
|
+
this.context.bridge.ready(() => {
|
|
3686
|
+
var _a;
|
|
3687
|
+
(_a = this.context) == null ? void 0 : _a.bridge.callNative(
|
|
3688
|
+
{
|
|
3689
|
+
action: "getScanWifiListAsync",
|
|
3690
|
+
params: options,
|
|
3691
|
+
timeout: options.timeout
|
|
3692
|
+
},
|
|
3693
|
+
callbacks
|
|
3694
|
+
);
|
|
3695
|
+
});
|
|
3276
3696
|
});
|
|
3277
3697
|
});
|
|
3278
3698
|
}
|