qsh-webview-sdk 2.0.4 → 2.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.
@@ -0,0 +1,4064 @@
1
+ var yt = Object.defineProperty, It = Object.defineProperties;
2
+ var At = Object.getOwnPropertyDescriptors;
3
+ var Pe = Object.getOwnPropertySymbols;
4
+ var Ot = Object.prototype.hasOwnProperty, _t = Object.prototype.propertyIsEnumerable;
5
+ var pe = (t, e, r) => e in t ? yt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r, h = (t, e) => {
6
+ for (var r in e || (e = {}))
7
+ Ot.call(e, r) && pe(t, r, e[r]);
8
+ if (Pe)
9
+ for (var r of Pe(e))
10
+ _t.call(e, r) && pe(t, r, e[r]);
11
+ return t;
12
+ }, A = (t, e) => It(t, At(e));
13
+ var L = (t, e, r) => pe(t, typeof e != "symbol" ? e + "" : e, r);
14
+ var m = (t, e, r) => new Promise((n, i) => {
15
+ var s = (c) => {
16
+ try {
17
+ l(r.next(c));
18
+ } catch (p) {
19
+ i(p);
20
+ }
21
+ }, f = (c) => {
22
+ try {
23
+ l(r.throw(c));
24
+ } catch (p) {
25
+ i(p);
26
+ }
27
+ }, l = (c) => c.done ? n(c.value) : Promise.resolve(c.value).then(s, f);
28
+ l((r = r.apply(t, e)).next());
29
+ });
30
+ function ce() {
31
+ return typeof window != "undefined" ? window : void 0;
32
+ }
33
+ function ye() {
34
+ return typeof navigator == "undefined" ? "" : navigator.userAgent || "";
35
+ }
36
+ function O() {
37
+ const t = ce();
38
+ if (!t) return !1;
39
+ if (t.__wxjs_environment === "miniprogram" || t.wx && t.wx.miniProgram)
40
+ return !0;
41
+ const e = ye();
42
+ return !!(e && /micromessenger/i.test(e) && /miniProgram/i.test(e));
43
+ }
44
+ function ue() {
45
+ const t = ce();
46
+ return !!(t && t.plus);
47
+ }
48
+ function le() {
49
+ const t = ce();
50
+ return !!(t && (t.__dcloud_weex_postMessage || t.__dcloud_weex_));
51
+ }
52
+ function de() {
53
+ const t = ce();
54
+ return !!(t && (t.__uniapp_x_postMessage || t.__uniapp_x_));
55
+ }
56
+ function fe() {
57
+ const t = ye();
58
+ return /uni-app/i.test(t);
59
+ }
60
+ function Ie() {
61
+ const t = ye();
62
+ return /Html5Plus/i.test(t);
63
+ }
64
+ function xe() {
65
+ return fe() || Ie();
66
+ }
67
+ function Nt() {
68
+ return de() ? "uvue" : le() ? "nvue" : O() ? "weixin" : ue() ? "plus" : xe() ? "webview" : fe() ? "UniApp" : "h5";
69
+ }
70
+ let re = null;
71
+ function Ae(t = !1) {
72
+ return re && !t || (re = {
73
+ isWeixinMiniProgram: O(),
74
+ isAppPlus: ue(),
75
+ isNvue: le(),
76
+ isUvue: de(),
77
+ isUniApp: fe(),
78
+ isHtml5Plus: Ie(),
79
+ isUniAppWebView: xe(),
80
+ type: Nt()
81
+ }), re;
82
+ }
83
+ const g = Ae(), U = {
84
+ PLATFORM_NOT_SUPPORTED: "PLATFORM_NOT_SUPPORTED",
85
+ API_CALL_FAILED: "API_CALL_FAILED",
86
+ BRIDGE_NOT_READY: "BRIDGE_NOT_READY",
87
+ INVALID_PARAMETERS: "INVALID_PARAMETERS",
88
+ NETWORK_ERROR: "NETWORK_ERROR"
89
+ };
90
+ class C extends Error {
91
+ /**
92
+ * 构造函数
93
+ * @param {string} type - 错误类型
94
+ * @param {string} message - 错误消息
95
+ * @param {Object} [context] - 错误上下文信息
96
+ * @param {Error} [originalError] - 原始错误对象
97
+ */
98
+ constructor(e, r, n = {}, i = null) {
99
+ super(r), this.name = "QshError", this.type = e, this.context = n, this.originalError = i, this.timestamp = (/* @__PURE__ */ new Date()).toISOString(), Error.captureStackTrace && Error.captureStackTrace(this, C);
100
+ }
101
+ /**
102
+ * 转换为 JSON 格式
103
+ * @returns {Object} JSON 对象
104
+ */
105
+ toJSON() {
106
+ return {
107
+ name: this.name,
108
+ type: this.type,
109
+ message: this.message,
110
+ context: this.context,
111
+ timestamp: this.timestamp,
112
+ stack: this.stack
113
+ };
114
+ }
115
+ }
116
+ const y = class y {
117
+ /**
118
+ * 设置调试模式
119
+ * @param {boolean} enabled - 是否启用调试模式
120
+ */
121
+ static setDebugMode(e) {
122
+ y.isDebugMode = e;
123
+ }
124
+ /**
125
+ * 添加错误回调
126
+ * @param {Function} callback - 错误处理回调函数
127
+ */
128
+ static addErrorCallback(e) {
129
+ typeof e == "function" && y.errorCallbacks.push(e);
130
+ }
131
+ /**
132
+ * 移除错误回调
133
+ * @param {Function} callback - 要移除的回调函数
134
+ */
135
+ static removeErrorCallback(e) {
136
+ const r = y.errorCallbacks.indexOf(e);
137
+ r > -1 && y.errorCallbacks.splice(r, 1);
138
+ }
139
+ /**
140
+ * 处理 API 调用错误
141
+ * @param {Error|string} error - 错误对象或消息
142
+ * @param {Object} context - 错误上下文
143
+ * @returns {QshError} 包装后的错误对象
144
+ */
145
+ static handleApiError(e, r = {}) {
146
+ let n;
147
+ return e instanceof C ? n = e : e instanceof Error ? n = new C(
148
+ U.API_CALL_FAILED,
149
+ e.message,
150
+ r,
151
+ e
152
+ ) : n = new C(
153
+ U.API_CALL_FAILED,
154
+ String(e),
155
+ r
156
+ ), y.logError(n), y.notifyCallbacks(n), n;
157
+ }
158
+ /**
159
+ * 处理平台不支持错误
160
+ * @param {string} platformType - 平台类型
161
+ * @param {string} apiName - API 名称
162
+ * @returns {QshError} 错误对象
163
+ */
164
+ static handlePlatformNotSupported(e, r) {
165
+ const n = new C(
166
+ U.PLATFORM_NOT_SUPPORTED,
167
+ `API "${r}" is not supported on platform "${e}"`,
168
+ { platformType: e, apiName: r }
169
+ );
170
+ return y.logError(n), y.notifyCallbacks(n), n;
171
+ }
172
+ /**
173
+ * 处理桥接未就绪错误
174
+ * @param {string} apiName - API 名称
175
+ * @returns {QshError} 错误对象
176
+ */
177
+ static handleBridgeNotReady(e) {
178
+ const r = new C(
179
+ U.BRIDGE_NOT_READY,
180
+ `Bridge is not ready when calling "${e}"`,
181
+ { apiName: e }
182
+ );
183
+ return y.logError(r), y.notifyCallbacks(r), r;
184
+ }
185
+ /**
186
+ * 处理参数验证错误
187
+ * @param {string} apiName - API 名称
188
+ * @param {string} paramName - 参数名称
189
+ * @param {string} expectedType - 期望的参数类型
190
+ * @param {any} actualValue - 实际参数值
191
+ * @returns {QshError} 错误对象
192
+ */
193
+ static handleInvalidParameters(e, r, n, i) {
194
+ const s = new C(
195
+ U.INVALID_PARAMETERS,
196
+ `Invalid parameter "${r}" in "${e}": expected ${n}, got ${typeof i}`,
197
+ { apiName: e, paramName: r, expectedType: n, actualValue: i }
198
+ );
199
+ return y.logError(s), y.notifyCallbacks(s), s;
200
+ }
201
+ /**
202
+ * 安全地包装函数执行,捕获并处理错误
203
+ * @param {Function} fn - 要执行的函数
204
+ * @param {Object} context - 执行上下文
205
+ * @returns {any} 函数执行结果
206
+ */
207
+ static safeExecute(e, r = {}) {
208
+ try {
209
+ return e();
210
+ } catch (n) {
211
+ return y.handleApiError(n, r);
212
+ }
213
+ }
214
+ /**
215
+ * 异步安全包装
216
+ * @param {Function} fn - 异步函数
217
+ * @param {Object} context - 执行上下文
218
+ * @returns {Promise} Promise 对象
219
+ */
220
+ static safeExecuteAsync(n) {
221
+ return m(this, arguments, function* (e, r = {}) {
222
+ try {
223
+ return yield e();
224
+ } catch (i) {
225
+ return y.handleApiError(i, r);
226
+ }
227
+ });
228
+ }
229
+ /**
230
+ * 记录错误日志
231
+ * @param {QshError} error - 错误对象
232
+ * @private
233
+ */
234
+ static logError(e) {
235
+ if (typeof console != "undefined") {
236
+ const r = `[QSH-SDK Error] ${e.type}: ${e.message}`;
237
+ y.isDebugMode ? console.error(r, {
238
+ context: e.context,
239
+ originalError: e.originalError,
240
+ stack: e.stack,
241
+ timestamp: e.timestamp
242
+ }) : console.error(r);
243
+ }
244
+ }
245
+ /**
246
+ * 通知错误回调
247
+ * @param {QshError} error - 错误对象
248
+ * @private
249
+ */
250
+ static notifyCallbacks(e) {
251
+ y.errorCallbacks.forEach((r) => {
252
+ try {
253
+ r(e);
254
+ } catch (n) {
255
+ typeof console != "undefined" && console.error("[QSH-SDK] Error in error callback:", n);
256
+ }
257
+ });
258
+ }
259
+ /**
260
+ * 创建错误处理装饰器
261
+ * @param {Object} context - 装饰器上下文
262
+ * @returns {Function} 装饰器函数
263
+ */
264
+ static createErrorDecorator(e = {}) {
265
+ return function(r, n, i) {
266
+ const s = i.value;
267
+ return i.value = function(...f) {
268
+ return y.safeExecute(() => s.apply(this, f), A(h({}, e), { method: n, target: r.constructor.name }));
269
+ }, i;
270
+ };
271
+ }
272
+ };
273
+ L(y, "isDebugMode", !1), L(y, "errorCallbacks", []);
274
+ let d = y;
275
+ const T = {
276
+ UNINITIALIZED: "uninitialized",
277
+ INITIALIZING: "initializing",
278
+ READY: "ready",
279
+ ERROR: "error"
280
+ };
281
+ class Rt {
282
+ constructor() {
283
+ this.state = T.UNINITIALIZED, this.readyPromise = null, this.readyCallbacks = [], this.errorCallbacks = [], this.initializationError = null, this.handleBridgeReady = this.handleBridgeReady.bind(this), this.handleInitializationError = this.handleInitializationError.bind(this);
284
+ }
285
+ /**
286
+ * 获取当前状态
287
+ * @returns {string} 当前状态
288
+ */
289
+ getState() {
290
+ return this.state;
291
+ }
292
+ /**
293
+ * 检查是否已准备就绪
294
+ * @returns {boolean} 是否就绪
295
+ */
296
+ isReady() {
297
+ return this.state === T.READY;
298
+ }
299
+ /**
300
+ * 检查是否正在初始化
301
+ * @returns {boolean} 是否正在初始化
302
+ */
303
+ isInitializing() {
304
+ return this.state === T.INITIALIZING;
305
+ }
306
+ /**
307
+ * 检查是否出错
308
+ * @returns {boolean} 是否出错
309
+ */
310
+ hasError() {
311
+ return this.state === T.ERROR;
312
+ }
313
+ /**
314
+ * 获取初始化错误
315
+ * @returns {Error|null} 错误对象
316
+ */
317
+ getInitializationError() {
318
+ return this.initializationError;
319
+ }
320
+ /**
321
+ * 等待 SDK 准备就绪(单例 Promise)
322
+ * @returns {Promise<void>} 准备就绪的 Promise
323
+ */
324
+ waitForReady() {
325
+ return this.isReady() ? Promise.resolve() : this.hasError() ? Promise.reject(this.initializationError) : (this.readyPromise || (this.readyPromise = new Promise((e, r) => {
326
+ this.isReady() ? e() : this.hasError() ? r(this.initializationError) : (this.readyCallbacks.push(e), this.errorCallbacks.push(r));
327
+ })), this.readyPromise);
328
+ }
329
+ /**
330
+ * 开始初始化
331
+ * @param {Function} initFunction - 初始化函数
332
+ * @returns {Promise<void>} 初始化 Promise
333
+ */
334
+ startInitialization(e) {
335
+ return m(this, null, function* () {
336
+ if (this.state !== T.UNINITIALIZED)
337
+ return this.waitForReady();
338
+ this.state = T.INITIALIZING;
339
+ try {
340
+ yield e(), this.handleBridgeReady();
341
+ } catch (r) {
342
+ throw this.handleInitializationError(r), r;
343
+ }
344
+ return this.waitForReady();
345
+ });
346
+ }
347
+ /**
348
+ * 处理桥接就绪事件
349
+ * @private
350
+ */
351
+ handleBridgeReady() {
352
+ this.state === T.INITIALIZING && (this.state = T.READY, this.readyCallbacks.forEach((e) => {
353
+ try {
354
+ e();
355
+ } catch (r) {
356
+ d.handleApiError(r, { context: "StateManager.handleBridgeReady" });
357
+ }
358
+ }), this.readyCallbacks = [], this.errorCallbacks = []);
359
+ }
360
+ /**
361
+ * 处理初始化错误
362
+ * @param {Error} error - 错误对象
363
+ * @private
364
+ */
365
+ handleInitializationError(e) {
366
+ this.state = T.ERROR, this.initializationError = e, this.errorCallbacks.forEach((r) => {
367
+ try {
368
+ r(e);
369
+ } catch (n) {
370
+ d.handleApiError(n, { context: "StateManager.handleInitializationError" });
371
+ }
372
+ }), this.readyCallbacks = [], this.errorCallbacks = [];
373
+ }
374
+ /**
375
+ * 重置状态管理器(用于测试或重新初始化)
376
+ */
377
+ reset() {
378
+ this.state = T.UNINITIALIZED, this.readyPromise = null, this.readyCallbacks = [], this.errorCallbacks = [], this.initializationError = null;
379
+ }
380
+ /**
381
+ * 添加状态变化监听器
382
+ * @param {string} targetState - 目标状态
383
+ * @param {Function} callback - 回调函数
384
+ * @returns {Function} 移除监听器的函数
385
+ */
386
+ onStateChange(e, r) {
387
+ if (this.state === e)
388
+ return setTimeout(() => r(this.state), 0), () => {
389
+ };
390
+ const n = () => {
391
+ this.state === e && r(this.state);
392
+ };
393
+ return e === T.READY ? this.readyCallbacks.push(n) : e === T.ERROR && this.errorCallbacks.push(n), () => {
394
+ const i = this.readyCallbacks.indexOf(n);
395
+ i > -1 && this.readyCallbacks.splice(i, 1);
396
+ const s = this.errorCallbacks.indexOf(n);
397
+ s > -1 && this.errorCallbacks.splice(s, 1);
398
+ };
399
+ }
400
+ /**
401
+ * 获取状态统计信息
402
+ * @returns {Object} 统计信息
403
+ */
404
+ getStats() {
405
+ return {
406
+ state: this.state,
407
+ readyCallbacksCount: this.readyCallbacks.length,
408
+ errorCallbacksCount: this.errorCallbacks.length,
409
+ hasReadyPromise: !!this.readyPromise,
410
+ hasInitializationError: !!this.initializationError
411
+ };
412
+ }
413
+ }
414
+ const K = new Rt(), Ue = () => K.waitForReady(), St = () => K.isReady(), Tt = () => K.getState(), w = {
415
+ ERROR: 0,
416
+ WARN: 1,
417
+ INFO: 2,
418
+ DEBUG: 3,
419
+ TRACE: 4
420
+ }, Y = {
421
+ [w.ERROR]: "ERROR",
422
+ [w.WARN]: "WARN",
423
+ [w.INFO]: "INFO",
424
+ [w.DEBUG]: "DEBUG",
425
+ [w.TRACE]: "TRACE"
426
+ }, u = class u {
427
+ // 可注入的外部 reporter
428
+ /**
429
+ * 设置日志级别
430
+ * @param {number} level - 日志级别
431
+ */
432
+ static setLevel(e) {
433
+ e >= w.ERROR && e <= w.TRACE && (u.currentLevel = e, u.log(w.INFO, "Logger", `日志级别设置为: ${Y[e]}`));
434
+ }
435
+ /**
436
+ * 启用开发模式(显示所有日志)
437
+ */
438
+ static enableDevMode() {
439
+ u.setLevel(w.DEBUG), u.log(w.INFO, "Logger", "开发模式已启用");
440
+ }
441
+ /**
442
+ * 启用生产模式(只显示错误和警告)
443
+ */
444
+ static enableProdMode() {
445
+ u.setLevel(w.WARN), u.log(w.INFO, "Logger", "生产模式已启用");
446
+ }
447
+ /**
448
+ * 启用特定模块的日志
449
+ * @param {string} module - 模块名称
450
+ */
451
+ static enableModule(e) {
452
+ u.enabledModules.add(e), u.log(w.INFO, "Logger", `模块日志已启用: ${e}`);
453
+ }
454
+ /**
455
+ * 禁用特定模块的日志
456
+ * @param {string} module - 模块名称
457
+ */
458
+ static disableModule(e) {
459
+ u.enabledModules.delete(e), u.log(w.INFO, "Logger", `模块日志已禁用: ${e}`);
460
+ }
461
+ /**
462
+ * 检查是否应该记录日志
463
+ * @param {number} level - 日志级别
464
+ * @param {string} module - 模块名称
465
+ * @returns {boolean} 是否应该记录
466
+ * @private
467
+ */
468
+ static shouldLog(e, r) {
469
+ return e > u.currentLevel ? !1 : r && u.enabledModules.size > 0 ? u.enabledModules.has(r) : !0;
470
+ }
471
+ /**
472
+ * 核心日志记录方法
473
+ * @param {number} level - 日志级别
474
+ * @param {string} module - 模块名称
475
+ * @param {string} message - 日志消息
476
+ * @param {any[]} args - 额外参数
477
+ * @private
478
+ */
479
+ static log(e, r, n, ...i) {
480
+ if (!u.shouldLog(e, r))
481
+ return;
482
+ const s = (/* @__PURE__ */ new Date()).toISOString(), f = Y[e], l = r ? `[${r}]` : "", c = `${u.prefix} ${l} ${n}`, p = {
483
+ timestamp: s,
484
+ level: e,
485
+ levelName: f,
486
+ module: r,
487
+ message: n,
488
+ args: i
489
+ };
490
+ if (u.addToHistory(p), typeof u.reporter == "function")
491
+ try {
492
+ u.reporter(p);
493
+ } catch (P) {
494
+ }
495
+ u.outputToConsole(e, c, ...i);
496
+ }
497
+ /**
498
+ * 添加日志到历史记录
499
+ * @param {Object} logEntry - 日志条目
500
+ * @private
501
+ */
502
+ static addToHistory(e) {
503
+ u.logHistory.push(e), u.logHistory.length > u.maxHistorySize && u.logHistory.shift();
504
+ }
505
+ /**
506
+ * 输出到控制台
507
+ * @param {number} level - 日志级别
508
+ * @param {string} message - 消息
509
+ * @param {any[]} args - 额外参数
510
+ * @private
511
+ */
512
+ static outputToConsole(e, r, ...n) {
513
+ if (typeof console == "undefined")
514
+ return;
515
+ const i = n && n.length > 0;
516
+ switch (e) {
517
+ case w.ERROR:
518
+ i ? console.error(r, ...n) : console.error(r);
519
+ break;
520
+ case w.WARN:
521
+ i ? console.warn(r, ...n) : console.warn(r);
522
+ break;
523
+ case w.INFO:
524
+ i ? console.info(r, ...n) : console.info(r);
525
+ break;
526
+ case w.DEBUG:
527
+ case w.TRACE:
528
+ i ? console.log(r, ...n) : console.log(r);
529
+ break;
530
+ }
531
+ }
532
+ /**
533
+ * 错误级别日志
534
+ * @param {string} module - 模块名称
535
+ * @param {string} message - 消息
536
+ * @param {any[]} args - 额外参数
537
+ */
538
+ static error(e, r, ...n) {
539
+ u.log(w.ERROR, e, r, ...n);
540
+ }
541
+ /**
542
+ * 警告级别日志
543
+ * @param {string} module - 模块名称
544
+ * @param {string} message - 消息
545
+ * @param {any[]} args - 额外参数
546
+ */
547
+ static warn(e, r, ...n) {
548
+ u.log(w.WARN, e, r, ...n);
549
+ }
550
+ /**
551
+ * 信息级别日志
552
+ * @param {string} module - 模块名称
553
+ * @param {string} message - 消息
554
+ * @param {any[]} args - 额外参数
555
+ */
556
+ static info(e, r, ...n) {
557
+ u.log(w.INFO, e, r, ...n);
558
+ }
559
+ /**
560
+ * 调试级别日志
561
+ * @param {string} module - 模块名称
562
+ * @param {string} message - 消息
563
+ * @param {any[]} args - 额外参数
564
+ */
565
+ static debug(e, r, ...n) {
566
+ u.log(w.DEBUG, e, r, ...n);
567
+ }
568
+ /**
569
+ * 跟踪级别日志
570
+ * @param {string} module - 模块名称
571
+ * @param {string} message - 消息
572
+ * @param {any[]} args - 额外参数
573
+ */
574
+ static trace(e, r, ...n) {
575
+ u.log(w.TRACE, e, r, ...n);
576
+ }
577
+ /**
578
+ * 获取日志历史
579
+ * @param {number} [count] - 获取的条数,默认全部
580
+ * @returns {Array} 日志条目数组
581
+ */
582
+ static getHistory(e) {
583
+ return e && e > 0 ? u.logHistory.slice(-e) : [...u.logHistory];
584
+ }
585
+ /**
586
+ * 清空日志历史
587
+ */
588
+ static clearHistory() {
589
+ u.logHistory = [], u.log(w.INFO, "Logger", "日志历史已清空");
590
+ }
591
+ /**
592
+ * 获取日志统计信息
593
+ * @returns {Object} 统计信息
594
+ */
595
+ static getStats() {
596
+ const e = {
597
+ currentLevel: u.currentLevel,
598
+ currentLevelName: Y[u.currentLevel],
599
+ enabledModules: Array.from(u.enabledModules),
600
+ historySize: u.logHistory.length,
601
+ maxHistorySize: u.maxHistorySize
602
+ }, r = {};
603
+ for (const n of Object.keys(Y))
604
+ r[Y[n]] = 0;
605
+ return u.logHistory.forEach((n) => {
606
+ r[n.levelName]++;
607
+ }), e.levelCounts = r, e;
608
+ }
609
+ /**
610
+ * 导出日志到 JSON
611
+ * @param {number} [count] - 导出的条数,默认全部
612
+ * @returns {string} JSON 字符串
613
+ */
614
+ static exportToJSON(e) {
615
+ const r = u.getHistory(e), n = u.getStats();
616
+ return JSON.stringify({
617
+ exportTime: (/* @__PURE__ */ new Date()).toISOString(),
618
+ stats: n,
619
+ logs: r
620
+ }, null, 2);
621
+ }
622
+ /**
623
+ * 创建模块专用日志器
624
+ * @param {string} moduleName - 模块名称
625
+ * @returns {Object} 模块日志器对象
626
+ */
627
+ static createModuleLogger(e) {
628
+ return {
629
+ error: (r, ...n) => u.error(e, r, ...n),
630
+ warn: (r, ...n) => u.warn(e, r, ...n),
631
+ info: (r, ...n) => u.info(e, r, ...n),
632
+ debug: (r, ...n) => u.debug(e, r, ...n),
633
+ trace: (r, ...n) => u.trace(e, r, ...n)
634
+ };
635
+ }
636
+ /**
637
+ * 设置外部 reporter,用于接入自定义观测/上报
638
+ * @param {(entry: any) => void|null} reporter
639
+ */
640
+ static setReporter(e) {
641
+ u.reporter = typeof e == "function" ? e : null;
642
+ }
643
+ };
644
+ L(u, "currentLevel", w.ERROR), // 生产环境默认只显示错误
645
+ L(u, "enabledModules", /* @__PURE__ */ new Set()), // 启用日志的模块
646
+ L(u, "logHistory", []), // 日志历史(最多保留1000条)
647
+ L(u, "maxHistorySize", 1e3), L(u, "prefix", "[QSH-SDK]"), L(u, "reporter", null);
648
+ let S = u;
649
+ if (typeof window != "undefined") {
650
+ const t = window.location && (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1" || window.location.hostname.includes("192.168.")), e = window.location && (window.location.search.includes("debug=true") || window.location.search.includes("qsh_debug=1"));
651
+ let r = !1;
652
+ try {
653
+ r = localStorage && localStorage.getItem("qsh_debug") === "true";
654
+ } catch (n) {
655
+ }
656
+ (t || e || r) && S.enableDevMode();
657
+ }
658
+ const E = S.createModuleLogger("Bridge"), I = S.createModuleLogger("Platform"), a = S.createModuleLogger("API"), M = S.createModuleLogger("State"), We = /complete|loaded|interactive/;
659
+ function Pt(t) {
660
+ return fe() || Ie() ? (E.debug("检测到 APP 环境,开始初始化"), window.__uniapp_x_postMessage || window.__uniapp_x_ || window.__dcloud_weex_postMessage || window.__dcloud_weex_ ? (E.debug("NVUE/UVUE 环境,等待 DOMContentLoaded"), document.addEventListener("DOMContentLoaded", t)) : window.plus && We.test(document.readyState) ? (E.debug("Plus 环境已就绪,立即初始化"), setTimeout(t, 0)) : (E.debug("Plus 环境,等待 plusready 事件"), document.addEventListener("plusready", t)), !0) : !1;
661
+ }
662
+ function Ct(t) {
663
+ return window.wx && window.wx.miniProgram ? (E.debug("检测到微信小程序环境,开始初始化"), window.WeixinJSBridge && window.WeixinJSBridge.invoke ? (E.debug("微信 JSBridge 已就绪,立即初始化"), setTimeout(t, 0)) : (E.debug("微信 JSBridge 未就绪,等待 WeixinJSBridgeReady 事件"), document.addEventListener("WeixinJSBridgeReady", t)), !0) : !1;
664
+ }
665
+ function Mt(t) {
666
+ return E.info("开始初始化 JSBridge"), Pt(t) ? (E.info("使用 APP 环境初始化"), !0) : Ct(t) ? (E.info("使用微信小程序环境初始化"), !0) : (E.debug("使用默认 H5 环境初始化"), We.test(document.readyState) ? (E.debug("DOM 已就绪,立即初始化"), setTimeout(t, 0)) : (E.debug("DOM 未就绪,等待 DOMContentLoaded"), document.addEventListener("DOMContentLoaded", t)), !0);
667
+ }
668
+ function bt() {
669
+ return K.waitForReady();
670
+ }
671
+ function $e() {
672
+ return K.startInitialization(() => m(null, null, function* () {
673
+ return new Promise((t, e) => {
674
+ const r = () => {
675
+ t();
676
+ }, n = (i) => {
677
+ const s = d.handleApiError(i, {
678
+ context: "bridge initialization"
679
+ });
680
+ e(s);
681
+ };
682
+ try {
683
+ Mt(() => {
684
+ r();
685
+ });
686
+ } catch (i) {
687
+ n(i);
688
+ }
689
+ });
690
+ }));
691
+ }
692
+ const R = {
693
+ UNINITIALIZED: "uninitialized",
694
+ CONFIGURING: "configuring",
695
+ CONFIGURED: "configured",
696
+ ERROR: "error"
697
+ };
698
+ class vt {
699
+ constructor() {
700
+ this.state = R.UNINITIALIZED, this.configPromise = null, this.readyCallbacks = [], this.errorCallbacks = [], this.lastError = null, this.CONFIG_API_URL = this.getConfigApiUrl(), this.CLIENT_ID = "bmfw-client", this.DEFAULT_JS_API_LIST = ["chooseImage", "uploadImage", "previewImage", "downloadImage", "getLocalImgData", "scanQRCode", "getLocation", "openLocation", "updateAppMessageShareData", "updateTimelineShareData"], this.handleConfigSuccess = this.handleConfigSuccess.bind(this), this.handleConfigError = this.handleConfigError.bind(this);
701
+ }
702
+ /**
703
+ * 获取配置API的URL(支持开发环境代理)
704
+ * @returns {string} API URL
705
+ * @private
706
+ */
707
+ getConfigApiUrl() {
708
+ return typeof window != "undefined" && (window.location.hostname === "localhost" || window.location.hostname.includes("127.0.0.1") || window.location.hostname.includes("natappfree.cc") || window.location.port === "5174"), "https://unified-platform-service.xjy2.cn/api/wechat/mp/jssdk-sign";
709
+ }
710
+ /**
711
+ * 获取当前页面URL(不包含hash部分)
712
+ * @returns {string} 页面URL
713
+ * @private
714
+ */
715
+ getCurrentPageUrl() {
716
+ if (typeof window == "undefined" || !window.location)
717
+ throw new Error("无法获取当前页面URL");
718
+ const e = window.location.href, r = e.indexOf("#");
719
+ return r !== -1 ? e.substring(0, r) : e;
720
+ }
721
+ /**
722
+ * 获取微信配置
723
+ * @returns {Promise<Object>} 配置对象
724
+ * @private
725
+ */
726
+ fetchWeixinConfig() {
727
+ return m(this, null, function* () {
728
+ const e = this.getCurrentPageUrl();
729
+ if (this.isTestMode())
730
+ return I.info("使用测试模式,返回模拟配置"), this.getMockConfig();
731
+ const r = `${this.CONFIG_API_URL}?clientId=${this.CLIENT_ID}&url=${encodeURIComponent(e)}`;
732
+ I.debug("请求微信配置", { url: r });
733
+ try {
734
+ const n = yield fetch(r);
735
+ if (!n.ok)
736
+ throw new Error(`HTTP ${n.status}: ${n.statusText}`);
737
+ const i = yield n.json();
738
+ if (I.debug("微信配置响应", i), !i.success || i.code !== 200)
739
+ throw new Error(`配置获取失败: ${i.message || "未知错误"}`);
740
+ const { data: s } = i;
741
+ if (!s || !s.appId || !s.timestamp || !s.nonceStr || !s.signature)
742
+ throw new Error("配置数据格式不正确,缺少必需字段");
743
+ return s;
744
+ } catch (n) {
745
+ if (I.error("获取微信配置失败", n), this.shouldUseTestMode(n))
746
+ return I.warn("网络请求失败,降级到测试模式"), this.getMockConfig();
747
+ throw new C(
748
+ U.NETWORK_ERROR,
749
+ `获取微信配置失败: ${n.message}`,
750
+ { url: r, originalError: n }
751
+ );
752
+ }
753
+ });
754
+ }
755
+ /**
756
+ * 检查是否为测试模式
757
+ * @returns {boolean}
758
+ * @private
759
+ */
760
+ isTestMode() {
761
+ if (typeof window == "undefined") return !1;
762
+ if (new URLSearchParams(window.location.search).get("qsh_test") === "true") return !0;
763
+ try {
764
+ if (localStorage.getItem("qsh_test") === "true") return !0;
765
+ } catch (r) {
766
+ }
767
+ return !1;
768
+ }
769
+ /**
770
+ * 检查是否应该降级到测试模式
771
+ * @param {Error} error - 网络错误
772
+ * @returns {boolean}
773
+ * @private
774
+ */
775
+ shouldUseTestMode(e) {
776
+ const r = window.location.hostname === "localhost" || window.location.hostname.includes("natappfree.cc"), n = !window.wx || !window.wx.miniProgram, i = e.message.includes("CORS") || e.message.includes("Failed to fetch");
777
+ return r && n && i;
778
+ }
779
+ /**
780
+ * 获取模拟配置(用于测试)
781
+ * @returns {Object} 模拟的配置对象
782
+ * @private
783
+ */
784
+ getMockConfig() {
785
+ return {
786
+ appId: "wx_test_app_id",
787
+ timestamp: Math.floor(Date.now() / 1e3).toString(),
788
+ nonceStr: Math.random().toString(36).substring(2, 15),
789
+ signature: "test_signature_" + Math.random().toString(36).substring(2, 10)
790
+ };
791
+ }
792
+ /**
793
+ * 执行微信配置
794
+ * @param {Object} configData - 配置数据
795
+ * @private
796
+ */
797
+ executeWeixinConfig(e) {
798
+ if (this.isTestMode() || e.appId === "wx_test_app_id") {
799
+ I.info("测试模式:模拟微信配置成功"), setTimeout(() => {
800
+ this.handleConfigSuccess();
801
+ }, 100);
802
+ return;
803
+ }
804
+ if (!window.wx)
805
+ throw new Error("微信JS-SDK未加载");
806
+ const r = {
807
+ debug: !1,
808
+ // 生产环境关闭调试
809
+ appId: e.appId,
810
+ timestamp: parseInt(e.timestamp),
811
+ nonceStr: e.nonceStr,
812
+ signature: e.signature,
813
+ jsApiList: this.DEFAULT_JS_API_LIST
814
+ };
815
+ I.info("执行微信配置", r), window.wx.ready(this.handleConfigSuccess), window.wx.error(this.handleConfigError), window.wx.config(r);
816
+ }
817
+ /**
818
+ * 处理配置成功
819
+ * @private
820
+ */
821
+ handleConfigSuccess() {
822
+ I.info("微信配置成功"), this.state = R.CONFIGURED, this.readyCallbacks.forEach((e) => {
823
+ try {
824
+ e();
825
+ } catch (r) {
826
+ d.handleApiError(r, { context: "WeixinConfigManager.handleConfigSuccess" });
827
+ }
828
+ }), this.readyCallbacks = [], this.errorCallbacks = [];
829
+ }
830
+ /**
831
+ * 处理配置错误
832
+ * @param {Object} res - 微信返回的错误信息
833
+ * @private
834
+ */
835
+ handleConfigError(e) {
836
+ const r = `微信配置验证失败: ${JSON.stringify(e)}`;
837
+ I.error(r, e), this.state = R.ERROR, this.lastError = new C(
838
+ U.API_CALL_FAILED,
839
+ r,
840
+ { weixinErrorResponse: e }
841
+ ), this.errorCallbacks.forEach((n) => {
842
+ try {
843
+ n(this.lastError);
844
+ } catch (i) {
845
+ d.handleApiError(i, { context: "WeixinConfigManager.handleConfigError" });
846
+ }
847
+ }), this.readyCallbacks = [], this.errorCallbacks = [];
848
+ }
849
+ /**
850
+ * 自动配置微信JS-SDK
851
+ * @returns {Promise<void>} 配置完成的Promise
852
+ */
853
+ autoConfig() {
854
+ return m(this, null, function* () {
855
+ return this.state === R.CONFIGURED ? Promise.resolve() : this.state === R.ERROR ? Promise.reject(this.lastError) : this.configPromise ? this.configPromise : (this.state = R.CONFIGURING, this.configPromise = this.performAutoConfig(), this.configPromise);
856
+ });
857
+ }
858
+ /**
859
+ * 执行自动配置逻辑
860
+ * @returns {Promise<void>}
861
+ * @private
862
+ */
863
+ performAutoConfig() {
864
+ return m(this, null, function* () {
865
+ return d.safeExecuteAsync(() => m(this, null, function* () {
866
+ if (typeof window == "undefined")
867
+ throw new Error("非浏览器环境无法执行微信配置");
868
+ if (!window.wx)
869
+ throw new Error("微信JS-SDK未加载,无法执行配置");
870
+ const e = yield this.fetchWeixinConfig();
871
+ return this.executeWeixinConfig(e), new Promise((r, n) => {
872
+ if (this.state === R.CONFIGURED) {
873
+ r();
874
+ return;
875
+ }
876
+ if (this.state === R.ERROR) {
877
+ n(this.lastError);
878
+ return;
879
+ }
880
+ this.readyCallbacks.push(r), this.errorCallbacks.push(n);
881
+ });
882
+ }), { context: "WeixinConfigManager.performAutoConfig" });
883
+ });
884
+ }
885
+ /**
886
+ * 等待配置完成
887
+ * @returns {Promise<void>} 配置完成的Promise
888
+ */
889
+ waitForReady() {
890
+ return this.state === R.CONFIGURED ? Promise.resolve() : this.state === R.ERROR ? Promise.reject(this.lastError) : this.state === R.UNINITIALIZED ? this.autoConfig() : new Promise((e, r) => {
891
+ this.readyCallbacks.push(e), this.errorCallbacks.push(r);
892
+ });
893
+ }
894
+ /**
895
+ * 检查配置状态
896
+ * @returns {boolean} 是否已配置
897
+ */
898
+ isReady() {
899
+ return this.state === R.CONFIGURED;
900
+ }
901
+ /**
902
+ * 获取当前状态
903
+ * @returns {string} 当前状态
904
+ */
905
+ getState() {
906
+ return this.state;
907
+ }
908
+ /**
909
+ * 获取最后的错误
910
+ * @returns {Error|null} 错误对象
911
+ */
912
+ getLastError() {
913
+ return this.lastError;
914
+ }
915
+ /**
916
+ * 重置配置管理器(用于重试或测试)
917
+ */
918
+ reset() {
919
+ this.state = R.UNINITIALIZED, this.configPromise = null, this.readyCallbacks = [], this.errorCallbacks = [], this.lastError = null, I.debug("微信配置管理器已重置");
920
+ }
921
+ /**
922
+ * 获取配置统计信息
923
+ * @returns {Object} 统计信息
924
+ */
925
+ getStats() {
926
+ return {
927
+ state: this.state,
928
+ readyCallbacksCount: this.readyCallbacks.length,
929
+ errorCallbacksCount: this.errorCallbacks.length,
930
+ hasConfigPromise: !!this.configPromise,
931
+ hasLastError: !!this.lastError,
932
+ configApiUrl: this.CONFIG_API_URL,
933
+ clientId: this.CLIENT_ID,
934
+ jsApiList: this.DEFAULT_JS_API_LIST
935
+ };
936
+ }
937
+ }
938
+ const $ = new vt();
939
+ let q = !1, me = !1, ie = !1;
940
+ function Lt() {
941
+ if (typeof window == "undefined" || me || q || window.wx && window.wx.miniProgram) return !1;
942
+ const t = navigator.userAgent || "", e = /micromessenger/i.test(t), r = /miniProgram/i.test(t), n = typeof window.__wxjs_environment != "undefined" && window.__wxjs_environment === "miniprogram";
943
+ return e && (r || n);
944
+ }
945
+ function we() {
946
+ return m(this, null, function* () {
947
+ if (ie)
948
+ return $.waitForReady();
949
+ ie = !0, I.info("开始自动配置微信JS-SDK");
950
+ try {
951
+ yield $.autoConfig(), I.info("微信JS-SDK自动配置完成");
952
+ } catch (t) {
953
+ I.error("微信JS-SDK自动配置失败", t);
954
+ }
955
+ });
956
+ }
957
+ function Dt() {
958
+ return Lt() ? document.getElementById("weixin-jssdk") ? (q = !1, me = !0, ie ? $.waitForReady() : we()) : new Promise((t) => {
959
+ q = !0;
960
+ try {
961
+ const e = document.createElement("script");
962
+ e.id = "weixin-jssdk", e.type = "text/javascript", e.async = !0, e.src = "https://res.wx.qq.com/open/js/jweixin-1.6.2.js", e.onload = function() {
963
+ return m(this, null, function* () {
964
+ me = !0, q = !1, I.info("微信 JS-SDK 已自动加载");
965
+ try {
966
+ yield we();
967
+ } catch (n) {
968
+ I.error("微信配置失败,将使用消息桥作为后备", n);
969
+ }
970
+ t();
971
+ });
972
+ }, e.onerror = function() {
973
+ q = !1, I.warn("微信 JS-SDK 加载失败,SDK 将使用消息桥作为后备"), t();
974
+ }, (document.getElementsByTagName("head")[0] || document.documentElement).appendChild(e);
975
+ } catch (e) {
976
+ q = !1, I.error("注入微信 JS-SDK 失败", e), t();
977
+ }
978
+ }) : Promise.resolve();
979
+ }
980
+ function k() {
981
+ return $.waitForReady();
982
+ }
983
+ function B() {
984
+ return $.isReady();
985
+ }
986
+ function xt() {
987
+ return $.getState();
988
+ }
989
+ function Ce() {
990
+ return $;
991
+ }
992
+ function Ut() {
993
+ return m(this, null, function* () {
994
+ return I.info("手动重试微信配置"), $.reset(), ie = !1, we();
995
+ });
996
+ }
997
+ class Wt {
998
+ constructor() {
999
+ this.plugins = /* @__PURE__ */ new Map(), this.installed = /* @__PURE__ */ new Set(), this.installOrder = [], a.debug("插件管理器已初始化");
1000
+ }
1001
+ /**
1002
+ * 注册插件
1003
+ * @param {Plugin} plugin - 插件对象
1004
+ * @returns {PluginManager} 返回自身以支持链式调用
1005
+ * @example
1006
+ * pluginManager.register(imagePlugin)
1007
+ */
1008
+ register(e) {
1009
+ return d.safeExecute(() => {
1010
+ this.validatePlugin(e);
1011
+ const { name: r, version: n } = e;
1012
+ if (this.plugins.has(r)) {
1013
+ const i = this.plugins.get(r);
1014
+ a.warn(`插件 ${r} 已注册(版本 ${i.version}),将被覆盖为版本 ${n}`);
1015
+ }
1016
+ return this.plugins.set(r, e), a.info(`插件已注册: ${r}@${n}`), this;
1017
+ }, {
1018
+ context: "PluginManager.register",
1019
+ pluginName: e == null ? void 0 : e.name
1020
+ });
1021
+ }
1022
+ /**
1023
+ * 验证插件对象
1024
+ * @param {Plugin} plugin - 插件对象
1025
+ * @throws {Error} 验证失败时抛出错误
1026
+ * @private
1027
+ */
1028
+ validatePlugin(e) {
1029
+ if (!e || typeof e != "object")
1030
+ throw new Error("插件必须是一个对象");
1031
+ if (!e.name || typeof e.name != "string")
1032
+ throw new Error("插件必须有 name 属性(字符串)");
1033
+ if (!e.version || typeof e.version != "string")
1034
+ throw new Error(`插件 ${e.name} 必须有 version 属性(字符串)`);
1035
+ if (!e.install || typeof e.install != "function")
1036
+ throw new Error(`插件 ${e.name} 必须实现 install 方法`);
1037
+ if (e.dependencies && !Array.isArray(e.dependencies))
1038
+ throw new Error(`插件 ${e.name} 的 dependencies 必须是数组`);
1039
+ }
1040
+ /**
1041
+ * 安装插件到 qsh 实例
1042
+ * @param {string} name - 插件名称
1043
+ * @param {Object} qshInstance - qsh SDK 实例
1044
+ * @returns {Promise<void>}
1045
+ * @example
1046
+ * await pluginManager.install('image', qsh)
1047
+ */
1048
+ install(e, r) {
1049
+ return m(this, null, function* () {
1050
+ return d.safeExecute(() => m(this, null, function* () {
1051
+ if (!this.plugins.has(e))
1052
+ throw new Error(`插件 ${e} 未注册`);
1053
+ if (this.installed.has(e)) {
1054
+ a.debug(`插件 ${e} 已安装,跳过`);
1055
+ return;
1056
+ }
1057
+ const n = this.plugins.get(e);
1058
+ if (n.dependencies && n.dependencies.length > 0) {
1059
+ a.debug(`安装插件 ${e} 的依赖:`, n.dependencies);
1060
+ for (const i of n.dependencies)
1061
+ yield this.install(i, r);
1062
+ }
1063
+ a.info(`开始安装插件: ${e}@${n.version}`), yield n.install(r), this.installed.add(e), this.installOrder.push(e), a.info(`插件安装成功: ${e}@${n.version}`);
1064
+ }), {
1065
+ context: "PluginManager.install",
1066
+ pluginName: e
1067
+ });
1068
+ });
1069
+ }
1070
+ /**
1071
+ * 卸载插件
1072
+ * @param {string} name - 插件名称
1073
+ * @param {Object} qshInstance - qsh SDK 实例
1074
+ * @returns {Promise<void>}
1075
+ * @example
1076
+ * await pluginManager.uninstall('image', qsh)
1077
+ */
1078
+ uninstall(e, r) {
1079
+ return m(this, null, function* () {
1080
+ return d.safeExecute(() => m(this, null, function* () {
1081
+ if (!this.installed.has(e)) {
1082
+ a.debug(`插件 ${e} 未安装,跳过卸载`);
1083
+ return;
1084
+ }
1085
+ const n = this.plugins.get(e);
1086
+ n.uninstall && typeof n.uninstall == "function" && (a.info(`开始卸载插件: ${e}`), yield n.uninstall(r)), this.installed.delete(e);
1087
+ const i = this.installOrder.indexOf(e);
1088
+ i > -1 && this.installOrder.splice(i, 1), a.info(`插件已卸载: ${e}`);
1089
+ }), {
1090
+ context: "PluginManager.uninstall",
1091
+ pluginName: e
1092
+ });
1093
+ });
1094
+ }
1095
+ /**
1096
+ * 卸载所有已安装的插件
1097
+ * @param {Object} qshInstance - qsh SDK 实例
1098
+ * @returns {Promise<void>}
1099
+ */
1100
+ uninstallAll(e) {
1101
+ return m(this, null, function* () {
1102
+ const r = [...this.installOrder].reverse();
1103
+ for (const n of r)
1104
+ yield this.uninstall(n, e);
1105
+ });
1106
+ }
1107
+ /**
1108
+ * 批量注册插件
1109
+ * @param {Plugin[]} plugins - 插件数组
1110
+ * @returns {PluginManager} 返回自身以支持链式调用
1111
+ * @example
1112
+ * pluginManager.registerAll([imagePlugin, locationPlugin])
1113
+ */
1114
+ registerAll(e) {
1115
+ if (!Array.isArray(e))
1116
+ throw new Error("plugins 必须是数组");
1117
+ return e.forEach((r) => this.register(r)), this;
1118
+ }
1119
+ /**
1120
+ * 批量安装插件
1121
+ * @param {string[]} names - 插件名称数组
1122
+ * @param {Object} qshInstance - qsh SDK 实例
1123
+ * @returns {Promise<void>}
1124
+ * @example
1125
+ * await pluginManager.installAll(['image', 'location'], qsh)
1126
+ */
1127
+ installAll(e, r) {
1128
+ return m(this, null, function* () {
1129
+ if (!Array.isArray(e))
1130
+ throw new Error("names 必须是数组");
1131
+ for (const n of e)
1132
+ yield this.install(n, r);
1133
+ });
1134
+ }
1135
+ /**
1136
+ * 检查插件是否已注册
1137
+ * @param {string} name - 插件名称
1138
+ * @returns {boolean}
1139
+ */
1140
+ isRegistered(e) {
1141
+ return this.plugins.has(e);
1142
+ }
1143
+ /**
1144
+ * 检查插件是否已安装
1145
+ * @param {string} name - 插件名称
1146
+ * @returns {boolean}
1147
+ */
1148
+ isInstalled(e) {
1149
+ return this.installed.has(e);
1150
+ }
1151
+ /**
1152
+ * 获取插件信息
1153
+ * @param {string} name - 插件名称
1154
+ * @returns {Plugin|undefined}
1155
+ */
1156
+ getPlugin(e) {
1157
+ return this.plugins.get(e);
1158
+ }
1159
+ /**
1160
+ * 获取所有已注册的插件列表
1161
+ * @returns {Array<{name: string, version: string, installed: boolean}>}
1162
+ */
1163
+ getPluginList() {
1164
+ return Array.from(this.plugins.entries()).map(([e, r]) => ({
1165
+ name: e,
1166
+ version: r.version,
1167
+ installed: this.installed.has(e),
1168
+ dependencies: r.dependencies || []
1169
+ }));
1170
+ }
1171
+ /**
1172
+ * 获取统计信息
1173
+ * @returns {Object}
1174
+ */
1175
+ getStats() {
1176
+ return {
1177
+ registered: this.plugins.size,
1178
+ installed: this.installed.size,
1179
+ plugins: this.getPluginList()
1180
+ };
1181
+ }
1182
+ /**
1183
+ * 清空所有插件(仅用于测试)
1184
+ * @private
1185
+ */
1186
+ clear() {
1187
+ this.plugins.clear(), this.installed.clear(), this.installOrder = [];
1188
+ }
1189
+ }
1190
+ const X = new Wt();
1191
+ class $t {
1192
+ constructor() {
1193
+ this.requestInterceptors = [], this.responseInterceptors = [], a.debug("拦截器链已初始化");
1194
+ }
1195
+ /**
1196
+ * 注册请求拦截器
1197
+ * @param {InterceptorFunction} interceptor - 拦截器函数
1198
+ * @param {Object} [options] - 选项
1199
+ * @param {number} [options.priority=0] - 优先级(数字越大越先执行)
1200
+ * @returns {Function} 移除拦截器的函数
1201
+ * @example
1202
+ * const unregister = chain.useRequest(async (ctx) => {
1203
+ * console.log('API 调用:', ctx.apiName)
1204
+ * return ctx
1205
+ * })
1206
+ */
1207
+ useRequest(e, r = {}) {
1208
+ if (typeof e != "function")
1209
+ throw new Error("拦截器必须是函数");
1210
+ const { priority: n = 0 } = r;
1211
+ return this.requestInterceptors.push({
1212
+ fn: e,
1213
+ priority: n
1214
+ }), this.requestInterceptors.sort((i, s) => s.priority - i.priority), a.debug("请求拦截器已注册", { priority: n }), () => {
1215
+ const i = this.requestInterceptors.findIndex((s) => s.fn === e);
1216
+ i > -1 && (this.requestInterceptors.splice(i, 1), a.debug("请求拦截器已移除"));
1217
+ };
1218
+ }
1219
+ /**
1220
+ * 注册响应拦截器
1221
+ * @param {Function} interceptor - 拦截器函数 (result, context) => result
1222
+ * @param {Object} [options] - 选项
1223
+ * @param {number} [options.priority=0] - 优先级(数字越大越先执行)
1224
+ * @returns {Function} 移除拦截器的函数
1225
+ * @example
1226
+ * const unregister = chain.useResponse(async (result, ctx) => {
1227
+ * console.log('API 完成:', ctx.apiName)
1228
+ * return result
1229
+ * })
1230
+ */
1231
+ useResponse(e, r = {}) {
1232
+ if (typeof e != "function")
1233
+ throw new Error("拦截器必须是函数");
1234
+ const { priority: n = 0 } = r;
1235
+ return this.responseInterceptors.push({
1236
+ fn: e,
1237
+ priority: n
1238
+ }), this.responseInterceptors.sort((i, s) => s.priority - i.priority), a.debug("响应拦截器已注册", { priority: n }), () => {
1239
+ const i = this.responseInterceptors.findIndex((s) => s.fn === e);
1240
+ i > -1 && (this.responseInterceptors.splice(i, 1), a.debug("响应拦截器已移除"));
1241
+ };
1242
+ }
1243
+ /**
1244
+ * 执行请求拦截链
1245
+ * @param {InterceptorContext} context - 上下文
1246
+ * @returns {Promise<InterceptorContext>}
1247
+ * @private
1248
+ */
1249
+ runRequest(e) {
1250
+ return m(this, null, function* () {
1251
+ let r = h({}, e);
1252
+ for (const { fn: n } of this.requestInterceptors) {
1253
+ if (r.abort) {
1254
+ a.debug("请求被中止", { apiName: r.apiName });
1255
+ break;
1256
+ }
1257
+ try {
1258
+ const i = yield n(r);
1259
+ i && (r = i);
1260
+ } catch (i) {
1261
+ a.error("请求拦截器执行失败", i), r.abort = !0, r.error = i;
1262
+ break;
1263
+ }
1264
+ }
1265
+ return r;
1266
+ });
1267
+ }
1268
+ /**
1269
+ * 执行响应拦截链
1270
+ * @param {any} result - 响应结果
1271
+ * @param {InterceptorContext} context - 上下文
1272
+ * @returns {Promise<any>}
1273
+ * @private
1274
+ */
1275
+ runResponse(e, r) {
1276
+ return m(this, null, function* () {
1277
+ let n = e;
1278
+ for (const { fn: i } of this.responseInterceptors)
1279
+ try {
1280
+ const s = yield i(n, r);
1281
+ s !== void 0 && (n = s);
1282
+ } catch (s) {
1283
+ a.error("响应拦截器执行失败", s);
1284
+ }
1285
+ return n;
1286
+ });
1287
+ }
1288
+ /**
1289
+ * 清空所有拦截器
1290
+ */
1291
+ clear() {
1292
+ this.requestInterceptors = [], this.responseInterceptors = [], a.debug("所有拦截器已清空");
1293
+ }
1294
+ /**
1295
+ * 获取统计信息
1296
+ * @returns {Object}
1297
+ */
1298
+ getStats() {
1299
+ return {
1300
+ requestInterceptors: this.requestInterceptors.length,
1301
+ responseInterceptors: this.responseInterceptors.length
1302
+ };
1303
+ }
1304
+ }
1305
+ const F = new $t(), kt = {
1306
+ /**
1307
+ * 请求日志
1308
+ */
1309
+ request: (t) => (t.startTime = Date.now(), a.debug(`[API 调用] ${t.apiName}`, {
1310
+ params: t.params
1311
+ }), t),
1312
+ /**
1313
+ * 响应日志
1314
+ */
1315
+ response: (t, e) => {
1316
+ const r = Date.now() - e.startTime;
1317
+ return a.debug(`[API 完成] ${e.apiName}`, {
1318
+ duration: `${r}ms`,
1319
+ success: t == null ? void 0 : t.success
1320
+ }), t;
1321
+ }
1322
+ }, W = {
1323
+ // 性能数据存储
1324
+ metrics: /* @__PURE__ */ new Map(),
1325
+ /**
1326
+ * 记录开始时间
1327
+ */
1328
+ request: (t) => (t.perfStartTime = performance.now(), t),
1329
+ /**
1330
+ * 记录性能数据
1331
+ */
1332
+ response: (t, e) => {
1333
+ const r = performance.now() - e.perfStartTime;
1334
+ W.metrics.has(e.apiName) || W.metrics.set(e.apiName, {
1335
+ count: 0,
1336
+ totalTime: 0,
1337
+ minTime: 1 / 0,
1338
+ maxTime: 0,
1339
+ avgTime: 0
1340
+ });
1341
+ const n = W.metrics.get(e.apiName);
1342
+ return n.count++, n.totalTime += r, n.minTime = Math.min(n.minTime, r), n.maxTime = Math.max(n.maxTime, r), n.avgTime = n.totalTime / n.count, t;
1343
+ },
1344
+ /**
1345
+ * 获取性能报告
1346
+ */
1347
+ getReport: () => {
1348
+ const t = {};
1349
+ return W.metrics.forEach((e, r) => {
1350
+ t[r] = h({}, e);
1351
+ }), t;
1352
+ },
1353
+ /**
1354
+ * 清空性能数据
1355
+ */
1356
+ clearMetrics: () => {
1357
+ W.metrics.clear();
1358
+ }
1359
+ };
1360
+ function Bt(t = {}) {
1361
+ const {
1362
+ maxRetries: e = 3,
1363
+ retryDelay: r = 1e3,
1364
+ shouldRetry: n = (i) => !i.success
1365
+ } = t;
1366
+ return {
1367
+ response: (i, s) => m(null, null, function* () {
1368
+ return s.retryCount || (s.retryCount = 0), n(i) && s.retryCount < e && (s.retryCount++, a.warn(`API 调用失败,第 ${s.retryCount} 次重试: ${s.apiName}`), yield new Promise((f) => setTimeout(f, r)), i.shouldRetry = !0, i.retryContext = s), i;
1369
+ })
1370
+ };
1371
+ }
1372
+ function Ft(t = {}) {
1373
+ return {
1374
+ request: (e) => {
1375
+ const r = t[e.apiName];
1376
+ if (r && typeof r == "function") {
1377
+ const n = r(e.params);
1378
+ n && (a.error(`参数验证失败: ${e.apiName}`, n), e.abort = !0, e.validationError = n);
1379
+ }
1380
+ return e;
1381
+ }
1382
+ };
1383
+ }
1384
+ class Kt {
1385
+ constructor() {
1386
+ this.state = {
1387
+ // SDK 状态
1388
+ sdk: {
1389
+ status: "uninitialized",
1390
+ // 'uninitialized' | 'initializing' | 'ready' | 'error'
1391
+ version: "2.0.5",
1392
+ error: null
1393
+ },
1394
+ // 平台信息
1395
+ platform: {
1396
+ type: g.type,
1397
+ isWeixinMiniProgram: g.isWeixinMiniProgram,
1398
+ isAppPlus: g.isAppPlus,
1399
+ isNvue: g.isNvue,
1400
+ isUvue: g.isUvue,
1401
+ features: {}
1402
+ // 平台支持的特性
1403
+ },
1404
+ // 微信配置状态
1405
+ weixin: {
1406
+ configStatus: "pending",
1407
+ // 'pending' | 'configuring' | 'configured' | 'failed'
1408
+ jsApiList: [],
1409
+ configError: null
1410
+ },
1411
+ // 网络状态
1412
+ network: {
1413
+ online: typeof navigator != "undefined" ? navigator.onLine : !0,
1414
+ type: "unknown"
1415
+ // 'wifi' | '4g' | '3g' | '2g' | 'unknown'
1416
+ },
1417
+ // 权限状态
1418
+ permissions: {
1419
+ camera: "prompt",
1420
+ // 'granted' | 'denied' | 'prompt'
1421
+ location: "prompt",
1422
+ album: "prompt"
1423
+ },
1424
+ // API 调用状态
1425
+ api: {
1426
+ // 格式: { apiName: { loading: boolean, lastCall: timestamp, lastResult: any } }
1427
+ }
1428
+ }, this.listeners = /* @__PURE__ */ new Map(), this.wildcardListeners = /* @__PURE__ */ new Set(), this.initNetworkListener(), M.debug("状态仓库已初始化");
1429
+ }
1430
+ /**
1431
+ * 获取状态值
1432
+ * @param {string} path - 状态路径(用 . 分隔)
1433
+ * @returns {any} 状态值
1434
+ * @example
1435
+ * store.get('sdk.status') // 'ready'
1436
+ * store.get('platform') // { type: 'weixin', ... }
1437
+ */
1438
+ get(e) {
1439
+ return e.split(".").reduce((n, i) => n != null ? n[i] : void 0, this.state);
1440
+ }
1441
+ /**
1442
+ * 设置状态值
1443
+ * @param {string} path - 状态路径
1444
+ * @param {any} value - 新值
1445
+ * @example
1446
+ * store.set('sdk.status', 'ready')
1447
+ * store.set('network.online', false)
1448
+ */
1449
+ set(e, r) {
1450
+ const n = e.split("."), i = n.pop(), s = n.reduce((l, c) => ((!l[c] || typeof l[c] != "object") && (l[c] = {}), l[c]), this.state), f = s[i];
1451
+ f !== r && (s[i] = r, M.debug(`状态已更新: ${e}`, { oldValue: f, newValue: r }), this.notify(e, r, f));
1452
+ }
1453
+ /**
1454
+ * 批量更新状态
1455
+ * @param {Object} updates - 更新对象 { path: value }
1456
+ * @example
1457
+ * store.batchUpdate({
1458
+ * 'sdk.status': 'ready',
1459
+ * 'network.online': true
1460
+ * })
1461
+ */
1462
+ batchUpdate(e) {
1463
+ Object.entries(e).forEach(([r, n]) => {
1464
+ this.set(r, n);
1465
+ });
1466
+ }
1467
+ /**
1468
+ * 订阅状态变化
1469
+ * @param {string} path - 状态路径(支持通配符 * )
1470
+ * @param {Function} listener - 监听函数 (newValue, oldValue, path) => void
1471
+ * @returns {Function} 取消订阅的函数
1472
+ * @example
1473
+ * const unsubscribe = store.subscribe('network.online', (online) => {
1474
+ * console.log('网络状态:', online)
1475
+ * })
1476
+ * // 取消订阅
1477
+ * unsubscribe()
1478
+ */
1479
+ subscribe(e, r) {
1480
+ if (typeof r != "function")
1481
+ throw new Error("listener 必须是函数");
1482
+ return e === "*" ? (this.wildcardListeners.add(r), M.debug("添加通配符订阅者"), () => {
1483
+ this.wildcardListeners.delete(r), M.debug("移除通配符订阅者");
1484
+ }) : (this.listeners.has(e) || this.listeners.set(e, /* @__PURE__ */ new Set()), this.listeners.get(e).add(r), M.debug(`添加订阅者: ${e}`), () => {
1485
+ const n = this.listeners.get(e);
1486
+ n && (n.delete(r), n.size === 0 && this.listeners.delete(e), M.debug(`移除订阅者: ${e}`));
1487
+ });
1488
+ }
1489
+ /**
1490
+ * 订阅一次(只触发一次后自动取消)
1491
+ * @param {string} path - 状态路径
1492
+ * @param {Function} listener - 监听函数
1493
+ * @returns {Function} 取消订阅的函数
1494
+ */
1495
+ subscribeOnce(e, r) {
1496
+ const n = this.subscribe(e, (i, s, f) => {
1497
+ r(i, s, f), n();
1498
+ });
1499
+ return n;
1500
+ }
1501
+ /**
1502
+ * 通知订阅者
1503
+ * @param {string} path - 状态路径
1504
+ * @param {any} newValue - 新值
1505
+ * @param {any} oldValue - 旧值
1506
+ * @private
1507
+ */
1508
+ notify(e, r, n) {
1509
+ const i = this.listeners.get(e);
1510
+ i && i.forEach((f) => {
1511
+ try {
1512
+ f(r, n, e);
1513
+ } catch (l) {
1514
+ M.error("订阅者执行失败", l);
1515
+ }
1516
+ });
1517
+ const s = e.split(".");
1518
+ for (let f = 1; f < s.length; f++) {
1519
+ const l = s.slice(0, f).join("."), c = this.listeners.get(l);
1520
+ if (c) {
1521
+ const p = this.get(l);
1522
+ c.forEach((P) => {
1523
+ try {
1524
+ P(p, void 0, l);
1525
+ } catch (N) {
1526
+ M.error("父路径订阅者执行失败", N);
1527
+ }
1528
+ });
1529
+ }
1530
+ }
1531
+ this.wildcardListeners.forEach((f) => {
1532
+ try {
1533
+ f(r, n, e);
1534
+ } catch (l) {
1535
+ M.error("通配符订阅者执行失败", l);
1536
+ }
1537
+ });
1538
+ }
1539
+ /**
1540
+ * 初始化网络状态监听
1541
+ * @private
1542
+ */
1543
+ initNetworkListener() {
1544
+ if (typeof window != "undefined" && (window.addEventListener("online", () => {
1545
+ this.set("network.online", !0);
1546
+ }), window.addEventListener("offline", () => {
1547
+ this.set("network.online", !1);
1548
+ }), navigator.connection)) {
1549
+ const e = navigator.connection, r = () => {
1550
+ this.set("network.type", e.effectiveType || "unknown");
1551
+ };
1552
+ e.addEventListener("change", r), r();
1553
+ }
1554
+ }
1555
+ /**
1556
+ * 记录 API 调用开始
1557
+ * @param {string} apiName - API 名称
1558
+ */
1559
+ setApiLoading(e, r = !0) {
1560
+ const n = `api.${e}`, i = this.get(n) || {};
1561
+ this.set(n, A(h({}, i), {
1562
+ loading: r,
1563
+ lastCall: r ? Date.now() : i.lastCall
1564
+ }));
1565
+ }
1566
+ /**
1567
+ * 记录 API 调用结果
1568
+ * @param {string} apiName - API 名称
1569
+ * @param {any} result - 结果
1570
+ */
1571
+ setApiResult(e, r) {
1572
+ const n = `api.${e}`, i = this.get(n) || {};
1573
+ this.set(n, A(h({}, i), {
1574
+ loading: !1,
1575
+ lastResult: r,
1576
+ lastCallEnd: Date.now()
1577
+ }));
1578
+ }
1579
+ /**
1580
+ * 获取完整状态快照
1581
+ * @returns {Object} 状态快照
1582
+ */
1583
+ getSnapshot() {
1584
+ return JSON.parse(JSON.stringify(this.state));
1585
+ }
1586
+ /**
1587
+ * 重置状态(用于测试)
1588
+ * @private
1589
+ */
1590
+ reset() {
1591
+ const { platform: e } = this.state;
1592
+ this.state = {
1593
+ sdk: {
1594
+ status: "uninitialized",
1595
+ version: "2.0.5",
1596
+ error: null
1597
+ },
1598
+ platform: e,
1599
+ weixin: {
1600
+ configStatus: "pending",
1601
+ jsApiList: [],
1602
+ configError: null
1603
+ },
1604
+ network: {
1605
+ online: typeof navigator != "undefined" ? navigator.onLine : !0,
1606
+ type: "unknown"
1607
+ },
1608
+ permissions: {
1609
+ camera: "prompt",
1610
+ location: "prompt",
1611
+ album: "prompt"
1612
+ },
1613
+ api: {}
1614
+ }, M.debug("状态已重置");
1615
+ }
1616
+ /**
1617
+ * 获取统计信息
1618
+ * @returns {Object}
1619
+ */
1620
+ getStats() {
1621
+ return {
1622
+ listeners: this.listeners.size,
1623
+ wildcardListeners: this.wildcardListeners.size,
1624
+ apiStates: Object.keys(this.state.api).length
1625
+ };
1626
+ }
1627
+ }
1628
+ const D = new Kt(), o = {
1629
+ // SDK 核心错误 (E_SDK_xxx)
1630
+ SDK_NOT_READY: "E_SDK_001",
1631
+ SDK_INIT_FAILED: "E_SDK_002",
1632
+ SDK_CONFIG_FAILED: "E_SDK_003",
1633
+ PLATFORM_NOT_SUPPORTED: "E_SDK_004",
1634
+ // 网络错误 (E_NET_xxx)
1635
+ NETWORK_ERROR: "E_NET_001",
1636
+ NETWORK_TIMEOUT: "E_NET_002",
1637
+ NETWORK_OFFLINE: "E_NET_003",
1638
+ // 图片错误 (E_IMG_xxx)
1639
+ IMAGE_CANCELLED: "E_IMG_001",
1640
+ // 用户取消
1641
+ IMAGE_NO_PERMISSION: "E_IMG_002",
1642
+ // 无权限
1643
+ IMAGE_SIZE_EXCEED: "E_IMG_003",
1644
+ // 图片过大
1645
+ IMAGE_COUNT_EXCEED: "E_IMG_004",
1646
+ // 数量超限
1647
+ IMAGE_FORMAT_ERROR: "E_IMG_005",
1648
+ // 格式错误
1649
+ IMAGE_CONFIG_NOT_READY: "E_IMG_006",
1650
+ // 配置未完成
1651
+ // 定位错误 (E_LOC_xxx)
1652
+ LOCATION_CANCELLED: "E_LOC_001",
1653
+ LOCATION_NO_PERMISSION: "E_LOC_002",
1654
+ LOCATION_UNAVAILABLE: "E_LOC_003",
1655
+ LOCATION_TIMEOUT: "E_LOC_004",
1656
+ // 扫码错误 (E_SCAN_xxx)
1657
+ SCAN_CANCELLED: "E_SCAN_001",
1658
+ // 用户取消
1659
+ SCAN_NO_PERMISSION: "E_SCAN_002",
1660
+ // 无相机权限
1661
+ SCAN_INVALID_CODE: "E_SCAN_003",
1662
+ // 无效的码
1663
+ SCAN_CONFIG_NOT_READY: "E_SCAN_004",
1664
+ // 配置未完成
1665
+ // 权限错误 (E_PERM_xxx)
1666
+ PERMISSION_DENIED: "E_PERM_001",
1667
+ PERMISSION_CAMERA: "E_PERM_002",
1668
+ PERMISSION_LOCATION: "E_PERM_003",
1669
+ PERMISSION_ALBUM: "E_PERM_004",
1670
+ PERMISSION_MICROPHONE: "E_PERM_005",
1671
+ // 参数错误 (E_PARAM_xxx)
1672
+ PARAM_INVALID: "E_PARAM_001",
1673
+ PARAM_MISSING: "E_PARAM_002",
1674
+ PARAM_TYPE_ERROR: "E_PARAM_003",
1675
+ // 超时错误 (E_TIMEOUT_xxx)
1676
+ API_TIMEOUT: "E_TIMEOUT_001",
1677
+ // 通用错误
1678
+ UNKNOWN_ERROR: "E_UNKNOWN_999"
1679
+ }, Ee = {
1680
+ // SDK 核心
1681
+ [o.SDK_NOT_READY]: "SDK 未就绪",
1682
+ [o.SDK_INIT_FAILED]: "SDK 初始化失败",
1683
+ [o.SDK_CONFIG_FAILED]: "SDK 配置失败",
1684
+ [o.PLATFORM_NOT_SUPPORTED]: "当前平台不支持此功能",
1685
+ // 网络
1686
+ [o.NETWORK_ERROR]: "网络错误",
1687
+ [o.NETWORK_TIMEOUT]: "网络超时",
1688
+ [o.NETWORK_OFFLINE]: "网络已断开",
1689
+ // 图片
1690
+ [o.IMAGE_CANCELLED]: "用户取消选择图片",
1691
+ [o.IMAGE_NO_PERMISSION]: "无相机/相册权限",
1692
+ [o.IMAGE_SIZE_EXCEED]: "图片大小超出限制",
1693
+ [o.IMAGE_COUNT_EXCEED]: "图片数量超出限制",
1694
+ [o.IMAGE_FORMAT_ERROR]: "图片格式不支持",
1695
+ [o.IMAGE_CONFIG_NOT_READY]: "微信配置未完成",
1696
+ // 定位
1697
+ [o.LOCATION_CANCELLED]: "用户取消定位",
1698
+ [o.LOCATION_NO_PERMISSION]: "无定位权限",
1699
+ [o.LOCATION_UNAVAILABLE]: "定位服务不可用",
1700
+ [o.LOCATION_TIMEOUT]: "定位超时",
1701
+ // 扫码
1702
+ [o.SCAN_CANCELLED]: "用户取消扫码",
1703
+ [o.SCAN_NO_PERMISSION]: "无相机权限",
1704
+ [o.SCAN_INVALID_CODE]: "无效的二维码/条形码",
1705
+ [o.SCAN_CONFIG_NOT_READY]: "微信配置未完成",
1706
+ // 权限
1707
+ [o.PERMISSION_DENIED]: "权限被拒绝",
1708
+ [o.PERMISSION_CAMERA]: "无相机权限",
1709
+ [o.PERMISSION_LOCATION]: "无定位权限",
1710
+ [o.PERMISSION_ALBUM]: "无相册权限",
1711
+ [o.PERMISSION_MICROPHONE]: "无麦克风权限",
1712
+ // 参数
1713
+ [o.PARAM_INVALID]: "参数无效",
1714
+ [o.PARAM_MISSING]: "缺少必需参数",
1715
+ [o.PARAM_TYPE_ERROR]: "参数类型错误",
1716
+ // 超时
1717
+ [o.API_TIMEOUT]: "API 调用超时",
1718
+ // 通用
1719
+ [o.UNKNOWN_ERROR]: "未知错误"
1720
+ }, b = {
1721
+ USER_CANCEL: "user_cancel",
1722
+ // 用户主动取消
1723
+ PERMISSION: "permission",
1724
+ // 权限问题
1725
+ NETWORK: "network",
1726
+ // 网络问题
1727
+ PARAM: "param",
1728
+ // 参数问题
1729
+ SYSTEM: "system",
1730
+ // 系统问题
1731
+ CONFIG: "config",
1732
+ // 配置问题
1733
+ UNKNOWN: "unknown"
1734
+ // 未知问题
1735
+ }, zt = {
1736
+ // 图片相关
1737
+ "IMAGE/USER_CANCEL": o.IMAGE_CANCELLED,
1738
+ "IMAGE/PERMISSION_DENIED": o.IMAGE_NO_PERMISSION,
1739
+ // 通用错误
1740
+ "COMMON/UNKNOWN": o.UNKNOWN_ERROR,
1741
+ "COMMON/CONFIG_NOT_READY": o.IMAGE_CONFIG_NOT_READY,
1742
+ "COMMON/PLATFORM_NOT_SUPPORTED": o.PLATFORM_NOT_SUPPORTED
1743
+ }, Me = {
1744
+ // 微信平台错误模式
1745
+ weixin: {
1746
+ patterns: [
1747
+ { pattern: /cancel/i, code: o.IMAGE_CANCELLED },
1748
+ { pattern: /permission|auth\s*deny/i, code: o.IMAGE_NO_PERMISSION },
1749
+ { pattern: /config/i, code: o.IMAGE_CONFIG_NOT_READY },
1750
+ { pattern: /timeout/i, code: o.API_TIMEOUT },
1751
+ { pattern: /network/i, code: o.NETWORK_ERROR }
1752
+ ],
1753
+ default: o.UNKNOWN_ERROR
1754
+ },
1755
+ // UniApp 平台错误模式
1756
+ uniapp: {
1757
+ patterns: [
1758
+ { pattern: /cancel/i, code: o.IMAGE_CANCELLED },
1759
+ { pattern: /permission|denied/i, code: o.IMAGE_NO_PERMISSION },
1760
+ { pattern: /timeout/i, code: o.API_TIMEOUT },
1761
+ { pattern: /network/i, code: o.NETWORK_ERROR },
1762
+ { pattern: /not_in_container/i, code: o.PLATFORM_NOT_SUPPORTED }
1763
+ ],
1764
+ default: o.UNKNOWN_ERROR
1765
+ }
1766
+ }, be = {
1767
+ chooseImage: {
1768
+ "fail cancel": o.IMAGE_CANCELLED,
1769
+ "fail auth deny": o.IMAGE_NO_PERMISSION,
1770
+ "fail No Permission": o.IMAGE_NO_PERMISSION,
1771
+ NOT_IN_CONTAINER: o.PLATFORM_NOT_SUPPORTED
1772
+ },
1773
+ scanCode: {
1774
+ "fail cancel": o.SCAN_CANCELLED,
1775
+ "fail auth deny": o.SCAN_NO_PERMISSION,
1776
+ "fail No Permission": o.SCAN_NO_PERMISSION,
1777
+ NOT_IN_CONTAINER: o.PLATFORM_NOT_SUPPORTED
1778
+ }
1779
+ };
1780
+ function ke(t) {
1781
+ return t ? t.includes("CANCEL") ? b.USER_CANCEL : t.includes("PERM") || t.includes("PERMISSION") ? b.PERMISSION : t.includes("NET") || t.includes("NETWORK") ? b.NETWORK : t.includes("PARAM") ? b.PARAM : t.includes("CONFIG") ? b.CONFIG : t.includes("SDK") || t.includes("PLATFORM") ? b.SYSTEM : b.UNKNOWN : b.UNKNOWN;
1782
+ }
1783
+ function Gt(t) {
1784
+ return t.includes("NET_") || t.includes("TIMEOUT") || t === o.NETWORK_ERROR || t === o.NETWORK_TIMEOUT || t === o.API_TIMEOUT;
1785
+ }
1786
+ function Vt(t) {
1787
+ return t.includes("CANCEL") || ke(t) === b.USER_CANCEL;
1788
+ }
1789
+ function J(t) {
1790
+ return Ee[t] || Ee[o.UNKNOWN_ERROR];
1791
+ }
1792
+ class x extends Error {
1793
+ /**
1794
+ * 构造函数
1795
+ * @param {string} code - 错误码
1796
+ * @param {string} message - 错误消息
1797
+ * @param {Object} options - 选项
1798
+ */
1799
+ constructor(e, r, n = {}) {
1800
+ super(r), this.name = "StandardError", this.code = e, this.message = r || J(e), this.platform = n.platform || g.type, this.apiName = n.apiName, this.category = n.category || ke(e), this.retriable = n.retriable !== void 0 ? n.retriable : Gt(e), this.originalError = n.originalError, this.details = n.details || {}, this.timestamp = Date.now();
1801
+ }
1802
+ /**
1803
+ * 是否可重试
1804
+ * @returns {boolean}
1805
+ */
1806
+ isRetriable() {
1807
+ return this.retriable;
1808
+ }
1809
+ /**
1810
+ * 是否用户主动操作(不需要提示)
1811
+ * @returns {boolean}
1812
+ */
1813
+ isUserAction() {
1814
+ return Vt(this.code);
1815
+ }
1816
+ /**
1817
+ * 转为普通对象
1818
+ * @returns {Object}
1819
+ */
1820
+ toJSON() {
1821
+ return h({
1822
+ code: this.code,
1823
+ message: this.message,
1824
+ platform: this.platform,
1825
+ apiName: this.apiName,
1826
+ category: this.category,
1827
+ retriable: this.retriable,
1828
+ timestamp: this.timestamp,
1829
+ details: this.details
1830
+ }, process.env.NODE_ENV !== "production" && this.originalError ? {
1831
+ originalError: this.originalError
1832
+ } : {});
1833
+ }
1834
+ }
1835
+ function Be(t, e = {}) {
1836
+ if (t instanceof x)
1837
+ return t;
1838
+ const { apiName: r, platform: n = g.type } = e;
1839
+ return t && typeof t.code == "string" && t.code.includes("/") ? jt(t, { apiName: r, platform: n }) : t && (t.errMsg || t.message) ? qt(t, { apiName: r, platform: n }) : typeof t == "string" ? new x(
1840
+ o.UNKNOWN_ERROR,
1841
+ t,
1842
+ { apiName: r, platform: n, originalError: t }
1843
+ ) : new x(
1844
+ o.UNKNOWN_ERROR,
1845
+ "未知错误",
1846
+ {
1847
+ apiName: r,
1848
+ platform: n,
1849
+ originalError: t,
1850
+ details: { errorType: typeof t }
1851
+ }
1852
+ );
1853
+ }
1854
+ function jt(t, e) {
1855
+ const { apiName: r, platform: n } = e, i = t.code, s = zt[i] || o.UNKNOWN_ERROR;
1856
+ return a.debug("转换旧版错误码", {
1857
+ legacy: i,
1858
+ new: s
1859
+ }), new x(
1860
+ s,
1861
+ t.message || J(s),
1862
+ {
1863
+ apiName: r,
1864
+ platform: t.platform || n,
1865
+ originalError: t,
1866
+ details: h({
1867
+ legacyCode: i,
1868
+ legacyVersion: t.version
1869
+ }, t.details)
1870
+ }
1871
+ );
1872
+ }
1873
+ function qt(t, e) {
1874
+ const { apiName: r, platform: n } = e, i = (t.errMsg || t.message || "").toLowerCase();
1875
+ if (r && be[r]) {
1876
+ const l = be[r];
1877
+ for (const [c, p] of Object.entries(l))
1878
+ if (i.includes(c.toLowerCase()))
1879
+ return new x(p, J(p), {
1880
+ apiName: r,
1881
+ platform: n,
1882
+ originalError: t
1883
+ });
1884
+ }
1885
+ const s = Me[n] || Me.uniapp;
1886
+ for (const { pattern: l, code: c } of s.patterns)
1887
+ if (l.test(i))
1888
+ return new x(c, J(c), {
1889
+ apiName: r,
1890
+ platform: n,
1891
+ originalError: t
1892
+ });
1893
+ const f = s.default || o.UNKNOWN_ERROR;
1894
+ return new x(
1895
+ f,
1896
+ t.errMsg || t.message || J(f),
1897
+ {
1898
+ apiName: r,
1899
+ platform: n,
1900
+ originalError: t
1901
+ }
1902
+ );
1903
+ }
1904
+ const Fe = {
1905
+ /**
1906
+ * 响应拦截器
1907
+ * @param {Object} result - API 响应结果
1908
+ * @param {Object} ctx - 拦截器上下文
1909
+ * @returns {Object} 处理后的结果
1910
+ */
1911
+ response: (t, e) => {
1912
+ if (!t.success && t.error) {
1913
+ const r = Be(t.error, {
1914
+ apiName: e.apiName,
1915
+ platform: g.type
1916
+ });
1917
+ t.error = r.toJSON(), t.errorCode = r.code, t.errorCategory = r.category, t.retriable = r.isRetriable(), a.debug("错误已标准化", {
1918
+ api: e.apiName,
1919
+ code: r.code,
1920
+ category: r.category
1921
+ });
1922
+ }
1923
+ return t;
1924
+ }
1925
+ };
1926
+ function Jt(t, e = {}) {
1927
+ return new x(t, J(t), e);
1928
+ }
1929
+ function Ht(t) {
1930
+ return t instanceof x;
1931
+ }
1932
+ function Yt(t, e, r) {
1933
+ return e ? Promise.race([
1934
+ t(),
1935
+ new Promise((n, i) => setTimeout(() => i(new Error(`Init task timeout: ${r}`)), e))
1936
+ ]) : t();
1937
+ }
1938
+ function Xt() {
1939
+ return m(this, arguments, function* (t = [], e = {}) {
1940
+ for (const r of t) {
1941
+ const n = (r == null ? void 0 : r.name) || "anonymous-task", i = (r == null ? void 0 : r.run) || r;
1942
+ if (typeof i == "function")
1943
+ try {
1944
+ yield Yt(() => Promise.resolve().then(() => i()), r.timeoutMs, n), typeof r.onSuccess == "function" && r.onSuccess();
1945
+ } catch (s) {
1946
+ if (typeof r.onError == "function" && r.onError(s), typeof e.onError == "function")
1947
+ e.onError(s, r);
1948
+ else
1949
+ throw s;
1950
+ }
1951
+ }
1952
+ });
1953
+ }
1954
+ class Ke {
1955
+ /**
1956
+ * 构造函数
1957
+ * @param {string} name - 平台名称
1958
+ */
1959
+ constructor(e) {
1960
+ this.name = e;
1961
+ }
1962
+ /**
1963
+ * 处理导航选项的公共逻辑
1964
+ * @param {Object} options - 导航选项
1965
+ * @returns {Object} 处理后的选项
1966
+ */
1967
+ processNavigationOptions(e = {}) {
1968
+ const { url: r, delta: n = 1 } = e, i = r && encodeURI(r), s = parseInt(n) || 1;
1969
+ return A(h({}, e), {
1970
+ url: i,
1971
+ delta: s
1972
+ });
1973
+ }
1974
+ /**
1975
+ * 处理消息选项的公共逻辑
1976
+ * @param {Object} options - 消息选项
1977
+ * @returns {Object} 处理后的选项
1978
+ */
1979
+ processMessageOptions(e = {}) {
1980
+ const { data: r = {} } = e;
1981
+ return { data: r };
1982
+ }
1983
+ // ===== 导航方法(子类需要实现具体逻辑)=====
1984
+ /**
1985
+ * 导航到新页面
1986
+ * @param {Object} options - 导航参数
1987
+ * @param {string} options.url - 目标页面路径
1988
+ * @returns {void}
1989
+ */
1990
+ navigateTo(e) {
1991
+ const r = this.processNavigationOptions(e);
1992
+ return this.performNavigation("navigateTo", r);
1993
+ }
1994
+ /**
1995
+ * 返回上一页
1996
+ * @param {Object} [options] - 返回参数
1997
+ * @param {number} [options.delta=1] - 返回页面层级数
1998
+ * @returns {void}
1999
+ */
2000
+ navigateBack(e = {}) {
2001
+ const r = this.processNavigationOptions(e);
2002
+ return this.performNavigation("navigateBack", r);
2003
+ }
2004
+ /**
2005
+ * 切换 Tab
2006
+ * @param {Object} options - 切换参数
2007
+ * @param {string} options.url - 目标 Tab 页面路径
2008
+ * @returns {void}
2009
+ */
2010
+ switchTab(e) {
2011
+ const r = this.processNavigationOptions(e);
2012
+ return this.performNavigation("switchTab", r);
2013
+ }
2014
+ /**
2015
+ * 重新启动并打开指定页面
2016
+ * @param {Object} options - 参数
2017
+ * @param {string} options.url - 目标页面路径
2018
+ * @returns {void}
2019
+ */
2020
+ reLaunch(e) {
2021
+ const r = this.processNavigationOptions(e);
2022
+ return this.performNavigation("reLaunch", r);
2023
+ }
2024
+ /**
2025
+ * 重定向到指定页面
2026
+ * @param {Object} options - 参数
2027
+ * @param {string} options.url - 目标页面路径
2028
+ * @returns {void}
2029
+ */
2030
+ redirectTo(e) {
2031
+ const r = this.processNavigationOptions(e);
2032
+ return this.performNavigation("redirectTo", r);
2033
+ }
2034
+ // ===== 消息方法(子类需要实现具体逻辑)=====
2035
+ /**
2036
+ * 发送消息到原生容器
2037
+ * @param {Object} [options] - 参数
2038
+ * @param {any} [options.data] - 需要发送的数据
2039
+ * @returns {void}
2040
+ */
2041
+ postMessage(e = {}) {
2042
+ const r = this.processMessageOptions(e);
2043
+ return this.performPostMessage(r);
2044
+ }
2045
+ /**
2046
+ * 获取环境信息
2047
+ * @param {Function} callback - 回调函数,参数为环境信息对象
2048
+ * @returns {void}
2049
+ */
2050
+ getEnv(e) {
2051
+ return this.performGetEnv(e);
2052
+ }
2053
+ // ===== 抽象方法(子类必须实现)=====
2054
+ /**
2055
+ * 执行具体的导航操作(抽象方法)
2056
+ * @param {string} type - 导航类型
2057
+ * @param {Object} options - 处理后的选项
2058
+ * @returns {void}
2059
+ */
2060
+ performNavigation(e, r) {
2061
+ throw new Error(`${this.name} platform must implement performNavigation method`);
2062
+ }
2063
+ /**
2064
+ * 执行具体的消息发送操作(抽象方法)
2065
+ * @param {Object} options - 处理后的消息选项
2066
+ * @returns {void}
2067
+ */
2068
+ performPostMessage(e) {
2069
+ throw new Error(`${this.name} platform must implement performPostMessage method`);
2070
+ }
2071
+ /**
2072
+ * 执行具体的环境信息获取操作(抽象方法)
2073
+ * @param {Function} callback - 回调函数
2074
+ * @returns {void}
2075
+ */
2076
+ performGetEnv(e) {
2077
+ throw new Error(`${this.name} platform must implement performGetEnv method`);
2078
+ }
2079
+ }
2080
+ let Z = [];
2081
+ function Zt() {
2082
+ if (Z.length === 0 && window.plus) {
2083
+ const t = plus.webview.currentWebview();
2084
+ if (!t)
2085
+ throw new Error("plus.webview.currentWebview() is undefined");
2086
+ const e = t.parent(), r = e ? e.id : t.id;
2087
+ Z.push(r);
2088
+ }
2089
+ return Z;
2090
+ }
2091
+ function Qt(t, e) {
2092
+ const r = {
2093
+ options: {
2094
+ timestamp: +/* @__PURE__ */ new Date()
2095
+ },
2096
+ name: t,
2097
+ arg: e
2098
+ };
2099
+ if (t === "postMessage") {
2100
+ const i = { data: e };
2101
+ return window.__uniapp_x_postMessage ? window.__uniapp_x_postMessage(i) : window.__uniapp_x_.postMessage(JSON.stringify(i));
2102
+ }
2103
+ const n = {
2104
+ type: "WEB_INVOKE_APPSERVICE",
2105
+ args: {
2106
+ data: r,
2107
+ webviewIds: Z
2108
+ }
2109
+ };
2110
+ window.__uniapp_x_postMessage ? window.__uniapp_x_postMessageToService(n) : window.__uniapp_x_.postMessageToService(JSON.stringify(n));
2111
+ }
2112
+ function er(t, e) {
2113
+ const r = {
2114
+ options: {
2115
+ timestamp: +/* @__PURE__ */ new Date()
2116
+ },
2117
+ name: t,
2118
+ arg: e
2119
+ };
2120
+ if (t === "postMessage") {
2121
+ const i = { data: [e] };
2122
+ return window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessage(i) : window.__dcloud_weex_.postMessage(JSON.stringify(i));
2123
+ }
2124
+ const n = {
2125
+ type: "WEB_INVOKE_APPSERVICE",
2126
+ args: {
2127
+ data: r,
2128
+ webviewIds: Z
2129
+ }
2130
+ };
2131
+ window.__dcloud_weex_postMessage ? window.__dcloud_weex_postMessageToService(n) : window.__dcloud_weex_.postMessageToService(JSON.stringify(n));
2132
+ }
2133
+ function tr(t, e) {
2134
+ const r = {
2135
+ options: {
2136
+ timestamp: +/* @__PURE__ */ new Date()
2137
+ },
2138
+ name: t,
2139
+ arg: e
2140
+ }, n = Zt();
2141
+ if (plus.webview.getWebviewById("__uniapp__service"))
2142
+ plus.webview.postMessageToUniNView({
2143
+ type: "WEB_INVOKE_APPSERVICE",
2144
+ args: {
2145
+ data: r,
2146
+ webviewIds: n
2147
+ }
2148
+ }, "__uniapp__service");
2149
+ else {
2150
+ const i = JSON.stringify(r), s = JSON.stringify(n);
2151
+ plus.webview.getLaunchWebview().evalJS(
2152
+ `UniPlusBridge.subscribeHandler("WEB_INVOKE_APPSERVICE",${i},${s});`
2153
+ );
2154
+ }
2155
+ }
2156
+ function rr(t, e) {
2157
+ const r = {
2158
+ options: {
2159
+ timestamp: +/* @__PURE__ */ new Date()
2160
+ },
2161
+ name: t,
2162
+ arg: e
2163
+ };
2164
+ window.parent.postMessage({
2165
+ type: "WEB_INVOKE_APPSERVICE",
2166
+ data: r,
2167
+ pageId: ""
2168
+ }, "*");
2169
+ }
2170
+ function Q(t, e) {
2171
+ de() ? Qt(t, e) : le() ? er(t, e) : ue() ? tr(t, e) : rr(t, e);
2172
+ }
2173
+ class ze extends Ke {
2174
+ constructor() {
2175
+ super("weixin");
2176
+ }
2177
+ /**
2178
+ * 检查微信 API 是否可用
2179
+ * @returns {boolean}
2180
+ * @private
2181
+ */
2182
+ isWeixinApiAvailable() {
2183
+ return typeof window != "undefined" && window.wx && window.wx.miniProgram;
2184
+ }
2185
+ /**
2186
+ * 执行具体的导航操作
2187
+ * @param {string} type - 导航类型
2188
+ * @param {Object} options - 处理后的选项
2189
+ * @returns {void}
2190
+ */
2191
+ performNavigation(e, r) {
2192
+ return d.safeExecute(() => {
2193
+ const { url: n, delta: i } = r;
2194
+ if (I.debug(`微信平台执行导航操作: ${e}`, r), this.isWeixinApiAvailable()) {
2195
+ const f = window.wx.miniProgram[e];
2196
+ if (typeof f == "function") {
2197
+ I.debug(`使用微信原生 API: wx.miniProgram.${e}`);
2198
+ const l = e === "navigateBack" ? { delta: i } : { url: n };
2199
+ return f.call(window.wx.miniProgram, l);
2200
+ }
2201
+ }
2202
+ I.debug(`使用消息桥接执行: ${e}`), Q(e, e === "navigateBack" ? { delta: i } : { url: n });
2203
+ }, {
2204
+ platform: this.name,
2205
+ method: "performNavigation",
2206
+ navigationType: e,
2207
+ options: r
2208
+ });
2209
+ }
2210
+ /**
2211
+ * 执行具体的消息发送操作
2212
+ * @param {Object} options - 处理后的消息选项
2213
+ * @returns {void}
2214
+ */
2215
+ performPostMessage(e) {
2216
+ return d.safeExecute(() => {
2217
+ const { data: r } = e;
2218
+ if (this.isWeixinApiAvailable())
2219
+ return window.wx.miniProgram.postMessage({ data: r });
2220
+ Q("postMessage", r);
2221
+ }, {
2222
+ platform: this.name,
2223
+ method: "performPostMessage",
2224
+ options: e
2225
+ });
2226
+ }
2227
+ /**
2228
+ * 执行具体的环境信息获取操作
2229
+ * @param {Function} callback - 回调函数
2230
+ * @returns {void}
2231
+ */
2232
+ performGetEnv(e) {
2233
+ return d.safeExecute(() => {
2234
+ if (!e || typeof e != "function")
2235
+ throw new Error("Callback function is required for getEnv");
2236
+ if (this.isWeixinApiAvailable() && window.wx.miniProgram.getEnv)
2237
+ return window.wx.miniProgram.getEnv(e);
2238
+ e({
2239
+ miniprogram: !0,
2240
+ weixin: !0
2241
+ });
2242
+ }, {
2243
+ platform: this.name,
2244
+ method: "performGetEnv"
2245
+ });
2246
+ }
2247
+ }
2248
+ const G = new ze(), nr = (t) => G.navigateTo(t), ir = (t) => G.navigateBack(t), sr = (t) => G.switchTab(t), ar = (t) => G.reLaunch(t), or = (t) => G.redirectTo(t), cr = (t) => G.postMessage(t), ur = (t) => G.getEnv(t);
2249
+ var Ge = /* @__PURE__ */ Object.freeze({
2250
+ __proto__: null,
2251
+ WeixinPlatform: ze,
2252
+ getEnv: ur,
2253
+ navigateBack: ir,
2254
+ navigateTo: nr,
2255
+ postMessage: cr,
2256
+ reLaunch: ar,
2257
+ redirectTo: or,
2258
+ switchTab: sr
2259
+ });
2260
+ class Ve extends Ke {
2261
+ constructor() {
2262
+ super("app");
2263
+ }
2264
+ /**
2265
+ * 执行具体的导航操作
2266
+ * @param {string} type - 导航类型
2267
+ * @param {Object} options - 处理后的选项
2268
+ * @returns {void}
2269
+ */
2270
+ performNavigation(e, r) {
2271
+ return d.safeExecute(() => {
2272
+ const { url: n, delta: i } = r;
2273
+ Q(e, e === "navigateBack" ? { delta: i } : { url: n });
2274
+ }, {
2275
+ platform: this.name,
2276
+ method: "performNavigation",
2277
+ navigationType: e,
2278
+ options: r
2279
+ });
2280
+ }
2281
+ /**
2282
+ * 执行具体的消息发送操作
2283
+ * @param {Object} options - 处理后的消息选项
2284
+ * @returns {void}
2285
+ */
2286
+ performPostMessage(e) {
2287
+ return d.safeExecute(() => {
2288
+ const { data: r } = e;
2289
+ Q("postMessage", r);
2290
+ }, {
2291
+ platform: this.name,
2292
+ method: "performPostMessage",
2293
+ options: e
2294
+ });
2295
+ }
2296
+ /**
2297
+ * 执行具体的环境信息获取操作
2298
+ * @param {Function} callback - 回调函数
2299
+ * @returns {void}
2300
+ */
2301
+ performGetEnv(e) {
2302
+ return d.safeExecute(() => {
2303
+ if (!e || typeof e != "function")
2304
+ throw new Error("Callback function is required for getEnv");
2305
+ const r = {};
2306
+ let n = !1;
2307
+ de() ? (r.uvue = !0, n = !0) : le() ? (r.nvue = !0, n = !0) : ue() && (r.plus = !0, n = !0), n ? r.app = !0 : r.h5 = !0, e(r);
2308
+ }, {
2309
+ platform: this.name,
2310
+ method: "performGetEnv"
2311
+ });
2312
+ }
2313
+ }
2314
+ const V = new Ve(), lr = (t) => V.navigateTo(t), dr = (t) => V.navigateBack(t), fr = (t) => V.switchTab(t), gr = (t) => V.reLaunch(t), hr = (t) => V.redirectTo(t), pr = (t) => V.postMessage(t), mr = (t) => V.getEnv(t);
2315
+ var je = /* @__PURE__ */ Object.freeze({
2316
+ __proto__: null,
2317
+ AppPlatform: Ve,
2318
+ getEnv: mr,
2319
+ navigateBack: dr,
2320
+ navigateTo: lr,
2321
+ postMessage: pr,
2322
+ reLaunch: gr,
2323
+ redirectTo: hr,
2324
+ switchTab: fr
2325
+ });
2326
+ function ee() {
2327
+ return O() ? Ge : je;
2328
+ }
2329
+ function wr(t) {
2330
+ return ee().navigateTo(t);
2331
+ }
2332
+ function Er(t) {
2333
+ return ee().navigateBack(t);
2334
+ }
2335
+ function yr(t) {
2336
+ return ee().switchTab(t);
2337
+ }
2338
+ function Ir(t) {
2339
+ return ee().reLaunch(t);
2340
+ }
2341
+ function Ar(t) {
2342
+ return ee().redirectTo(t);
2343
+ }
2344
+ function qe() {
2345
+ return O() ? Ge : je;
2346
+ }
2347
+ function Or(t = {}) {
2348
+ return qe().postMessage(t);
2349
+ }
2350
+ function _r(t) {
2351
+ return qe().getEnv(t);
2352
+ }
2353
+ function Nr(t) {
2354
+ return t && typeof t == "object" && t.__v_raw ? t.__v_raw : t;
2355
+ }
2356
+ function Rr() {
2357
+ return "qsh_callback_" + Date.now() + "_" + Math.random().toString(36).substring(2, 9);
2358
+ }
2359
+ class Sr {
2360
+ constructor() {
2361
+ this.callbacks = /* @__PURE__ */ new Map(), this.timeouts = /* @__PURE__ */ new Map(), this.defaultTimeout = 3e4, typeof window != "undefined" && (window.qshWebviewCallbacks || (window.qshWebviewCallbacks = {})), E.debug("WebView 桥接器已初始化");
2362
+ }
2363
+ /**
2364
+ * 向主应用发送 API 调用消息
2365
+ * @param {string} apiName - API 名称
2366
+ * @param {Object} params - 参数对象
2367
+ * @param {Object} callbacks - 回调函数 {success, fail, complete}
2368
+ * @returns {void}
2369
+ */
2370
+ callApi(i) {
2371
+ return m(this, arguments, function* (e, r = {}, n = {}) {
2372
+ return d.safeExecute(() => m(this, null, function* () {
2373
+ var p;
2374
+ if (typeof window != "undefined" && window === window.parent && !window.plus && !window.__uniapp_x_postMessage && !window.__uniapp_x_ && !window.__dcloud_weex_postMessage && !window.__dcloud_weex_) {
2375
+ const P = new C(
2376
+ U.PLATFORM_NOT_SUPPORTED,
2377
+ "当前不在宿主 WebView 容器中,无法发送消息"
2378
+ );
2379
+ n && typeof n.fail == "function" && n.fail({ errMsg: P.message, code: "NOT_IN_CONTAINER" }), n && typeof n.complete == "function" && n.complete({ success: !1, error: { errMsg: P.message } });
2380
+ return;
2381
+ }
2382
+ const f = {
2383
+ apiName: e,
2384
+ params: r,
2385
+ callbacks: n,
2386
+ timestamp: Date.now(),
2387
+ abort: !1,
2388
+ metadata: {}
2389
+ };
2390
+ D.setApiLoading(e, !0);
2391
+ const l = yield F.runRequest(f);
2392
+ if (l.abort) {
2393
+ E.warn("API 调用被拦截器中止", { api: e }), D.setApiLoading(e, !1), n.fail && n.fail({
2394
+ errMsg: ((p = l.error) == null ? void 0 : p.message) || "API 调用被中止",
2395
+ code: "INTERCEPTED"
2396
+ }), n.complete && n.complete({ success: !1 });
2397
+ return;
2398
+ }
2399
+ const c = Rr();
2400
+ if (n.success || n.fail || n.complete) {
2401
+ if (this.callbacks.set(c, A(h({}, n), {
2402
+ context: l
2403
+ // 保存上下文用于响应拦截
2404
+ })), window.qshWebviewCallbacks[c] = (he) => {
2405
+ this.handleCallback(c, he);
2406
+ }, r.isPersistent || r.disableTimeout)
2407
+ E.info(`API ${e} 禁用超时清理,将等待回调返回后清理`, {
2408
+ callbackId: c,
2409
+ isPersistent: r.isPersistent,
2410
+ disableTimeout: r.disableTimeout
2411
+ });
2412
+ else {
2413
+ const he = setTimeout(() => {
2414
+ E.warn("API 调用超时,自动清理回调", { api: e, callbackId: c }), n.fail && n.fail({
2415
+ errMsg: `API ${e} 调用超时`,
2416
+ code: "TIMEOUT"
2417
+ }), this.cleanupCallback(c);
2418
+ }, r.timeout || this.defaultTimeout);
2419
+ this.timeouts.set(c, he);
2420
+ }
2421
+ const N = {
2422
+ type: "qsh_api_call",
2423
+ api: e,
2424
+ params: l.params,
2425
+ callbackId: c,
2426
+ timestamp: Date.now()
2427
+ };
2428
+ E.info("发送 API 调用消息", {
2429
+ api: e,
2430
+ callbackId: c,
2431
+ hasSuccess: !!n.success,
2432
+ hasFail: !!n.fail
2433
+ }), console.log("message:", JSON.stringify(Nr(N), null, 2)), Q("postMessage", N);
2434
+ }
2435
+ }), {
2436
+ context: "WebViewBridge.callApi",
2437
+ api: e
2438
+ });
2439
+ });
2440
+ }
2441
+ /**
2442
+ * 处理来自主应用的回调
2443
+ * @param {string} callbackId - 回调ID
2444
+ * @param {Object} result - 结果对象
2445
+ * @private
2446
+ */
2447
+ handleCallback(e, r) {
2448
+ return m(this, null, function* () {
2449
+ return d.safeExecute(() => m(this, null, function* () {
2450
+ var P, N;
2451
+ const n = this.callbacks.get(e);
2452
+ if (!n) {
2453
+ E.warn("未找到回调函数", { callbackId: e });
2454
+ return;
2455
+ }
2456
+ const { success: i, fail: s, complete: f, context: l } = n;
2457
+ E.debug("处理回调", { callbackId: e, result: r });
2458
+ const c = yield F.runResponse(r, l);
2459
+ l && D.setApiResult(l.apiName, c), c.success && i ? i(c.data) : !c.success && s && s(c.error || { errMsg: "操作失败" }), f && f(c), ((N = (P = n.context) == null ? void 0 : P.params) == null ? void 0 : N.isPersistent) ? E.debug("持久监听API:保留回调", { callbackId: e }) : (this.cleanupCallback(e), E.debug("回调执行完成,已清理", { callbackId: e }));
2460
+ }), {
2461
+ context: "WebViewBridge.handleCallback",
2462
+ callbackId: e
2463
+ });
2464
+ });
2465
+ }
2466
+ /**
2467
+ * 清理回调和相关资源
2468
+ * @param {string} callbackId - 回调ID
2469
+ * @private
2470
+ */
2471
+ cleanupCallback(e) {
2472
+ const r = this.timeouts.get(e);
2473
+ r && (clearTimeout(r), this.timeouts.delete(e)), this.callbacks.delete(e), typeof window != "undefined" && window.qshWebviewCallbacks && delete window.qshWebviewCallbacks[e];
2474
+ }
2475
+ /**
2476
+ * 清理所有待处理的回调
2477
+ */
2478
+ clearCallbacks() {
2479
+ E.debug("清理所有回调", { count: this.callbacks.size }), this.timeouts.forEach((e) => clearTimeout(e)), this.timeouts.clear(), this.callbacks.clear(), typeof window != "undefined" && window.qshWebviewCallbacks && Object.keys(window.qshWebviewCallbacks).forEach((e) => {
2480
+ e.startsWith("qsh_callback_") && delete window.qshWebviewCallbacks[e];
2481
+ });
2482
+ }
2483
+ /**
2484
+ * 获取桥接器状态信息
2485
+ * @returns {Object} 状态信息
2486
+ */
2487
+ getStatus() {
2488
+ return {
2489
+ isSupported: typeof window != "undefined" && window.uni && typeof window.uni.postMessage == "function",
2490
+ activeCallbacks: this.callbacks.size,
2491
+ globalCallbacksCount: typeof window != "undefined" && window.qshWebviewCallbacks ? Object.keys(window.qshWebviewCallbacks).length : 0
2492
+ };
2493
+ }
2494
+ }
2495
+ const Tr = new Sr(), v = (t, e, r) => Tr.callApi(t, e, r), se = {
2496
+ ALBUM: "album",
2497
+ // 相册
2498
+ CAMERA: "camera"
2499
+ // 相机
2500
+ }, ae = {
2501
+ ORIGINAL: "original",
2502
+ // 原图
2503
+ COMPRESSED: "compressed"
2504
+ // 压缩图
2505
+ }, Pr = {
2506
+ count: 9,
2507
+ sizeType: [ae.ORIGINAL, ae.COMPRESSED],
2508
+ sourceType: [se.ALBUM, se.CAMERA]
2509
+ };
2510
+ function Cr(t = {}) {
2511
+ const e = h(h({}, Pr), t);
2512
+ return Array.isArray(e.sizeType) || (e.sizeType = [e.sizeType].filter(Boolean)), Array.isArray(e.sourceType) || (e.sourceType = [e.sourceType].filter(Boolean)), e.count = Math.max(1, Math.min(9, parseInt(e.count) || 1)), e.sizeType.length === 0 && (e.sizeType = [ae.COMPRESSED]), e.sourceType.length === 0 && (e.sourceType = [se.ALBUM]), e;
2513
+ }
2514
+ function Je() {
2515
+ return ["weixin", "webview", "UniApp", "plus", "nvue", "uvue"].includes(g.type);
2516
+ }
2517
+ function He(t) {
2518
+ return d.safeExecute(() => {
2519
+ var e;
2520
+ if (!window.wx) {
2521
+ const r = {
2522
+ errMsg: "微信JS-SDK未加载",
2523
+ code: "WEIXIN_SDK_NOT_LOADED"
2524
+ };
2525
+ (e = t.fail) == null || e.call(t, r);
2526
+ return;
2527
+ }
2528
+ if (!B()) {
2529
+ a.info("等待微信配置完成"), k().then(() => He(t)).catch((r) => {
2530
+ var n;
2531
+ a.error("微信配置失败", r), (n = t.fail) == null || n.call(t, { errMsg: `微信配置失败: ${r.message}` });
2532
+ });
2533
+ return;
2534
+ }
2535
+ a.debug("调用微信图片选择", t), window.wx.chooseImage({
2536
+ count: t.count,
2537
+ sizeType: t.sizeType,
2538
+ sourceType: t.sourceType,
2539
+ success: (r) => {
2540
+ var n, i;
2541
+ a.info("微信图片选择成功", { count: ((n = r.localIds) == null ? void 0 : n.length) || 0 }), (i = t.success) == null || i.call(t, r);
2542
+ },
2543
+ fail: (r) => {
2544
+ var n;
2545
+ a.error("微信图片选择失败", r), (n = t.fail) == null || n.call(t, r);
2546
+ },
2547
+ complete: t.complete
2548
+ });
2549
+ }, {
2550
+ context: "chooseImageInWeixin",
2551
+ platform: "weixin"
2552
+ });
2553
+ }
2554
+ function Mr(t) {
2555
+ return d.safeExecute(() => {
2556
+ a.debug("通过 WebView 桥接调用图片选择", t), v("chooseImage", A(h({}, t), { disableTimeout: !0 }), {
2557
+ success: (e) => {
2558
+ var r, n;
2559
+ a.info("UniApp 图片选择成功", {
2560
+ count: ((r = e == null ? void 0 : e.tempFilePaths) == null ? void 0 : r.length) || 0
2561
+ }), (n = t.success) == null || n.call(t, e);
2562
+ },
2563
+ fail: (e) => {
2564
+ var r;
2565
+ a.error("UniApp 图片选择失败", e), (r = t.fail) == null || r.call(t, e);
2566
+ },
2567
+ complete: t.complete
2568
+ });
2569
+ }, {
2570
+ context: "chooseImageInUniApp",
2571
+ platform: "uniapp"
2572
+ });
2573
+ }
2574
+ function br(t = {}) {
2575
+ return d.safeExecute(() => {
2576
+ var r;
2577
+ if (!Je()) {
2578
+ const n = {
2579
+ errMsg: `当前环境 (${g.type}) 不支持图片选择功能`,
2580
+ code: "PLATFORM_NOT_SUPPORTED"
2581
+ };
2582
+ a.error("平台不支持图片选择", { platform: g.type }), (r = t.fail) == null || r.call(t, n);
2583
+ return;
2584
+ }
2585
+ const e = Cr(t);
2586
+ a.info("开始选择图片", {
2587
+ platform: g.type,
2588
+ count: e.count,
2589
+ sizeType: e.sizeType,
2590
+ sourceType: e.sourceType
2591
+ }), O() ? He(e) : Mr(e);
2592
+ }, {
2593
+ context: "chooseImage",
2594
+ options: t
2595
+ });
2596
+ }
2597
+ function vr() {
2598
+ return {
2599
+ supported: Je(),
2600
+ environment: g.type,
2601
+ implementation: O() ? "weixin" : "webview",
2602
+ features: {
2603
+ multipleSelection: !0,
2604
+ // 支持多选
2605
+ sizeTypeSelection: !0,
2606
+ // 支持质量选择
2607
+ sourceTypeSelection: !0,
2608
+ // 支持来源选择
2609
+ asyncSupport: !0
2610
+ // 支持 Promise
2611
+ }
2612
+ };
2613
+ }
2614
+ const z = {
2615
+ QR_CODE: "qrCode",
2616
+ // 二维码
2617
+ BAR_CODE: "barCode",
2618
+ // 一维码(条形码)
2619
+ DATA_MATRIX: "datamatrix",
2620
+ // Data Matrix 码
2621
+ PDF417: "pdf417"
2622
+ // PDF417 条码
2623
+ }, Lr = {
2624
+ onlyFromCamera: !0,
2625
+ // 只从相机扫码
2626
+ scanType: [z.QR_CODE, z.BAR_CODE]
2627
+ // 支持二维码和一维码
2628
+ };
2629
+ function Dr(t = {}) {
2630
+ const e = h(h({}, Lr), t);
2631
+ return Array.isArray(e.scanType) || (e.scanType = [e.scanType].filter(Boolean)), e.scanType.length === 0 && (e.scanType = [z.QR_CODE, z.BAR_CODE]), e.onlyFromCamera = !!e.onlyFromCamera, e;
2632
+ }
2633
+ function Ye() {
2634
+ return ["weixin", "webview", "UniApp", "plus", "nvue", "uvue"].includes(g.type);
2635
+ }
2636
+ function Xe(t) {
2637
+ return d.safeExecute(() => {
2638
+ var e;
2639
+ if (!window.wx) {
2640
+ const r = {
2641
+ errMsg: "微信JS-SDK未加载",
2642
+ code: "WEIXIN_SDK_NOT_LOADED"
2643
+ };
2644
+ (e = t.fail) == null || e.call(t, r);
2645
+ return;
2646
+ }
2647
+ if (!B()) {
2648
+ a.info("等待微信配置完成"), k().then(() => Xe(t)).catch((r) => {
2649
+ var n;
2650
+ a.error("微信配置失败", r), (n = t.fail) == null || n.call(t, { errMsg: `微信配置失败: ${r.message}` });
2651
+ });
2652
+ return;
2653
+ }
2654
+ a.debug("调用微信扫码", t), window.wx.scanQRCode({
2655
+ needResult: 1,
2656
+ // 直接返回扫码结果
2657
+ scanType: t.scanType,
2658
+ success: (r) => {
2659
+ var i;
2660
+ a.info("微信扫码成功", { result: r.resultStr });
2661
+ const n = {
2662
+ result: r.resultStr,
2663
+ // 扫码内容
2664
+ scanType: xr(r.resultStr),
2665
+ // 推测扫码类型
2666
+ charSet: "utf-8",
2667
+ // 微信默认 UTF-8
2668
+ errMsg: "scanCode:ok"
2669
+ };
2670
+ (i = t.success) == null || i.call(t, n);
2671
+ },
2672
+ fail: (r) => {
2673
+ var n;
2674
+ a.error("微信扫码失败", r), (n = t.fail) == null || n.call(t, r);
2675
+ },
2676
+ complete: t.complete
2677
+ });
2678
+ }, {
2679
+ context: "scanCodeInWeixin",
2680
+ platform: "weixin"
2681
+ });
2682
+ }
2683
+ function xr(t) {
2684
+ return t ? t.length > 50 || /[^\d]/.test(t) ? z.QR_CODE : z.BAR_CODE : "unknown";
2685
+ }
2686
+ function Ur(t) {
2687
+ return d.safeExecute(() => {
2688
+ a.debug("通过 WebView 桥接调用扫码", t), v("scanCode", A(h({}, t), { disableTimeout: !0 }), {
2689
+ success: (e) => {
2690
+ var r;
2691
+ a.info("UniApp 扫码成功", {
2692
+ result: e == null ? void 0 : e.result,
2693
+ scanType: e == null ? void 0 : e.scanType
2694
+ }), (r = t.success) == null || r.call(t, e);
2695
+ },
2696
+ fail: (e) => {
2697
+ var r;
2698
+ a.error("UniApp 扫码失败", e), (r = t.fail) == null || r.call(t, e);
2699
+ },
2700
+ complete: t.complete
2701
+ });
2702
+ }, {
2703
+ context: "scanCodeInUniApp",
2704
+ platform: "uniapp"
2705
+ });
2706
+ }
2707
+ function Wr(t = {}) {
2708
+ return d.safeExecute(() => {
2709
+ var r;
2710
+ if (!Ye()) {
2711
+ const n = {
2712
+ errMsg: `当前环境 (${g.type}) 不支持扫码功能`,
2713
+ code: "PLATFORM_NOT_SUPPORTED"
2714
+ };
2715
+ a.error("平台不支持扫码", { platform: g.type }), (r = t.fail) == null || r.call(t, n);
2716
+ return;
2717
+ }
2718
+ const e = Dr(t);
2719
+ a.info("开始扫码", {
2720
+ platform: g.type,
2721
+ onlyFromCamera: e.onlyFromCamera,
2722
+ scanType: e.scanType
2723
+ }), O() ? Xe(e) : Ur(e);
2724
+ }, {
2725
+ context: "scanCode",
2726
+ options: t
2727
+ });
2728
+ }
2729
+ function $r() {
2730
+ return {
2731
+ supported: Ye(),
2732
+ environment: g.type,
2733
+ implementation: O() ? "weixin" : "webview",
2734
+ features: {
2735
+ onlyFromCamera: !0,
2736
+ // 支持只从相机扫码
2737
+ scanTypeSelection: !0,
2738
+ // 支持扫码类型选择
2739
+ multipleTypes: !0,
2740
+ // 支持多种扫码类型
2741
+ asyncSupport: !0
2742
+ // 支持 Promise
2743
+ }
2744
+ };
2745
+ }
2746
+ const oe = {
2747
+ WGS84: "wgs84",
2748
+ // GPS 坐标
2749
+ GCJ02: "gcj02",
2750
+ // 国测局坐标(火星坐标)
2751
+ BD09: "bd09"
2752
+ // 百度坐标
2753
+ }, kr = {
2754
+ type: oe.WGS84,
2755
+ altitude: !1
2756
+ }, Br = {
2757
+ scale: 18
2758
+ // 地图缩放级别 1-28
2759
+ };
2760
+ function Fr(t = {}) {
2761
+ const e = h(h({}, kr), t);
2762
+ return Object.values(oe).includes(e.type) || (e.type = oe.WGS84), e.altitude = !!e.altitude, e;
2763
+ }
2764
+ function Kr(t = {}) {
2765
+ const e = h(h({}, Br), t);
2766
+ if (e.latitude === void 0 || e.latitude === null)
2767
+ throw {
2768
+ errMsg: "缺少必需参数:latitude(纬度)",
2769
+ code: "PARAM_MISSING"
2770
+ };
2771
+ if (typeof e.latitude != "number")
2772
+ throw {
2773
+ errMsg: `latitude 参数类型错误:期望 number,实际 ${typeof e.latitude}`,
2774
+ code: "PARAM_TYPE_ERROR",
2775
+ details: {
2776
+ param: "latitude",
2777
+ expected: "number",
2778
+ actual: typeof e.latitude,
2779
+ value: e.latitude
2780
+ }
2781
+ };
2782
+ if (e.latitude < -90 || e.latitude > 90)
2783
+ throw {
2784
+ errMsg: `latitude 超出范围:有效范围 -90 ~ 90,实际值 ${e.latitude}`,
2785
+ code: "PARAM_INVALID",
2786
+ details: {
2787
+ param: "latitude",
2788
+ value: e.latitude,
2789
+ validRange: "-90 ~ 90"
2790
+ }
2791
+ };
2792
+ if (e.longitude === void 0 || e.longitude === null)
2793
+ throw {
2794
+ errMsg: "缺少必需参数:longitude(经度)",
2795
+ code: "PARAM_MISSING"
2796
+ };
2797
+ if (typeof e.longitude != "number")
2798
+ throw {
2799
+ errMsg: `longitude 参数类型错误:期望 number,实际 ${typeof e.longitude}`,
2800
+ code: "PARAM_TYPE_ERROR",
2801
+ details: {
2802
+ param: "longitude",
2803
+ expected: "number",
2804
+ actual: typeof e.longitude,
2805
+ value: e.longitude
2806
+ }
2807
+ };
2808
+ if (e.longitude < -180 || e.longitude > 180)
2809
+ throw {
2810
+ errMsg: `longitude 超出范围:有效范围 -180 ~ 180,实际值 ${e.longitude}`,
2811
+ code: "PARAM_INVALID",
2812
+ details: {
2813
+ param: "longitude",
2814
+ value: e.longitude,
2815
+ validRange: "-180 ~ 180"
2816
+ }
2817
+ };
2818
+ if (e.scale !== void 0 && e.scale !== null) {
2819
+ const r = Number(e.scale);
2820
+ isNaN(r) ? (a.warn("scale 参数无效,使用默认值 18", { scale: e.scale }), e.scale = 18) : e.scale = Math.max(1, Math.min(28, Math.floor(r)));
2821
+ }
2822
+ return e;
2823
+ }
2824
+ function Oe() {
2825
+ return ["weixin", "webview", "UniApp", "plus", "nvue", "uvue"].includes(g.type);
2826
+ }
2827
+ function Ze(t) {
2828
+ return d.safeExecute(() => {
2829
+ var e;
2830
+ if (!window.wx) {
2831
+ const r = {
2832
+ errMsg: "微信JS-SDK未加载",
2833
+ code: "WEIXIN_SDK_NOT_LOADED"
2834
+ };
2835
+ (e = t.fail) == null || e.call(t, r);
2836
+ return;
2837
+ }
2838
+ if (!B()) {
2839
+ a.info("等待微信配置完成"), k().then(() => Ze(t)).catch((r) => {
2840
+ var n;
2841
+ a.error("微信配置失败", r), (n = t.fail) == null || n.call(t, { errMsg: `微信配置失败: ${r.message}` });
2842
+ });
2843
+ return;
2844
+ }
2845
+ a.debug("调用微信定位", t), window.wx.getLocation({
2846
+ type: t.type,
2847
+ success: (r) => {
2848
+ var n;
2849
+ a.info("微信定位成功", {
2850
+ latitude: r.latitude,
2851
+ longitude: r.longitude
2852
+ }), (n = t.success) == null || n.call(t, r);
2853
+ },
2854
+ fail: (r) => {
2855
+ var n;
2856
+ a.error("微信定位失败", r), (n = t.fail) == null || n.call(t, r);
2857
+ },
2858
+ complete: t.complete
2859
+ });
2860
+ }, {
2861
+ context: "getLocationInWeixin",
2862
+ platform: "weixin"
2863
+ });
2864
+ }
2865
+ function Qe(t) {
2866
+ return d.safeExecute(() => {
2867
+ var e;
2868
+ if (!window.wx) {
2869
+ const r = {
2870
+ errMsg: "微信JS-SDK未加载",
2871
+ code: "WEIXIN_SDK_NOT_LOADED"
2872
+ };
2873
+ (e = t.fail) == null || e.call(t, r);
2874
+ return;
2875
+ }
2876
+ if (!B()) {
2877
+ a.info("等待微信配置完成"), k().then(() => Qe(t)).catch((r) => {
2878
+ var n;
2879
+ a.error("微信配置失败", r), (n = t.fail) == null || n.call(t, { errMsg: `微信配置失败: ${r.message}` });
2880
+ });
2881
+ return;
2882
+ }
2883
+ a.debug("调用微信查看位置", t), window.wx.openLocation({
2884
+ latitude: t.latitude,
2885
+ longitude: t.longitude,
2886
+ name: t.name || "",
2887
+ address: t.address || "",
2888
+ scale: t.scale || 18,
2889
+ infoUrl: t.infoUrl || "",
2890
+ success: (r) => {
2891
+ var n;
2892
+ a.info("微信查看位置成功"), (n = t.success) == null || n.call(t, r);
2893
+ },
2894
+ fail: (r) => {
2895
+ var n;
2896
+ a.error("微信查看位置失败", r), (n = t.fail) == null || n.call(t, r);
2897
+ },
2898
+ complete: t.complete
2899
+ });
2900
+ }, {
2901
+ context: "openLocationInWeixin",
2902
+ platform: "weixin"
2903
+ });
2904
+ }
2905
+ function zr(t) {
2906
+ return d.safeExecute(() => {
2907
+ a.debug("通过 WebView 桥接调用获取位置", t), v("getLocation", t, {
2908
+ success: (e) => {
2909
+ var r;
2910
+ a.info("UniApp 获取位置成功", {
2911
+ latitude: e == null ? void 0 : e.latitude,
2912
+ longitude: e == null ? void 0 : e.longitude
2913
+ }), (r = t.success) == null || r.call(t, e);
2914
+ },
2915
+ fail: (e) => {
2916
+ var r;
2917
+ a.error("UniApp 获取位置失败", e), (r = t.fail) == null || r.call(t, e);
2918
+ },
2919
+ complete: t.complete
2920
+ });
2921
+ }, {
2922
+ context: "getLocationInUniApp",
2923
+ platform: "uniapp"
2924
+ });
2925
+ }
2926
+ function Gr(t) {
2927
+ return d.safeExecute(() => {
2928
+ a.debug("通过 WebView 桥接调用查看位置", t), v("openLocation", t, {
2929
+ success: (e) => {
2930
+ var r;
2931
+ a.info("UniApp 查看位置成功"), (r = t.success) == null || r.call(t, e);
2932
+ },
2933
+ fail: (e) => {
2934
+ var r;
2935
+ a.error("UniApp 查看位置失败", e), (r = t.fail) == null || r.call(t, e);
2936
+ },
2937
+ complete: t.complete
2938
+ });
2939
+ }, {
2940
+ context: "openLocationInUniApp",
2941
+ platform: "uniapp"
2942
+ });
2943
+ }
2944
+ function Vr(t = {}) {
2945
+ return d.safeExecute(() => {
2946
+ var r;
2947
+ if (!Oe()) {
2948
+ const n = {
2949
+ errMsg: `当前环境 (${g.type}) 不支持定位功能`,
2950
+ code: "PLATFORM_NOT_SUPPORTED"
2951
+ };
2952
+ a.error("平台不支持定位", { platform: g.type }), (r = t.fail) == null || r.call(t, n);
2953
+ return;
2954
+ }
2955
+ const e = Fr(t);
2956
+ a.info("开始获取位置", {
2957
+ platform: g.type,
2958
+ type: e.type,
2959
+ altitude: e.altitude
2960
+ }), O() ? Ze(e) : zr(e);
2961
+ }, {
2962
+ context: "getLocation",
2963
+ options: t
2964
+ });
2965
+ }
2966
+ function jr(t = {}) {
2967
+ return d.safeExecute(() => {
2968
+ var r, n, i;
2969
+ if (!Oe()) {
2970
+ const s = {
2971
+ errMsg: `当前环境 (${g.type}) 不支持查看位置功能`,
2972
+ code: "PLATFORM_NOT_SUPPORTED"
2973
+ };
2974
+ a.error("平台不支持查看位置", { platform: g.type }), (r = t.fail) == null || r.call(t, s);
2975
+ return;
2976
+ }
2977
+ let e;
2978
+ try {
2979
+ e = Kr(t);
2980
+ } catch (s) {
2981
+ a.error("参数验证失败", s), (n = t.fail) == null || n.call(t, s), (i = t.complete) == null || i.call(t);
2982
+ return;
2983
+ }
2984
+ a.info("开始查看位置", {
2985
+ platform: g.type,
2986
+ latitude: e.latitude,
2987
+ longitude: e.longitude,
2988
+ name: e.name
2989
+ }), O() ? Qe(e) : Gr(e);
2990
+ }, {
2991
+ context: "openLocation",
2992
+ options: t
2993
+ });
2994
+ }
2995
+ function qr() {
2996
+ return {
2997
+ supported: Oe(),
2998
+ environment: g.type,
2999
+ implementation: O() ? "weixin" : "webview",
3000
+ features: {
3001
+ getLocation: !0,
3002
+ // 获取位置
3003
+ openLocation: !0,
3004
+ // 查看位置
3005
+ coordinateTypes: !0,
3006
+ // 支持坐标类型选择
3007
+ altitudeSupport: !0,
3008
+ // 支持高度信息
3009
+ asyncSupport: !0
3010
+ // 支持 Promise
3011
+ }
3012
+ };
3013
+ }
3014
+ const Jr = {
3015
+ latitude: null,
3016
+ // 目标地纬度
3017
+ longitude: null
3018
+ // 目标地经度
3019
+ };
3020
+ function Hr(t = {}) {
3021
+ const e = h(h({}, Jr), t);
3022
+ return e.latitude !== null && e.latitude !== void 0 && (typeof e.latitude != "number" ? (a.warn("latitude 参数类型错误,已忽略", {
3023
+ latitude: e.latitude
3024
+ }), e.latitude = null) : (e.latitude < -90 || e.latitude > 90) && (a.warn("latitude 超出范围,已忽略", {
3025
+ latitude: e.latitude
3026
+ }), e.latitude = null)), e.longitude !== null && e.longitude !== void 0 && (typeof e.longitude != "number" ? (a.warn("longitude 参数类型错误,已忽略", {
3027
+ longitude: e.longitude
3028
+ }), e.longitude = null) : (e.longitude < -180 || e.longitude > 180) && (a.warn("longitude 超出范围,已忽略", {
3029
+ longitude: e.longitude
3030
+ }), e.longitude = null)), e;
3031
+ }
3032
+ function et() {
3033
+ return ["weixin", "webview", "UniApp", "plus", "nvue", "uvue"].includes(g.type);
3034
+ }
3035
+ function tt(t) {
3036
+ return d.safeExecute(() => {
3037
+ var n;
3038
+ if (!window.wx) {
3039
+ const i = {
3040
+ errMsg: "微信JS-SDK未加载",
3041
+ code: "WEIXIN_SDK_NOT_LOADED"
3042
+ };
3043
+ (n = t.fail) == null || n.call(t, i);
3044
+ return;
3045
+ }
3046
+ if (!B()) {
3047
+ a.info("等待微信配置完成"), k().then(() => tt(t)).catch((i) => {
3048
+ var s;
3049
+ a.error("微信配置失败", i), (s = t.fail) == null || s.call(t, { errMsg: `微信配置失败: ${i.message}` });
3050
+ });
3051
+ return;
3052
+ }
3053
+ a.debug("调用微信位置选择", t);
3054
+ const e = {
3055
+ success: (i) => {
3056
+ var f;
3057
+ a.info("微信位置选择成功", {
3058
+ name: i.name,
3059
+ address: i.address,
3060
+ latitude: i.latitude,
3061
+ longitude: i.longitude
3062
+ });
3063
+ const s = {
3064
+ name: i.name,
3065
+ // 位置名称
3066
+ address: i.address,
3067
+ // 详细地址
3068
+ latitude: i.latitude,
3069
+ // 纬度
3070
+ longitude: i.longitude,
3071
+ // 经度
3072
+ errMsg: "chooseLocation:ok"
3073
+ };
3074
+ (f = t.success) == null || f.call(t, s);
3075
+ },
3076
+ fail: (i) => {
3077
+ var s;
3078
+ a.error("微信位置选择失败", i), (s = t.fail) == null || s.call(t, i);
3079
+ },
3080
+ complete: t.complete
3081
+ }, r = {};
3082
+ t.latitude !== null && t.latitude !== void 0 && (r.latitude = t.latitude), t.longitude !== null && t.longitude !== void 0 && (r.longitude = t.longitude), window.wx.chooseLocation(A(h({}, r), {
3083
+ success: e.success,
3084
+ fail: e.fail,
3085
+ complete: e.complete
3086
+ }));
3087
+ }, {
3088
+ context: "chooseLocationInWeixin",
3089
+ platform: "weixin"
3090
+ });
3091
+ }
3092
+ function Yr(t) {
3093
+ return d.safeExecute(() => {
3094
+ a.debug("通过 WebView 桥接调用位置选择", t);
3095
+ const e = {
3096
+ // 禁用超时清理,等待用户操作完成后才清理
3097
+ disableTimeout: !0,
3098
+ success: (r) => {
3099
+ var n;
3100
+ a.info("UniApp 位置选择成功", {
3101
+ name: r == null ? void 0 : r.name,
3102
+ address: r == null ? void 0 : r.address,
3103
+ latitude: r == null ? void 0 : r.latitude,
3104
+ longitude: r == null ? void 0 : r.longitude
3105
+ }), (n = t.success) == null || n.call(t, r);
3106
+ },
3107
+ fail: (r) => {
3108
+ var n;
3109
+ a.error("UniApp 位置选择失败", r), (n = t.fail) == null || n.call(t, r);
3110
+ },
3111
+ complete: t.complete
3112
+ };
3113
+ t.latitude !== null && t.latitude !== void 0 && (e.latitude = t.latitude), t.longitude !== null && t.longitude !== void 0 && (e.longitude = t.longitude), v("chooseLocation", e, {
3114
+ success: (r) => {
3115
+ e.success(r);
3116
+ },
3117
+ fail: (r) => {
3118
+ e.fail(r);
3119
+ },
3120
+ complete: e.complete
3121
+ });
3122
+ }, {
3123
+ context: "chooseLocationInUniApp",
3124
+ platform: "uniapp"
3125
+ });
3126
+ }
3127
+ function Xr(t = {}) {
3128
+ return d.safeExecute(() => {
3129
+ var r;
3130
+ if (!et()) {
3131
+ const n = {
3132
+ errMsg: `当前环境 (${g.type}) 不支持位置选择功能`,
3133
+ code: "PLATFORM_NOT_SUPPORTED"
3134
+ };
3135
+ a.error("平台不支持位置选择", { platform: g.type }), (r = t.fail) == null || r.call(t, n);
3136
+ return;
3137
+ }
3138
+ const e = Hr(t);
3139
+ a.info("开始选择位置", {
3140
+ platform: g.type,
3141
+ latitude: e.latitude,
3142
+ longitude: e.longitude
3143
+ }), O() ? tt(e) : Yr(e);
3144
+ }, {
3145
+ context: "chooseLocation",
3146
+ options: t
3147
+ });
3148
+ }
3149
+ function Zr() {
3150
+ return {
3151
+ supported: et(),
3152
+ environment: g.type,
3153
+ implementation: O() ? "weixin" : "webview",
3154
+ features: {
3155
+ chooseLocation: !0,
3156
+ // 支持位置选择
3157
+ centerPoint: !0,
3158
+ // 支持指定中心点(latitude/longitude)
3159
+ asyncSupport: !0
3160
+ // 支持 Promise
3161
+ }
3162
+ };
3163
+ }
3164
+ const rt = /* @__PURE__ */ new Map();
3165
+ function Qr(t, e = {}) {
3166
+ rt.set(t, e);
3167
+ }
3168
+ function en(t, e) {
3169
+ const r = rt.get(t);
3170
+ if (r)
3171
+ return r[e] || r.default;
3172
+ }
3173
+ const tn = {
3174
+ 0: "WXSceneSession",
3175
+ // 聊天界面
3176
+ 1: "WXSceneTimeline"
3177
+ // 朋友圈
3178
+ }, rn = {
3179
+ 0: "图文/网页",
3180
+ 1: "纯文字",
3181
+ 2: "纯图片",
3182
+ 3: "音乐",
3183
+ 4: "视频",
3184
+ 5: "小程序"
3185
+ };
3186
+ function nt(t = {}) {
3187
+ return d.safeExecute(
3188
+ () => {
3189
+ var n, i;
3190
+ if (typeof window == "undefined" || !window.wx) {
3191
+ const s = { errMsg: "微信JS-SDK未加载", code: "WEIXIN_SDK_NOT_LOADED" };
3192
+ return (n = t.fail) == null || n.call(t, s), Promise.reject(s);
3193
+ }
3194
+ if (!B())
3195
+ return a.info("等待微信配置完成"), k().then(() => nt(t));
3196
+ const e = it(t);
3197
+ if (!e.success) {
3198
+ const s = { errMsg: e.message || "参数校验失败", code: "INVALID_PARAMS" };
3199
+ return (i = t.fail) == null || i.call(t, s), Promise.reject(s);
3200
+ }
3201
+ const r = e.params;
3202
+ return a.debug("调用微信分享", r), new Promise((s, f) => {
3203
+ window.wx[r.scene](A(h({}, r), {
3204
+ success: () => {
3205
+ var c;
3206
+ const l = { errMsg: "weixinShare:ok" };
3207
+ (c = t.success) == null || c.call(t, l), s(l);
3208
+ },
3209
+ fail: (l) => {
3210
+ var p;
3211
+ const c = { errMsg: (l == null ? void 0 : l.errMsg) || "weixinShare:fail", details: l };
3212
+ a.error("微信分享失败", c), (p = t.fail) == null || p.call(t, c), f(c);
3213
+ },
3214
+ complete: t.complete
3215
+ }));
3216
+ });
3217
+ },
3218
+ {
3219
+ context: "toShareInWeixin",
3220
+ platform: "weixin"
3221
+ }
3222
+ );
3223
+ }
3224
+ function it(t = {}) {
3225
+ const e = h({}, t), r = {
3226
+ scene: e.scene === 1 ? "updateTimelineShareData" : "updateAppMessageShareData"
3227
+ };
3228
+ return a.info("格式化微信参数", e), Object.prototype.hasOwnProperty.call(e, "title") ? Object.prototype.hasOwnProperty.call(e, "imageUrl") ? Object.prototype.hasOwnProperty.call(e, "path") ? Object.prototype.hasOwnProperty.call(e, "summary") ? (r.title = e.title, r.imgUrl = e.imageUrl, r.link = e.path, r.desc = e.summary, { params: r, success: !0 }) : { message: "参数字段summary值缺少!", success: !1 } : { message: "参数字段path值缺少!", success: !1 } : { message: "参数字段imageUrl值缺少!", success: !1 } : { message: "参数字段title值缺少!", success: !1 };
3229
+ }
3230
+ function j(t = {}) {
3231
+ return d.safeExecute(
3232
+ () => (a.debug("通过 WebView 桥接调用微信分享", t), new Promise((e, r) => {
3233
+ v("toShareData", t, {
3234
+ success: (n) => {
3235
+ var i;
3236
+ (i = t.success) == null || i.call(t, n), e(n);
3237
+ },
3238
+ fail: (n) => {
3239
+ var i;
3240
+ a.error("UniApp 微信分享失败", n), (i = t.fail) == null || i.call(t, n), r(n);
3241
+ },
3242
+ complete: t.complete
3243
+ });
3244
+ })),
3245
+ {
3246
+ context: "toShareInUniApp",
3247
+ platform: "uniapp"
3248
+ }
3249
+ );
3250
+ }
3251
+ function nn(t = {}) {
3252
+ const e = h({}, t), r = {
3253
+ provider: "weixin",
3254
+ scene: "WXSceneSession"
3255
+ };
3256
+ if (a.info("格式化 UniApp 参数", e), [0, 1].some((n) => parseInt(n) === parseInt(e.scene)) ? r.scene = tn[e.scene] : r.scene = "WXSceneSession", Object.prototype.hasOwnProperty.call(e, "type")) {
3257
+ const n = Number(e.type);
3258
+ if (Object.keys(rn).some((s) => parseInt(s) === n)) {
3259
+ if (r.type = n, [0].includes(n))
3260
+ if (Object.prototype.hasOwnProperty.call(e, "path"))
3261
+ r.href = e.path;
3262
+ else
3263
+ return { message: "参数字段path值缺少!", success: !1 };
3264
+ if ([0, 1].includes(n))
3265
+ if (Object.prototype.hasOwnProperty.call(e, "summary"))
3266
+ r.summary = e.summary;
3267
+ else
3268
+ return { message: "参数字段summary值缺少!", success: !1 };
3269
+ if ([0, 2, 5].includes(n))
3270
+ if (Object.prototype.hasOwnProperty.call(e, "imageUrl"))
3271
+ r.imageUrl = e.imageUrl;
3272
+ else
3273
+ return { message: "参数字段imageUrl值缺少!", success: !1 };
3274
+ [5].includes(n) && Object.prototype.hasOwnProperty.call(e, "miniProgram") && h({}, e.miniProgram), Object.prototype.hasOwnProperty.call(e, "title") && (r.title = e.title), Object.prototype.hasOwnProperty.call(e, "success") && (r.success = e.success), Object.prototype.hasOwnProperty.call(e, "fail") && (r.fail = e.fail), Object.prototype.hasOwnProperty.call(e, "complete") && (r.complete = e.complete);
3275
+ } else
3276
+ return { message: "参数字段type值有误!", success: !1 };
3277
+ } else
3278
+ return { message: "参数字段type缺少!", success: !1 };
3279
+ return { params: r, success: !0 };
3280
+ }
3281
+ const st = "share.toShare";
3282
+ Qr(st, {
3283
+ weixin: nt,
3284
+ webview: j,
3285
+ plus: j,
3286
+ nvue: j,
3287
+ uvue: j,
3288
+ UniApp: j,
3289
+ h5: j,
3290
+ default: void 0
3291
+ });
3292
+ function sn(t = {}) {
3293
+ return d.safeExecute(
3294
+ () => {
3295
+ var s, f;
3296
+ const e = Ae(), r = en(st, e.type);
3297
+ if (typeof r != "function") {
3298
+ const l = {
3299
+ errMsg: `当前环境 (${e.type}) 不支持微信分享功能`,
3300
+ code: "PLATFORM_NOT_SUPPORTED"
3301
+ };
3302
+ return a.error("平台不支持微信分享", { platform: e.type }), (s = t.fail) == null || s.call(t, l), Promise.reject(l);
3303
+ }
3304
+ const n = O() ? it(t) : nn(t);
3305
+ if (!n.success) {
3306
+ const l = { errMsg: n.message || "参数校验失败", code: "INVALID_PARAMS" };
3307
+ return (f = t.fail) == null || f.call(t, l), Promise.reject(l);
3308
+ }
3309
+ const i = n.params;
3310
+ return a.info("开始微信分享", { platform: e.type, type: i == null ? void 0 : i.type }), r(i);
3311
+ },
3312
+ {
3313
+ context: "toShare",
3314
+ options: t
3315
+ }
3316
+ );
3317
+ }
3318
+ const an = {
3319
+ OFF: "off",
3320
+ // 蓝牙关闭
3321
+ ON: "on",
3322
+ // 蓝牙开启
3323
+ UNAVAILABLE: "unavailable",
3324
+ // 不支持蓝牙
3325
+ UNAUTHORIZED: "unauthorized"
3326
+ // 未授权
3327
+ }, on = {
3328
+ allowDuplicatesKey: !1,
3329
+ // 是否允许重复上报同一设备
3330
+ services: []
3331
+ // 指定服务 UUID 列表
3332
+ };
3333
+ function ge(t = {}) {
3334
+ return h(h({}, on), t);
3335
+ }
3336
+ function te() {
3337
+ return ["weixin", "webview", "UniApp", "plus", "nvue", "uvue"].includes(g.type);
3338
+ }
3339
+ function cn(t) {
3340
+ return d.safeExecute(() => m(null, null, function* () {
3341
+ var e;
3342
+ if (!window.wx) {
3343
+ const r = { errMsg: "微信JS-SDK未加载", code: "WEIXIN_SDK_NOT_LOADED" };
3344
+ (e = t.fail) == null || e.call(t, r);
3345
+ return;
3346
+ }
3347
+ B() || (a.info("等待微信配置完成"), yield k()), wx.openBluetoothAdapter({
3348
+ success: () => {
3349
+ a.info("微信蓝牙适配器已打开"), at(t);
3350
+ },
3351
+ fail: (r) => {
3352
+ var n;
3353
+ a.error("蓝牙适配器打开失败", r), (n = t.fail) == null || n.call(t, r);
3354
+ }
3355
+ });
3356
+ }), { context: "openBluetoothAdapterInWeixin" });
3357
+ }
3358
+ function un(t) {
3359
+ return d.safeExecute(() => {
3360
+ a.debug("通过 WebView 桥接调用蓝牙功能", t), v("bluetooth", t, {
3361
+ success: (e) => {
3362
+ var r;
3363
+ a.info("UniApp 蓝牙调用成功", e), (r = t.success) == null || r.call(t, e);
3364
+ },
3365
+ fail: (e) => {
3366
+ var r;
3367
+ a.error("UniApp 蓝牙调用失败", e), (r = t.fail) == null || r.call(t, e);
3368
+ },
3369
+ complete: t.complete
3370
+ });
3371
+ }, { context: "bluetoothInUniApp" });
3372
+ }
3373
+ function ln(t) {
3374
+ return d.safeExecute(() => {
3375
+ var e;
3376
+ a.debug("通过 WebView 桥接调用蓝牙设备搜索功能", t), v("bluetoothDevicesDiscovery", {
3377
+ action: "startBluetoothDevicesDiscovery",
3378
+ params: {
3379
+ services: t.services || [],
3380
+ allowDuplicatesKey: (e = t.allowDuplicatesKey) != null ? e : !1
3381
+ }
3382
+ }, {
3383
+ success: (r) => {
3384
+ var n;
3385
+ console.log("[Bluetooth] 设备开启搜索成功:", r), a.info("UniApp 蓝牙设备开启搜索成功", r), (n = t.success) == null || n.call(t, r);
3386
+ },
3387
+ fail: (r) => {
3388
+ var n;
3389
+ console.error("[Bluetooth] 设备开启搜索失败:", r), a.error("UniApp 蓝牙设备开启搜索失败", r), (n = t.fail) == null || n.call(t, r);
3390
+ },
3391
+ complete: t.complete
3392
+ });
3393
+ }, { context: "startBluetoothDevicesDiscoveryInUniApp" });
3394
+ }
3395
+ const ne = /* @__PURE__ */ new Set();
3396
+ function dn(t, e = {}) {
3397
+ return d.safeExecute(() => {
3398
+ var r;
3399
+ return ne.add(t), ne.size === 1 && v("onBluetoothDeviceFound", {
3400
+ action: "onBluetoothDeviceFound",
3401
+ isPersistent: !0,
3402
+ params: {
3403
+ services: e.services || [],
3404
+ allowDuplicatesKey: (r = e.allowDuplicatesKey) != null ? r : !1
3405
+ }
3406
+ }, {
3407
+ success: (n) => {
3408
+ ne.forEach((i) => {
3409
+ typeof i == "function" ? d.safeExecute(() => i(n), { context: "BluetoothDeviceCallback" }) : console.warn("[BluetoothDeviceCallback] 不是函数:", i);
3410
+ });
3411
+ },
3412
+ fail: (n) => {
3413
+ var i;
3414
+ console.error("[Bluetooth] 搜索失败:", n), (i = e.fail) == null || i.call(e, n);
3415
+ },
3416
+ complete: e.complete
3417
+ }), () => ne.delete(t);
3418
+ }, { context: "qsh_onBluetoothDeviceFound" });
3419
+ }
3420
+ function fn(t) {
3421
+ return d.safeExecute(() => {
3422
+ var e;
3423
+ a.debug("通过 WebView 桥接调用蓝牙连接功能", t), v("bluetoothConnection", {
3424
+ action: "createBLEConnection",
3425
+ params: {
3426
+ deviceId: t.deviceId,
3427
+ name: t.name,
3428
+ autoConnect: (e = t.autoConnect) != null ? e : !1
3429
+ }
3430
+ }, {
3431
+ success: (r) => {
3432
+ var n;
3433
+ console.log("[Bluetooth] 蓝牙连接成功:", r), a.info("UniApp 蓝牙连接成功", r), (n = t.success) == null || n.call(t, r);
3434
+ },
3435
+ fail: (r) => {
3436
+ var n;
3437
+ console.error("[Bluetooth] 蓝牙连接失败:", r), a.error("UniApp 蓝牙连接失败", r), (n = t.fail) == null || n.call(t, r);
3438
+ },
3439
+ complete: t.complete
3440
+ });
3441
+ }, { context: "createBLEConnectionInUniApp" });
3442
+ }
3443
+ function gn(t = {}) {
3444
+ return d.safeExecute(() => {
3445
+ var r;
3446
+ if (!te()) {
3447
+ const n = {
3448
+ errMsg: `当前环境 (${g.type}) 不支持蓝牙功能`,
3449
+ code: "PLATFORM_NOT_SUPPORTED"
3450
+ };
3451
+ a.error("平台不支持蓝牙", { platform: g.type }), (r = t.fail) == null || r.call(t, n);
3452
+ return;
3453
+ }
3454
+ const e = ge(t);
3455
+ a.info("开始蓝牙操作", {
3456
+ platform: g.type,
3457
+ services: e.services,
3458
+ allowDuplicatesKey: e.allowDuplicatesKey
3459
+ }), O() ? cn(e) : un(e);
3460
+ }, { context: "openBluetoothAdapter", options: t });
3461
+ }
3462
+ function hn(t = {}) {
3463
+ return d.safeExecute(() => {
3464
+ var r, n;
3465
+ if (!te()) {
3466
+ const i = {
3467
+ errMsg: `当前环境 (${g.type}) 不支持蓝牙功能`,
3468
+ code: "PLATFORM_NOT_SUPPORTED"
3469
+ };
3470
+ a.error("平台不支持蓝牙", { platform: g.type }), (r = t.fail) == null || r.call(t, i), (n = t.complete) == null || n.call(t, i);
3471
+ return;
3472
+ }
3473
+ const e = ge(t);
3474
+ a.info("开始搜索蓝牙设备", {
3475
+ platform: g.type,
3476
+ services: e.services,
3477
+ allowDuplicatesKey: e.allowDuplicatesKey
3478
+ }), O() ? startBluetoothDevicesDiscoveryInWeixin(e) : ln(e);
3479
+ }, { context: "startBluetoothDevicesDiscovery", options: t });
3480
+ }
3481
+ function at(t, e = {}) {
3482
+ return d.safeExecute(() => {
3483
+ var n, i;
3484
+ if (!te()) {
3485
+ const s = {
3486
+ errMsg: `当前环境 (${g.type}) 不支持蓝牙功能`,
3487
+ code: "PLATFORM_NOT_SUPPORTED"
3488
+ };
3489
+ a.error("平台不支持蓝牙", { platform: g.type }), (n = e.fail) == null || n.call(e, s), (i = e.complete) == null || i.call(e, s);
3490
+ return;
3491
+ }
3492
+ const r = ge(e);
3493
+ a.info("注册蓝牙设备发现监听", { platform: g.type }), O() ? onBluetoothDeviceFoundInWeixin(r) : dn(t, r);
3494
+ }, { context: "onBluetoothDeviceFound", options: e });
3495
+ }
3496
+ function pn(t = {}) {
3497
+ return d.safeExecute(() => {
3498
+ var s, f, l, c;
3499
+ if (!te()) {
3500
+ const p = {
3501
+ errMsg: `当前环境 (${g.type}) 不支持蓝牙功能`,
3502
+ code: "PLATFORM_NOT_SUPPORTED"
3503
+ };
3504
+ a.error("平台不支持蓝牙连接", { platform: g.type }), (s = t.fail) == null || s.call(t, p), (f = t.complete) == null || f.call(t, p);
3505
+ return;
3506
+ }
3507
+ const e = ge(t), { name: r, deviceId: n, autoConnect: i = !1 } = e;
3508
+ if (!n) {
3509
+ const p = { errMsg: "缺少 deviceId 参数", code: "INVALID_PARAMS" };
3510
+ (l = t.fail) == null || l.call(t, p), (c = t.complete) == null || c.call(t, p);
3511
+ return;
3512
+ }
3513
+ a.info("创建蓝牙连接", { deviceId: n, autoConnect: i, platform: g.type }), O() ? uni.createBLEConnection({
3514
+ deviceId: n,
3515
+ autoConnect: i,
3516
+ success: t.success,
3517
+ fail: t.fail,
3518
+ complete: t.complete
3519
+ }) : fn(e);
3520
+ }, { context: "createBLEConnection", options: t });
3521
+ }
3522
+ function mn() {
3523
+ return {
3524
+ supported: te(),
3525
+ environment: g.type,
3526
+ implementation: O() ? "weixin" : "webview",
3527
+ features: {
3528
+ discovery: !0,
3529
+ connect: !0,
3530
+ readWrite: !0,
3531
+ notify: !0,
3532
+ asyncSupport: !0
3533
+ }
3534
+ };
3535
+ }
3536
+ const ot = Ae();
3537
+ F.useResponse(Fe.response, { priority: 1e3 });
3538
+ let ve = !1;
3539
+ function Le() {
3540
+ if (ve) return;
3541
+ ve = !0, Xt([
3542
+ { name: "load-weixin-sdk", run: Dt, timeoutMs: 8e3 },
3543
+ { name: "init-bridge", run: $e, timeoutMs: 8e3 }
3544
+ ], {
3545
+ onError: (e, r) => {
3546
+ console.error(`[QSH-SDK] 初始化失败(${(r == null ? void 0 : r.name) || "unknown"}):`, e);
3547
+ }
3548
+ });
3549
+ }
3550
+ typeof window != "undefined" && (document.readyState === "complete" || document.readyState === "interactive" ? setTimeout(Le, 0) : document.addEventListener("DOMContentLoaded", Le));
3551
+ function _(t, { apiName: e } = {}) {
3552
+ return function(r = {}, ...n) {
3553
+ const i = r && typeof r == "object" && (typeof r.success == "function" || typeof r.fail == "function" || typeof r.complete == "function"), s = r && typeof r == "object" ? r : {}, f = () => i ? t(s, ...n) : new Promise((c, p) => {
3554
+ const P = A(h({}, s), {
3555
+ success: (N) => {
3556
+ typeof s.success == "function" && s.success(N), c(N);
3557
+ },
3558
+ fail: (N) => {
3559
+ typeof s.fail == "function" && s.fail(N), p(N);
3560
+ },
3561
+ complete: s.complete
3562
+ });
3563
+ t(P, ...n);
3564
+ });
3565
+ return (typeof window == "undefined" ? Promise.resolve() : Ue()).then(() => f()).catch((c) => {
3566
+ throw console.error(`[QSH-SDK] ${e || "API"} call failed:`, c), c;
3567
+ });
3568
+ };
3569
+ }
3570
+ const ct = _(wr), ut = _(Er), lt = _(yr), dt = _(Ir), ft = _(Ar), gt = _(Or);
3571
+ function ht(t) {
3572
+ const e = () => _r(t);
3573
+ return (typeof window == "undefined" ? Promise.resolve() : Ue()).then(() => e());
3574
+ }
3575
+ const _e = _(br);
3576
+ function wn(t = {}) {
3577
+ return new Promise((e, r) => {
3578
+ _e(A(h({}, t), {
3579
+ success: e,
3580
+ fail: r
3581
+ }));
3582
+ });
3583
+ }
3584
+ const Ne = _(Wr);
3585
+ function En(t = {}) {
3586
+ return new Promise((e, r) => {
3587
+ Ne(A(h({}, t), {
3588
+ success: e,
3589
+ fail: r
3590
+ }));
3591
+ });
3592
+ }
3593
+ const yn = _(sn), Re = _(Vr);
3594
+ function In(t = {}) {
3595
+ return new Promise((e, r) => {
3596
+ Re(A(h({}, t), {
3597
+ success: e,
3598
+ fail: r
3599
+ }));
3600
+ });
3601
+ }
3602
+ const Se = _(jr);
3603
+ function An(t = {}) {
3604
+ return new Promise((e, r) => {
3605
+ Se(A(h({}, t), {
3606
+ success: e,
3607
+ fail: r
3608
+ }));
3609
+ });
3610
+ }
3611
+ const Te = _(Xr);
3612
+ function On(t = {}) {
3613
+ return new Promise((e, r) => {
3614
+ Te(A(h({}, t), {
3615
+ success: e,
3616
+ fail: r
3617
+ }));
3618
+ });
3619
+ }
3620
+ const pt = _(gn);
3621
+ function _n(t = {}) {
3622
+ return new Promise((e, r) => {
3623
+ pt(A(h({}, t), {
3624
+ success: e,
3625
+ fail: r
3626
+ }));
3627
+ });
3628
+ }
3629
+ const mt = _(hn);
3630
+ function Nn(t = {}) {
3631
+ return new Promise((e, r) => {
3632
+ mt(A(h({}, t), {
3633
+ success: e,
3634
+ fail: r
3635
+ }));
3636
+ });
3637
+ }
3638
+ const wt = _(at);
3639
+ function Rn(t = {}) {
3640
+ return new Promise((e, r) => {
3641
+ wt(A(h({}, t), {
3642
+ success: e,
3643
+ fail: r
3644
+ }));
3645
+ });
3646
+ }
3647
+ const Et = _(pn);
3648
+ function Sn(t = {}) {
3649
+ return new Promise((e, r) => {
3650
+ Et(A(h({}, t), {
3651
+ success: e,
3652
+ fail: r
3653
+ }));
3654
+ });
3655
+ }
3656
+ const H = {
3657
+ // 导航 API
3658
+ navigateTo: ct,
3659
+ navigateBack: ut,
3660
+ switchTab: lt,
3661
+ reLaunch: dt,
3662
+ redirectTo: ft,
3663
+ // 消息 API
3664
+ postMessage: gt,
3665
+ getEnv: ht,
3666
+ // 图片 API
3667
+ chooseImage: _e,
3668
+ chooseImageAsync: wn,
3669
+ // 扫码 API
3670
+ scanCode: Ne,
3671
+ scanCodeAsync: En,
3672
+ // 位置 API
3673
+ getLocation: Re,
3674
+ getLocationAsync: In,
3675
+ openLocation: Se,
3676
+ openLocationAsync: An,
3677
+ chooseLocation: Te,
3678
+ chooseLocationAsync: On,
3679
+ // 环境信息
3680
+ environment: ot,
3681
+ /**
3682
+ * 等待 JSBridge 就绪
3683
+ * 返回一个 Promise,当桥接完成初始化后 resolve。
3684
+ * @returns {Promise<void>}
3685
+ * @example
3686
+ * await qsh.ready()
3687
+ * @since 2.0.0
3688
+ */
3689
+ ready: bt,
3690
+ /**
3691
+ * 手动初始化 JSBridge
3692
+ * 默认会在 DOM 就绪时自动初始化;如需更早或手动控制,可调用本方法。
3693
+ * @returns {Promise<void>}
3694
+ * @example
3695
+ * await qsh.init()
3696
+ * @since 2.0.0
3697
+ */
3698
+ init: $e,
3699
+ /**
3700
+ * 检查 JSBridge 是否就绪
3701
+ * @returns {boolean}
3702
+ * @example
3703
+ * if (qsh.isReady()) { console.log('ready') }
3704
+ * @since 2.0.0
3705
+ */
3706
+ isReady: St,
3707
+ /**
3708
+ * 获取当前 SDK 状态
3709
+ * @returns {string}
3710
+ * @example
3711
+ * console.log(qsh.getState()) // 'ready'
3712
+ * @since 2.0.0
3713
+ */
3714
+ getState: Tt,
3715
+ // 微信配置 API
3716
+ weixin: {
3717
+ /**
3718
+ * 等待微信配置完成
3719
+ * @returns {Promise<void>}
3720
+ * @example
3721
+ * await qsh.weixin.waitForConfig()
3722
+ * @since 2.0.0
3723
+ */
3724
+ waitForConfig: k,
3725
+ /**
3726
+ * 检查微信配置是否完成
3727
+ * @returns {boolean}
3728
+ * @example
3729
+ * if (qsh.weixin.isConfigReady()) { wx.chooseImage({}) }
3730
+ * @since 2.0.0
3731
+ */
3732
+ isConfigReady: B,
3733
+ /**
3734
+ * 获取微信配置状态
3735
+ * @returns {string}
3736
+ * @example
3737
+ * console.log(qsh.weixin.getConfigState()) // 'configured'
3738
+ * @since 2.0.0
3739
+ */
3740
+ getConfigState: xt,
3741
+ /**
3742
+ * 手动重试微信配置
3743
+ * @returns {Promise<void>}
3744
+ * @example
3745
+ * await qsh.weixin.retryConfig()
3746
+ * @since 2.0.0
3747
+ */
3748
+ retryConfig: Ut
3749
+ },
3750
+ // WebView 对象(兼容旧版本)
3751
+ webView: null,
3752
+ // 图片相关常量
3753
+ ImageSourceTypes: se,
3754
+ ImageSizeTypes: ae,
3755
+ /**
3756
+ * 获取图片功能能力信息
3757
+ * @returns {Object} 能力信息对象
3758
+ * @example
3759
+ * const capabilities = qsh.getImageCapabilities()
3760
+ * console.log('是否支持:', capabilities.supported)
3761
+ * @since 2.0.0
3762
+ */
3763
+ getImageCapabilities: vr,
3764
+ // 扫码相关常量
3765
+ ScanTypes: z,
3766
+ /**
3767
+ * 获取扫码功能能力信息
3768
+ * @returns {Object} 能力信息对象
3769
+ * @example
3770
+ * const capabilities = qsh.getScanCapabilities()
3771
+ * console.log('是否支持:', capabilities.supported)
3772
+ * @since 2.1.0
3773
+ */
3774
+ getScanCapabilities: $r,
3775
+ // 位置相关常量
3776
+ CoordinateTypes: oe,
3777
+ /**
3778
+ * 获取位置功能能力信息
3779
+ * @returns {Object} 能力信息对象
3780
+ * @example
3781
+ * const capabilities = qsh.getLocationCapabilities()
3782
+ * console.log('是否支持:', capabilities.supported)
3783
+ * @since 2.1.0
3784
+ */
3785
+ getLocationCapabilities: qr,
3786
+ /**
3787
+ * 获取位置选择功能能力信息
3788
+ * @returns {Object} 能力信息对象
3789
+ * @example
3790
+ * const capabilities = qsh.getChooseLocationCapabilities()
3791
+ * console.log('是否支持:', capabilities.supported)
3792
+ * @since 2.1.0
3793
+ */
3794
+ getChooseLocationCapabilities: Zr,
3795
+ // 蓝牙 API
3796
+ openBluetoothAdapter: pt,
3797
+ openBluetoothAdapterAsync: _n,
3798
+ startBluetoothDevicesDiscovery: mt,
3799
+ startBluetoothDevicesDiscoveryAsync: Nn,
3800
+ onBluetoothDeviceFound: wt,
3801
+ onBluetoothDeviceFoundAsync: Rn,
3802
+ createBLEConnection: Et,
3803
+ createBLEConnectionAsync: Sn,
3804
+ // 蓝牙相关常量
3805
+ BluetoothStates: an,
3806
+ //微信分享
3807
+ toShare: yn,
3808
+ /**
3809
+ * 获取蓝牙功能能力信息
3810
+ * @returns {Object} 能力信息对象
3811
+ * @example
3812
+ * const capabilities = qsh.getBluetoothCapabilities()
3813
+ * console.log('是否支持:', capabilities.supported)
3814
+ */
3815
+ getBluetoothCapabilities: mn,
3816
+ // 插件系统
3817
+ plugins: {
3818
+ /**
3819
+ * 插件管理器
3820
+ */
3821
+ manager: X,
3822
+ /**
3823
+ * 注册插件
3824
+ * @param {Object} plugin - 插件对象
3825
+ * @returns {Object} pluginManager 实例
3826
+ * @example
3827
+ * qsh.plugins.register(myPlugin)
3828
+ */
3829
+ register: (t) => X.register(t),
3830
+ /**
3831
+ * 安装插件
3832
+ * @param {string} name - 插件名称
3833
+ * @returns {Promise<void>}
3834
+ * @example
3835
+ * await qsh.plugins.install('image')
3836
+ */
3837
+ install: (t) => X.install(t, H),
3838
+ /**
3839
+ * 获取插件列表
3840
+ * @returns {Array} 插件列表
3841
+ * @example
3842
+ * console.log(qsh.plugins.list())
3843
+ */
3844
+ list: () => X.getPluginList()
3845
+ },
3846
+ // 拦截器系统
3847
+ interceptors: {
3848
+ /**
3849
+ * 拦截器链
3850
+ */
3851
+ chain: F,
3852
+ /**
3853
+ * 注册请求拦截器
3854
+ * @param {Function} interceptor - 拦截器函数
3855
+ * @param {Object} [options] - 选项
3856
+ * @returns {Function} 移除拦截器的函数
3857
+ * @example
3858
+ * qsh.interceptors.useRequest(async (ctx) => {
3859
+ * console.log('API 调用:', ctx.apiName)
3860
+ * return ctx
3861
+ * })
3862
+ */
3863
+ useRequest: (t, e) => F.useRequest(t, e),
3864
+ /**
3865
+ * 注册响应拦截器
3866
+ * @param {Function} interceptor - 拦截器函数
3867
+ * @param {Object} [options] - 选项
3868
+ * @returns {Function} 移除拦截器的函数
3869
+ * @example
3870
+ * qsh.interceptors.useResponse(async (result, ctx) => {
3871
+ * console.log('API 完成:', ctx.apiName)
3872
+ * return result
3873
+ * })
3874
+ */
3875
+ useResponse: (t, e) => F.useResponse(t, e),
3876
+ /**
3877
+ * 内置拦截器
3878
+ */
3879
+ builtin: {
3880
+ logging: kt,
3881
+ performance: W,
3882
+ createRetry: Bt,
3883
+ createValidation: Ft,
3884
+ errorNormalizer: Fe
3885
+ }
3886
+ },
3887
+ // 观测指标
3888
+ metrics: {
3889
+ /**
3890
+ * 获取性能指标报告
3891
+ */
3892
+ getPerformanceReport: () => W.getReport(),
3893
+ /**
3894
+ * 清空性能指标
3895
+ */
3896
+ clearPerformanceMetrics: () => W.clearMetrics()
3897
+ },
3898
+ // 错误处理工具
3899
+ errors: {
3900
+ /**
3901
+ * 错误码枚举
3902
+ */
3903
+ codes: o,
3904
+ /**
3905
+ * 错误消息
3906
+ */
3907
+ messages: Ee,
3908
+ /**
3909
+ * 错误分类
3910
+ */
3911
+ categories: b,
3912
+ /**
3913
+ * 标准化错误
3914
+ * @param {any} error - 原始错误
3915
+ * @param {Object} context - 上下文
3916
+ * @returns {Object} 标准化错误
3917
+ * @example
3918
+ * const standardError = qsh.errors.normalize(error, { apiName: 'chooseImage' })
3919
+ */
3920
+ normalize: Be,
3921
+ /**
3922
+ * 创建标准错误
3923
+ * @param {string} code - 错误码
3924
+ * @param {Object} options - 选项
3925
+ * @returns {Object} 标准错误
3926
+ * @example
3927
+ * const error = qsh.errors.create('E_IMG_001', { apiName: 'chooseImage' })
3928
+ */
3929
+ create: Jt,
3930
+ /**
3931
+ * 判断是否为标准错误
3932
+ * @param {any} error - 错误对象
3933
+ * @returns {boolean}
3934
+ * @example
3935
+ * if (qsh.errors.isStandard(error)) { ... }
3936
+ */
3937
+ isStandard: Ht
3938
+ },
3939
+ // 状态管理
3940
+ store: {
3941
+ /**
3942
+ * 状态仓库实例
3943
+ */
3944
+ instance: D,
3945
+ /**
3946
+ * 获取状态
3947
+ * @param {string} path - 状态路径
3948
+ * @returns {any} 状态值
3949
+ * @example
3950
+ * const status = qsh.store.get('sdk.status')
3951
+ */
3952
+ get: (t) => D.get(t),
3953
+ /**
3954
+ * 设置状态
3955
+ * @param {string} path - 状态路径
3956
+ * @param {any} value - 新值
3957
+ * @example
3958
+ * qsh.store.set('sdk.status', 'ready')
3959
+ */
3960
+ set: (t, e) => D.set(t, e),
3961
+ /**
3962
+ * 订阅状态变化
3963
+ * @param {string} path - 状态路径
3964
+ * @param {Function} listener - 监听函数
3965
+ * @returns {Function} 取消订阅的函数
3966
+ * @example
3967
+ * const unsubscribe = qsh.store.subscribe('network.online', (online) => {
3968
+ * console.log('网络状态:', online)
3969
+ * })
3970
+ */
3971
+ subscribe: (t, e) => D.subscribe(t, e),
3972
+ /**
3973
+ * 获取状态快照
3974
+ * @returns {Object} 状态快照
3975
+ * @example
3976
+ * console.log(qsh.store.getSnapshot())
3977
+ */
3978
+ getSnapshot: () => D.getSnapshot()
3979
+ },
3980
+ // 调试工具(生产环境可能被优化掉)
3981
+ debug: {
3982
+ /**
3983
+ * 日志记录器
3984
+ */
3985
+ logger: S,
3986
+ /**
3987
+ * 设置外部日志 reporter,便于对接埋点/观测
3988
+ */
3989
+ setLogReporter: (t) => S.setReporter(t),
3990
+ /**
3991
+ * 错误处理器
3992
+ */
3993
+ errorHandler: d,
3994
+ /**
3995
+ * 状态管理器
3996
+ */
3997
+ stateManager: K,
3998
+ /**
3999
+ * 启用调试模式
4000
+ * @example
4001
+ * qsh.debug.enableDevMode()
4002
+ */
4003
+ enableDevMode: () => S.enableDevMode(),
4004
+ /**
4005
+ * 获取日志历史
4006
+ * @param {number} [count] - 获取条数
4007
+ * @returns {Array} 日志历史
4008
+ * @example
4009
+ * console.log(qsh.debug.getLogs(10))
4010
+ */
4011
+ getLogs: (t) => S.getHistory(t),
4012
+ /**
4013
+ * 获取 SDK 统计信息
4014
+ * @returns {Object} 统计信息
4015
+ * @example
4016
+ * console.log(qsh.debug.getStats())
4017
+ */
4018
+ getStats: () => ({
4019
+ logger: S.getStats(),
4020
+ state: K.getStats(),
4021
+ weixinConfig: Ce().getStats(),
4022
+ plugins: X.getStats(),
4023
+ interceptors: F.getStats(),
4024
+ store: D.getStats()
4025
+ }),
4026
+ /**
4027
+ * 获取微信配置管理器
4028
+ * @returns {Object} 微信配置管理器
4029
+ * @example
4030
+ * console.log(qsh.debug.getWeixinConfigManager().getStats())
4031
+ */
4032
+ getWeixinConfigManager: Ce,
4033
+ /**
4034
+ * 导出调试信息
4035
+ * @returns {string} JSON 格式的调试信息
4036
+ * @example
4037
+ * console.log(qsh.debug.exportDebugInfo())
4038
+ */
4039
+ exportDebugInfo: () => S.exportToJSON()
4040
+ }
4041
+ };
4042
+ ot.isWeixinMiniProgram ? H.webView = window.wx && window.wx.miniProgram : H.webView = {
4043
+ navigateTo: ct,
4044
+ navigateBack: ut,
4045
+ switchTab: lt,
4046
+ reLaunch: dt,
4047
+ redirectTo: ft,
4048
+ postMessage: gt,
4049
+ getEnv: ht,
4050
+ chooseImage: _e,
4051
+ scanCode: Ne,
4052
+ getLocation: Re,
4053
+ openLocation: Se,
4054
+ chooseLocation: Te
4055
+ };
4056
+ const De = typeof window.uni != "undefined" ? window.uni : {};
4057
+ Object.keys(De).forEach((t) => {
4058
+ H.hasOwnProperty(t) || (H[t] = De[t]);
4059
+ });
4060
+ typeof window != "undefined" && (window.qsh = H);
4061
+ export {
4062
+ H as default
4063
+ };
4064
+ //# sourceMappingURL=qsh-webview-sdk.es.js.map