qsh-webview-sdk 2.4.6 → 2.4.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -73
- package/dist/index.d.ts +4 -0
- package/dist/qsh-webview-sdk.es.js +690 -671
- package/dist/qsh-webview-sdk.es.js.map +1 -1
- package/dist/qsh-webview-sdk.umd.js +1 -1
- package/dist/qsh-webview-sdk.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(R,M){typeof exports=="object"&&typeof module!="undefined"?module.exports=M():typeof define=="function"&&define.amd?define(M):(R=typeof globalThis!="undefined"?globalThis:R||self,R.qsh=M())})(this,function(){"use strict";var la=Object.defineProperty,fa=Object.defineProperties;var da=Object.getOwnPropertyDescriptors;var tr=Object.getOwnPropertySymbols;var ga=Object.prototype.hasOwnProperty,ha=Object.prototype.propertyIsEnumerable;var Ye=(R,M,p)=>M in R?la(R,M,{enumerable:!0,configurable:!0,writable:!0,value:p}):R[M]=p,g=(R,M)=>{for(var p in M||(M={}))ga.call(M,p)&&Ye(R,p,M[p]);if(tr)for(var p of tr(M))ha.call(M,p)&&Ye(R,p,M[p]);return R},w=(R,M)=>fa(R,da(M));var X=(R,M,p)=>Ye(R,typeof M!="symbol"?M+"":M,p);var I=(R,M,p)=>new Promise((le,te)=>{var fe=k=>{try{re(p.next(k))}catch(F){te(F)}},de=k=>{try{re(p.throw(k))}catch(F){te(F)}},re=k=>k.done?le(k.value):Promise.resolve(k.value).then(fe,de);re((p=p.apply(R,M)).next())});function R(){return typeof window!="undefined"?window:void 0}function M(){return typeof navigator=="undefined"?"":navigator.userAgent||""}function p(){const t=R();if(!t)return!1;if(t.__wxjs_environment==="miniprogram"||t.wx&&t.wx.miniProgram)return!0;const e=M();return!!(e&&/micromessenger/i.test(e)&&/miniProgram/i.test(e))}function le(){const t=R();return!!(t&&t.plus)}function te(){const t=R();return!!(t&&(t.__dcloud_weex_postMessage||t.__dcloud_weex_))}function fe(){const t=R();return!!(t&&(t.__uniapp_x_postMessage||t.__uniapp_x_))}function de(){const t=M();return/uni-app/i.test(t)}function re(){const t=M();return/Html5Plus/i.test(t)}function k(){return de()||re()}function F(){const t=R();if(!t)return!1;if(t.__offline_bridge_postMessage)return!0;try{const e=t.location&&t.location.hostname;if(e&&/\.?offline\.?/i.test(e))return!0}catch(e){}return!1}function rr(){return fe()?"uvue":te()?"nvue":p()?"weixin":F()?"offline":le()?"plus":k()?"webview":de()?"UniApp":"h5"}let Re=null;function V(t=!1){return Re&&!t||(Re={isWeixinMiniProgram:p(),isAppPlus:le(),isNvue:te(),isUvue:fe(),isUniApp:de(),isHtml5Plus:re(),isUniAppWebView:k(),isOfflineWebview:F(),type:rr()}),Re}const f=V(),L={PLATFORM_NOT_SUPPORTED:"PLATFORM_NOT_SUPPORTED",API_CALL_FAILED:"API_CALL_FAILED",BRIDGE_NOT_READY:"BRIDGE_NOT_READY",INVALID_PARAMETERS:"INVALID_PARAMETERS",NETWORK_ERROR:"NETWORK_ERROR"};class v extends Error{constructor(e,r,i={},n=null){super(r),this.name="QshError",this.type=e,this.context=i,this.originalError=n,this.timestamp=new Date().toISOString(),Error.captureStackTrace&&Error.captureStackTrace(this,v)}toJSON(){return{name:this.name,type:this.type,message:this.message,context:this.context,timestamp:this.timestamp,stack:this.stack}}}const b=class b{static setDebugMode(e){b.isDebugMode=e}static addErrorCallback(e){typeof e=="function"&&b.errorCallbacks.push(e)}static removeErrorCallback(e){const r=b.errorCallbacks.indexOf(e);r>-1&&b.errorCallbacks.splice(r,1)}static handleApiError(e,r={}){let i;return e instanceof v?i=e:e instanceof Error?i=new v(L.API_CALL_FAILED,e.message,r,e):i=new v(L.API_CALL_FAILED,String(e),r),b.logError(i),b.notifyCallbacks(i),i}static handlePlatformNotSupported(e,r){const i=new v(L.PLATFORM_NOT_SUPPORTED,`API "${r}" is not supported on platform "${e}"`,{platformType:e,apiName:r});return b.logError(i),b.notifyCallbacks(i),i}static handleBridgeNotReady(e){const r=new v(L.BRIDGE_NOT_READY,`Bridge is not ready when calling "${e}"`,{apiName:e});return b.logError(r),b.notifyCallbacks(r),r}static handleInvalidParameters(e,r,i,n){const a=new v(L.INVALID_PARAMETERS,`Invalid parameter "${r}" in "${e}": expected ${i}, got ${typeof n}`,{apiName:e,paramName:r,expectedType:i,actualValue:n});return b.logError(a),b.notifyCallbacks(a),a}static safeExecute(e,r={}){try{return e()}catch(i){return b.handleApiError(i,r)}}static safeExecuteAsync(i){return I(this,arguments,function*(e,r={}){try{return yield e()}catch(n){return b.handleApiError(n,r)}})}static logError(e){if(typeof console!="undefined"){const r=`[QSH-SDK Error] ${e.type}: ${e.message}`;b.isDebugMode?console.error(r,{context:e.context,originalError:e.originalError,stack:e.stack,timestamp:e.timestamp}):console.error(r)}}static notifyCallbacks(e){b.errorCallbacks.forEach(r=>{try{r(e)}catch(i){typeof console!="undefined"&&console.error("[QSH-SDK] Error in error callback:",i)}})}static createErrorDecorator(e={}){return function(r,i,n){const a=n.value;return n.value=function(...o){return b.safeExecute(()=>a.apply(this,o),w(g({},e),{method:i,target:r.constructor.name}))},n}}};X(b,"isDebugMode",!1),X(b,"errorCallbacks",[]);let l=b;const $={UNINITIALIZED:"uninitialized",INITIALIZING:"initializing",READY:"ready",ERROR:"error"};class ir{constructor(){this.state=$.UNINITIALIZED,this.readyPromise=null,this.readyCallbacks=[],this.errorCallbacks=[],this.initializationError=null,this.handleBridgeReady=this.handleBridgeReady.bind(this),this.handleInitializationError=this.handleInitializationError.bind(this)}getState(){return this.state}isReady(){return this.state===$.READY}isInitializing(){return this.state===$.INITIALIZING}hasError(){return this.state===$.ERROR}getInitializationError(){return this.initializationError}waitForReady(){return this.isReady()?Promise.resolve():this.hasError()?Promise.reject(this.initializationError):(this.readyPromise||(this.readyPromise=new Promise((e,r)=>{this.isReady()?e():this.hasError()?r(this.initializationError):(this.readyCallbacks.push(e),this.errorCallbacks.push(r))})),this.readyPromise)}startInitialization(e){return I(this,null,function*(){if(this.state!==$.UNINITIALIZED)return this.waitForReady();this.state=$.INITIALIZING;try{yield e(),this.handleBridgeReady()}catch(r){throw this.handleInitializationError(r),r}return this.waitForReady()})}handleBridgeReady(){this.state===$.INITIALIZING&&(this.state=$.READY,this.readyCallbacks.forEach(e=>{try{e()}catch(r){l.handleApiError(r,{context:"StateManager.handleBridgeReady"})}}),this.readyCallbacks=[],this.errorCallbacks=[])}handleInitializationError(e){this.state=$.ERROR,this.initializationError=e,this.errorCallbacks.forEach(r=>{try{r(e)}catch(i){l.handleApiError(i,{context:"StateManager.handleInitializationError"})}}),this.readyCallbacks=[],this.errorCallbacks=[]}reset(){this.state=$.UNINITIALIZED,this.readyPromise=null,this.readyCallbacks=[],this.errorCallbacks=[],this.initializationError=null}onStateChange(e,r){if(this.state===e)return setTimeout(()=>r(this.state),0),()=>{};const i=()=>{this.state===e&&r(this.state)};return e===$.READY?this.readyCallbacks.push(i):e===$.ERROR&&this.errorCallbacks.push(i),()=>{const n=this.readyCallbacks.indexOf(i);n>-1&&this.readyCallbacks.splice(n,1);const a=this.errorCallbacks.indexOf(i);a>-1&&this.errorCallbacks.splice(a,1)}}getStats(){return{state:this.state,readyCallbacksCount:this.readyCallbacks.length,errorCallbacksCount:this.errorCallbacks.length,hasReadyPromise:!!this.readyPromise,hasInitializationError:!!this.initializationError}}}const ie=new ir,Xe=()=>ie.waitForReady(),nr=()=>ie.isReady(),ar=()=>ie.getState(),C={ERROR:0,WARN:1,INFO:2,DEBUG:3,TRACE:4},we={[C.ERROR]:"ERROR",[C.WARN]:"WARN",[C.INFO]:"INFO",[C.DEBUG]:"DEBUG",[C.TRACE]:"TRACE"},h=class h{static setLevel(e){e>=C.ERROR&&e<=C.TRACE&&(h.currentLevel=e,h.log(C.INFO,"Logger",`日志级别设置为: ${we[e]}`))}static enableDevMode(){h.setLevel(C.DEBUG),h.log(C.INFO,"Logger","开发模式已启用")}static enableProdMode(){h.setLevel(C.WARN),h.log(C.INFO,"Logger","生产模式已启用")}static enableModule(e){h.enabledModules.add(e),h.log(C.INFO,"Logger",`模块日志已启用: ${e}`)}static disableModule(e){h.enabledModules.delete(e),h.log(C.INFO,"Logger",`模块日志已禁用: ${e}`)}static shouldLog(e,r){return e>h.currentLevel?!1:r&&h.enabledModules.size>0?h.enabledModules.has(r):!0}static log(e,r,i,...n){if(!h.shouldLog(e,r))return;const a=new Date().toISOString(),o=we[e],c=r?`[${r}]`:"",d=`${h.prefix} ${c} ${i}`,m={timestamp:a,level:e,levelName:o,module:r,message:i,args:n};if(h.addToHistory(m),typeof h.reporter=="function")try{h.reporter(m)}catch(O){}h.outputToConsole(e,d,...n)}static addToHistory(e){h.logHistory.push(e),h.logHistory.length>h.maxHistorySize&&h.logHistory.shift()}static outputToConsole(e,r,...i){if(typeof console=="undefined")return;const n=i&&i.length>0;switch(e){case C.ERROR:n?console.error(r,...i):console.error(r);break;case C.WARN:n?console.warn(r,...i):console.warn(r);break;case C.INFO:n?console.info(r,...i):console.info(r);break;case C.DEBUG:case C.TRACE:n?console.log(r,...i):console.log(r);break}}static error(e,r,...i){h.log(C.ERROR,e,r,...i)}static warn(e,r,...i){h.log(C.WARN,e,r,...i)}static info(e,r,...i){h.log(C.INFO,e,r,...i)}static debug(e,r,...i){h.log(C.DEBUG,e,r,...i)}static trace(e,r,...i){h.log(C.TRACE,e,r,...i)}static getHistory(e){return e&&e>0?h.logHistory.slice(-e):[...h.logHistory]}static clearHistory(){h.logHistory=[],h.log(C.INFO,"Logger","日志历史已清空")}static getStats(){const e={currentLevel:h.currentLevel,currentLevelName:we[h.currentLevel],enabledModules:Array.from(h.enabledModules),historySize:h.logHistory.length,maxHistorySize:h.maxHistorySize},r={};for(const i of Object.keys(we))r[we[i]]=0;return h.logHistory.forEach(i=>{r[i.levelName]++}),e.levelCounts=r,e}static exportToJSON(e){const r=h.getHistory(e),i=h.getStats();return JSON.stringify({exportTime:new Date().toISOString(),stats:i,logs:r},null,2)}static createModuleLogger(e){return{error:(r,...i)=>h.error(e,r,...i),warn:(r,...i)=>h.warn(e,r,...i),info:(r,...i)=>h.info(e,r,...i),debug:(r,...i)=>h.debug(e,r,...i),trace:(r,...i)=>h.trace(e,r,...i)}}static setReporter(e){h.reporter=typeof e=="function"?e:null}};X(h,"currentLevel",C.ERROR),X(h,"enabledModules",new Set),X(h,"logHistory",[]),X(h,"maxHistorySize",1e3),X(h,"prefix","[QSH-SDK]"),X(h,"reporter",null);let W=h;if(typeof window!="undefined"){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"));let r=!1;try{r=localStorage&&localStorage.getItem("qsh_debug")==="true"}catch(i){}(t||e||r)&&W.enableDevMode()}const P=W.createModuleLogger("Bridge"),E=W.createModuleLogger("Platform"),s=W.createModuleLogger("API"),B=W.createModuleLogger("State"),Oe=/complete|loaded|interactive/;function sr(t){if(!F())return!1;P.debug("检测到离线包环境,开始初始化");const e=()=>{t()};if(Oe.test(document.readyState))P.debug("离线包环境 DOM 已就绪,立即初始化"),setTimeout(e,0);else{P.debug("离线包环境,等待 DOMContentLoaded");let r=!1;const i=()=>{r||(r=!0,e())};document.addEventListener("DOMContentLoaded",i),setTimeout(i,500)}return!0}function or(t){return de()||re()?(P.debug("检测到 APP 环境,开始初始化"),window.__uniapp_x_postMessage||window.__uniapp_x_||window.__dcloud_weex_postMessage||window.__dcloud_weex_?(P.debug("NVUE/UVUE 环境,等待 DOMContentLoaded"),document.addEventListener("DOMContentLoaded",t)):window.plus&&Oe.test(document.readyState)?(P.debug("Plus 环境已就绪,立即初始化"),setTimeout(t,0)):window.plus?(P.debug("Plus 环境,等待 plusready 事件"),document.addEventListener("plusready",t)):Oe.test(document.readyState)?setTimeout(t,0):document.addEventListener("DOMContentLoaded",t,{once:!0}),!0):!1}function cr(t){return window.wx&&window.wx.miniProgram?(P.debug("检测到微信小程序环境,开始初始化"),window.WeixinJSBridge&&window.WeixinJSBridge.invoke?(P.debug("微信 JSBridge 已就绪,立即初始化"),setTimeout(t,0)):(P.debug("微信 JSBridge 未就绪,等待 WeixinJSBridgeReady 事件"),document.addEventListener("WeixinJSBridgeReady",t)),!0):!1}function ur(t){return P.info("开始初始化 JSBridge"),sr(t)?(P.info("使用离线包环境初始化"),!0):or(t)?(P.info("使用 APP 环境初始化"),!0):cr(t)?(P.info("使用微信小程序环境初始化"),!0):(P.debug("使用默认 H5 环境初始化"),Oe.test(document.readyState)?(P.debug("DOM 已就绪,立即初始化"),setTimeout(t,0)):(P.debug("DOM 未就绪,等待 DOMContentLoaded"),document.addEventListener("DOMContentLoaded",t)),!0)}function lr(){return ie.waitForReady()}function Ze(){return ie.startInitialization(()=>I(null,null,function*(){return new Promise((t,e)=>{const r=()=>{t()},i=n=>{const a=l.handleApiError(n,{context:"bridge initialization"});e(a)};try{ur(()=>{r()})}catch(n){i(n)}})}))}const x={UNINITIALIZED:"uninitialized",CONFIGURING:"configuring",CONFIGURED:"configured",ERROR:"error"};function q(){return typeof window=="undefined"||!window.wx?!1:typeof window.wx.config=="function"&&typeof window.wx.ready=="function"&&typeof window.wx.error=="function"}class fr{constructor(){this.state=x.UNINITIALIZED,this.configPromise=null,this.readyCallbacks=[],this.errorCallbacks=[],this.lastError=null,this.configVersion=0,this.configuredConfigKey=null,this.runtimeConfig={clientId:null,isProd:!1,debug:!1,url:""},this.CONFIG_API_URL=this.getConfigApiUrl(this.runtimeConfig.isProd),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)}configure(e={}){if(!e||typeof e!="object"||Array.isArray(e))throw new v(L.INVALID_PARAMETERS,"config参数异常",{config:e});if(!Object.prototype.hasOwnProperty.call(e,"clientId"))throw this.createMissingClientIdError();if(typeof e.clientId!="string"||!e.clientId.trim())throw new v(L.INVALID_PARAMETERS,"clientId参数异常",{clientId:e.clientId});if(Object.prototype.hasOwnProperty.call(e,"isProd")&&typeof e.isProd!="boolean")throw new v(L.INVALID_PARAMETERS,"isProd参数异常",{isProd:e.isProd});if(Object.prototype.hasOwnProperty.call(e,"debug")&&typeof e.debug!="boolean")throw new v(L.INVALID_PARAMETERS,"debug参数异常",{debug:e.debug});if(Object.prototype.hasOwnProperty.call(e,"url")&&typeof e.url!="string")throw new v(L.INVALID_PARAMETERS,"url参数异常",{url:e.url});const r=e.clientId.trim(),i=e.isProd===!0,n=i?!1:e.debug===!0,a=typeof e.url=="string"?e.url.trim():"",o=r!==this.runtimeConfig.clientId||i!==this.runtimeConfig.isProd||n!==this.runtimeConfig.debug||a!==this.runtimeConfig.url;return this.runtimeConfig=w(g({},this.runtimeConfig),{clientId:r,isProd:i,debug:n,url:a}),this.CONFIG_API_URL=this.getConfigApiUrl(i),(this.state===x.ERROR||o&&(this.state===x.CONFIGURING||this.state===x.CONFIGURED))&&this.reset({preserveCallbacks:!0}),E.info("Updated Weixin runtime config",{clientId:this.runtimeConfig.clientId,isProd:this.runtimeConfig.isProd,debug:this.runtimeConfig.debug,url:this.runtimeConfig.url,configApiUrl:this.CONFIG_API_URL}),this.getRuntimeConfig()}getRuntimeConfig(){return g({},this.runtimeConfig)}getEffectiveConfigUrl(e={}){const{requireWindow:r=!1}=e;return this.runtimeConfig.url?this.runtimeConfig.url:r?this.getCurrentPageUrl():typeof window=="undefined"||!window.location?"":this.getCurrentPageUrl()}getRuntimeConfigKey(){return JSON.stringify({clientId:this.runtimeConfig.clientId,isProd:this.runtimeConfig.isProd,debug:this.runtimeConfig.debug,url:this.getEffectiveConfigUrl()})}isCurrentConfigRun(e,r){return e===this.configVersion&&r===this.getRuntimeConfigKey()}hasClientId(){return typeof this.runtimeConfig.clientId=="string"&&this.runtimeConfig.clientId.length>0}hasRequiredConfig(){return this.isTestMode()||this.hasClientId()}createMissingClientIdError(){return new v(L.INVALID_PARAMETERS,"clientId错误",{field:"clientId"})}getConfigApiUrl(e=!1){return e?"https://tyck-service.xj-agri.gov.cn/api/wechat/mp/jssdk-sign":"https://unified-platform-service.xjy2.cn/api/wechat/mp/jssdk-sign"}getCurrentPageUrl(){if(typeof window=="undefined"||!window.location)throw new Error("无法获取当前页面URL");const e=window.location.href,r=e.indexOf("#");return r!==-1?e.substring(0,r):e}fetchWeixinConfig(){return I(this,null,function*(){const e=this.getEffectiveConfigUrl({requireWindow:!0});if(this.isTestMode())return E.info("使用测试模式,返回模拟配置"),this.getMockConfig();if(!this.hasClientId())throw this.createMissingClientIdError();const r=this.getConfigApiUrl(this.runtimeConfig.isProd);this.CONFIG_API_URL=r;const i=`${r}?clientId=${this.runtimeConfig.clientId}&url=${encodeURIComponent(e)}`;E.debug("请求微信配置",{url:i});try{const n=yield fetch(i);if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`);const a=yield n.json();if(E.debug("微信配置响应",a),!a.success||a.code!==200)throw new Error(`配置获取失败: ${a.message||"未知错误"}`);const{data:o}=a;if(!o||!o.appId||!o.timestamp||!o.nonceStr||!o.signature)throw new Error("配置数据格式不正确,缺少必需字段");return o}catch(n){if(E.error("获取微信配置失败",n),this.shouldUseTestMode(n))return E.warn("网络请求失败,降级到测试模式"),this.getMockConfig();throw new v(L.NETWORK_ERROR,`获取微信配置失败: ${n.message}`,{url:i,originalError:n})}})}isTestMode(){if(typeof window=="undefined")return!1;if(new URLSearchParams(window.location.search).get("qsh_test")==="true")return!0;try{if(localStorage.getItem("qsh_test")==="true")return!0}catch(r){}return!1}shouldUseTestMode(e){if(typeof window=="undefined")return!1;const r=window.location.hostname==="localhost"||window.location.hostname.includes("natappfree.cc"),i=!window.wx||!window.wx.miniProgram,n=e.message.includes("CORS")||e.message.includes("Failed to fetch");return r&&i&&n}getMockConfig(){return{appId:"wx_test_app_id",timestamp:Math.floor(Date.now()/1e3).toString(),nonceStr:Math.random().toString(36).substring(2,15),signature:"test_signature_"+Math.random().toString(36).substring(2,10)}}executeWeixinConfig(e,r,i){if(this.isTestMode()||e.appId==="wx_test_app_id"){E.info("测试模式:模拟微信配置成功"),setTimeout(()=>{this.handleConfigSuccess(r,i)},100);return}if(!q())throw new Error("微信JS-SDK未加载");const n={debug:this.runtimeConfig.debug,appId:e.appId,timestamp:parseInt(e.timestamp),nonceStr:e.nonceStr,signature:e.signature,jsApiList:this.DEFAULT_JS_API_LIST};E.info("执行微信配置",n),window.wx.ready(()=>this.handleConfigSuccess(r,i)),window.wx.error(a=>this.handleConfigError(a,r,i)),window.wx.config(n)}handleConfigSuccess(e=this.configVersion,r=this.getRuntimeConfigKey()){if(!this.isCurrentConfigRun(e,r)){E.debug("忽略过期的微信配置成功回调");return}E.info("微信配置成功"),this.state=x.CONFIGURED,this.configuredConfigKey=r,this.lastError=null,this.configPromise=null;const i=[...this.readyCallbacks];this.readyCallbacks=[],this.errorCallbacks=[],i.forEach(n=>{try{n()}catch(a){l.handleApiError(a,{context:"WeixinConfigManager.handleConfigSuccess"})}})}handleConfigError(e,r=this.configVersion,i=this.getRuntimeConfigKey()){if(!this.isCurrentConfigRun(r,i)){E.debug("忽略过期的微信配置错误回调",e);return}const n=`微信配置验证失败: ${JSON.stringify(e)}`;E.error(n,e);const a=new v(L.API_CALL_FAILED,n,{weixinErrorResponse:e});this.state=x.ERROR,this.lastError=a,this.configPromise=null;const o=[...this.errorCallbacks];this.readyCallbacks=[],this.errorCallbacks=[],o.forEach(c=>{try{c(a)}catch(d){l.handleApiError(d,{context:"WeixinConfigManager.handleConfigError"})}})}autoConfig(){return I(this,null,function*(){if(!this.hasRequiredConfig())return E.warn("clientId为空,等待qsh.config({ clientId })"),Promise.resolve();if(this.isReady())return Promise.resolve();if(this.state===x.CONFIGURED&&this.reset({preserveCallbacks:!0}),this.state===x.ERROR)return Promise.reject(this.lastError);if(this.configPromise)return this.configPromise;this.state=x.CONFIGURING;const e=this.configVersion,r=this.getRuntimeConfigKey();return this.configPromise=this.performAutoConfig(e,r),this.configPromise})}performAutoConfig(e,r){return I(this,null,function*(){try{if(typeof window=="undefined")throw new Error("非浏览器环境无法执行微信配置");if(!q())throw new Error("微信JS-SDK未加载,无法执行配置");const i=yield this.fetchWeixinConfig();if(!this.isCurrentConfigRun(e,r)){E.debug("忽略过期的微信配置响应");return}return this.executeWeixinConfig(i,e,r),yield new Promise((n,a)=>{if(this.isReady()){n();return}if(this.state===x.ERROR){a(this.lastError);return}this.readyCallbacks.push(n),this.errorCallbacks.push(a)})}catch(i){if(!this.isCurrentConfigRun(e,r)){E.debug("忽略过期的微信配置异常",i);return}const n=i instanceof v?i:l.handleApiError(i,{context:"WeixinConfigManager.performAutoConfig"});this.state=x.ERROR,this.lastError=n,this.configPromise=null;const a=[...this.errorCallbacks];throw this.readyCallbacks=[],this.errorCallbacks=[],a.forEach(o=>{try{o(n)}catch(c){l.handleApiError(c,{context:"WeixinConfigManager.performAutoConfig.errorCallback"})}}),n}})}waitForReady(){return this.isReady()?Promise.resolve():(this.state===x.CONFIGURED&&this.reset({preserveCallbacks:!0}),this.state===x.ERROR?Promise.reject(this.lastError):this.hasRequiredConfig()?this.state===x.UNINITIALIZED?this.autoConfig():new Promise((e,r)=>{this.readyCallbacks.push(e),this.errorCallbacks.push(r)}):Promise.reject(this.createMissingClientIdError()))}isReady(){return this.state===x.CONFIGURED&&this.configuredConfigKey===this.getRuntimeConfigKey()}getState(){return this.state}getLastError(){return this.lastError}reset(e={}){const{preserveCallbacks:r=!1}=e;this.configVersion+=1,this.state=x.UNINITIALIZED,this.configPromise=null,r||(this.readyCallbacks=[],this.errorCallbacks=[]),this.lastError=null,this.configuredConfigKey=null,E.debug("微信配置管理器已重置")}getStats(){return{state:this.state,readyCallbacksCount:this.readyCallbacks.length,errorCallbacksCount:this.errorCallbacks.length,hasConfigPromise:!!this.configPromise,hasLastError:!!this.lastError,configVersion:this.configVersion,configuredConfigKey:this.configuredConfigKey,configApiUrl:this.CONFIG_API_URL,clientId:this.runtimeConfig.clientId,isProd:this.runtimeConfig.isProd,debug:this.runtimeConfig.debug,url:this.runtimeConfig.url,effectiveUrl:this.getEffectiveConfigUrl(),jsApiList:this.DEFAULT_JS_API_LIST}}}const D=new fr;let ge=!1,Ee=!1,G=null,Se=!1;function dr(t){return new Promise(e=>{let r=!1,i=null;const n=c=>I(null,null,function*(){if(!r){if(r=!0,i&&clearTimeout(i),ge=!1,Ee=c,c)try{yield Qe()}catch(d){E.error("微信配置失败,将使用消息桥作为后备",d)}e()}}),a=()=>n(q()),o=()=>{E.warn("已存在的微信 JS-SDK 脚本加载失败,SDK 将使用消息桥作为后备"),n(!1)};t.addEventListener("load",a,{once:!0}),t.addEventListener("error",o,{once:!0}),setTimeout(()=>{q()&&a()},0),i=setTimeout(()=>{n(q())},3e3)})}function We(){return I(this,arguments,function*(t={}){const{force:e=!1,recoverFromError:r=!1}=t;if(yield et({force:e}),!q())throw new Error("微信 JS-SDK 未正确加载,无法执行配置");r&&hr()})}function gr(t=!1){if(typeof window=="undefined")return!1;if(q())return Ee=!0,!1;if(Ee||F())return!1;if(t)return!0;const e=navigator.userAgent||"",r=/micromessenger/i.test(e),i=/miniProgram/i.test(e),n=typeof window.__wxjs_environment!="undefined"&&window.__wxjs_environment==="miniprogram",a=!!(window.wx&&window.wx.miniProgram);return r&&(i||n||a)}function hr(){D.getState()==="error"&&(D.reset(),Se=!1)}function Qe(){return I(this,null,function*(){if(Se)return D.waitForReady();Se=!0,E.info("开始自动配置微信JS-SDK");try{yield D.autoConfig(),E.info("微信JS-SDK自动配置完成")}catch(t){E.error("微信JS-SDK自动配置失败",t)}})}function et(t={}){const{force:e=!1}=t;if(typeof window=="undefined")return Promise.resolve();if(q())return Ee=!0,Promise.resolve();const r=document.getElementById("weixin-jssdk");return r?G||(ge=!0,G=dr(r).finally(()=>{G=null}),G):gr(e)?G||(G=new Promise(i=>{ge=!0;try{const n=document.createElement("script");n.id="weixin-jssdk",n.type="text/javascript",n.async=!0,n.src="https://res.wx.qq.com/open/js/jweixin-1.6.2.js",n.onload=function(){return I(this,null,function*(){Ee=!0,ge=!1,E.info("微信 JS-SDK 已自动加载");try{yield Qe()}catch(o){E.error("微信配置失败,将使用消息桥作为后备",o)}i()})},n.onerror=function(){ge=!1,E.warn("微信 JS-SDK 加载失败,SDK 将使用消息桥作为后备"),i()},(document.getElementsByTagName("head")[0]||document.documentElement).appendChild(n)}catch(n){ge=!1,E.error("注入微信 JS-SDK 失败",n),i()}}).finally(()=>{G=null}),G):Promise.resolve()}function ne(){return We({force:!0,recoverFromError:!0}).then(()=>D.waitForReady())}function tt(t={}){const e=D.configure(t);return typeof window=="undefined"||We({force:!0,recoverFromError:D.getState()==="error"}).then(()=>{if(!D.isReady())return D.waitForReady().catch(r=>{E.error("Failed to auto-configure Weixin after qsh.config()",r)});window.wx&&!q()&&E.warn("window.wx 已存在,但微信 JS-SDK 尚未就绪,跳过自动配置")}).catch(r=>{E.error("Failed to preload Weixin JS-SDK",r)}),e}function he(){return D.isReady()}function mr(){return D.getState()}function $e(){return D}function pr(){return I(this,null,function*(){return E.info("手动重试微信配置"),D.reset(),Se=!1,yield We({force:!0}),D.waitForReady()})}class wr{constructor(){this.plugins=new Map,this.installed=new Set,this.installOrder=[],s.debug("插件管理器已初始化")}register(e){return l.safeExecute(()=>{this.validatePlugin(e);const{name:r,version:i}=e;if(this.plugins.has(r)){const n=this.plugins.get(r);s.warn(`插件 ${r} 已注册(版本 ${n.version}),将被覆盖为版本 ${i}`)}return this.plugins.set(r,e),s.info(`插件已注册: ${r}@${i}`),this},{context:"PluginManager.register",pluginName:e==null?void 0:e.name})}validatePlugin(e){if(!e||typeof e!="object")throw new Error("插件必须是一个对象");if(!e.name||typeof e.name!="string")throw new Error("插件必须有 name 属性(字符串)");if(!e.version||typeof e.version!="string")throw new Error(`插件 ${e.name} 必须有 version 属性(字符串)`);if(!e.install||typeof e.install!="function")throw new Error(`插件 ${e.name} 必须实现 install 方法`);if(e.dependencies&&!Array.isArray(e.dependencies))throw new Error(`插件 ${e.name} 的 dependencies 必须是数组`)}install(e,r){return I(this,null,function*(){return l.safeExecute(()=>I(this,null,function*(){if(!this.plugins.has(e))throw new Error(`插件 ${e} 未注册`);if(this.installed.has(e)){s.debug(`插件 ${e} 已安装,跳过`);return}const i=this.plugins.get(e);if(i.dependencies&&i.dependencies.length>0){s.debug(`安装插件 ${e} 的依赖:`,i.dependencies);for(const n of i.dependencies)yield this.install(n,r)}s.info(`开始安装插件: ${e}@${i.version}`),yield i.install(r),this.installed.add(e),this.installOrder.push(e),s.info(`插件安装成功: ${e}@${i.version}`)}),{context:"PluginManager.install",pluginName:e})})}uninstall(e,r){return I(this,null,function*(){return l.safeExecute(()=>I(this,null,function*(){if(!this.installed.has(e)){s.debug(`插件 ${e} 未安装,跳过卸载`);return}const i=this.plugins.get(e);i.uninstall&&typeof i.uninstall=="function"&&(s.info(`开始卸载插件: ${e}`),yield i.uninstall(r)),this.installed.delete(e);const n=this.installOrder.indexOf(e);n>-1&&this.installOrder.splice(n,1),s.info(`插件已卸载: ${e}`)}),{context:"PluginManager.uninstall",pluginName:e})})}uninstallAll(e){return I(this,null,function*(){const r=[...this.installOrder].reverse();for(const i of r)yield this.uninstall(i,e)})}registerAll(e){if(!Array.isArray(e))throw new Error("plugins 必须是数组");return e.forEach(r=>this.register(r)),this}installAll(e,r){return I(this,null,function*(){if(!Array.isArray(e))throw new Error("names 必须是数组");for(const i of e)yield this.install(i,r)})}isRegistered(e){return this.plugins.has(e)}isInstalled(e){return this.installed.has(e)}getPlugin(e){return this.plugins.get(e)}getPluginList(){return Array.from(this.plugins.entries()).map(([e,r])=>({name:e,version:r.version,installed:this.installed.has(e),dependencies:r.dependencies||[]}))}getStats(){return{registered:this.plugins.size,installed:this.installed.size,plugins:this.getPluginList()}}clear(){this.plugins.clear(),this.installed.clear(),this.installOrder=[]}}const ye=new wr;class Er{constructor(){this.requestInterceptors=[],this.responseInterceptors=[],s.debug("拦截器链已初始化")}useRequest(e,r={}){if(typeof e!="function")throw new Error("拦截器必须是函数");const{priority:i=0}=r;return this.requestInterceptors.push({fn:e,priority:i}),this.requestInterceptors.sort((n,a)=>a.priority-n.priority),s.debug("请求拦截器已注册",{priority:i}),()=>{const n=this.requestInterceptors.findIndex(a=>a.fn===e);n>-1&&(this.requestInterceptors.splice(n,1),s.debug("请求拦截器已移除"))}}useResponse(e,r={}){if(typeof e!="function")throw new Error("拦截器必须是函数");const{priority:i=0}=r;return this.responseInterceptors.push({fn:e,priority:i}),this.responseInterceptors.sort((n,a)=>a.priority-n.priority),s.debug("响应拦截器已注册",{priority:i}),()=>{const n=this.responseInterceptors.findIndex(a=>a.fn===e);n>-1&&(this.responseInterceptors.splice(n,1),s.debug("响应拦截器已移除"))}}runRequest(e){return I(this,null,function*(){let r=g({},e);for(const{fn:i}of this.requestInterceptors){if(r.abort){s.debug("请求被中止",{apiName:r.apiName});break}try{const n=yield i(r);n&&(r=n)}catch(n){s.error("请求拦截器执行失败",n),r.abort=!0,r.error=n;break}}return r})}runResponse(e,r){return I(this,null,function*(){let i=e;for(const{fn:n}of this.responseInterceptors)try{const a=yield n(i,r);a!==void 0&&(i=a)}catch(a){s.error("响应拦截器执行失败",a)}return i})}clear(){this.requestInterceptors=[],this.responseInterceptors=[],s.debug("所有拦截器已清空")}getStats(){return{requestInterceptors:this.requestInterceptors.length,responseInterceptors:this.responseInterceptors.length}}}const ae=new Er,yr={request:t=>(t.startTime=Date.now(),s.debug(`[API 调用] ${t.apiName}`,{params:t.params}),t),response:(t,e)=>{const r=Date.now()-e.startTime;return s.debug(`[API 完成] ${e.apiName}`,{duration:`${r}ms`,success:t==null?void 0:t.success}),t}},Z={metrics:new Map,request:t=>(t.perfStartTime=performance.now(),t),response:(t,e)=>{const r=performance.now()-e.perfStartTime;Z.metrics.has(e.apiName)||Z.metrics.set(e.apiName,{count:0,totalTime:0,minTime:1/0,maxTime:0,avgTime:0});const i=Z.metrics.get(e.apiName);return i.count++,i.totalTime+=r,i.minTime=Math.min(i.minTime,r),i.maxTime=Math.max(i.maxTime,r),i.avgTime=i.totalTime/i.count,t},getReport:()=>{const t={};return Z.metrics.forEach((e,r)=>{t[r]=g({},e)}),t},clearMetrics:()=>{Z.metrics.clear()}};function Ar(t={}){const{maxRetries:e=3,retryDelay:r=1e3,shouldRetry:i=n=>!n.success}=t;return{response:(n,a)=>I(null,null,function*(){return a.retryCount||(a.retryCount=0),i(n)&&a.retryCount<e&&(a.retryCount++,s.warn(`API 调用失败,第 ${a.retryCount} 次重试: ${a.apiName}`),yield new Promise(o=>setTimeout(o,r)),n.shouldRetry=!0,n.retryContext=a),n})}}function Ir(t={}){return{request:e=>{const r=t[e.apiName];if(r&&typeof r=="function"){const i=r(e.params);i&&(s.error(`参数验证失败: ${e.apiName}`,i),e.abort=!0,e.validationError=i)}return e}}}class Pr{constructor(){this.state={sdk:{status:"uninitialized",version:"2.0.5",error:null},platform:{type:f.type,isWeixinMiniProgram:f.isWeixinMiniProgram,isAppPlus:f.isAppPlus,isNvue:f.isNvue,isUvue:f.isUvue,isOfflineWebview:f.isOfflineWebview,features:{}},weixin:{configStatus:"pending",jsApiList:[],configError:null},network:{online:typeof navigator!="undefined"?navigator.onLine:!0,type:"unknown"},permissions:{camera:"prompt",location:"prompt",album:"prompt"},api:{}},this.listeners=new Map,this.wildcardListeners=new Set,this.initNetworkListener(),B.debug("状态仓库已初始化")}get(e){return e.split(".").reduce((i,n)=>i!=null?i[n]:void 0,this.state)}set(e,r){const i=e.split("."),n=i.pop(),a=i.reduce((c,d)=>((!c[d]||typeof c[d]!="object")&&(c[d]={}),c[d]),this.state),o=a[n];o!==r&&(a[n]=r,B.debug(`状态已更新: ${e}`,{oldValue:o,newValue:r}),this.notify(e,r,o))}batchUpdate(e){Object.entries(e).forEach(([r,i])=>{this.set(r,i)})}subscribe(e,r){if(typeof r!="function")throw new Error("listener 必须是函数");return e==="*"?(this.wildcardListeners.add(r),B.debug("添加通配符订阅者"),()=>{this.wildcardListeners.delete(r),B.debug("移除通配符订阅者")}):(this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(r),B.debug(`添加订阅者: ${e}`),()=>{const i=this.listeners.get(e);i&&(i.delete(r),i.size===0&&this.listeners.delete(e),B.debug(`移除订阅者: ${e}`))})}subscribeOnce(e,r){const i=this.subscribe(e,(n,a,o)=>{r(n,a,o),i()});return i}notify(e,r,i){const n=this.listeners.get(e);n&&n.forEach(o=>{try{o(r,i,e)}catch(c){B.error("订阅者执行失败",c)}});const a=e.split(".");for(let o=1;o<a.length;o++){const c=a.slice(0,o).join("."),d=this.listeners.get(c);if(d){const m=this.get(c);d.forEach(O=>{try{O(m,void 0,c)}catch(_){B.error("父路径订阅者执行失败",_)}})}}this.wildcardListeners.forEach(o=>{try{o(r,i,e)}catch(c){B.error("通配符订阅者执行失败",c)}})}initNetworkListener(){if(typeof window!="undefined"&&(window.addEventListener("online",()=>{this.set("network.online",!0)}),window.addEventListener("offline",()=>{this.set("network.online",!1)}),navigator.connection)){const e=navigator.connection,r=()=>{this.set("network.type",e.effectiveType||"unknown")};e.addEventListener("change",r),r()}}setApiLoading(e,r=!0){const i=`api.${e}`,n=this.get(i)||{};this.set(i,w(g({},n),{loading:r,lastCall:r?Date.now():n.lastCall}))}setApiResult(e,r){const i=`api.${e}`,n=this.get(i)||{};this.set(i,w(g({},n),{loading:!1,lastResult:r,lastCallEnd:Date.now()}))}getSnapshot(){return JSON.parse(JSON.stringify(this.state))}reset(){const{platform:e}=this.state;this.state={sdk:{status:"uninitialized",version:"2.0.5",error:null},platform:e,weixin:{configStatus:"pending",jsApiList:[],configError:null},network:{online:typeof navigator!="undefined"?navigator.onLine:!0,type:"unknown"},permissions:{camera:"prompt",location:"prompt",album:"prompt"},api:{}},B.debug("状态已重置")}getStats(){return{listeners:this.listeners.size,wildcardListeners:this.wildcardListeners.size,apiStates:Object.keys(this.state.api).length}}}const j=new Pr,u={SDK_NOT_READY:"E_SDK_001",SDK_INIT_FAILED:"E_SDK_002",SDK_CONFIG_FAILED:"E_SDK_003",PLATFORM_NOT_SUPPORTED:"E_SDK_004",NETWORK_ERROR:"E_NET_001",NETWORK_TIMEOUT:"E_NET_002",NETWORK_OFFLINE:"E_NET_003",IMAGE_CANCELLED:"E_IMG_001",IMAGE_NO_PERMISSION:"E_IMG_002",IMAGE_SIZE_EXCEED:"E_IMG_003",IMAGE_COUNT_EXCEED:"E_IMG_004",IMAGE_FORMAT_ERROR:"E_IMG_005",IMAGE_CONFIG_NOT_READY:"E_IMG_006",LOCATION_CANCELLED:"E_LOC_001",LOCATION_NO_PERMISSION:"E_LOC_002",LOCATION_UNAVAILABLE:"E_LOC_003",LOCATION_TIMEOUT:"E_LOC_004",SCAN_CANCELLED:"E_SCAN_001",SCAN_NO_PERMISSION:"E_SCAN_002",SCAN_INVALID_CODE:"E_SCAN_003",SCAN_CONFIG_NOT_READY:"E_SCAN_004",PERMISSION_DENIED:"E_PERM_001",PERMISSION_CAMERA:"E_PERM_002",PERMISSION_LOCATION:"E_PERM_003",PERMISSION_ALBUM:"E_PERM_004",PERMISSION_MICROPHONE:"E_PERM_005",PARAM_INVALID:"E_PARAM_001",PARAM_MISSING:"E_PARAM_002",PARAM_TYPE_ERROR:"E_PARAM_003",API_TIMEOUT:"E_TIMEOUT_001",UNKNOWN_ERROR:"E_UNKNOWN_999"},Fe={[u.SDK_NOT_READY]:"SDK 未就绪",[u.SDK_INIT_FAILED]:"SDK 初始化失败",[u.SDK_CONFIG_FAILED]:"SDK 配置失败",[u.PLATFORM_NOT_SUPPORTED]:"当前平台不支持此功能",[u.NETWORK_ERROR]:"网络错误",[u.NETWORK_TIMEOUT]:"网络超时",[u.NETWORK_OFFLINE]:"网络已断开",[u.IMAGE_CANCELLED]:"用户取消选择图片",[u.IMAGE_NO_PERMISSION]:"无相机/相册权限",[u.IMAGE_SIZE_EXCEED]:"图片大小超出限制",[u.IMAGE_COUNT_EXCEED]:"图片数量超出限制",[u.IMAGE_FORMAT_ERROR]:"图片格式不支持",[u.IMAGE_CONFIG_NOT_READY]:"微信配置未完成",[u.LOCATION_CANCELLED]:"用户取消定位",[u.LOCATION_NO_PERMISSION]:"无定位权限",[u.LOCATION_UNAVAILABLE]:"定位服务不可用",[u.LOCATION_TIMEOUT]:"定位超时",[u.SCAN_CANCELLED]:"用户取消扫码",[u.SCAN_NO_PERMISSION]:"无相机权限",[u.SCAN_INVALID_CODE]:"无效的二维码/条形码",[u.SCAN_CONFIG_NOT_READY]:"微信配置未完成",[u.PERMISSION_DENIED]:"权限被拒绝",[u.PERMISSION_CAMERA]:"无相机权限",[u.PERMISSION_LOCATION]:"无定位权限",[u.PERMISSION_ALBUM]:"无相册权限",[u.PERMISSION_MICROPHONE]:"无麦克风权限",[u.PARAM_INVALID]:"参数无效",[u.PARAM_MISSING]:"缺少必需参数",[u.PARAM_TYPE_ERROR]:"参数类型错误",[u.API_TIMEOUT]:"API 调用超时",[u.UNKNOWN_ERROR]:"未知错误"},K={USER_CANCEL:"user_cancel",PERMISSION:"permission",NETWORK:"network",PARAM:"param",SYSTEM:"system",CONFIG:"config",UNKNOWN:"unknown"},Mr={"IMAGE/USER_CANCEL":u.IMAGE_CANCELLED,"IMAGE/PERMISSION_DENIED":u.IMAGE_NO_PERMISSION,"COMMON/UNKNOWN":u.UNKNOWN_ERROR,"COMMON/CONFIG_NOT_READY":u.IMAGE_CONFIG_NOT_READY,"COMMON/PLATFORM_NOT_SUPPORTED":u.PLATFORM_NOT_SUPPORTED},rt={weixin:{patterns:[{pattern:/cancel/i,code:u.IMAGE_CANCELLED},{pattern:/permission|auth\s*deny/i,code:u.IMAGE_NO_PERMISSION},{pattern:/config/i,code:u.IMAGE_CONFIG_NOT_READY},{pattern:/timeout/i,code:u.API_TIMEOUT},{pattern:/network/i,code:u.NETWORK_ERROR}],default:u.UNKNOWN_ERROR},uniapp:{patterns:[{pattern:/cancel/i,code:u.IMAGE_CANCELLED},{pattern:/permission|denied/i,code:u.IMAGE_NO_PERMISSION},{pattern:/timeout/i,code:u.API_TIMEOUT},{pattern:/network/i,code:u.NETWORK_ERROR},{pattern:/not_in_container/i,code:u.PLATFORM_NOT_SUPPORTED}],default:u.UNKNOWN_ERROR},offline:{patterns:[{pattern:/cancel/i,code:u.IMAGE_CANCELLED},{pattern:/permission|denied/i,code:u.IMAGE_NO_PERMISSION},{pattern:/timeout/i,code:u.API_TIMEOUT},{pattern:/network/i,code:u.NETWORK_ERROR},{pattern:/not_in_container/i,code:u.PLATFORM_NOT_SUPPORTED}],default:u.UNKNOWN_ERROR}},it={chooseImage:{"fail cancel":u.IMAGE_CANCELLED,"fail auth deny":u.IMAGE_NO_PERMISSION,"fail No Permission":u.IMAGE_NO_PERMISSION,NOT_IN_CONTAINER:u.PLATFORM_NOT_SUPPORTED},scanCode:{"fail cancel":u.SCAN_CANCELLED,"fail auth deny":u.SCAN_NO_PERMISSION,"fail No Permission":u.SCAN_NO_PERMISSION,NOT_IN_CONTAINER:u.PLATFORM_NOT_SUPPORTED}};function nt(t){return t?t.includes("CANCEL")?K.USER_CANCEL:t.includes("PERM")||t.includes("PERMISSION")?K.PERMISSION:t.includes("NET")||t.includes("NETWORK")?K.NETWORK:t.includes("PARAM")?K.PARAM:t.includes("CONFIG")?K.CONFIG:t.includes("SDK")||t.includes("PLATFORM")?K.SYSTEM:K.UNKNOWN:K.UNKNOWN}function Cr(t){return t.includes("NET_")||t.includes("TIMEOUT")||t===u.NETWORK_ERROR||t===u.NETWORK_TIMEOUT||t===u.API_TIMEOUT}function _r(t){return t.includes("CANCEL")||nt(t)===K.USER_CANCEL}function me(t){return Fe[t]||Fe[u.UNKNOWN_ERROR]}class J extends Error{constructor(e,r,i={}){super(r),this.name="StandardError",this.code=e,this.message=r||me(e),this.platform=i.platform||f.type,this.apiName=i.apiName,this.category=i.category||nt(e),this.retriable=i.retriable!==void 0?i.retriable:Cr(e),this.originalError=i.originalError,this.details=i.details||{},this.timestamp=Date.now()}isRetriable(){return this.retriable}isUserAction(){return _r(this.code)}toJSON(){return g({code:this.code,message:this.message,platform:this.platform,apiName:this.apiName,category:this.category,retriable:this.retriable,timestamp:this.timestamp,details:this.details},process.env.NODE_ENV!=="production"&&this.originalError?{originalError:this.originalError}:{})}}function at(t,e={}){if(t instanceof J)return t;const{apiName:r,platform:i=f.type}=e;return t&&typeof t.code=="string"&&t.code.includes("/")?Rr(t,{apiName:r,platform:i}):t&&(t.errMsg||t.message)?Or(t,{apiName:r,platform:i}):typeof t=="string"?new J(u.UNKNOWN_ERROR,t,{apiName:r,platform:i,originalError:t}):new J(u.UNKNOWN_ERROR,"未知错误",{apiName:r,platform:i,originalError:t,details:{errorType:typeof t}})}function Rr(t,e){const{apiName:r,platform:i}=e,n=t.code,a=Mr[n]||u.UNKNOWN_ERROR;return s.debug("转换旧版错误码",{legacy:n,new:a}),new J(a,t.message||me(a),{apiName:r,platform:t.platform||i,originalError:t,details:g({legacyCode:n,legacyVersion:t.version},t.details)})}function Or(t,e){const{apiName:r,platform:i}=e,n=(t.errMsg||t.message||"").toLowerCase();if(r&&it[r]){const c=it[r];for(const[d,m]of Object.entries(c))if(n.includes(d.toLowerCase()))return new J(m,me(m),{apiName:r,platform:i,originalError:t})}const a=rt[i]||rt.uniapp;for(const{pattern:c,code:d}of a.patterns)if(c.test(n))return new J(d,me(d),{apiName:r,platform:i,originalError:t});const o=a.default||u.UNKNOWN_ERROR;return new J(o,t.errMsg||t.message||me(o),{apiName:r,platform:i,originalError:t})}const st={response:(t,e)=>{if(!t.success&&t.error){const r=at(t.error,{apiName:e.apiName,platform:f.type});t.error=r.toJSON(),t.errorCode=r.code,t.errorCategory=r.category,t.retriable=r.isRetriable(),s.debug("错误已标准化",{api:e.apiName,code:r.code,category:r.category})}return t}};function Sr(t,e={}){return new J(t,me(t),e)}function Nr(t){return t instanceof J}function br(t,e,r){return e?Promise.race([t(),new Promise((i,n)=>setTimeout(()=>n(new Error(`Init task timeout: ${r}`)),e))]):t()}function vr(){return I(this,arguments,function*(t=[],e={}){for(const r of t){const i=(r==null?void 0:r.name)||"anonymous-task",n=(r==null?void 0:r.run)||r;if(typeof n=="function")try{yield br(()=>Promise.resolve().then(()=>n()),r.timeoutMs,i),typeof r.onSuccess=="function"&&r.onSuccess()}catch(a){if(typeof r.onError=="function"&&r.onError(a),typeof e.onError=="function")e.onError(a,r);else throw a}}})}class ot{constructor(e){this.name=e}processNavigationOptions(e={}){const{url:r,delta:i=1}=e,n=r&&encodeURI(r),a=parseInt(i)||1;return w(g({},e),{url:n,delta:a})}processMessageOptions(e={}){const{data:r={}}=e;return{data:r}}navigateTo(e){const r=this.processNavigationOptions(e);return this.performNavigation("navigateTo",r)}navigateBack(e={}){const r=this.processNavigationOptions(e);return this.performNavigation("navigateBack",r)}switchTab(e){const r=this.processNavigationOptions(e);return this.performNavigation("switchTab",r)}reLaunch(e){const r=this.processNavigationOptions(e);return this.performNavigation("reLaunch",r)}redirectTo(e){const r=this.processNavigationOptions(e);return this.performNavigation("redirectTo",r)}postMessage(e={}){const r=this.processMessageOptions(e);return this.performPostMessage(r)}getEnv(e){return this.performGetEnv(e)}performNavigation(e,r){throw new Error(`${this.name} platform must implement performNavigation method`)}performPostMessage(e){throw new Error(`${this.name} platform must implement performPostMessage method`)}performGetEnv(e){throw new Error(`${this.name} platform must implement performGetEnv method`)}}let Ae=[];function Tr(){if(Ae.length===0&&window.plus){const t=plus.webview.currentWebview();if(!t)throw new Error("plus.webview.currentWebview() is undefined");const e=t.parent(),r=e?e.id:t.id;Ae.push(r)}return Ae}function xr(t,e){const r={options:{timestamp:+new Date},name:t,arg:e};if(t==="postMessage"){const n={data:e};return window.__uniapp_x_postMessage?window.__uniapp_x_postMessage(n):window.__uniapp_x_.postMessage(JSON.stringify(n))}const i={type:"WEB_INVOKE_APPSERVICE",args:{data:r,webviewIds:Ae}};window.__uniapp_x_postMessage?window.__uniapp_x_postMessageToService(i):window.__uniapp_x_.postMessageToService(JSON.stringify(i))}function Lr(t,e){const r={options:{timestamp:+new Date},name:t,arg:e};if(t==="postMessage"){const n={data:[e]};return window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessage(n):window.__dcloud_weex_.postMessage(JSON.stringify(n))}const i={type:"WEB_INVOKE_APPSERVICE",args:{data:r,webviewIds:Ae}};window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessageToService(i):window.__dcloud_weex_.postMessageToService(JSON.stringify(i))}function Dr(t,e){const r={options:{timestamp:+new Date},name:t,arg:e},i=Tr();if(plus.webview.getWebviewById("__uniapp__service"))plus.webview.postMessageToUniNView({type:"WEB_INVOKE_APPSERVICE",args:{data:r,webviewIds:i}},"__uniapp__service");else{const n=JSON.stringify(r),a=JSON.stringify(i);plus.webview.getLaunchWebview().evalJS(`UniPlusBridge.subscribeHandler("WEB_INVOKE_APPSERVICE",${n},${a});`)}}function Ur(t,e){const r={options:{timestamp:+new Date},name:t,arg:e};window.parent.postMessage({type:"WEB_INVOKE_APPSERVICE",data:r,pageId:""},"*")}function Wr(t){return!!(t&&typeof t=="object"&&t.type==="qsh_api_call"&&typeof t.api=="string"&&typeof t.callbackId=="string")}function $r(t,e){const r={options:{timestamp:+new Date},name:t,arg:e};if(t==="postMessage"&&Wr(e))return window.__offline_bridge_postMessage(e);window.__offline_bridge_postMessage({type:"WEB_INVOKE_APPSERVICE",data:r,pageId:""})}function Ie(t,e){fe()?xr(t,e):te()?Lr(t,e):F()?$r(t,e):le()?Dr(t,e):Ur(t,e)}class ct extends ot{constructor(){super("weixin")}isWeixinApiAvailable(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram}performNavigation(e,r){return l.safeExecute(()=>{const{url:i,delta:n}=r;if(E.debug(`微信平台执行导航操作: ${e}`,r),this.isWeixinApiAvailable()){const o=window.wx.miniProgram[e];if(typeof o=="function"){E.debug(`使用微信原生 API: wx.miniProgram.${e}`);const c=e==="navigateBack"?{delta:n}:{url:i};return o.call(window.wx.miniProgram,c)}}E.debug(`使用消息桥接执行: ${e}`),Ie(e,e==="navigateBack"?{delta:n}:{url:i})},{platform:this.name,method:"performNavigation",navigationType:e,options:r})}performPostMessage(e){return l.safeExecute(()=>{const{data:r}=e;if(this.isWeixinApiAvailable())return window.wx.miniProgram.postMessage({data:r});Ie("postMessage",r)},{platform:this.name,method:"performPostMessage",options:e})}performGetEnv(e){return l.safeExecute(()=>{if(!e||typeof e!="function")throw new Error("Callback function is required for getEnv");if(this.isWeixinApiAvailable()&&window.wx.miniProgram.getEnv)return window.wx.miniProgram.getEnv(e);e({miniprogram:!0,weixin:!0})},{platform:this.name,method:"performGetEnv"})}}const se=new ct;var ut=Object.freeze({__proto__:null,WeixinPlatform:ct,getEnv:t=>se.getEnv(t),navigateBack:t=>se.navigateBack(t),navigateTo:t=>se.navigateTo(t),postMessage:t=>se.postMessage(t),reLaunch:t=>se.reLaunch(t),redirectTo:t=>se.redirectTo(t),switchTab:t=>se.switchTab(t)});class lt extends ot{constructor(){super("app")}performNavigation(e,r){return l.safeExecute(()=>{const{url:i,delta:n}=r;Ie(e,e==="navigateBack"?{delta:n}:{url:i})},{platform:this.name,method:"performNavigation",navigationType:e,options:r})}performPostMessage(e){return l.safeExecute(()=>{const{data:r}=e;Ie("postMessage",r)},{platform:this.name,method:"performPostMessage",options:e})}performGetEnv(e){return l.safeExecute(()=>{if(!e||typeof e!="function")throw new Error("Callback function is required for getEnv");const r={};let i=!1;fe()?(r.uvue=!0,i=!0):te()?(r.nvue=!0,i=!0):le()?(r.plus=!0,i=!0):F()&&(r.offline=!0,i=!0),i?r.app=!0:r.h5=!0,e(r)},{platform:this.name,method:"performGetEnv"})}}const oe=new lt;var ft=Object.freeze({__proto__:null,AppPlatform:lt,getEnv:t=>oe.getEnv(t),navigateBack:t=>oe.navigateBack(t),navigateTo:t=>oe.navigateTo(t),postMessage:t=>oe.postMessage(t),reLaunch:t=>oe.reLaunch(t),redirectTo:t=>oe.redirectTo(t),switchTab:t=>oe.switchTab(t)});function Pe(){return p()?ut:ft}function Fr(t){return Pe().navigateTo(t)}function kr(t){return Pe().navigateBack(t)}function Br(t){return Pe().switchTab(t)}function Gr(t){return Pe().reLaunch(t)}function Kr(t){return Pe().redirectTo(t)}function dt(){return p()?ut:ft}function Vr(t={}){return dt().postMessage(t)}function qr(t){return dt().getEnv(t)}function jr(t){return t&&typeof t=="object"&&t.__v_raw?t.__v_raw:t}function Jr(){return"qsh_callback_"+Date.now()+"_"+Math.random().toString(36).substring(2,9)}class Hr{constructor(){this.callbacks=new Map,this.timeouts=new Map,this.persistentCallbacksByApi=new Map,this.defaultTimeout=3e4,typeof window!="undefined"&&(window.qshWebviewCallbacks||(window.qshWebviewCallbacks={})),P.debug("WebView 桥接器已初始化")}callApi(n){return I(this,arguments,function*(e,r={},i={}){return l.safeExecute(()=>I(this,null,function*(){var m;if(typeof window!="undefined"&&window===window.parent&&!window.plus&&!window.__uniapp_x_postMessage&&!window.__uniapp_x_&&!window.__dcloud_weex_postMessage&&!window.__dcloud_weex_&&!F()){const O=new v(L.PLATFORM_NOT_SUPPORTED,"当前不在宿主 WebView 容器中,无法发送消息");i&&typeof i.fail=="function"&&i.fail({errMsg:O.message,code:"NOT_IN_CONTAINER"}),i&&typeof i.complete=="function"&&i.complete({success:!1,error:{errMsg:O.message}});return}const o={apiName:e,params:r,callbacks:i,timestamp:Date.now(),abort:!1,metadata:{}};j.setApiLoading(e,!0);const c=yield ae.runRequest(o);if(c.abort){P.warn("API 调用被拦截器中止",{api:e}),j.setApiLoading(e,!1),i.fail&&i.fail({errMsg:((m=c.error)==null?void 0:m.message)||"API 调用被中止",code:"INTERCEPTED"}),i.complete&&i.complete({success:!1});return}const d=Jr();if(i.success||i.fail||i.complete){if(this.callbacks.set(d,w(g({},i),{context:c})),window.qshWebviewCallbacks[d]=H=>{this.handleCallback(d,H)},r.isPersistent&&(this.persistentCallbacksByApi.has(e)||this.persistentCallbacksByApi.set(e,new Set),this.persistentCallbacksByApi.get(e).add(d)),r.isPersistent||r.disableTimeout)P.info(`API ${e} 禁用超时清理,将等待回调返回后清理`,{callbackId:d,isPersistent:r.isPersistent,disableTimeout:r.disableTimeout});else{const H=setTimeout(()=>{P.warn("API 调用超时,自动清理回调",{api:e,callbackId:d}),i.fail&&i.fail({errMsg:`API ${e} 调用超时`,code:"TIMEOUT"}),this.cleanupCallback(d)},r.timeout||this.defaultTimeout);this.timeouts.set(d,H)}const _={type:"qsh_api_call",api:e,params:c.params,callbackId:d,timestamp:Date.now()};P.info("发送 API 调用消息",{api:e,callbackId:d,hasSuccess:!!i.success,hasFail:!!i.fail}),console.log("message:",JSON.stringify(jr(_),null,2)),Ie("postMessage",_)}}),{context:"WebViewBridge.callApi",api:e})})}handleCallback(e,r){return I(this,null,function*(){return l.safeExecute(()=>I(this,null,function*(){var O,_;const i=this.callbacks.get(e);if(!i){P.warn("未找到回调函数",{callbackId:e});return}const{success:n,fail:a,complete:o,context:c}=i;P.debug("处理回调",{callbackId:e,result:r});const d=yield ae.runResponse(r,c);c&&j.setApiResult(c.apiName,d),d.success&&n?n(d.data):!d.success&&a&&a(d.error||{errMsg:"操作失败"}),o&&o(d),((_=(O=i.context)==null?void 0:O.params)==null?void 0:_.isPersistent)?P.debug("持久监听API:保留回调",{callbackId:e}):(this.cleanupCallback(e),P.debug("回调执行完成,已清理",{callbackId:e}))}),{context:"WebViewBridge.handleCallback",callbackId:e})})}cleanupCallback(e){const r=this.timeouts.get(e);if(r&&(clearTimeout(r),this.timeouts.delete(e)),this.callbacks.delete(e),typeof window!="undefined"&&window.qshWebviewCallbacks&&delete window.qshWebviewCallbacks[e],this.persistentCallbacksByApi&&this.persistentCallbacksByApi.size>0){const i=[];this.persistentCallbacksByApi.forEach((n,a)=>{n.has(e)&&(n.delete(e),n.size===0&&i.push(a))}),i.forEach(n=>this.persistentCallbacksByApi.delete(n))}}clearCallbacks(){P.debug("清理所有回调",{count:this.callbacks.size}),this.timeouts.forEach(e=>clearTimeout(e)),this.timeouts.clear(),this.callbacks.clear(),this.persistentCallbacksByApi&&this.persistentCallbacksByApi.clear(),typeof window!="undefined"&&window.qshWebviewCallbacks&&Object.keys(window.qshWebviewCallbacks).forEach(e=>{e.startsWith("qsh_callback_")&&delete window.qshWebviewCallbacks[e]})}cleanupPersistentCallbacksByApi(e){const r=this.persistentCallbacksByApi.get(e);if(!r||r.size===0)return 0;const i=Array.from(r);return i.forEach(n=>this.cleanupCallback(n)),this.persistentCallbacksByApi.delete(e),P.info("已清理持久回调",{api:e,count:i.length}),i.length}getStatus(){return{isSupported:typeof window!="undefined"&&window.uni&&typeof window.uni.postMessage=="function",activeCallbacks:this.callbacks.size,globalCallbacksCount:typeof window!="undefined"&&window.qshWebviewCallbacks?Object.keys(window.qshWebviewCallbacks).length:0}}}const gt=new Hr,N=(t,e,r)=>gt.callApi(t,e,r),pe=t=>gt.cleanupPersistentCallbacksByApi(t);function ht(){return V(!0)}function zr(t){return t==="offline"}function Yr(t={}){return l.safeExecute(()=>{s.debug("Call getCode through offline webview bridge",{clientId:t.clientId}),N("getCode",{clientId:t.clientId},{success:e=>{var r;s.info("Get code success"),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("Get code failed",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"getCodeInHost",platform:ht().type})}function Xr(t={}){return l.safeExecute(()=>{var i,n;const e=ht(),r=String((t==null?void 0:t.clientId)||"").trim();if(!r){const a={errMsg:"clientId is required",code:"APP_KEY_MISSING"};s.error("Get code missing clientId"),(i=t.fail)==null||i.call(t,a);return}if(!zr(e.type)){const a={errMsg:`Current environment (${e.type}) does not support getCode`,code:"PLATFORM_NOT_SUPPORTED"};s.error("Platform does not support getCode",{platform:e.type}),(n=t.fail)==null||n.call(t,a);return}Yr(w(g({},t),{clientId:r}))},{context:"getCode",options:t})}function mt(){return V(!0)}const pt=["release","trial","develop"];function Zr(t={}){const e=String((t==null?void 0:t.appid)||"").trim(),r=(t==null?void 0:t.path)==null?"":t.path,i=t==null?void 0:t.env,n=i==null||i===""?void 0:String(i).trim();if(!e)throw{errMsg:"appid is required",code:"PARAM_MISSING"};if(typeof r!="string")throw{errMsg:"path must be a string",code:"PARAM_TYPE_ERROR"};if(n!==void 0&&!pt.includes(n))throw{errMsg:`env must be one of ${pt.join("/")}`,code:"PARAM_INVALID"};return w(g({},t),{appid:e,path:r.trim(),env:n})}function Qr(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram&&typeof window.wx.miniProgram.postMessage=="function"&&typeof window.wx.miniProgram.navigateBack=="function"}function ei(t={}){return l.safeExecute(()=>{var r;if(!Qr()){const i={errMsg:"wx.miniProgram.postMessage or wx.miniProgram.navigateBack is not available",code:"PLATFORM_NOT_SUPPORTED"};s.error("Weixin web-view relay APIs are not available"),(r=t.fail)==null||r.call(t,i);return}const e={type:"qsh_api_call",api:"navigateToMiniProgram",params:{appid:t.appid,path:t.path,env:t.env},timestamp:Date.now()};return s.debug("Relay navigateToMiniProgram through wx.miniProgram.postMessage",{appid:t.appid,path:t.path,env:t.env}),new Promise((i,n)=>{var a;try{window.wx.miniProgram.postMessage({data:e})}catch(o){s.error("Post navigateToMiniProgram message failed",o),(a=t.fail)==null||a.call(t,o),n(o);return}window.wx.miniProgram.navigateBack({delta:1,success:o=>{var d;const c=w(g({},o),{errMsg:(o==null?void 0:o.errMsg)||"navigateToMiniProgram:queued"});s.info("Navigate to mini program request queued in weixin web-view",{appid:t.appid,path:t.path,env:t.env}),(d=t.success)==null||d.call(t,c),i(c)},fail:o=>{var c;s.error("Navigate back after posting mini program message failed",o),(c=t.fail)==null||c.call(t,o),n(o)},complete:t.complete})})},{context:"navigateToMiniProgramInWeixin",platform:"weixin"})}function ti(t={}){return l.safeExecute(()=>(s.debug("Call navigateToMiniProgram through webview bridge",{appid:t.appid,path:t.path,env:t.env}),new Promise((e,r)=>{N("navigateToMiniProgram",{appid:t.appid,path:t.path,env:t.env},{success:i=>{var n;s.info("Navigate to mini program success"),(n=t.success)==null||n.call(t,i),e(i)},fail:i=>{var n;s.error("Navigate to mini program failed",i),(n=t.fail)==null||n.call(t,i),r(i)},complete:t.complete})})),{context:"navigateToMiniProgramInHost",platform:mt().type})}function ri(t={}){return l.safeExecute(()=>{var i;const e=mt();let r;try{r=Zr(t)}catch(n){s.error("Navigate to mini program params validation failed",n),(i=t.fail)==null||i.call(t,n);return}return s.info("Start navigateToMiniProgram",{platform:e.type,appid:r.appid,path:r.path,env:r.env}),e.isWeixinMiniProgram?ei(r):ti(r)},{context:"navigateToMiniProgram",options:t})}function wt(){return V(!0)}function ii(t={}){const e=String((t==null?void 0:t.url)||"").trim(),r=(t==null?void 0:t.showMenu)==null?!1:t.showMenu;if(!e)throw{errMsg:"url is required",code:"PARAM_MISSING"};if(typeof r!="boolean")throw{errMsg:"showMenu must be a boolean",code:"PARAM_TYPE_ERROR"};return w(g({},t),{url:e,showMenu:r})}function ni(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram&&typeof window.wx.miniProgram.postMessage=="function"&&typeof window.wx.miniProgram.navigateBack=="function"}function ai(t={}){return l.safeExecute(()=>{var r;if(!ni()){const i={errMsg:"wx.miniProgram.postMessage or wx.miniProgram.navigateBack is not available",code:"PLATFORM_NOT_SUPPORTED"};s.error("Weixin web-view relay APIs are not available"),(r=t.fail)==null||r.call(t,i);return}const e={type:"qsh_api_call",api:"filePreview",params:{url:t.url,showMenu:t.showMenu},timestamp:Date.now()};return s.debug("Relay filePreview through wx.miniProgram.postMessage",{url:t.url,showMenu:t.showMenu}),new Promise((i,n)=>{var a;try{window.wx.miniProgram.postMessage({data:e})}catch(o){s.error("Post filePreview message failed",o),(a=t.fail)==null||a.call(t,o),n(o);return}window.wx.miniProgram.navigateBack({delta:1,success:o=>{var d;const c=w(g({},o),{errMsg:(o==null?void 0:o.errMsg)||"filePreview:queued"});s.info("File preview request queued in weixin web-view",{url:t.url,showMenu:t.showMenu}),(d=t.success)==null||d.call(t,c),i(c)},fail:o=>{var c;s.error("Navigate back after posting filePreview message failed",o),(c=t.fail)==null||c.call(t,o),n(o)},complete:t.complete})})},{context:"filePreviewInWeixin",platform:"weixin"})}function si(t={}){return l.safeExecute(()=>(s.debug("Call filePreview through webview bridge",{url:t.url,showMenu:t.showMenu}),new Promise((e,r)=>{N("filePreview",{url:t.url,showMenu:t.showMenu},{success:i=>{var n;s.info("File preview success"),(n=t.success)==null||n.call(t,i),e(i)},fail:i=>{var n;s.error("File preview failed",i),(n=t.fail)==null||n.call(t,i),r(i)},complete:t.complete})})),{context:"filePreviewInHost",platform:wt().type})}function oi(t={}){return l.safeExecute(()=>{var i;const e=wt();let r;try{r=ii(t)}catch(n){s.error("File preview params validation failed",n),(i=t.fail)==null||i.call(t,n);return}return s.info("Start filePreview",{platform:e.type,url:r.url,showMenu:r.showMenu}),e.isWeixinMiniProgram?ai(r):si(r)},{context:"filePreview",options:t})}function ci(t=""){return/^https?:\/\//i.test(String(t||"").trim())}function ui(t){if(t==null||t==="")return!1;if(typeof t=="boolean")return t;const e=String(t).trim().toLowerCase();return e==="true"||e==="1"}function li(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram&&typeof window.wx.miniProgram.postMessage=="function"&&typeof window.wx.miniProgram.navigateBack=="function"}function fi(t={}){if(!t||typeof t!="object")throw{errMsg:"manualShare options must be an object",code:"PARAM_TYPE_ERROR"};const e=String(t.title||"").trim(),r=String(t.h5Url||"").trim(),i=String(t.clientId||"").trim(),n=ui(t.isPublic),a=String(t.imageUrl||"").trim(),o=String(t.description||t.desc||"").trim();if(!e)throw{errMsg:"manualShare: title is required",code:"PARAM_MISSING"};if(!r)throw{errMsg:"manualShare: h5Url is required",code:"PARAM_MISSING"};if(!i)throw{errMsg:"manualShare: clientId is required",code:"PARAM_MISSING"};if(r&&!ci(r))throw{errMsg:"manualShare: h5Url must be a valid http(s) url",code:"PARAM_INVALID"};return{title:e,h5Url:r,clientId:i,isPublic:n,imageUrl:a,description:o,success:t.success,fail:t.fail,complete:t.complete}}function di(t){return{type:"qsh_api_call",api:"manualShare",params:{title:t.title,h5Url:t.h5Url,clientId:t.clientId,isPublic:t.isPublic,imageUrl:t.imageUrl,description:t.description},timestamp:Date.now()}}function gi(t){return new Promise((e,r)=>{const i=di(t);s.debug("Relay manualShare through wx.miniProgram.postMessage",i);try{window.wx.miniProgram.postMessage({data:i})}catch(n){s.error("Post manualShare message failed",n),r(n);return}window.wx.miniProgram.navigateBack({delta:1,success:n=>{const a=w(g({},n||{}),{success:!0,errMsg:(n==null?void 0:n.errMsg)||"manualShare:queued"});s.info("manualShare request queued in weixin web-view",{h5Url:t.h5Url,clientId:t.clientId,isPublic:t.isPublic}),e(a)},fail:n=>{s.error("Navigate back after posting manualShare message failed",n),r(n)}})})}function Et(t={}){return l.safeExecute(()=>{var i,n,a,o,c,d;const e=V(!0);let r;try{r=fi(t)}catch(m){return(i=t.fail)==null||i.call(t,m),(n=t.complete)==null||n.call(t,m),Promise.reject(m)}if(!e.isWeixinMiniProgram){const m={errMsg:"manualShare only supports Weixin mini-program web-view environment",code:"ENV_NOT_SUPPORTED"};return(a=r.fail)==null||a.call(r,m),(o=r.complete)==null||o.call(r,m),Promise.reject(m)}if(!li()){const m={errMsg:"wx.miniProgram.postMessage or wx.miniProgram.navigateBack is not available",code:"PLATFORM_NOT_SUPPORTED"};return(c=r.fail)==null||c.call(r,m),(d=r.complete)==null||d.call(r,m),Promise.reject(m)}return gi(r).then(m=>{var O,_;return(O=r.success)==null||O.call(r,m),(_=r.complete)==null||_.call(r,m),m}).catch(m=>{var O,_;return(O=r.fail)==null||O.call(r,m),(_=r.complete)==null||_.call(r,m),Promise.reject(m)})},{context:"manualShare",options:t})}function hi(t={}){return new Promise((e,r)=>{Et(w(g({},t),{success:e,fail:r}))})}const Ne={ALBUM:"album",CAMERA:"camera"},be={ORIGINAL:"original",COMPRESSED:"compressed"},mi={count:9,sizeType:[be.ORIGINAL,be.COMPRESSED],sourceType:[Ne.ALBUM,Ne.CAMERA]};function pi(t={}){const e=g(g({},mi),t);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=[be.COMPRESSED]),e.sourceType.length===0&&(e.sourceType=[Ne.ALBUM]),e}function yt(){return["weixin","webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function At(t){return l.safeExecute(()=>{var e;if(!window.wx){const r={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(e=t.fail)==null||e.call(t,r);return}if(!he()){s.info("等待微信配置完成"),ne().then(()=>At(t)).catch(r=>{var i;s.error("微信配置失败",r),(i=t.fail)==null||i.call(t,{errMsg:`微信配置失败: ${r.message}`})});return}s.debug("调用微信图片选择",t),window.wx.chooseImage({count:t.count,sizeType:t.sizeType,sourceType:t.sourceType,success:r=>{var i,n;s.info("微信图片选择成功",{count:((i=r.localIds)==null?void 0:i.length)||0}),(n=t.success)==null||n.call(t,r)},fail:r=>{var i;s.error("微信图片选择失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"chooseImageInWeixin",platform:"weixin"})}function wi(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用图片选择",t),N("chooseImage",w(g({},t),{disableTimeout:!0}),{success:e=>{var r,i;s.info("UniApp 图片选择成功",{count:((r=e==null?void 0:e.tempFilePaths)==null?void 0:r.length)||0}),(i=t.success)==null||i.call(t,e)},fail:e=>{var r;s.error("UniApp 图片选择失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"chooseImageInUniApp",platform:"uniapp"})}function Ei(t={}){return l.safeExecute(()=>{var r;if(!yt()){const i={errMsg:`当前环境 (${f.type}) 不支持图片选择功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持图片选择",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=pi(t);s.info("开始选择图片",{platform:f.type,count:e.count,sizeType:e.sizeType,sourceType:e.sourceType}),p()?At(e):wi(e)},{context:"chooseImage",options:t})}function yi(){return{supported:yt(),environment:f.type,implementation:p()?"weixin":"webview",features:{multipleSelection:!0,sizeTypeSelection:!0,sourceTypeSelection:!0,asyncSupport:!0}}}const ce={QR_CODE:"qrCode",BAR_CODE:"barCode",DATA_MATRIX:"datamatrix",PDF417:"pdf417"},Ai={onlyFromCamera:!0,scanType:[ce.QR_CODE,ce.BAR_CODE]};function Ii(t={}){const e=g(g({},Ai),t);return Array.isArray(e.scanType)||(e.scanType=[e.scanType].filter(Boolean)),e.scanType.length===0&&(e.scanType=[ce.QR_CODE,ce.BAR_CODE]),e.onlyFromCamera=!!e.onlyFromCamera,e}function It(){return["weixin","webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function Pt(t){return l.safeExecute(()=>{var e;if(!window.wx){const r={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(e=t.fail)==null||e.call(t,r);return}if(!he()){s.info("等待微信配置完成"),ne().then(()=>Pt(t)).catch(r=>{var i;s.error("微信配置失败",r),(i=t.fail)==null||i.call(t,{errMsg:`微信配置失败: ${r.message}`})});return}s.debug("调用微信扫码",t),window.wx.scanQRCode({needResult:1,scanType:t.scanType,success:r=>{var n;s.info("微信扫码成功",{result:r.resultStr});const i={result:r.resultStr,scanType:Pi(r.resultStr),charSet:"utf-8",errMsg:"scanCode:ok"};(n=t.success)==null||n.call(t,i)},fail:r=>{var i;s.error("微信扫码失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"scanCodeInWeixin",platform:"weixin"})}function Pi(t){return t?t.length>50||/[^\d]/.test(t)?ce.QR_CODE:ce.BAR_CODE:"unknown"}function Mi(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用扫码",t),N("scanCode",w(g({},t),{disableTimeout:!0}),{success:e=>{var r;s.info("UniApp 扫码成功",{result:e==null?void 0:e.result,scanType:e==null?void 0:e.scanType}),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("UniApp 扫码失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"scanCodeInUniApp",platform:"uniapp"})}function Ci(t={}){return l.safeExecute(()=>{var r;if(!It()){const i={errMsg:`当前环境 (${f.type}) 不支持扫码功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持扫码",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=Ii(t);s.info("开始扫码",{platform:f.type,onlyFromCamera:e.onlyFromCamera,scanType:e.scanType}),p()?Pt(e):Mi(e)},{context:"scanCode",options:t})}function _i(){return{supported:It(),environment:f.type,implementation:p()?"weixin":"webview",features:{onlyFromCamera:!0,scanTypeSelection:!0,multipleTypes:!0,asyncSupport:!0}}}const T=3.141592653589793,ve=6378245,Te=.006693421622965943;function Mt(t,e){t=+t,e=+e;let r=-100+2*t+3*e+.2*e*e+.1*t*e+.2*Math.sqrt(Math.abs(t));return r+=(20*Math.sin(6*t*T)+20*Math.sin(2*t*T))*2/3,r+=(20*Math.sin(e*T)+40*Math.sin(e/3*T))*2/3,r+=(160*Math.sin(e/12*T)+320*Math.sin(e*T/30))*2/3,r}function Ct(t,e){t=+t,e=+e;let r=300+t+2*e+.1*t*t+.1*t*e+.1*Math.sqrt(Math.abs(t));return r+=(20*Math.sin(6*t*T)+20*Math.sin(2*t*T))*2/3,r+=(20*Math.sin(t*T)+40*Math.sin(t/3*T))*2/3,r+=(150*Math.sin(t/12*T)+300*Math.sin(t/30*T))*2/3,r}function _t(t,e){return t=+t,e=+e,!(t>73.66&&t<135.05&&e>3.86&&e<53.55)}function Ri(t,e){if(t=+t,e=+e,_t(t,e))return[t,e];let r=Mt(t-105,e-35),i=Ct(t-105,e-35);const n=e/180*T;let a=Math.sin(n);a=1-Te*a*a;const o=Math.sqrt(a);r=r*180/(ve*(1-Te)/(a*o)*T),i=i*180/(ve/o*Math.cos(n)*T);const c=e+r;return[t+i,c]}function Oi(t,e){if(t=+t,e=+e,_t(t,e))return[t,e];let r=Mt(t-105,e-35),i=Ct(t-105,e-35);const n=e/180*T;let a=Math.sin(n);a=1-Te*a*a;const o=Math.sqrt(a);r=r*180/(ve*(1-Te)/(a*o)*T),i=i*180/(ve/o*Math.cos(n)*T);const c=e+r,d=t+i;return[t*2-d,e*2-c]}const U={WGS84:"wgs84",GCJ02:"gcj02",BD09:"bd09"},Si={type:U.WGS84,altitude:!1},Ni={type:U.WGS84,scale:12},bi=[U.WGS84,U.GCJ02];function vi(t={}){const e=g(g({},Si),t);return Object.values(U).includes(e.type)||(e.type=U.WGS84),e.altitude=!!e.altitude,e}function Ti(t={}){const e=g({},t);return Object.values(U).includes(e.type)||(e.type=U.WGS84),e.needFullAccuracy=!!e.needFullAccuracy,e}function xi(t={}){const e=g(g({},Ni),t);if(bi.includes(e.type)||(e.type=U.WGS84),e.latitude===void 0||e.latitude===null)throw{errMsg:"缺少必需参数:latitude(纬度)",code:"PARAM_MISSING"};if(typeof e.latitude!="number")throw{errMsg:`latitude 参数类型错误:期望 number,实际 ${typeof e.latitude}`,code:"PARAM_TYPE_ERROR",details:{param:"latitude",expected:"number",actual:typeof e.latitude,value:e.latitude}};if(e.latitude<-90||e.latitude>90)throw{errMsg:`latitude 超出范围:有效范围 -90 ~ 90,实际值 ${e.latitude}`,code:"PARAM_INVALID",details:{param:"latitude",value:e.latitude,validRange:"-90 ~ 90"}};if(e.longitude===void 0||e.longitude===null)throw{errMsg:"缺少必需参数:longitude(经度)",code:"PARAM_MISSING"};if(typeof e.longitude!="number")throw{errMsg:`longitude 参数类型错误:期望 number,实际 ${typeof e.longitude}`,code:"PARAM_TYPE_ERROR",details:{param:"longitude",expected:"number",actual:typeof e.longitude,value:e.longitude}};if(e.longitude<-180||e.longitude>180)throw{errMsg:`longitude 超出范围:有效范围 -180 ~ 180,实际值 ${e.longitude}`,code:"PARAM_INVALID",details:{param:"longitude",value:e.longitude,validRange:"-180 ~ 180"}};if(e.scale!==void 0&&e.scale!==null){const r=Number(e.scale);isNaN(r)?(s.warn("scale 参数无效,使用默认值 12",{scale:e.scale}),e.scale=12):e.scale=Math.max(1,Math.min(28,Math.floor(r)))}return e}function Li(t){if(t.type!==U.WGS84)return t;const[e,r]=Ri(t.longitude,t.latitude);return w(g({},t),{latitude:r,longitude:e,type:U.GCJ02})}function Di(t){if(t.type!==U.GCJ02)return t;const[e,r]=Oi(t.longitude,t.latitude);return w(g({},t),{latitude:r,longitude:e,type:U.WGS84})}function ke(){return["weixin","webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function Rt(t){return l.safeExecute(()=>{var e;if(!window.wx){const r={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(e=t.fail)==null||e.call(t,r);return}if(!he()){s.info("等待微信配置完成"),ne().then(()=>Rt(t)).catch(r=>{var i;s.error("微信配置失败",r),(i=t.fail)==null||i.call(t,{errMsg:`微信配置失败: ${r.message}`})});return}s.debug("调用微信定位",t),window.wx.getLocation({type:t.type,success:r=>{var i;s.info("微信定位成功",{latitude:r.latitude,longitude:r.longitude}),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;s.error("微信定位失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"getLocationInWeixin",platform:"weixin"})}function Ot(t){return l.safeExecute(()=>{var r;if(!window.wx){const i={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(r=t.fail)==null||r.call(t,i);return}if(!he()){s.info("等待微信配置完成"),ne().then(()=>Ot(t)).catch(i=>{var n;s.error("微信配置失败",i),(n=t.fail)==null||n.call(t,{errMsg:`微信配置失败: ${i.message}`})});return}const e=Li(t);s.debug("调用微信查看位置",e),window.wx.openLocation({latitude:e.latitude,longitude:e.longitude,name:e.name||"",address:e.address||"",scale:e.scale||12,infoUrl:e.infoUrl||"",success:i=>{var n;s.info("微信查看位置成功"),(n=t.success)==null||n.call(t,i)},fail:i=>{var n;s.error("微信查看位置失败",i),(n=t.fail)==null||n.call(t,i)},complete:t.complete})},{context:"openLocationInWeixin",platform:"weixin"})}function Ui(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用获取位置",t),N("getLocation",t,{success:e=>{var r;s.info("UniApp 获取位置成功",{latitude:e==null?void 0:e.latitude,longitude:e==null?void 0:e.longitude}),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("UniApp 获取位置失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"getLocationInUniApp",platform:"uniapp"})}function Wi(t){return l.safeExecute(()=>{const e=Di(t);s.debug("通过 WebView 桥接调用查看位置",e),N("openLocation",e,{success:r=>{var i;s.info("UniApp 查看位置成功"),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;s.error("UniApp 查看位置失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"openLocationInUniApp",platform:"uniapp"})}function $i(t={}){return l.safeExecute(()=>{var r;if(!ke()){const i={errMsg:`当前环境 (${f.type}) 不支持定位功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持定位",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=vi(t);s.info("开始获取位置",{platform:f.type,type:e.type,altitude:e.altitude}),p()?Rt(e):Ui(e)},{context:"getLocation",options:t})}function Fi(t={}){return l.safeExecute(()=>{var r,i,n;if(!ke()){const a={errMsg:`当前环境 (${f.type}) 不支持查看位置功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持查看位置",{platform:f.type}),(r=t.fail)==null||r.call(t,a);return}let e;try{e=xi(t)}catch(a){s.error("参数验证失败",a),(i=t.fail)==null||i.call(t,a),(n=t.complete)==null||n.call(t);return}s.info("开始查看位置",{platform:f.type,type:e.type,latitude:e.latitude,longitude:e.longitude,name:e.name}),p()?Ot(e):Wi(e)},{context:"openLocation",options:t})}function ki(){const t=p();return{supported:ke(),environment:f.type,implementation:t?"weixin":"webview",features:{getLocation:!0,openLocation:!0,coordinateTypes:!0,altitudeSupport:!0,asyncSupport:!0,onLocationChange:!t}}}const Q=new Set,ee=new Set;function St(t,e,r){t.forEach(i=>{if(typeof i=="function"){l.safeExecute(()=>i(e),{context:r});return}s.warn("监听回调不是函数,已跳过",{type:typeof i})})}function Bi(t={}){return l.safeExecute(()=>{var r,i;if(p()){const n={errMsg:`当前环境 (${f.type}) 不支持该接口`,code:"PLATFORM_NOT_SUPPORTED"};s.error("当前环境不支持此接口",{platform:f.type}),(r=t.fail)==null||r.call(t,n),(i=t.complete)==null||i.call(t,n);return}const e=Ti(t);s.info("正在开启定位监听"),N("startLocationUpdate",{type:e.type,needFullAccuracy:e.needFullAccuracy},{success:n=>{var a;s.info("定位监听已启动"),(a=t.success)==null||a.call(t,n)},fail:n=>{var a;return(a=t.fail)==null?void 0:a.call(t,n)},complete:t.complete})},{context:"startLocationUpdate"})}function Gi(t={}){return l.safeExecute(()=>{var e,r;if(p()){const i={errMsg:`当前环境 (${f.type}) 不支持该接口`,code:"PLATFORM_NOT_SUPPORTED"};s.error("当前环境不支持此接口",{platform:f.type}),(e=t.fail)==null||e.call(t,i),(r=t.complete)==null||r.call(t,i);return}s.info("正在停止定位监听"),N("stopLocationUpdate",t,{success:i=>{var n;s.info("定位监听已停止"),(n=t.success)==null||n.call(t,i)},fail:i=>{var n;return(n=t.fail)==null?void 0:n.call(t,i)},complete:t.complete})},{context:"stopLocationUpdate"})}function Ki(t){return l.safeExecute(()=>{if(p()){s.warn("当前环境不支持此接口",{platform:f.type});return}if(typeof t!="function")throw s.error("onLocationChange 回调不是函数",{type:typeof t}),{errMsg:"onLocationChange 回调必须是函数",code:"INVALID_CALLBACK"};const e=Q.size>0;Q.add(t),e||(s.debug("注册实时位置变化监听器"),N("onLocationChange",{isPersistent:!0},{success:r=>{s.debug("收到实时位置推送",r),St(Q,r,"onLocationChange")},fail:r=>{s.warn("位置变化监听出错,请通过 onLocationChangeError 监听错误",r),Q.delete(t),Q.size===0&&pe("onLocationChange")}}))},{context:"onLocationChange"})}function Vi(t){return l.safeExecute(()=>{if(p()){s.warn("当前环境不支持此接口",{platform:f.type});return}if(t&&typeof t!="function")throw s.error("offLocationChange 回调不是函数",{type:typeof t}),{errMsg:"offLocationChange 回调必须是函数",code:"INVALID_CALLBACK"};t?Q.delete(t):Q.clear(),!(Q.size>0)&&(s.info("移除位置变化监听器"),N("offLocationChange",{},{success:()=>{s.info("位置变化监听已移除"),pe("onLocationChange")},fail:e=>{s.error("移除位置变化监听失败",e),pe("onLocationChange")}}))},{context:"offLocationChange"})}function qi(t){return l.safeExecute(()=>{if(p()){s.warn("当前环境不支持此接口",{platform:f.type});return}if(typeof t!="function")throw s.error("onLocationChangeError 回调不是函数",{type:typeof t}),{errMsg:"onLocationChangeError 回调必须是函数",code:"INVALID_CALLBACK"};const e=ee.size>0;ee.add(t),e||(s.debug("注册位置更新错误监听器"),N("onLocationChangeError",{isPersistent:!0},{success:r=>{s.warn("持续定位发生异常",r),St(ee,r,"onLocationChangeError")},fail:r=>{s.warn("位置更新错误监听注册失败",r),ee.delete(t),ee.size===0&&pe("onLocationChangeError")}}))},{context:"onLocationChangeError"})}function ji(t){return l.safeExecute(()=>{if(p()){s.warn("当前环境不支持此接口",{platform:f.type});return}if(t&&typeof t!="function")throw s.error("offLocationChangeError 回调不是函数",{type:typeof t}),{errMsg:"offLocationChangeError 回调必须是函数",code:"INVALID_CALLBACK"};t?ee.delete(t):ee.clear(),!(ee.size>0)&&(s.info("移除定位错误监听器"),N("offLocationChangeError",{},{success:()=>{s.info("定位错误监听已移除"),pe("onLocationChangeError")},fail:e=>{s.error("移除定位错误监听失败",e),pe("onLocationChangeError")}}))},{context:"offLocationChangeError"})}const Ji={latitude:null,longitude:null};function Hi(t={}){const e=g(g({},Ji),t);return e.latitude!==null&&e.latitude!==void 0&&(typeof e.latitude!="number"?(s.warn("latitude 参数类型错误,已忽略",{latitude:e.latitude}),e.latitude=null):(e.latitude<-90||e.latitude>90)&&(s.warn("latitude 超出范围,已忽略",{latitude:e.latitude}),e.latitude=null)),e.longitude!==null&&e.longitude!==void 0&&(typeof e.longitude!="number"?(s.warn("longitude 参数类型错误,已忽略",{longitude:e.longitude}),e.longitude=null):(e.longitude<-180||e.longitude>180)&&(s.warn("longitude 超出范围,已忽略",{longitude:e.longitude}),e.longitude=null)),e}function Nt(){return["webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function zi(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用位置选择",t);const e={disableTimeout:!0,success:r=>{var i;s.info("UniApp 位置选择成功",{name:r==null?void 0:r.name,address:r==null?void 0:r.address,latitude:r==null?void 0:r.latitude,longitude:r==null?void 0:r.longitude}),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;s.error("UniApp 位置选择失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete};t.latitude!==null&&t.latitude!==void 0&&(e.latitude=t.latitude),t.longitude!==null&&t.longitude!==void 0&&(e.longitude=t.longitude),N("chooseLocation",e,{success:r=>{e.success(r)},fail:r=>{e.fail(r)},complete:e.complete})},{context:"chooseLocationInUniApp",platform:"uniapp"})}function Yi(t={}){return l.safeExecute(()=>{var r;if(!Nt()){const i={errMsg:`当前环境 (${f.type}) 不支持位置选择功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持位置选择",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=Hi(t);s.info("开始选择位置",{platform:f.type,latitude:e.latitude,longitude:e.longitude}),p()||zi(e)},{context:"chooseLocation",options:t})}function Xi(){return{supported:Nt(),environment:f.type,implementation:p()?"weixin":"webview",features:{chooseLocation:!0,centerPoint:!0,asyncSupport:!0}}}const bt="https://iafs.xjy2.cn/img/bg.143351f0.jpg";function Zi(t){return t==="timeline"||Number(t)===1?1:0}function xe(t="",e="targetPath"){if(!t||typeof t!="string")throw{errMsg:`share: ${e} 必须是最终小程序页面路径`,code:"PARAM_INVALID"};const r=t.trim(),[,i=""]=r.split("?");return{path:r,query:i}}function vt(t="",e="webTarget"){if(!t||typeof t!="string")throw{errMsg:`share: ${e} 必须是公网链接,例如 https://example.com/path?a=1`,code:"PARAM_INVALID"};const r=t.trim();if(!/^https?:\/\//.test(r))throw{errMsg:`share: ${e} 必须是公网链接,例如 https://example.com/path?a=1`,code:"PARAM_INVALID"};return r}function Qi(){return new Promise((t,e)=>{var a,o;const r=typeof window!="undefined"?window:null;if(!r)return e({errMsg:"当前环境不支持 plus",code:"PLUS_UNAVAILABLE"});if(r.plus)return t(r.plus);const i=setTimeout(()=>{var c,d;(d=(c=r.document)==null?void 0:c.removeEventListener)==null||d.call(c,"plusready",n),e({errMsg:"等待 plusready 超时",code:"PLUS_READY_TIMEOUT"})},8e3);function n(){clearTimeout(i),t(r.plus)}(o=(a=r.document)==null?void 0:a.addEventListener)==null||o.call(a,"plusready",n,{once:!0})})}function en(){return new Promise((t,e)=>{const r=typeof window!="undefined"?window.plus:null;if(!r||!r.share||typeof r.share.getServices!="function")return e({errMsg:"当前环境不支持 plus.share",code:"PLUS_SHARE_UNSUPPORTED"});r.share.getServices(i=>{const n=i.find(a=>a.id==="weixin");if(!n)return e({errMsg:"未找到微信分享服务",code:"WEIXIN_SERVICE_NOT_FOUND"});t(n)},i=>e(i||{errMsg:"获取分享服务失败",code:"GET_SHARE_SERVICES_FAILED"}))})}function tn(t){return t.isWeixinMiniProgram?"已同步分享内容,请点击右上角“···”选择发送给朋友或分享到朋友圈。":"正在拉起微信分享面板,请选择聊天框或朋友圈。"}function rn(t={}){if(!t||typeof t!="object")throw{errMsg:"shareDirected 参数必须是对象",code:"PARAM_TYPE_ERROR"};const e=String(t.kind||"").trim(),r=t.payload||{},i=Zi(t.scene);if(!["web","image","text"].includes(e))throw{errMsg:'shareDirected: kind 仅支持 "web"|"image"|"text"',code:"PARAM_INVALID"};if(![0,1].includes(i))throw{errMsg:"shareDirected: scene 仅支持 0|1",code:"PARAM_INVALID"};if(e==="web"&&(!r.title||!r.description||!r.imageUrl))throw{errMsg:"shareDirected(web): title/description/imageUrl 必填",code:"PARAM_MISSING"};if(e==="image"&&!r.imageUrl)throw{errMsg:"shareDirected(image): payload.imageUrl 必填",code:"PARAM_MISSING"};if(e==="text"&&!r.description)throw{errMsg:"shareDirected(text): payload.description 必填",code:"PARAM_MISSING"};return{kind:e,scene:i,payload:r,resolvedTargetPath:"",resolvedWebTarget:"",success:t.success,fail:t.fail,complete:t.complete}}function nn(t,e){const{payload:r}=t;if(e.isWeixinMiniProgram)try{const i=xe(r.target,"target");return t.resolvedTargetPath=i.path,t}catch(i){throw{errMsg:(i==null?void 0:i.errMsg)||"shareDirected: 小程序环境下 payload.target 不合法",code:(i==null?void 0:i.code)||"PARAM_INVALID"}}if(e.isAppPlus){const i=(o,c)=>{try{return vt(o,c)}catch(d){return""}},n=i(r.target,"target");if(n)return t.resolvedWebTarget=n,t;const a=i(r.webTarget,"webTarget");if(a)return t.resolvedWebTarget=a,t;throw{errMsg:"shareDirected: App 环境下 payload.target 必须是公网链接;若 target 不存在或不合法,则 payload.webTarget 也必须是公网链接",code:"PARAM_INVALID"}}return t}function an(t){const{kind:e,payload:r,resolvedTargetPath:i}=t,n=xe(i||r.target,"target"),a=r.imageUrl||bt;return{title:r.title||"分享",path:n.path,query:n.query,imageUrl:a,custom:{kind:e,target:n.path,webTarget:r.webTarget||"",description:r.description||""}}}function sn(t){const{kind:e,scene:r,payload:i,resolvedWebTarget:n}=t,a=r===1?"WXSceneTimeline":"WXSceneSession",o=i.imageUrl||bt;return e==="image"?{message:{type:"image",pictures:[i.imageUrl],extra:{scene:a}},degradedFromText:!1}:{message:{type:"web",title:i.title||"分享",content:i.description||"",href:n,thumbs:[o],extra:{scene:a}},degradedFromText:e==="text"}}function on(t){return I(this,null,function*(){yield Qi();const e=yield en(),{message:r,degradedFromText:i}=sn(t);return new Promise((n,a)=>{e.send(r,()=>n({success:!0,data:{degradedFromText:i,hint:i?"纯文字已自动降级为图文分享,避免微信通道不支持纯文本":void 0}}),o=>a(o||{errMsg:"微信分享失败",code:"WEIXIN_SHARE_FAILED"}))})})}function Tt(t,e="share"){const r=typeof window!="undefined"&&window.wx&&window.wx.miniProgram;if(!r||typeof r.postMessage!="function")throw{errMsg:`当前微信小程序容器未注入 postMessage 能力,无法发起 ${e}`,code:"MINIPROGRAM_BRIDGE_UNAVAILABLE"};r.postMessage({data:t})}function cn(t,e){return{type:"qsh_api_call",api:"shareDirected",params:{miniProgramShare:an(t),rowCustom:e},timestamp:Date.now()}}function un(t={}){if(!t||typeof t!="object")throw{errMsg:"shareMiniProgramCard 参数必须是对象",code:"PARAM_TYPE_ERROR"};const e=t.payload||{};if(!e.title)throw{errMsg:"shareMiniProgramCard: payload.title 必填",code:"PARAM_MISSING"};if(!e.imageUrl)throw{errMsg:"shareMiniProgramCard: payload.imageUrl 必填",code:"PARAM_MISSING"};if(!e.targetPath)throw{errMsg:"shareMiniProgramCard: payload.targetPath 必填",code:"PARAM_MISSING"};return xe(e.targetPath,"targetPath"),{payload:e,success:t.success,fail:t.fail,complete:t.complete}}function ln(t){switch(String(t||"release").trim().toLowerCase()){case"develop":case"development":case"test":return"test";case"trial":case"preview":case"experience":return"preview";case"release":case"formal":case"production":return"release";default:throw{errMsg:'shareMiniProgramCard: payload.envVersion 仅支持 "develop"|"trial"|"release"',code:"PARAM_INVALID"}}}function fn(t){switch(String(t||"release").trim().toLowerCase()){case"develop":case"development":case"test":return 1;case"trial":case"preview":case"experience":return 2;case"release":case"formal":case"production":return 0;default:throw{errMsg:'shareMiniProgramCard: payload.envVersion 仅支持 "develop"|"trial"|"release"',code:"PARAM_INVALID"}}}function dn(t){const{payload:e}=t;if(!e.appid)throw{errMsg:"shareMiniProgramCard: App 环境下 payload.appid 必填",code:"PARAM_MISSING"};try{vt(e.webUrl,"webUrl")}catch(r){throw{errMsg:"shareMiniProgramCard: App 环境下 payload.webUrl 必填,且必须是公网链接",code:(r==null?void 0:r.code)||"PARAM_INVALID"}}return ln(e.envVersion),t}function gn(t){const{payload:e}=t,r=xe(e.targetPath,"targetPath");return{title:e.title,path:r.path,query:r.query,imageUrl:e.imageUrl}}function hn(t){const{payload:e}=t;return{provider:"weixin",scene:"WXSceneSession",type:5,title:e.title,imageUrl:e.imageUrl,miniProgram:{id:e.appid,path:e.targetPath,type:fn(e.envVersion),webUrl:e.webUrl}}}function mn(t,e){return{type:"qsh_api_call",api:"shareMiniProgramCard",params:{miniProgramShare:gn(t),rowCustom:e},timestamp:Date.now()}}function pn(t){return I(this,null,function*(){return new Promise((e,r)=>{N("shareMiniProgramCard",{appShare:hn(t)},{success:i=>e(i||{}),fail:i=>r(i)})})})}function xt(t={}){return l.safeExecute(()=>{var a,o,c,d,m,O,_,H,Ce,S,z;let e;try{e=rn(t)}catch(A){return(a=t.fail)==null||a.call(t,A),Promise.reject(A)}const r=V(!0);try{e=nn(e,r)}catch(A){return(o=e.fail)==null||o.call(e,A),(c=e.complete)==null||c.call(e,A),Promise.reject(A)}const i=tn(r);if(r.isAppPlus)return on(e).then(A=>{var _e,er;const Y=w(g({},(A==null?void 0:A.data)||{}),{hint:i});return(_e=e.success)==null||_e.call(e,Y),(er=e.complete)==null||er.call(e,Y),Y}).catch(A=>{var Y,_e;return(Y=e.fail)==null||Y.call(e,A),(_e=e.complete)==null||_e.call(e,A),Promise.reject(A)});if(r.isWeixinMiniProgram)try{Tt(cn(e,t.rowCustom),"shareDirected");const A={success:!0,hint:i};return(d=e.success)==null||d.call(e,A),(m=e.complete)==null||m.call(e,A),Promise.resolve(A)}catch(A){return(O=e.fail)==null||O.call(e,A),(_=e.complete)==null||_.call(e,A),Promise.reject(A)}if(r.type==="h5"&&!r.isUniAppWebView&&!r.isOfflineWebview){const A={errMsg:"当前页面不在宿主 WebView 中,无法分享。请在 unified-platform-app 内打开该 H5 再重试。",code:"NOT_IN_CONTAINER"};return(H=e.fail)==null||H.call(e,A),(Ce=e.complete)==null||Ce.call(e,A),Promise.reject(A)}const n={errMsg:"当前环境暂不支持 shareDirected,请在 App 或微信小程序容器内使用。",code:"ENV_NOT_SUPPORTED"};return(S=e.fail)==null||S.call(e,n),(z=e.complete)==null||z.call(e,n),Promise.reject(n)},{context:"shareDirected",options:t})}function wn(t={}){return new Promise((e,r)=>{xt(w(g({},t),{success:e,fail:r}))})}function Lt(t={}){return l.safeExecute(()=>{var a,o,c,d,m,O,_,H,Ce;let e;try{e=un(t)}catch(S){return(a=t.fail)==null||a.call(t,S),Promise.reject(S)}const r=V(!0);if(r.isAppPlus)try{e=dn(e)}catch(S){return(o=e.fail)==null||o.call(e,S),(c=e.complete)==null||c.call(e,S),Promise.reject(S)}const i=r.isWeixinMiniProgram?"已同步小程序卡片内容,请点击右上角“···”后发送给朋友。":"正在拉起微信发送给朋友面板,请继续完成小程序卡片分享。";if(r.isAppPlus)return pn(e).then(S=>{var A,Y;const z=w(g({},S||{}),{hint:i});return(A=e.success)==null||A.call(e,z),(Y=e.complete)==null||Y.call(e,z),z}).catch(S=>{var z,A;return(z=e.fail)==null||z.call(e,S),(A=e.complete)==null||A.call(e,S),Promise.reject(S)});if(r.isWeixinMiniProgram)try{Tt(mn(e,t.rowCustom),"shareMiniProgramCard");const S={success:!0,hint:i};return(d=e.success)==null||d.call(e,S),(m=e.complete)==null||m.call(e,S),Promise.resolve(S)}catch(S){return(O=e.fail)==null||O.call(e,S),(_=e.complete)==null||_.call(e,S),Promise.reject(S)}const n={errMsg:"当前环境暂不支持 shareMiniProgramCard,请在 App 或微信小程序容器内使用。",code:"ENV_NOT_SUPPORTED"};return(H=e.fail)==null||H.call(e,n),(Ce=e.complete)==null||Ce.call(e,n),Promise.reject(n)},{context:"shareMiniProgramCard",options:t})}function En(t={}){return new Promise((e,r)=>{Lt(w(g({},t),{success:e,fail:r}))})}const yn={OFF:"off",ON:"on",UNAVAILABLE:"unavailable",UNAUTHORIZED:"unauthorized"},An={allowDuplicatesKey:!1,services:[]};function Le(t={}){return g(g({},An),t)}function Me(){return["weixin","webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function In(t){return l.safeExecute(()=>I(null,null,function*(){var e;if(!window.wx){const r={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(e=t.fail)==null||e.call(t,r);return}he()||(s.info("等待微信配置完成"),yield ne()),wx.openBluetoothAdapter({success:()=>{s.info("微信蓝牙适配器已打开"),Dt(t)},fail:r=>{var i;s.error("蓝牙适配器打开失败",r),(i=t.fail)==null||i.call(t,r)}})}),{context:"openBluetoothAdapterInWeixin"})}function Pn(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用蓝牙功能",t),N("bluetooth",t,{success:e=>{var r;s.info("UniApp 蓝牙调用成功",e),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("UniApp 蓝牙调用失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"bluetoothInUniApp"})}function Mn(t){return l.safeExecute(()=>{var e;s.debug("通过 WebView 桥接调用蓝牙设备搜索功能",t),N("bluetoothDevicesDiscovery",{action:"startBluetoothDevicesDiscovery",params:{services:t.services||[],allowDuplicatesKey:(e=t.allowDuplicatesKey)!=null?e:!1}},{success:r=>{var i;console.log("[Bluetooth] 设备开启搜索成功:",r),s.info("UniApp 蓝牙设备开启搜索成功",r),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;console.error("[Bluetooth] 设备开启搜索失败:",r),s.error("UniApp 蓝牙设备开启搜索失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"startBluetoothDevicesDiscoveryInUniApp"})}const De=new Set;function Cn(t,e={}){return l.safeExecute(()=>{var r;return De.add(t),De.size===1&&N("onBluetoothDeviceFound",{action:"onBluetoothDeviceFound",isPersistent:!0,params:{services:e.services||[],allowDuplicatesKey:(r=e.allowDuplicatesKey)!=null?r:!1}},{success:i=>{De.forEach(n=>{typeof n=="function"?l.safeExecute(()=>n(i),{context:"BluetoothDeviceCallback"}):console.warn("[BluetoothDeviceCallback] 不是函数:",n)})},fail:i=>{var n;console.error("[Bluetooth] 搜索失败:",i),(n=e.fail)==null||n.call(e,i)},complete:e.complete}),()=>De.delete(t)},{context:"qsh_onBluetoothDeviceFound"})}function _n(t){return l.safeExecute(()=>{var e;s.debug("通过 WebView 桥接调用蓝牙连接功能",t),N("bluetoothConnection",{action:"createBLEConnection",params:{deviceId:t.deviceId,name:t.name,autoConnect:(e=t.autoConnect)!=null?e:!1}},{success:r=>{var i;console.log("[Bluetooth] 蓝牙连接成功:",r),s.info("UniApp 蓝牙连接成功",r),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;console.error("[Bluetooth] 蓝牙连接失败:",r),s.error("UniApp 蓝牙连接失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"createBLEConnectionInUniApp"})}function Rn(t={}){return l.safeExecute(()=>{var r;if(!Me()){const i={errMsg:`当前环境 (${f.type}) 不支持蓝牙功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持蓝牙",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=Le(t);s.info("开始蓝牙操作",{platform:f.type,services:e.services,allowDuplicatesKey:e.allowDuplicatesKey}),p()?In(e):Pn(e)},{context:"openBluetoothAdapter",options:t})}function On(t={}){return l.safeExecute(()=>{var r,i;if(!Me()){const n={errMsg:`当前环境 (${f.type}) 不支持蓝牙功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持蓝牙",{platform:f.type}),(r=t.fail)==null||r.call(t,n),(i=t.complete)==null||i.call(t,n);return}const e=Le(t);s.info("开始搜索蓝牙设备",{platform:f.type,services:e.services,allowDuplicatesKey:e.allowDuplicatesKey}),p()?startBluetoothDevicesDiscoveryInWeixin(e):Mn(e)},{context:"startBluetoothDevicesDiscovery",options:t})}function Dt(t,e={}){return l.safeExecute(()=>{var i,n;if(!Me()){const a={errMsg:`当前环境 (${f.type}) 不支持蓝牙功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持蓝牙",{platform:f.type}),(i=e.fail)==null||i.call(e,a),(n=e.complete)==null||n.call(e,a);return}const r=Le(e);s.info("注册蓝牙设备发现监听",{platform:f.type}),p()?onBluetoothDeviceFoundInWeixin(r):Cn(t,r)},{context:"onBluetoothDeviceFound",options:e})}function Sn(t={}){return l.safeExecute(()=>{var a,o,c,d;if(!Me()){const m={errMsg:`当前环境 (${f.type}) 不支持蓝牙功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持蓝牙连接",{platform:f.type}),(a=t.fail)==null||a.call(t,m),(o=t.complete)==null||o.call(t,m);return}const e=Le(t),{name:r,deviceId:i,autoConnect:n=!1}=e;if(!i){const m={errMsg:"缺少 deviceId 参数",code:"INVALID_PARAMS"};(c=t.fail)==null||c.call(t,m),(d=t.complete)==null||d.call(t,m);return}s.info("创建蓝牙连接",{deviceId:i,autoConnect:n,platform:f.type}),p()?uni.createBLEConnection({deviceId:i,autoConnect:n,success:t.success,fail:t.fail,complete:t.complete}):_n(e)},{context:"createBLEConnection",options:t})}function Nn(){return{supported:Me(),environment:f.type,implementation:p()?"weixin":"webview",features:{discovery:!0,connect:!0,readWrite:!0,notify:!0,asyncSupport:!0}}}const bn={};function vn(t={}){return g(g({},bn),t)}function Ut(){return["webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function Tn(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用打印PDF",t),N("printPdf",w(g({},t),{isPersistent:!0}),{success:e=>{var r;s.info("UniApp 打印PDF成功",e),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("UniApp 打印PDF失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"printPdfInUniApp",platform:"uniapp"})}function xn(t={}){return l.safeExecute(()=>{var r;if(!Ut()){const i={errMsg:`当前环境 (${f.type}) 不支持打印PDF功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持打印PDF",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=vn(t);s.info("开始打印PDF",{platform:f.type}),Tn(e)},{context:"printPdf",options:t})}function Ln(){return{supported:Ut(),environment:f.type,implementation:"uniapp",features:{asyncSupport:!0}}}const Be="/pages/face/index";function Dn(t={}){const e=g({},t);if(!e.name||typeof e.name!="string"||!e.name.trim())throw{errMsg:"缺少必需参数:name(姓名)",code:"PARAM_MISSING"};if(e.name=e.name.trim(),!e.idCardNumber||typeof e.idCardNumber!="string"||!e.idCardNumber.trim())throw{errMsg:"缺少必需参数:idCardNumber(身份证号)",code:"PARAM_MISSING"};return e.idCardNumber=e.idCardNumber.trim(),e}function Wt(){return["weixin","webview","UniApp","plus","nvue","uvue"].includes(f.type)}function Un(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram&&typeof window.wx.miniProgram.navigateTo=="function"}function Wn(t){const e=w(g({},t),{title:document.title||"",url:window.location.href||""}),r=Object.entries(e).filter(([,i])=>i!=null&&i!=="").map(([i,n])=>`${encodeURIComponent(i)}=${encodeURIComponent(String(n))}`).join("&");return r?`${Be}?${r}`:Be}function $n(t){return l.safeExecute(()=>{if(!Un()){s.error("微信小程序导航API不可用");return}const e=Wn(t);s.debug("跳转宿主人脸识别页面",{name:t.name,targetUrl:e}),window.wx.miniProgram.navigateTo({url:e,success:()=>{s.info("已跳转到宿主人脸识别页面",{targetUrl:e})},fail:r=>{s.error("跳转宿主人脸识别页面失败",r)}})},{context:"faceVerifyInWeixin",platform:"weixin"})}function Fn(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用人脸识别",{platform:f.type,name:t.name}),N("faceVerify",g({},t),{success:e=>{s.info("UniApp 人脸识别调用成功",e)},fail:e=>{s.error("UniApp 人脸识别调用失败",e)}})},{context:"faceVerifyInUniApp",platform:"uniapp"})}function kn(t={}){return l.safeExecute(()=>{if(!Wt()){s.error("平台不支持人脸识别",{platform:f.type});return}let e;try{e=Dn(t)}catch(r){s.error("人脸识别参数校验失败",r);return}if(s.info("开始人脸识别",{platform:f.type,name:e.name,pagePath:Be}),p()){$n(e);return}Fn(e)},{context:"faceVerify",options:t})}function Bn(){let t="weixin";return f.type==="UniApp"&&(t="uniapp"),{supported:Wt(),environment:f.type,implementation:t,features:{asyncSupport:!0,hostPageNavigation:p(),hostBridge:f.type==="UniApp"}}}const $t=V();function Gn(){if(typeof window=="undefined"||!V(!0).isWeixinMiniProgram)return!1;const e=$e().getRuntimeConfig();return typeof e.clientId=="string"&&e.clientId.length>0}function Kn(){return I(this,null,function*(){yield lr(),Gn()&&(yield ne())})}ae.useResponse(st.response,{priority:1e3});let Ft=!1;function kt(){if(Ft)return;Ft=!0,vr([{name:"load-weixin-sdk",run:et,timeoutMs:8e3},{name:"init-bridge",run:Ze,timeoutMs:8e3}],{onError:(e,r)=>{console.error(`[QSH-SDK] 初始化失败(${(r==null?void 0:r.name)||"unknown"}):`,e)}})}typeof window!="undefined"&&(document.readyState==="complete"||document.readyState==="interactive"?setTimeout(kt,0):document.addEventListener("DOMContentLoaded",kt));function y(t,{apiName:e}={}){return function(r={},...i){const n=r&&typeof r=="object"&&(typeof r.success=="function"||typeof r.fail=="function"||typeof r.complete=="function"),a=r&&typeof r=="object"?r:{},o=()=>n?t(a,...i):new Promise((d,m)=>{const O=w(g({},a),{success:_=>{typeof a.success=="function"&&a.success(_),d(_)},fail:_=>{typeof a.fail=="function"&&a.fail(_),m(_)},complete:a.complete});t(O,...i)});return(typeof window=="undefined"?Promise.resolve():Xe()).then(()=>o()).catch(d=>{throw console.error(`[QSH-SDK] ${e||"API"} call failed:`,d),d})}}function Ue(t){return typeof t=="function"?{success:t}:t&&typeof t=="object"?t:{}}const Bt=y(Fr),Gt=y(kr),Kt=y(Br),Vt=y(Gr),qt=y(Kr),jt=y(Vr);function Jt(t){const e=()=>qr(t);return(typeof window=="undefined"?Promise.resolve():Xe()).then(()=>e())}const Ge=y(Xr,{apiName:"getCode"});function Vn(t={}){return new Promise((e,r)=>{Ge(w(g({},t),{success:e,fail:r}))})}const Ke=y(ri,{apiName:"navigateToMiniProgram"});function qn(t={}){return new Promise((e,r)=>{Ke(w(g({},t),{success:e,fail:r}))})}const Ve=y(oi,{apiName:"filePreview"});function jn(t={}){return new Promise((e,r)=>{Ve(w(g({},t),{success:e,fail:r}))})}const qe=y(Ei);function Jn(t={}){return new Promise((e,r)=>{qe(w(g({},t),{success:e,fail:r}))})}const Ht=y(xn);function Hn(t={}){return new Promise((e,r)=>{Ht(w(g({},t),{success:e,fail:r}))})}const je=y(Ci),zn=y(kn);function Yn(t={}){return new Promise((e,r)=>{je(w(g({},t),{success:e,fail:r}))})}const Xn=y(xt,{apiName:"shareDirected"}),Zn=y(wn,{apiName:"shareDirectedAsync"}),Qn=y(Et,{apiName:"manualShare"}),ea=y(hi,{apiName:"manualShareAsync"}),Je=y($i);function ta(t={}){return new Promise((e,r)=>{Je(w(g({},t),{success:e,fail:r}))})}const He=y(Fi);function ra(t={}){return new Promise((e,r)=>{He(w(g({},t),{success:e,fail:r}))})}const ze=y(Yi);function ia(t={}){return new Promise((e,r)=>{ze(w(g({},t),{success:e,fail:r}))})}const zt=y(Rn);function na(t={}){return new Promise((e,r)=>{zt(w(g({},t),{success:e,fail:r}))})}const Yt=y(On);function aa(t={}){return new Promise((e,r)=>{Yt(w(g({},t),{success:e,fail:r}))})}const Xt=y(Dt);function sa(t={}){return new Promise((e,r)=>{Xt(w(g({},t),{success:e,fail:r}))})}const Zt=y(Sn);function oa(t={}){return new Promise((e,r)=>{Zt(w(g({},t),{success:e,fail:r}))})}const ca=y(Lt,{apiName:"shareMiniProgramCard"}),ua=y(En,{apiName:"shareMiniProgramCardAsync"}),ue={navigateTo:Bt,navigateBack:Gt,switchTab:Kt,reLaunch:Vt,redirectTo:qt,postMessage:jt,getEnv:Jt,getCode:Ge,getCodeAsync:Vn,navigateToMiniProgram:Ke,navigateToMiniProgramAsync:qn,filePreview:Ve,filePreviewAsync:jn,chooseImage:qe,chooseImageAsync:Jn,scanCode:je,scanCodeAsync:Yn,getLocation:Je,getLocationAsync:ta,openLocation:He,openLocationAsync:ra,chooseLocation:ze,chooseLocationAsync:ia,onLocationChange:t=>y((e={})=>Ki(e.success),{apiName:"onLocationChange"})(Ue(t)),offLocationChange:t=>y((e={})=>Vi(e.success),{apiName:"offLocationChange"})(Ue(t)),onLocationChangeError:t=>y((e={})=>qi(e.success),{apiName:"onLocationChangeError"})(Ue(t)),offLocationChangeError:t=>y((e={})=>ji(e.success),{apiName:"offLocationChangeError"})(Ue(t)),startLocationUpdate:y(Bi,{apiName:"startLocationUpdate"}),stopLocationUpdate:y(Gi,{apiName:"stopLocationUpdate"}),environment:$t,ready:Kn,init:Ze,isReady:nr,getState:ar,config:tt,weixin:{config:tt,waitForConfig:ne,isConfigReady:he,getConfigState:mr,retryConfig:pr},webView:null,ImageSourceTypes:Ne,ImageSizeTypes:be,getImageCapabilities:yi,ScanTypes:ce,getScanCapabilities:_i,CoordinateTypes:U,getLocationCapabilities:ki,getChooseLocationCapabilities:Xi,openBluetoothAdapter:zt,openBluetoothAdapterAsync:na,startBluetoothDevicesDiscovery:Yt,startBluetoothDevicesDiscoveryAsync:aa,onBluetoothDeviceFound:Xt,onBluetoothDeviceFoundAsync:sa,createBLEConnection:Zt,createBLEConnectionAsync:oa,BluetoothStates:yn,shareDirected:Xn,shareDirectedAsync:Zn,manualShare:Qn,manualShareAsync:ea,shareMiniProgramCard:ca,shareMiniProgramCardAsync:ua,getBluetoothCapabilities:Nn,printPdf:Ht,printPdfAsync:Hn,getPrintCapabilities:Ln,faceVerify:zn,getFaceCapabilities:Bn,plugins:{manager:ye,register:t=>ye.register(t),install:t=>ye.install(t,ue),list:()=>ye.getPluginList()},interceptors:{chain:ae,useRequest:(t,e)=>ae.useRequest(t,e),useResponse:(t,e)=>ae.useResponse(t,e),builtin:{logging:yr,performance:Z,createRetry:Ar,createValidation:Ir,errorNormalizer:st}},metrics:{getPerformanceReport:()=>Z.getReport(),clearPerformanceMetrics:()=>Z.clearMetrics()},errors:{codes:u,messages:Fe,categories:K,normalize:at,create:Sr,isStandard:Nr},store:{instance:j,get:t=>j.get(t),set:(t,e)=>j.set(t,e),subscribe:(t,e)=>j.subscribe(t,e),getSnapshot:()=>j.getSnapshot()},debug:{logger:W,setLogReporter:t=>W.setReporter(t),errorHandler:l,stateManager:ie,enableDevMode:()=>W.enableDevMode(),getLogs:t=>W.getHistory(t),getStats:()=>({logger:W.getStats(),state:ie.getStats(),weixinConfig:$e().getStats(),plugins:ye.getStats(),interceptors:ae.getStats(),store:j.getStats()}),getWeixinConfigManager:$e,exportDebugInfo:()=>W.exportToJSON()}};$t.isWeixinMiniProgram?ue.webView=window.wx&&window.wx.miniProgram:ue.webView={navigateTo:Bt,navigateBack:Gt,switchTab:Kt,reLaunch:Vt,redirectTo:qt,postMessage:jt,getEnv:Jt,getCode:Ge,navigateToMiniProgram:Ke,filePreview:Ve,chooseImage:qe,scanCode:je,getLocation:Je,openLocation:He,chooseLocation:ze};const Qt=typeof window.uni!="undefined"?window.uni:{};return Object.keys(Qt).forEach(t=>{ue.hasOwnProperty(t)||(ue[t]=Qt[t])}),typeof window!="undefined"&&(window.qsh=ue),ue});
|
|
1
|
+
(function(R,M){typeof exports=="object"&&typeof module!="undefined"?module.exports=M():typeof define=="function"&&define.amd?define(M):(R=typeof globalThis!="undefined"?globalThis:R||self,R.qsh=M())})(this,function(){"use strict";var ga=Object.defineProperty,ha=Object.defineProperties;var ma=Object.getOwnPropertyDescriptors;var ir=Object.getOwnPropertySymbols;var pa=Object.prototype.hasOwnProperty,wa=Object.prototype.propertyIsEnumerable;var Xe=(R,M,p)=>M in R?ga(R,M,{enumerable:!0,configurable:!0,writable:!0,value:p}):R[M]=p,g=(R,M)=>{for(var p in M||(M={}))pa.call(M,p)&&Xe(R,p,M[p]);if(ir)for(var p of ir(M))wa.call(M,p)&&Xe(R,p,M[p]);return R},w=(R,M)=>ha(R,ma(M));var X=(R,M,p)=>Xe(R,typeof M!="symbol"?M+"":M,p);var I=(R,M,p)=>new Promise((le,te)=>{var fe=k=>{try{re(p.next(k))}catch(F){te(F)}},de=k=>{try{re(p.throw(k))}catch(F){te(F)}},re=k=>k.done?le(k.value):Promise.resolve(k.value).then(fe,de);re((p=p.apply(R,M)).next())});function R(){return typeof window!="undefined"?window:void 0}function M(){return typeof navigator=="undefined"?"":navigator.userAgent||""}function p(){const t=R();if(!t)return!1;if(t.__wxjs_environment==="miniprogram"||t.wx&&t.wx.miniProgram)return!0;const e=M();return!!(e&&/micromessenger/i.test(e)&&/miniProgram/i.test(e))}function le(){const t=R();return!!(t&&t.plus)}function te(){const t=R();return!!(t&&(t.__dcloud_weex_postMessage||t.__dcloud_weex_))}function fe(){const t=R();return!!(t&&(t.__uniapp_x_postMessage||t.__uniapp_x_))}function de(){const t=M();return/uni-app/i.test(t)}function re(){const t=M();return/Html5Plus/i.test(t)}function k(){return de()||re()}function F(){const t=R();if(!t)return!1;if(t.__offline_bridge_postMessage)return!0;try{const e=t.location&&t.location.hostname;if(e&&/\.?offline\.?/i.test(e))return!0}catch(e){}return!1}function nr(){return p()?"weixin":F()?"offline":fe()?"uvue":te()?"nvue":le()?"plus":k()?"webview":de()?"UniApp":"h5"}let Se=null;function V(t=!1){return Se&&!t||(Se={isWeixinMiniProgram:p(),isAppPlus:le(),isNvue:te(),isUvue:fe(),isUniApp:de(),isHtml5Plus:re(),isUniAppWebView:k(),isOfflineWebview:F(),type:nr()}),Se}const f=V(),L={PLATFORM_NOT_SUPPORTED:"PLATFORM_NOT_SUPPORTED",API_CALL_FAILED:"API_CALL_FAILED",BRIDGE_NOT_READY:"BRIDGE_NOT_READY",INVALID_PARAMETERS:"INVALID_PARAMETERS",NETWORK_ERROR:"NETWORK_ERROR"};class b extends Error{constructor(e,r,i={},n=null){super(r),this.name="QshError",this.type=e,this.context=i,this.originalError=n,this.timestamp=new Date().toISOString(),Error.captureStackTrace&&Error.captureStackTrace(this,b)}toJSON(){return{name:this.name,type:this.type,message:this.message,context:this.context,timestamp:this.timestamp,stack:this.stack}}}const T=class T{static setDebugMode(e){T.isDebugMode=e}static addErrorCallback(e){typeof e=="function"&&T.errorCallbacks.push(e)}static removeErrorCallback(e){const r=T.errorCallbacks.indexOf(e);r>-1&&T.errorCallbacks.splice(r,1)}static handleApiError(e,r={}){let i;return e instanceof b?i=e:e instanceof Error?i=new b(L.API_CALL_FAILED,e.message,r,e):i=new b(L.API_CALL_FAILED,String(e),r),T.logError(i),T.notifyCallbacks(i),i}static handlePlatformNotSupported(e,r){const i=new b(L.PLATFORM_NOT_SUPPORTED,`API "${r}" is not supported on platform "${e}"`,{platformType:e,apiName:r});return T.logError(i),T.notifyCallbacks(i),i}static handleBridgeNotReady(e){const r=new b(L.BRIDGE_NOT_READY,`Bridge is not ready when calling "${e}"`,{apiName:e});return T.logError(r),T.notifyCallbacks(r),r}static handleInvalidParameters(e,r,i,n){const a=new b(L.INVALID_PARAMETERS,`Invalid parameter "${r}" in "${e}": expected ${i}, got ${typeof n}`,{apiName:e,paramName:r,expectedType:i,actualValue:n});return T.logError(a),T.notifyCallbacks(a),a}static safeExecute(e,r={}){try{return e()}catch(i){return T.handleApiError(i,r)}}static safeExecuteAsync(i){return I(this,arguments,function*(e,r={}){try{return yield e()}catch(n){return T.handleApiError(n,r)}})}static logError(e){if(typeof console!="undefined"){const r=`[QSH-SDK Error] ${e.type}: ${e.message}`;T.isDebugMode?console.error(r,{context:e.context,originalError:e.originalError,stack:e.stack,timestamp:e.timestamp}):console.error(r)}}static notifyCallbacks(e){T.errorCallbacks.forEach(r=>{try{r(e)}catch(i){typeof console!="undefined"&&console.error("[QSH-SDK] Error in error callback:",i)}})}static createErrorDecorator(e={}){return function(r,i,n){const a=n.value;return n.value=function(...o){return T.safeExecute(()=>a.apply(this,o),w(g({},e),{method:i,target:r.constructor.name}))},n}}};X(T,"isDebugMode",!1),X(T,"errorCallbacks",[]);let l=T;const $={UNINITIALIZED:"uninitialized",INITIALIZING:"initializing",READY:"ready",ERROR:"error"};class ar{constructor(){this.state=$.UNINITIALIZED,this.readyPromise=null,this.readyCallbacks=[],this.errorCallbacks=[],this.initializationError=null,this.handleBridgeReady=this.handleBridgeReady.bind(this),this.handleInitializationError=this.handleInitializationError.bind(this)}getState(){return this.state}isReady(){return this.state===$.READY}isInitializing(){return this.state===$.INITIALIZING}hasError(){return this.state===$.ERROR}getInitializationError(){return this.initializationError}waitForReady(){return this.isReady()?Promise.resolve():this.hasError()?Promise.reject(this.initializationError):(this.readyPromise||(this.readyPromise=new Promise((e,r)=>{this.isReady()?e():this.hasError()?r(this.initializationError):(this.readyCallbacks.push(e),this.errorCallbacks.push(r))})),this.readyPromise)}startInitialization(e){return I(this,null,function*(){if(this.state!==$.UNINITIALIZED)return this.waitForReady();this.state=$.INITIALIZING;try{yield e(),this.handleBridgeReady()}catch(r){throw this.handleInitializationError(r),r}return this.waitForReady()})}handleBridgeReady(){this.state===$.INITIALIZING&&(this.state=$.READY,this.readyCallbacks.forEach(e=>{try{e()}catch(r){l.handleApiError(r,{context:"StateManager.handleBridgeReady"})}}),this.readyCallbacks=[],this.errorCallbacks=[])}handleInitializationError(e){this.state=$.ERROR,this.initializationError=e,this.errorCallbacks.forEach(r=>{try{r(e)}catch(i){l.handleApiError(i,{context:"StateManager.handleInitializationError"})}}),this.readyCallbacks=[],this.errorCallbacks=[]}reset(){this.state=$.UNINITIALIZED,this.readyPromise=null,this.readyCallbacks=[],this.errorCallbacks=[],this.initializationError=null}onStateChange(e,r){if(this.state===e)return setTimeout(()=>r(this.state),0),()=>{};const i=()=>{this.state===e&&r(this.state)};return e===$.READY?this.readyCallbacks.push(i):e===$.ERROR&&this.errorCallbacks.push(i),()=>{const n=this.readyCallbacks.indexOf(i);n>-1&&this.readyCallbacks.splice(n,1);const a=this.errorCallbacks.indexOf(i);a>-1&&this.errorCallbacks.splice(a,1)}}getStats(){return{state:this.state,readyCallbacksCount:this.readyCallbacks.length,errorCallbacksCount:this.errorCallbacks.length,hasReadyPromise:!!this.readyPromise,hasInitializationError:!!this.initializationError}}}const ie=new ar,Ze=()=>ie.waitForReady(),sr=()=>ie.isReady(),or=()=>ie.getState(),C={ERROR:0,WARN:1,INFO:2,DEBUG:3,TRACE:4},we={[C.ERROR]:"ERROR",[C.WARN]:"WARN",[C.INFO]:"INFO",[C.DEBUG]:"DEBUG",[C.TRACE]:"TRACE"},h=class h{static setLevel(e){e>=C.ERROR&&e<=C.TRACE&&(h.currentLevel=e,h.log(C.INFO,"Logger",`日志级别设置为: ${we[e]}`))}static enableDevMode(){h.setLevel(C.DEBUG),h.log(C.INFO,"Logger","开发模式已启用")}static enableProdMode(){h.setLevel(C.WARN),h.log(C.INFO,"Logger","生产模式已启用")}static enableModule(e){h.enabledModules.add(e),h.log(C.INFO,"Logger",`模块日志已启用: ${e}`)}static disableModule(e){h.enabledModules.delete(e),h.log(C.INFO,"Logger",`模块日志已禁用: ${e}`)}static shouldLog(e,r){return e>h.currentLevel?!1:r&&h.enabledModules.size>0?h.enabledModules.has(r):!0}static log(e,r,i,...n){if(!h.shouldLog(e,r))return;const a=new Date().toISOString(),o=we[e],c=r?`[${r}]`:"",d=`${h.prefix} ${c} ${i}`,m={timestamp:a,level:e,levelName:o,module:r,message:i,args:n};if(h.addToHistory(m),typeof h.reporter=="function")try{h.reporter(m)}catch(S){}h.outputToConsole(e,d,...n)}static addToHistory(e){h.logHistory.push(e),h.logHistory.length>h.maxHistorySize&&h.logHistory.shift()}static outputToConsole(e,r,...i){if(typeof console=="undefined")return;const n=i&&i.length>0;switch(e){case C.ERROR:n?console.error(r,...i):console.error(r);break;case C.WARN:n?console.warn(r,...i):console.warn(r);break;case C.INFO:n?console.info(r,...i):console.info(r);break;case C.DEBUG:case C.TRACE:n?console.log(r,...i):console.log(r);break}}static error(e,r,...i){h.log(C.ERROR,e,r,...i)}static warn(e,r,...i){h.log(C.WARN,e,r,...i)}static info(e,r,...i){h.log(C.INFO,e,r,...i)}static debug(e,r,...i){h.log(C.DEBUG,e,r,...i)}static trace(e,r,...i){h.log(C.TRACE,e,r,...i)}static getHistory(e){return e&&e>0?h.logHistory.slice(-e):[...h.logHistory]}static clearHistory(){h.logHistory=[],h.log(C.INFO,"Logger","日志历史已清空")}static getStats(){const e={currentLevel:h.currentLevel,currentLevelName:we[h.currentLevel],enabledModules:Array.from(h.enabledModules),historySize:h.logHistory.length,maxHistorySize:h.maxHistorySize},r={};for(const i of Object.keys(we))r[we[i]]=0;return h.logHistory.forEach(i=>{r[i.levelName]++}),e.levelCounts=r,e}static exportToJSON(e){const r=h.getHistory(e),i=h.getStats();return JSON.stringify({exportTime:new Date().toISOString(),stats:i,logs:r},null,2)}static createModuleLogger(e){return{error:(r,...i)=>h.error(e,r,...i),warn:(r,...i)=>h.warn(e,r,...i),info:(r,...i)=>h.info(e,r,...i),debug:(r,...i)=>h.debug(e,r,...i),trace:(r,...i)=>h.trace(e,r,...i)}}static setReporter(e){h.reporter=typeof e=="function"?e:null}};X(h,"currentLevel",C.ERROR),X(h,"enabledModules",new Set),X(h,"logHistory",[]),X(h,"maxHistorySize",1e3),X(h,"prefix","[QSH-SDK]"),X(h,"reporter",null);let W=h;if(typeof window!="undefined"){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"));let r=!1;try{r=localStorage&&localStorage.getItem("qsh_debug")==="true"}catch(i){}(t||e||r)&&W.enableDevMode()}const P=W.createModuleLogger("Bridge"),E=W.createModuleLogger("Platform"),s=W.createModuleLogger("API"),B=W.createModuleLogger("State"),Ee=/complete|loaded|interactive/,cr=500;function Oe(t,e=cr){if(Ee.test(document.readyState)){setTimeout(t,0);return}let r=!1,i=null;const n=()=>{r||(r=!0,document.removeEventListener("DOMContentLoaded",n),i&&clearTimeout(i),t())};document.addEventListener("DOMContentLoaded",n,{once:!0}),i=setTimeout(n,e)}function ur(t){if(!F())return!1;P.debug("检测到离线包环境,开始初始化");const e=()=>{t()};return Ee.test(document.readyState)?(P.debug("离线包环境 DOM 已就绪,立即初始化"),setTimeout(e,0)):(P.debug("离线包环境,等待 DOMContentLoaded"),Oe(e)),!0}function lr(t){return de()||re()?(P.debug("检测到 APP 环境,开始初始化"),window.__uniapp_x_postMessage||window.__uniapp_x_||window.__dcloud_weex_postMessage||window.__dcloud_weex_?(P.debug("NVUE/UVUE 环境,等待 DOMContentLoaded"),Oe(t)):window.plus&&Ee.test(document.readyState)?(P.debug("Plus 环境已就绪,立即初始化"),setTimeout(t,0)):window.plus?(P.debug("Plus 环境,等待 plusready 事件"),document.addEventListener("plusready",t)):Ee.test(document.readyState)?setTimeout(t,0):Oe(t),!0):!1}function fr(t){return window.wx&&window.wx.miniProgram?(P.debug("检测到微信小程序环境,开始初始化"),window.WeixinJSBridge&&window.WeixinJSBridge.invoke?(P.debug("微信 JSBridge 已就绪,立即初始化"),setTimeout(t,0)):(P.debug("微信 JSBridge 未就绪,等待 WeixinJSBridgeReady 事件"),document.addEventListener("WeixinJSBridgeReady",t)),!0):!1}function dr(t){return P.info("开始初始化 JSBridge"),ur(t)?(P.info("使用离线包环境初始化"),!0):lr(t)?(P.info("使用 APP 环境初始化"),!0):fr(t)?(P.info("使用微信小程序环境初始化"),!0):(P.debug("使用默认 H5 环境初始化"),Ee.test(document.readyState)?(P.debug("DOM 已就绪,立即初始化"),setTimeout(t,0)):(P.debug("DOM 未就绪,等待 DOMContentLoaded"),Oe(t)),!0)}function gr(){return ie.waitForReady()}function Qe(){return ie.startInitialization(()=>I(null,null,function*(){return new Promise((t,e)=>{const r=()=>{t()},i=n=>{const a=l.handleApiError(n,{context:"bridge initialization"});e(a)};try{dr(()=>{r()})}catch(n){i(n)}})}))}const x={UNINITIALIZED:"uninitialized",CONFIGURING:"configuring",CONFIGURED:"configured",ERROR:"error"};function q(){return typeof window=="undefined"||!window.wx?!1:typeof window.wx.config=="function"&&typeof window.wx.ready=="function"&&typeof window.wx.error=="function"}class hr{constructor(){this.state=x.UNINITIALIZED,this.configPromise=null,this.readyCallbacks=[],this.errorCallbacks=[],this.lastError=null,this.configVersion=0,this.configuredConfigKey=null,this.runtimeConfig={clientId:null,isProd:!1,debug:!1,url:""},this.CONFIG_API_URL=this.getConfigApiUrl(this.runtimeConfig.isProd),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)}configure(e={}){if(!e||typeof e!="object"||Array.isArray(e))throw new b(L.INVALID_PARAMETERS,"config参数异常",{config:e});if(!Object.prototype.hasOwnProperty.call(e,"clientId"))throw this.createMissingClientIdError();if(typeof e.clientId!="string"||!e.clientId.trim())throw new b(L.INVALID_PARAMETERS,"clientId参数异常",{clientId:e.clientId});if(Object.prototype.hasOwnProperty.call(e,"isProd")&&typeof e.isProd!="boolean")throw new b(L.INVALID_PARAMETERS,"isProd参数异常",{isProd:e.isProd});if(Object.prototype.hasOwnProperty.call(e,"debug")&&typeof e.debug!="boolean")throw new b(L.INVALID_PARAMETERS,"debug参数异常",{debug:e.debug});if(Object.prototype.hasOwnProperty.call(e,"url")&&typeof e.url!="string")throw new b(L.INVALID_PARAMETERS,"url参数异常",{url:e.url});const r=e.clientId.trim(),i=e.isProd===!0,n=i?!1:e.debug===!0,a=typeof e.url=="string"?e.url.trim():"",o=r!==this.runtimeConfig.clientId||i!==this.runtimeConfig.isProd||n!==this.runtimeConfig.debug||a!==this.runtimeConfig.url;return this.runtimeConfig=w(g({},this.runtimeConfig),{clientId:r,isProd:i,debug:n,url:a}),this.CONFIG_API_URL=this.getConfigApiUrl(i),(this.state===x.ERROR||o&&(this.state===x.CONFIGURING||this.state===x.CONFIGURED))&&this.reset({preserveCallbacks:!0}),E.info("Updated Weixin runtime config",{clientId:this.runtimeConfig.clientId,isProd:this.runtimeConfig.isProd,debug:this.runtimeConfig.debug,url:this.runtimeConfig.url,configApiUrl:this.CONFIG_API_URL}),this.getRuntimeConfig()}getRuntimeConfig(){return g({},this.runtimeConfig)}getEffectiveConfigUrl(e={}){const{requireWindow:r=!1}=e;return this.runtimeConfig.url?this.runtimeConfig.url:r?this.getCurrentPageUrl():typeof window=="undefined"||!window.location?"":this.getCurrentPageUrl()}getRuntimeConfigKey(){return JSON.stringify({clientId:this.runtimeConfig.clientId,isProd:this.runtimeConfig.isProd,debug:this.runtimeConfig.debug,url:this.getEffectiveConfigUrl()})}isCurrentConfigRun(e,r){return e===this.configVersion&&r===this.getRuntimeConfigKey()}hasClientId(){return typeof this.runtimeConfig.clientId=="string"&&this.runtimeConfig.clientId.length>0}hasRequiredConfig(){return this.isTestMode()||this.hasClientId()}createMissingClientIdError(){return new b(L.INVALID_PARAMETERS,"clientId错误",{field:"clientId"})}getConfigApiUrl(e=!1){return e?"https://tyck-service.xj-agri.gov.cn/api/wechat/mp/jssdk-sign":"https://unified-platform-service.xjy2.cn/api/wechat/mp/jssdk-sign"}getCurrentPageUrl(){if(typeof window=="undefined"||!window.location)throw new Error("无法获取当前页面URL");const e=window.location.href,r=e.indexOf("#");return r!==-1?e.substring(0,r):e}fetchWeixinConfig(){return I(this,null,function*(){const e=this.getEffectiveConfigUrl({requireWindow:!0});if(this.isTestMode())return E.info("使用测试模式,返回模拟配置"),this.getMockConfig();if(!this.hasClientId())throw this.createMissingClientIdError();const r=this.getConfigApiUrl(this.runtimeConfig.isProd);this.CONFIG_API_URL=r;const i=`${r}?clientId=${this.runtimeConfig.clientId}&url=${encodeURIComponent(e)}`;E.debug("请求微信配置",{url:i});try{const n=yield fetch(i);if(!n.ok)throw new Error(`HTTP ${n.status}: ${n.statusText}`);const a=yield n.json();if(E.debug("微信配置响应",a),!a.success||a.code!==200)throw new Error(`配置获取失败: ${a.message||"未知错误"}`);const{data:o}=a;if(!o||!o.appId||!o.timestamp||!o.nonceStr||!o.signature)throw new Error("配置数据格式不正确,缺少必需字段");return o}catch(n){if(E.error("获取微信配置失败",n),this.shouldUseTestMode(n))return E.warn("网络请求失败,降级到测试模式"),this.getMockConfig();throw new b(L.NETWORK_ERROR,`获取微信配置失败: ${n.message}`,{url:i,originalError:n})}})}isTestMode(){if(typeof window=="undefined")return!1;if(new URLSearchParams(window.location.search).get("qsh_test")==="true")return!0;try{if(localStorage.getItem("qsh_test")==="true")return!0}catch(r){}return!1}shouldUseTestMode(e){if(typeof window=="undefined")return!1;const r=window.location.hostname==="localhost"||window.location.hostname.includes("natappfree.cc"),i=!window.wx||!window.wx.miniProgram,n=e.message.includes("CORS")||e.message.includes("Failed to fetch");return r&&i&&n}getMockConfig(){return{appId:"wx_test_app_id",timestamp:Math.floor(Date.now()/1e3).toString(),nonceStr:Math.random().toString(36).substring(2,15),signature:"test_signature_"+Math.random().toString(36).substring(2,10)}}executeWeixinConfig(e,r,i){if(this.isTestMode()||e.appId==="wx_test_app_id"){E.info("测试模式:模拟微信配置成功"),setTimeout(()=>{this.handleConfigSuccess(r,i)},100);return}if(!q())throw new Error("微信JS-SDK未加载");const n={debug:this.runtimeConfig.debug,appId:e.appId,timestamp:parseInt(e.timestamp),nonceStr:e.nonceStr,signature:e.signature,jsApiList:this.DEFAULT_JS_API_LIST};E.info("执行微信配置",n),window.wx.ready(()=>this.handleConfigSuccess(r,i)),window.wx.error(a=>this.handleConfigError(a,r,i)),window.wx.config(n)}handleConfigSuccess(e=this.configVersion,r=this.getRuntimeConfigKey()){if(!this.isCurrentConfigRun(e,r)){E.debug("忽略过期的微信配置成功回调");return}E.info("微信配置成功"),this.state=x.CONFIGURED,this.configuredConfigKey=r,this.lastError=null,this.configPromise=null;const i=[...this.readyCallbacks];this.readyCallbacks=[],this.errorCallbacks=[],i.forEach(n=>{try{n()}catch(a){l.handleApiError(a,{context:"WeixinConfigManager.handleConfigSuccess"})}})}handleConfigError(e,r=this.configVersion,i=this.getRuntimeConfigKey()){if(!this.isCurrentConfigRun(r,i)){E.debug("忽略过期的微信配置错误回调",e);return}const n=`微信配置验证失败: ${JSON.stringify(e)}`;E.error(n,e);const a=new b(L.API_CALL_FAILED,n,{weixinErrorResponse:e});this.state=x.ERROR,this.lastError=a,this.configPromise=null;const o=[...this.errorCallbacks];this.readyCallbacks=[],this.errorCallbacks=[],o.forEach(c=>{try{c(a)}catch(d){l.handleApiError(d,{context:"WeixinConfigManager.handleConfigError"})}})}autoConfig(){return I(this,null,function*(){if(!this.hasRequiredConfig())return E.warn("clientId为空,等待qsh.config({ clientId })"),Promise.resolve();if(this.isReady())return Promise.resolve();if(this.state===x.CONFIGURED&&this.reset({preserveCallbacks:!0}),this.state===x.ERROR)return Promise.reject(this.lastError);if(this.configPromise)return this.configPromise;this.state=x.CONFIGURING;const e=this.configVersion,r=this.getRuntimeConfigKey();return this.configPromise=this.performAutoConfig(e,r),this.configPromise})}performAutoConfig(e,r){return I(this,null,function*(){try{if(typeof window=="undefined")throw new Error("非浏览器环境无法执行微信配置");if(!q())throw new Error("微信JS-SDK未加载,无法执行配置");const i=yield this.fetchWeixinConfig();if(!this.isCurrentConfigRun(e,r)){E.debug("忽略过期的微信配置响应");return}return this.executeWeixinConfig(i,e,r),yield new Promise((n,a)=>{if(this.isReady()){n();return}if(this.state===x.ERROR){a(this.lastError);return}this.readyCallbacks.push(n),this.errorCallbacks.push(a)})}catch(i){if(!this.isCurrentConfigRun(e,r)){E.debug("忽略过期的微信配置异常",i);return}const n=i instanceof b?i:l.handleApiError(i,{context:"WeixinConfigManager.performAutoConfig"});this.state=x.ERROR,this.lastError=n,this.configPromise=null;const a=[...this.errorCallbacks];throw this.readyCallbacks=[],this.errorCallbacks=[],a.forEach(o=>{try{o(n)}catch(c){l.handleApiError(c,{context:"WeixinConfigManager.performAutoConfig.errorCallback"})}}),n}})}waitForReady(){return this.isReady()?Promise.resolve():(this.state===x.CONFIGURED&&this.reset({preserveCallbacks:!0}),this.state===x.ERROR?Promise.reject(this.lastError):this.hasRequiredConfig()?this.state===x.UNINITIALIZED?this.autoConfig():new Promise((e,r)=>{this.readyCallbacks.push(e),this.errorCallbacks.push(r)}):Promise.reject(this.createMissingClientIdError()))}isReady(){return this.state===x.CONFIGURED&&this.configuredConfigKey===this.getRuntimeConfigKey()}getState(){return this.state}getLastError(){return this.lastError}reset(e={}){const{preserveCallbacks:r=!1}=e;this.configVersion+=1,this.state=x.UNINITIALIZED,this.configPromise=null,r||(this.readyCallbacks=[],this.errorCallbacks=[]),this.lastError=null,this.configuredConfigKey=null,E.debug("微信配置管理器已重置")}getStats(){return{state:this.state,readyCallbacksCount:this.readyCallbacks.length,errorCallbacksCount:this.errorCallbacks.length,hasConfigPromise:!!this.configPromise,hasLastError:!!this.lastError,configVersion:this.configVersion,configuredConfigKey:this.configuredConfigKey,configApiUrl:this.CONFIG_API_URL,clientId:this.runtimeConfig.clientId,isProd:this.runtimeConfig.isProd,debug:this.runtimeConfig.debug,url:this.runtimeConfig.url,effectiveUrl:this.getEffectiveConfigUrl(),jsApiList:this.DEFAULT_JS_API_LIST}}}const D=new hr;let ge=!1,ye=!1,G=null,Ne=!1;function mr(t){return new Promise(e=>{let r=!1,i=null;const n=c=>I(null,null,function*(){if(!r){if(r=!0,i&&clearTimeout(i),ge=!1,ye=c,c)try{yield et()}catch(d){E.error("微信配置失败,将使用消息桥作为后备",d)}e()}}),a=()=>n(q()),o=()=>{E.warn("已存在的微信 JS-SDK 脚本加载失败,SDK 将使用消息桥作为后备"),n(!1)};t.addEventListener("load",a,{once:!0}),t.addEventListener("error",o,{once:!0}),setTimeout(()=>{q()&&a()},0),i=setTimeout(()=>{n(q())},3e3)})}function $e(){return I(this,arguments,function*(t={}){const{force:e=!1,recoverFromError:r=!1}=t;if(yield tt({force:e}),!q())throw new Error("微信 JS-SDK 未正确加载,无法执行配置");r&&wr()})}function pr(t=!1){if(typeof window=="undefined")return!1;if(q())return ye=!0,!1;if(ye||F())return!1;if(t)return!0;const e=navigator.userAgent||"",r=/micromessenger/i.test(e),i=/miniProgram/i.test(e),n=typeof window.__wxjs_environment!="undefined"&&window.__wxjs_environment==="miniprogram",a=!!(window.wx&&window.wx.miniProgram);return r&&(i||n||a)}function wr(){D.getState()==="error"&&(D.reset(),Ne=!1)}function et(){return I(this,null,function*(){if(Ne)return D.waitForReady();Ne=!0,E.info("开始自动配置微信JS-SDK");try{yield D.autoConfig(),E.info("微信JS-SDK自动配置完成")}catch(t){E.error("微信JS-SDK自动配置失败",t)}})}function tt(t={}){const{force:e=!1}=t;if(typeof window=="undefined")return Promise.resolve();if(q())return ye=!0,Promise.resolve();const r=document.getElementById("weixin-jssdk");return r?G||(ge=!0,G=mr(r).finally(()=>{G=null}),G):pr(e)?G||(G=new Promise(i=>{ge=!0;try{const n=document.createElement("script");n.id="weixin-jssdk",n.type="text/javascript",n.async=!0,n.src="https://res.wx.qq.com/open/js/jweixin-1.6.2.js",n.onload=function(){return I(this,null,function*(){ye=!0,ge=!1,E.info("微信 JS-SDK 已自动加载");try{yield et()}catch(o){E.error("微信配置失败,将使用消息桥作为后备",o)}i()})},n.onerror=function(){ge=!1,E.warn("微信 JS-SDK 加载失败,SDK 将使用消息桥作为后备"),i()},(document.getElementsByTagName("head")[0]||document.documentElement).appendChild(n)}catch(n){ge=!1,E.error("注入微信 JS-SDK 失败",n),i()}}).finally(()=>{G=null}),G):Promise.resolve()}function ne(){return $e({force:!0,recoverFromError:!0}).then(()=>D.waitForReady())}function rt(t={}){const e=D.configure(t);return typeof window=="undefined"||$e({force:!0,recoverFromError:D.getState()==="error"}).then(()=>{if(!D.isReady())return D.waitForReady().catch(r=>{E.error("Failed to auto-configure Weixin after qsh.config()",r)});window.wx&&!q()&&E.warn("window.wx 已存在,但微信 JS-SDK 尚未就绪,跳过自动配置")}).catch(r=>{E.error("Failed to preload Weixin JS-SDK",r)}),e}function he(){return D.isReady()}function Er(){return D.getState()}function Fe(){return D}function yr(){return I(this,null,function*(){return E.info("手动重试微信配置"),D.reset(),Ne=!1,yield $e({force:!0}),D.waitForReady()})}class Ar{constructor(){this.plugins=new Map,this.installed=new Set,this.installOrder=[],s.debug("插件管理器已初始化")}register(e){return l.safeExecute(()=>{this.validatePlugin(e);const{name:r,version:i}=e;if(this.plugins.has(r)){const n=this.plugins.get(r);s.warn(`插件 ${r} 已注册(版本 ${n.version}),将被覆盖为版本 ${i}`)}return this.plugins.set(r,e),s.info(`插件已注册: ${r}@${i}`),this},{context:"PluginManager.register",pluginName:e==null?void 0:e.name})}validatePlugin(e){if(!e||typeof e!="object")throw new Error("插件必须是一个对象");if(!e.name||typeof e.name!="string")throw new Error("插件必须有 name 属性(字符串)");if(!e.version||typeof e.version!="string")throw new Error(`插件 ${e.name} 必须有 version 属性(字符串)`);if(!e.install||typeof e.install!="function")throw new Error(`插件 ${e.name} 必须实现 install 方法`);if(e.dependencies&&!Array.isArray(e.dependencies))throw new Error(`插件 ${e.name} 的 dependencies 必须是数组`)}install(e,r){return I(this,null,function*(){return l.safeExecute(()=>I(this,null,function*(){if(!this.plugins.has(e))throw new Error(`插件 ${e} 未注册`);if(this.installed.has(e)){s.debug(`插件 ${e} 已安装,跳过`);return}const i=this.plugins.get(e);if(i.dependencies&&i.dependencies.length>0){s.debug(`安装插件 ${e} 的依赖:`,i.dependencies);for(const n of i.dependencies)yield this.install(n,r)}s.info(`开始安装插件: ${e}@${i.version}`),yield i.install(r),this.installed.add(e),this.installOrder.push(e),s.info(`插件安装成功: ${e}@${i.version}`)}),{context:"PluginManager.install",pluginName:e})})}uninstall(e,r){return I(this,null,function*(){return l.safeExecute(()=>I(this,null,function*(){if(!this.installed.has(e)){s.debug(`插件 ${e} 未安装,跳过卸载`);return}const i=this.plugins.get(e);i.uninstall&&typeof i.uninstall=="function"&&(s.info(`开始卸载插件: ${e}`),yield i.uninstall(r)),this.installed.delete(e);const n=this.installOrder.indexOf(e);n>-1&&this.installOrder.splice(n,1),s.info(`插件已卸载: ${e}`)}),{context:"PluginManager.uninstall",pluginName:e})})}uninstallAll(e){return I(this,null,function*(){const r=[...this.installOrder].reverse();for(const i of r)yield this.uninstall(i,e)})}registerAll(e){if(!Array.isArray(e))throw new Error("plugins 必须是数组");return e.forEach(r=>this.register(r)),this}installAll(e,r){return I(this,null,function*(){if(!Array.isArray(e))throw new Error("names 必须是数组");for(const i of e)yield this.install(i,r)})}isRegistered(e){return this.plugins.has(e)}isInstalled(e){return this.installed.has(e)}getPlugin(e){return this.plugins.get(e)}getPluginList(){return Array.from(this.plugins.entries()).map(([e,r])=>({name:e,version:r.version,installed:this.installed.has(e),dependencies:r.dependencies||[]}))}getStats(){return{registered:this.plugins.size,installed:this.installed.size,plugins:this.getPluginList()}}clear(){this.plugins.clear(),this.installed.clear(),this.installOrder=[]}}const Ae=new Ar;class Ir{constructor(){this.requestInterceptors=[],this.responseInterceptors=[],s.debug("拦截器链已初始化")}useRequest(e,r={}){if(typeof e!="function")throw new Error("拦截器必须是函数");const{priority:i=0}=r;return this.requestInterceptors.push({fn:e,priority:i}),this.requestInterceptors.sort((n,a)=>a.priority-n.priority),s.debug("请求拦截器已注册",{priority:i}),()=>{const n=this.requestInterceptors.findIndex(a=>a.fn===e);n>-1&&(this.requestInterceptors.splice(n,1),s.debug("请求拦截器已移除"))}}useResponse(e,r={}){if(typeof e!="function")throw new Error("拦截器必须是函数");const{priority:i=0}=r;return this.responseInterceptors.push({fn:e,priority:i}),this.responseInterceptors.sort((n,a)=>a.priority-n.priority),s.debug("响应拦截器已注册",{priority:i}),()=>{const n=this.responseInterceptors.findIndex(a=>a.fn===e);n>-1&&(this.responseInterceptors.splice(n,1),s.debug("响应拦截器已移除"))}}runRequest(e){return I(this,null,function*(){let r=g({},e);for(const{fn:i}of this.requestInterceptors){if(r.abort){s.debug("请求被中止",{apiName:r.apiName});break}try{const n=yield i(r);n&&(r=n)}catch(n){s.error("请求拦截器执行失败",n),r.abort=!0,r.error=n;break}}return r})}runResponse(e,r){return I(this,null,function*(){let i=e;for(const{fn:n}of this.responseInterceptors)try{const a=yield n(i,r);a!==void 0&&(i=a)}catch(a){s.error("响应拦截器执行失败",a)}return i})}clear(){this.requestInterceptors=[],this.responseInterceptors=[],s.debug("所有拦截器已清空")}getStats(){return{requestInterceptors:this.requestInterceptors.length,responseInterceptors:this.responseInterceptors.length}}}const ae=new Ir,Pr={request:t=>(t.startTime=Date.now(),s.debug(`[API 调用] ${t.apiName}`,{params:t.params}),t),response:(t,e)=>{const r=Date.now()-e.startTime;return s.debug(`[API 完成] ${e.apiName}`,{duration:`${r}ms`,success:t==null?void 0:t.success}),t}},Z={metrics:new Map,request:t=>(t.perfStartTime=performance.now(),t),response:(t,e)=>{const r=performance.now()-e.perfStartTime;Z.metrics.has(e.apiName)||Z.metrics.set(e.apiName,{count:0,totalTime:0,minTime:1/0,maxTime:0,avgTime:0});const i=Z.metrics.get(e.apiName);return i.count++,i.totalTime+=r,i.minTime=Math.min(i.minTime,r),i.maxTime=Math.max(i.maxTime,r),i.avgTime=i.totalTime/i.count,t},getReport:()=>{const t={};return Z.metrics.forEach((e,r)=>{t[r]=g({},e)}),t},clearMetrics:()=>{Z.metrics.clear()}};function Mr(t={}){const{maxRetries:e=3,retryDelay:r=1e3,shouldRetry:i=n=>!n.success}=t;return{response:(n,a)=>I(null,null,function*(){return a.retryCount||(a.retryCount=0),i(n)&&a.retryCount<e&&(a.retryCount++,s.warn(`API 调用失败,第 ${a.retryCount} 次重试: ${a.apiName}`),yield new Promise(o=>setTimeout(o,r)),n.shouldRetry=!0,n.retryContext=a),n})}}function Cr(t={}){return{request:e=>{const r=t[e.apiName];if(r&&typeof r=="function"){const i=r(e.params);i&&(s.error(`参数验证失败: ${e.apiName}`,i),e.abort=!0,e.validationError=i)}return e}}}class _r{constructor(){this.state={sdk:{status:"uninitialized",version:"2.0.5",error:null},platform:{type:f.type,isWeixinMiniProgram:f.isWeixinMiniProgram,isAppPlus:f.isAppPlus,isNvue:f.isNvue,isUvue:f.isUvue,isOfflineWebview:f.isOfflineWebview,features:{}},weixin:{configStatus:"pending",jsApiList:[],configError:null},network:{online:typeof navigator!="undefined"?navigator.onLine:!0,type:"unknown"},permissions:{camera:"prompt",location:"prompt",album:"prompt"},api:{}},this.listeners=new Map,this.wildcardListeners=new Set,this.initNetworkListener(),B.debug("状态仓库已初始化")}get(e){return e.split(".").reduce((i,n)=>i!=null?i[n]:void 0,this.state)}set(e,r){const i=e.split("."),n=i.pop(),a=i.reduce((c,d)=>((!c[d]||typeof c[d]!="object")&&(c[d]={}),c[d]),this.state),o=a[n];o!==r&&(a[n]=r,B.debug(`状态已更新: ${e}`,{oldValue:o,newValue:r}),this.notify(e,r,o))}batchUpdate(e){Object.entries(e).forEach(([r,i])=>{this.set(r,i)})}subscribe(e,r){if(typeof r!="function")throw new Error("listener 必须是函数");return e==="*"?(this.wildcardListeners.add(r),B.debug("添加通配符订阅者"),()=>{this.wildcardListeners.delete(r),B.debug("移除通配符订阅者")}):(this.listeners.has(e)||this.listeners.set(e,new Set),this.listeners.get(e).add(r),B.debug(`添加订阅者: ${e}`),()=>{const i=this.listeners.get(e);i&&(i.delete(r),i.size===0&&this.listeners.delete(e),B.debug(`移除订阅者: ${e}`))})}subscribeOnce(e,r){const i=this.subscribe(e,(n,a,o)=>{r(n,a,o),i()});return i}notify(e,r,i){const n=this.listeners.get(e);n&&n.forEach(o=>{try{o(r,i,e)}catch(c){B.error("订阅者执行失败",c)}});const a=e.split(".");for(let o=1;o<a.length;o++){const c=a.slice(0,o).join("."),d=this.listeners.get(c);if(d){const m=this.get(c);d.forEach(S=>{try{S(m,void 0,c)}catch(_){B.error("父路径订阅者执行失败",_)}})}}this.wildcardListeners.forEach(o=>{try{o(r,i,e)}catch(c){B.error("通配符订阅者执行失败",c)}})}initNetworkListener(){if(typeof window!="undefined"&&(window.addEventListener("online",()=>{this.set("network.online",!0)}),window.addEventListener("offline",()=>{this.set("network.online",!1)}),navigator.connection)){const e=navigator.connection,r=()=>{this.set("network.type",e.effectiveType||"unknown")};e.addEventListener("change",r),r()}}setApiLoading(e,r=!0){const i=`api.${e}`,n=this.get(i)||{};this.set(i,w(g({},n),{loading:r,lastCall:r?Date.now():n.lastCall}))}setApiResult(e,r){const i=`api.${e}`,n=this.get(i)||{};this.set(i,w(g({},n),{loading:!1,lastResult:r,lastCallEnd:Date.now()}))}getSnapshot(){return JSON.parse(JSON.stringify(this.state))}reset(){const{platform:e}=this.state;this.state={sdk:{status:"uninitialized",version:"2.0.5",error:null},platform:e,weixin:{configStatus:"pending",jsApiList:[],configError:null},network:{online:typeof navigator!="undefined"?navigator.onLine:!0,type:"unknown"},permissions:{camera:"prompt",location:"prompt",album:"prompt"},api:{}},B.debug("状态已重置")}getStats(){return{listeners:this.listeners.size,wildcardListeners:this.wildcardListeners.size,apiStates:Object.keys(this.state.api).length}}}const j=new _r,u={SDK_NOT_READY:"E_SDK_001",SDK_INIT_FAILED:"E_SDK_002",SDK_CONFIG_FAILED:"E_SDK_003",PLATFORM_NOT_SUPPORTED:"E_SDK_004",NETWORK_ERROR:"E_NET_001",NETWORK_TIMEOUT:"E_NET_002",NETWORK_OFFLINE:"E_NET_003",IMAGE_CANCELLED:"E_IMG_001",IMAGE_NO_PERMISSION:"E_IMG_002",IMAGE_SIZE_EXCEED:"E_IMG_003",IMAGE_COUNT_EXCEED:"E_IMG_004",IMAGE_FORMAT_ERROR:"E_IMG_005",IMAGE_CONFIG_NOT_READY:"E_IMG_006",LOCATION_CANCELLED:"E_LOC_001",LOCATION_NO_PERMISSION:"E_LOC_002",LOCATION_UNAVAILABLE:"E_LOC_003",LOCATION_TIMEOUT:"E_LOC_004",SCAN_CANCELLED:"E_SCAN_001",SCAN_NO_PERMISSION:"E_SCAN_002",SCAN_INVALID_CODE:"E_SCAN_003",SCAN_CONFIG_NOT_READY:"E_SCAN_004",PERMISSION_DENIED:"E_PERM_001",PERMISSION_CAMERA:"E_PERM_002",PERMISSION_LOCATION:"E_PERM_003",PERMISSION_ALBUM:"E_PERM_004",PERMISSION_MICROPHONE:"E_PERM_005",PARAM_INVALID:"E_PARAM_001",PARAM_MISSING:"E_PARAM_002",PARAM_TYPE_ERROR:"E_PARAM_003",API_TIMEOUT:"E_TIMEOUT_001",UNKNOWN_ERROR:"E_UNKNOWN_999"},ke={[u.SDK_NOT_READY]:"SDK 未就绪",[u.SDK_INIT_FAILED]:"SDK 初始化失败",[u.SDK_CONFIG_FAILED]:"SDK 配置失败",[u.PLATFORM_NOT_SUPPORTED]:"当前平台不支持此功能",[u.NETWORK_ERROR]:"网络错误",[u.NETWORK_TIMEOUT]:"网络超时",[u.NETWORK_OFFLINE]:"网络已断开",[u.IMAGE_CANCELLED]:"用户取消选择图片",[u.IMAGE_NO_PERMISSION]:"无相机/相册权限",[u.IMAGE_SIZE_EXCEED]:"图片大小超出限制",[u.IMAGE_COUNT_EXCEED]:"图片数量超出限制",[u.IMAGE_FORMAT_ERROR]:"图片格式不支持",[u.IMAGE_CONFIG_NOT_READY]:"微信配置未完成",[u.LOCATION_CANCELLED]:"用户取消定位",[u.LOCATION_NO_PERMISSION]:"无定位权限",[u.LOCATION_UNAVAILABLE]:"定位服务不可用",[u.LOCATION_TIMEOUT]:"定位超时",[u.SCAN_CANCELLED]:"用户取消扫码",[u.SCAN_NO_PERMISSION]:"无相机权限",[u.SCAN_INVALID_CODE]:"无效的二维码/条形码",[u.SCAN_CONFIG_NOT_READY]:"微信配置未完成",[u.PERMISSION_DENIED]:"权限被拒绝",[u.PERMISSION_CAMERA]:"无相机权限",[u.PERMISSION_LOCATION]:"无定位权限",[u.PERMISSION_ALBUM]:"无相册权限",[u.PERMISSION_MICROPHONE]:"无麦克风权限",[u.PARAM_INVALID]:"参数无效",[u.PARAM_MISSING]:"缺少必需参数",[u.PARAM_TYPE_ERROR]:"参数类型错误",[u.API_TIMEOUT]:"API 调用超时",[u.UNKNOWN_ERROR]:"未知错误"},K={USER_CANCEL:"user_cancel",PERMISSION:"permission",NETWORK:"network",PARAM:"param",SYSTEM:"system",CONFIG:"config",UNKNOWN:"unknown"},Rr={"IMAGE/USER_CANCEL":u.IMAGE_CANCELLED,"IMAGE/PERMISSION_DENIED":u.IMAGE_NO_PERMISSION,"COMMON/UNKNOWN":u.UNKNOWN_ERROR,"COMMON/CONFIG_NOT_READY":u.IMAGE_CONFIG_NOT_READY,"COMMON/PLATFORM_NOT_SUPPORTED":u.PLATFORM_NOT_SUPPORTED},it={weixin:{patterns:[{pattern:/cancel/i,code:u.IMAGE_CANCELLED},{pattern:/permission|auth\s*deny/i,code:u.IMAGE_NO_PERMISSION},{pattern:/config/i,code:u.IMAGE_CONFIG_NOT_READY},{pattern:/timeout/i,code:u.API_TIMEOUT},{pattern:/network/i,code:u.NETWORK_ERROR}],default:u.UNKNOWN_ERROR},uniapp:{patterns:[{pattern:/cancel/i,code:u.IMAGE_CANCELLED},{pattern:/permission|denied/i,code:u.IMAGE_NO_PERMISSION},{pattern:/timeout/i,code:u.API_TIMEOUT},{pattern:/network/i,code:u.NETWORK_ERROR},{pattern:/not_in_container/i,code:u.PLATFORM_NOT_SUPPORTED}],default:u.UNKNOWN_ERROR},offline:{patterns:[{pattern:/cancel/i,code:u.IMAGE_CANCELLED},{pattern:/permission|denied/i,code:u.IMAGE_NO_PERMISSION},{pattern:/timeout/i,code:u.API_TIMEOUT},{pattern:/network/i,code:u.NETWORK_ERROR},{pattern:/not_in_container/i,code:u.PLATFORM_NOT_SUPPORTED}],default:u.UNKNOWN_ERROR}},nt={chooseImage:{"fail cancel":u.IMAGE_CANCELLED,"fail auth deny":u.IMAGE_NO_PERMISSION,"fail No Permission":u.IMAGE_NO_PERMISSION,NOT_IN_CONTAINER:u.PLATFORM_NOT_SUPPORTED},scanCode:{"fail cancel":u.SCAN_CANCELLED,"fail auth deny":u.SCAN_NO_PERMISSION,"fail No Permission":u.SCAN_NO_PERMISSION,NOT_IN_CONTAINER:u.PLATFORM_NOT_SUPPORTED}};function at(t){return t?t.includes("CANCEL")?K.USER_CANCEL:t.includes("PERM")||t.includes("PERMISSION")?K.PERMISSION:t.includes("NET")||t.includes("NETWORK")?K.NETWORK:t.includes("PARAM")?K.PARAM:t.includes("CONFIG")?K.CONFIG:t.includes("SDK")||t.includes("PLATFORM")?K.SYSTEM:K.UNKNOWN:K.UNKNOWN}function Sr(t){return t.includes("NET_")||t.includes("TIMEOUT")||t===u.NETWORK_ERROR||t===u.NETWORK_TIMEOUT||t===u.API_TIMEOUT}function Or(t){return t.includes("CANCEL")||at(t)===K.USER_CANCEL}function me(t){return ke[t]||ke[u.UNKNOWN_ERROR]}class J extends Error{constructor(e,r,i={}){super(r),this.name="StandardError",this.code=e,this.message=r||me(e),this.platform=i.platform||f.type,this.apiName=i.apiName,this.category=i.category||at(e),this.retriable=i.retriable!==void 0?i.retriable:Sr(e),this.originalError=i.originalError,this.details=i.details||{},this.timestamp=Date.now()}isRetriable(){return this.retriable}isUserAction(){return Or(this.code)}toJSON(){return g({code:this.code,message:this.message,platform:this.platform,apiName:this.apiName,category:this.category,retriable:this.retriable,timestamp:this.timestamp,details:this.details},process.env.NODE_ENV!=="production"&&this.originalError?{originalError:this.originalError}:{})}}function st(t,e={}){if(t instanceof J)return t;const{apiName:r,platform:i=f.type}=e;return t&&typeof t.code=="string"&&t.code.includes("/")?Nr(t,{apiName:r,platform:i}):t&&(t.errMsg||t.message)?Tr(t,{apiName:r,platform:i}):typeof t=="string"?new J(u.UNKNOWN_ERROR,t,{apiName:r,platform:i,originalError:t}):new J(u.UNKNOWN_ERROR,"未知错误",{apiName:r,platform:i,originalError:t,details:{errorType:typeof t}})}function Nr(t,e){const{apiName:r,platform:i}=e,n=t.code,a=Rr[n]||u.UNKNOWN_ERROR;return s.debug("转换旧版错误码",{legacy:n,new:a}),new J(a,t.message||me(a),{apiName:r,platform:t.platform||i,originalError:t,details:g({legacyCode:n,legacyVersion:t.version},t.details)})}function Tr(t,e){const{apiName:r,platform:i}=e,n=(t.errMsg||t.message||"").toLowerCase();if(r&&nt[r]){const c=nt[r];for(const[d,m]of Object.entries(c))if(n.includes(d.toLowerCase()))return new J(m,me(m),{apiName:r,platform:i,originalError:t})}const a=it[i]||it.uniapp;for(const{pattern:c,code:d}of a.patterns)if(c.test(n))return new J(d,me(d),{apiName:r,platform:i,originalError:t});const o=a.default||u.UNKNOWN_ERROR;return new J(o,t.errMsg||t.message||me(o),{apiName:r,platform:i,originalError:t})}const ot={response:(t,e)=>{if(!t.success&&t.error){const r=st(t.error,{apiName:e.apiName,platform:f.type});t.error=r.toJSON(),t.errorCode=r.code,t.errorCategory=r.category,t.retriable=r.isRetriable(),s.debug("错误已标准化",{api:e.apiName,code:r.code,category:r.category})}return t}};function br(t,e={}){return new J(t,me(t),e)}function vr(t){return t instanceof J}function xr(t,e,r){return e?Promise.race([t(),new Promise((i,n)=>setTimeout(()=>n(new Error(`Init task timeout: ${r}`)),e))]):t()}function Lr(){return I(this,arguments,function*(t=[],e={}){for(const r of t){const i=(r==null?void 0:r.name)||"anonymous-task",n=(r==null?void 0:r.run)||r;if(typeof n=="function")try{yield xr(()=>Promise.resolve().then(()=>n()),r.timeoutMs,i),typeof r.onSuccess=="function"&&r.onSuccess()}catch(a){if(typeof r.onError=="function"&&r.onError(a),typeof e.onError=="function")e.onError(a,r);else throw a}}})}class ct{constructor(e){this.name=e}processNavigationOptions(e={}){const{url:r,delta:i=1}=e,n=r&&encodeURI(r),a=parseInt(i)||1;return w(g({},e),{url:n,delta:a})}processMessageOptions(e={}){const{data:r={}}=e;return{data:r}}navigateTo(e){const r=this.processNavigationOptions(e);return this.performNavigation("navigateTo",r)}navigateBack(e={}){const r=this.processNavigationOptions(e);return this.performNavigation("navigateBack",r)}switchTab(e){const r=this.processNavigationOptions(e);return this.performNavigation("switchTab",r)}reLaunch(e){const r=this.processNavigationOptions(e);return this.performNavigation("reLaunch",r)}redirectTo(e){const r=this.processNavigationOptions(e);return this.performNavigation("redirectTo",r)}postMessage(e={}){const r=this.processMessageOptions(e);return this.performPostMessage(r)}getEnv(e){return this.performGetEnv(e)}performNavigation(e,r){throw new Error(`${this.name} platform must implement performNavigation method`)}performPostMessage(e){throw new Error(`${this.name} platform must implement performPostMessage method`)}performGetEnv(e){throw new Error(`${this.name} platform must implement performGetEnv method`)}}let Ie=[];function Dr(){if(Ie.length===0&&window.plus){const t=plus.webview.currentWebview();if(!t)throw new Error("plus.webview.currentWebview() is undefined");const e=t.parent(),r=e?e.id:t.id;Ie.push(r)}return Ie}function Ur(t,e){const r={options:{timestamp:+new Date},name:t,arg:e};if(t==="postMessage"){const n={data:e};return window.__uniapp_x_postMessage?window.__uniapp_x_postMessage(n):window.__uniapp_x_.postMessage(JSON.stringify(n))}const i={type:"WEB_INVOKE_APPSERVICE",args:{data:r,webviewIds:Ie}};window.__uniapp_x_postMessage?window.__uniapp_x_postMessageToService(i):window.__uniapp_x_.postMessageToService(JSON.stringify(i))}function Wr(t,e){const r={options:{timestamp:+new Date},name:t,arg:e};if(t==="postMessage"){const n={data:[e]};return window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessage(n):window.__dcloud_weex_.postMessage(JSON.stringify(n))}const i={type:"WEB_INVOKE_APPSERVICE",args:{data:r,webviewIds:Ie}};window.__dcloud_weex_postMessage?window.__dcloud_weex_postMessageToService(i):window.__dcloud_weex_.postMessageToService(JSON.stringify(i))}function $r(t,e){const r={options:{timestamp:+new Date},name:t,arg:e},i=Dr();if(plus.webview.getWebviewById("__uniapp__service"))plus.webview.postMessageToUniNView({type:"WEB_INVOKE_APPSERVICE",args:{data:r,webviewIds:i}},"__uniapp__service");else{const n=JSON.stringify(r),a=JSON.stringify(i);plus.webview.getLaunchWebview().evalJS(`UniPlusBridge.subscribeHandler("WEB_INVOKE_APPSERVICE",${n},${a});`)}}function Fr(t,e){const r={options:{timestamp:+new Date},name:t,arg:e};window.parent.postMessage({type:"WEB_INVOKE_APPSERVICE",data:r,pageId:""},"*")}function kr(t){return!!(t&&typeof t=="object"&&t.type==="qsh_api_call"&&typeof t.api=="string"&&typeof t.callbackId=="string")}function Br(t,e){const r={options:{timestamp:+new Date},name:t,arg:e};if(t==="postMessage"&&kr(e))return window.__offline_bridge_postMessage(e);window.__offline_bridge_postMessage({type:"WEB_INVOKE_APPSERVICE",data:r,pageId:""})}function Pe(t,e){fe()?Ur(t,e):te()?Wr(t,e):F()?Br(t,e):le()?$r(t,e):Fr(t,e)}class ut extends ct{constructor(){super("weixin")}isWeixinApiAvailable(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram}performNavigation(e,r){return l.safeExecute(()=>{const{url:i,delta:n}=r;if(E.debug(`微信平台执行导航操作: ${e}`,r),this.isWeixinApiAvailable()){const o=window.wx.miniProgram[e];if(typeof o=="function"){E.debug(`使用微信原生 API: wx.miniProgram.${e}`);const c=e==="navigateBack"?{delta:n}:{url:i};return o.call(window.wx.miniProgram,c)}}E.debug(`使用消息桥接执行: ${e}`),Pe(e,e==="navigateBack"?{delta:n}:{url:i})},{platform:this.name,method:"performNavigation",navigationType:e,options:r})}performPostMessage(e){return l.safeExecute(()=>{const{data:r}=e;if(this.isWeixinApiAvailable())return window.wx.miniProgram.postMessage({data:r});Pe("postMessage",r)},{platform:this.name,method:"performPostMessage",options:e})}performGetEnv(e){return l.safeExecute(()=>{if(!e||typeof e!="function")throw new Error("Callback function is required for getEnv");if(this.isWeixinApiAvailable()&&window.wx.miniProgram.getEnv)return window.wx.miniProgram.getEnv(e);e({miniprogram:!0,weixin:!0})},{platform:this.name,method:"performGetEnv"})}}const se=new ut;var lt=Object.freeze({__proto__:null,WeixinPlatform:ut,getEnv:t=>se.getEnv(t),navigateBack:t=>se.navigateBack(t),navigateTo:t=>se.navigateTo(t),postMessage:t=>se.postMessage(t),reLaunch:t=>se.reLaunch(t),redirectTo:t=>se.redirectTo(t),switchTab:t=>se.switchTab(t)});class ft extends ct{constructor(){super("app")}performNavigation(e,r){return l.safeExecute(()=>{const{url:i,delta:n}=r;Pe(e,e==="navigateBack"?{delta:n}:{url:i})},{platform:this.name,method:"performNavigation",navigationType:e,options:r})}performPostMessage(e){return l.safeExecute(()=>{const{data:r}=e;Pe("postMessage",r)},{platform:this.name,method:"performPostMessage",options:e})}performGetEnv(e){return l.safeExecute(()=>{if(!e||typeof e!="function")throw new Error("Callback function is required for getEnv");const r={};let i=!1;F()?(r.offline=!0,i=!0):fe()?(r.uvue=!0,i=!0):te()?(r.nvue=!0,i=!0):le()&&(r.plus=!0,i=!0),i?r.app=!0:r.h5=!0,e(r)},{platform:this.name,method:"performGetEnv"})}}const oe=new ft;var dt=Object.freeze({__proto__:null,AppPlatform:ft,getEnv:t=>oe.getEnv(t),navigateBack:t=>oe.navigateBack(t),navigateTo:t=>oe.navigateTo(t),postMessage:t=>oe.postMessage(t),reLaunch:t=>oe.reLaunch(t),redirectTo:t=>oe.redirectTo(t),switchTab:t=>oe.switchTab(t)});function Me(){return p()?lt:dt}function Gr(t){return Me().navigateTo(t)}function Kr(t){return Me().navigateBack(t)}function Vr(t){return Me().switchTab(t)}function qr(t){return Me().reLaunch(t)}function jr(t){return Me().redirectTo(t)}function gt(){return p()?lt:dt}function Jr(t={}){return gt().postMessage(t)}function Hr(t){return gt().getEnv(t)}function zr(t){return t&&typeof t=="object"&&t.__v_raw?t.__v_raw:t}function Yr(){return"qsh_callback_"+Date.now()+"_"+Math.random().toString(36).substring(2,9)}class Xr{constructor(){this.callbacks=new Map,this.timeouts=new Map,this.persistentCallbacksByApi=new Map,this.defaultTimeout=15e3,typeof window!="undefined"&&(window.qshWebviewCallbacks||(window.qshWebviewCallbacks={})),P.debug("WebView 桥接器已初始化")}callApi(n){return I(this,arguments,function*(e,r={},i={}){return l.safeExecute(()=>I(this,null,function*(){var m;if(typeof window!="undefined"&&window===window.parent&&!window.plus&&!window.__uniapp_x_postMessage&&!window.__uniapp_x_&&!window.__dcloud_weex_postMessage&&!window.__dcloud_weex_&&!F()){const S=new b(L.PLATFORM_NOT_SUPPORTED,"当前不在宿主 WebView 容器中,无法发送消息");i&&typeof i.fail=="function"&&i.fail({errMsg:S.message,code:"NOT_IN_CONTAINER"}),i&&typeof i.complete=="function"&&i.complete({success:!1,error:{errMsg:S.message}});return}const o={apiName:e,params:r,callbacks:i,timestamp:Date.now(),abort:!1,metadata:{}};j.setApiLoading(e,!0);const c=yield ae.runRequest(o);if(c.abort){P.warn("API 调用被拦截器中止",{api:e}),j.setApiLoading(e,!1),i.fail&&i.fail({errMsg:((m=c.error)==null?void 0:m.message)||"API 调用被中止",code:"INTERCEPTED"}),i.complete&&i.complete({success:!1});return}const d=Yr();if(i.success||i.fail||i.complete){if(this.callbacks.set(d,w(g({},i),{context:c})),window.qshWebviewCallbacks[d]=H=>{this.handleCallback(d,H)},r.isPersistent&&(this.persistentCallbacksByApi.has(e)||this.persistentCallbacksByApi.set(e,new Set),this.persistentCallbacksByApi.get(e).add(d)),r.isPersistent||r.disableTimeout)P.info(`API ${e} 禁用超时清理,将等待回调返回后清理`,{callbackId:d,isPersistent:r.isPersistent,disableTimeout:r.disableTimeout});else{const H=setTimeout(()=>{P.warn("API 调用超时,自动清理回调",{api:e,callbackId:d}),i.fail&&i.fail({errMsg:`API ${e} 调用超时`,code:"TIMEOUT"}),this.cleanupCallback(d)},r.timeout||this.defaultTimeout);this.timeouts.set(d,H)}const _={type:"qsh_api_call",api:e,params:c.params,callbackId:d,timestamp:Date.now()};P.info("发送 API 调用消息",{api:e,callbackId:d,hasSuccess:!!i.success,hasFail:!!i.fail}),console.log("message:",JSON.stringify(zr(_),null,2)),Pe("postMessage",_)}}),{context:"WebViewBridge.callApi",api:e})})}handleCallback(e,r){return I(this,null,function*(){return l.safeExecute(()=>I(this,null,function*(){var S,_;const i=this.callbacks.get(e);if(!i){P.warn("未找到回调函数",{callbackId:e});return}const{success:n,fail:a,complete:o,context:c}=i;P.debug("处理回调",{callbackId:e,result:r});const d=yield ae.runResponse(r,c);c&&j.setApiResult(c.apiName,d),d.success&&n?n(d.data):!d.success&&a&&a(d.error||{errMsg:"操作失败"}),o&&o(d),((_=(S=i.context)==null?void 0:S.params)==null?void 0:_.isPersistent)?P.debug("持久监听API:保留回调",{callbackId:e}):(this.cleanupCallback(e),P.debug("回调执行完成,已清理",{callbackId:e}))}),{context:"WebViewBridge.handleCallback",callbackId:e})})}cleanupCallback(e){const r=this.timeouts.get(e);if(r&&(clearTimeout(r),this.timeouts.delete(e)),this.callbacks.delete(e),typeof window!="undefined"&&window.qshWebviewCallbacks&&delete window.qshWebviewCallbacks[e],this.persistentCallbacksByApi&&this.persistentCallbacksByApi.size>0){const i=[];this.persistentCallbacksByApi.forEach((n,a)=>{n.has(e)&&(n.delete(e),n.size===0&&i.push(a))}),i.forEach(n=>this.persistentCallbacksByApi.delete(n))}}clearCallbacks(){P.debug("清理所有回调",{count:this.callbacks.size}),this.timeouts.forEach(e=>clearTimeout(e)),this.timeouts.clear(),this.callbacks.clear(),this.persistentCallbacksByApi&&this.persistentCallbacksByApi.clear(),typeof window!="undefined"&&window.qshWebviewCallbacks&&Object.keys(window.qshWebviewCallbacks).forEach(e=>{e.startsWith("qsh_callback_")&&delete window.qshWebviewCallbacks[e]})}cleanupPersistentCallbacksByApi(e){const r=this.persistentCallbacksByApi.get(e);if(!r||r.size===0)return 0;const i=Array.from(r);return i.forEach(n=>this.cleanupCallback(n)),this.persistentCallbacksByApi.delete(e),P.info("已清理持久回调",{api:e,count:i.length}),i.length}getStatus(){return{isSupported:typeof window!="undefined"&&window.uni&&typeof window.uni.postMessage=="function",activeCallbacks:this.callbacks.size,globalCallbacksCount:typeof window!="undefined"&&window.qshWebviewCallbacks?Object.keys(window.qshWebviewCallbacks).length:0}}}const ht=new Xr,N=(t,e,r)=>ht.callApi(t,e,r),pe=t=>ht.cleanupPersistentCallbacksByApi(t);function mt(){return V(!0)}function Zr(t){return t==="offline"}function Qr(t={}){return l.safeExecute(()=>{s.debug("Call getCode through offline webview bridge",{clientId:t.clientId}),N("getCode",{clientId:t.clientId},{success:e=>{var r;s.info("Get code success"),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("Get code failed",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"getCodeInHost",platform:mt().type})}function ei(t={}){return l.safeExecute(()=>{var i,n;const e=mt(),r=String((t==null?void 0:t.clientId)||"").trim();if(!r){const a={errMsg:"clientId is required",code:"APP_KEY_MISSING"};s.error("Get code missing clientId"),(i=t.fail)==null||i.call(t,a);return}if(!Zr(e.type)){const a={errMsg:`Current environment (${e.type}) does not support getCode`,code:"PLATFORM_NOT_SUPPORTED"};s.error("Platform does not support getCode",{platform:e.type}),(n=t.fail)==null||n.call(t,a);return}Qr(w(g({},t),{clientId:r}))},{context:"getCode",options:t})}function pt(){return V(!0)}const wt=["release","trial","develop"];function ti(t={}){const e=String((t==null?void 0:t.appid)||"").trim(),r=(t==null?void 0:t.path)==null?"":t.path,i=t==null?void 0:t.env,n=i==null||i===""?void 0:String(i).trim();if(!e)throw{errMsg:"appid is required",code:"PARAM_MISSING"};if(typeof r!="string")throw{errMsg:"path must be a string",code:"PARAM_TYPE_ERROR"};if(n!==void 0&&!wt.includes(n))throw{errMsg:`env must be one of ${wt.join("/")}`,code:"PARAM_INVALID"};return w(g({},t),{appid:e,path:r.trim(),env:n})}function ri(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram&&typeof window.wx.miniProgram.postMessage=="function"&&typeof window.wx.miniProgram.navigateBack=="function"}function ii(t={}){return l.safeExecute(()=>{var r;if(!ri()){const i={errMsg:"wx.miniProgram.postMessage or wx.miniProgram.navigateBack is not available",code:"PLATFORM_NOT_SUPPORTED"};s.error("Weixin web-view relay APIs are not available"),(r=t.fail)==null||r.call(t,i);return}const e={type:"qsh_api_call",api:"navigateToMiniProgram",params:{appid:t.appid,path:t.path,env:t.env},timestamp:Date.now()};return s.debug("Relay navigateToMiniProgram through wx.miniProgram.postMessage",{appid:t.appid,path:t.path,env:t.env}),new Promise((i,n)=>{var a;try{window.wx.miniProgram.postMessage({data:e})}catch(o){s.error("Post navigateToMiniProgram message failed",o),(a=t.fail)==null||a.call(t,o),n(o);return}window.wx.miniProgram.navigateBack({delta:1,success:o=>{var d;const c=w(g({},o),{errMsg:(o==null?void 0:o.errMsg)||"navigateToMiniProgram:queued"});s.info("Navigate to mini program request queued in weixin web-view",{appid:t.appid,path:t.path,env:t.env}),(d=t.success)==null||d.call(t,c),i(c)},fail:o=>{var c;s.error("Navigate back after posting mini program message failed",o),(c=t.fail)==null||c.call(t,o),n(o)},complete:t.complete})})},{context:"navigateToMiniProgramInWeixin",platform:"weixin"})}function ni(t={}){return l.safeExecute(()=>(s.debug("Call navigateToMiniProgram through webview bridge",{appid:t.appid,path:t.path,env:t.env}),new Promise((e,r)=>{N("navigateToMiniProgram",{appid:t.appid,path:t.path,env:t.env},{success:i=>{var n;s.info("Navigate to mini program success"),(n=t.success)==null||n.call(t,i),e(i)},fail:i=>{var n;s.error("Navigate to mini program failed",i),(n=t.fail)==null||n.call(t,i),r(i)},complete:t.complete})})),{context:"navigateToMiniProgramInHost",platform:pt().type})}function ai(t={}){return l.safeExecute(()=>{var i;const e=pt();let r;try{r=ti(t)}catch(n){s.error("Navigate to mini program params validation failed",n),(i=t.fail)==null||i.call(t,n);return}return s.info("Start navigateToMiniProgram",{platform:e.type,appid:r.appid,path:r.path,env:r.env}),e.isWeixinMiniProgram?ii(r):ni(r)},{context:"navigateToMiniProgram",options:t})}function Et(){return V(!0)}const yt=["doc","xls","ppt","pdf","docx","xlsx","pptx"];function si(t={}){const e=String((t==null?void 0:t.url)||"").trim(),r=String((t==null?void 0:t.fileType)||"").trim().toLowerCase(),i=(t==null?void 0:t.showMenu)==null?!1:t.showMenu;if(!e)throw{errMsg:"url is required",code:"PARAM_MISSING"};if(!r)throw{errMsg:"fileType is required",code:"PARAM_MISSING"};if(!yt.includes(r))throw{errMsg:`fileType must be one of ${yt.join("/")}`,code:"PARAM_INVALID"};if(typeof i!="boolean")throw{errMsg:"showMenu must be a boolean",code:"PARAM_TYPE_ERROR"};return w(g({},t),{url:e,fileType:r,showMenu:i})}function oi(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram&&typeof window.wx.miniProgram.postMessage=="function"&&typeof window.wx.miniProgram.navigateBack=="function"}function ci(t={}){return l.safeExecute(()=>{var r;if(!oi()){const i={errMsg:"wx.miniProgram.postMessage or wx.miniProgram.navigateBack is not available",code:"PLATFORM_NOT_SUPPORTED"};s.error("Weixin web-view relay APIs are not available"),(r=t.fail)==null||r.call(t,i);return}const e={type:"qsh_api_call",api:"filePreview",params:{url:t.url,fileType:t.fileType,showMenu:t.showMenu},timestamp:Date.now()};return s.debug("Relay filePreview through wx.miniProgram.postMessage",{url:t.url,fileType:t.fileType,showMenu:t.showMenu}),new Promise((i,n)=>{var a;try{window.wx.miniProgram.postMessage({data:e})}catch(o){s.error("Post filePreview message failed",o),(a=t.fail)==null||a.call(t,o),n(o);return}window.wx.miniProgram.navigateBack({delta:1,success:o=>{var d;const c=w(g({},o),{errMsg:(o==null?void 0:o.errMsg)||"filePreview:queued"});s.info("File preview request queued in weixin web-view",{url:t.url,fileType:t.fileType,showMenu:t.showMenu}),(d=t.success)==null||d.call(t,c),i(c)},fail:o=>{var c;s.error("Navigate back after posting filePreview message failed",o),(c=t.fail)==null||c.call(t,o),n(o)},complete:t.complete})})},{context:"filePreviewInWeixin",platform:"weixin"})}function ui(t={}){return l.safeExecute(()=>(s.debug("Call filePreview through webview bridge",{url:t.url,fileType:t.fileType,showMenu:t.showMenu}),new Promise((e,r)=>{N("filePreview",{url:t.url,fileType:t.fileType,showMenu:t.showMenu},{success:i=>{var n;s.info("File preview success"),(n=t.success)==null||n.call(t,i),e(i)},fail:i=>{var n;s.error("File preview failed",i),(n=t.fail)==null||n.call(t,i),r(i)},complete:t.complete})})),{context:"filePreviewInHost",platform:Et().type})}function li(t={}){return l.safeExecute(()=>{var i;const e=Et();let r;try{r=si(t)}catch(n){s.error("File preview params validation failed",n),(i=t.fail)==null||i.call(t,n);return}return s.info("Start filePreview",{platform:e.type,url:r.url,fileType:r.fileType,showMenu:r.showMenu}),e.isWeixinMiniProgram?ci(r):ui(r)},{context:"filePreview",options:t})}function fi(t=""){return/^https?:\/\//i.test(String(t||"").trim())}function di(t){if(t==null||t==="")return!1;if(typeof t=="boolean")return t;const e=String(t).trim().toLowerCase();return e==="true"||e==="1"}function gi(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram&&typeof window.wx.miniProgram.postMessage=="function"&&typeof window.wx.miniProgram.navigateBack=="function"}function hi(t={}){if(!t||typeof t!="object")throw{errMsg:"manualShare options must be an object",code:"PARAM_TYPE_ERROR"};const e=String(t.title||"").trim(),r=String(t.h5Url||"").trim(),i=String(t.clientId||"").trim(),n=di(t.isPublic),a=String(t.imageUrl||"").trim(),o=String(t.description||t.desc||"").trim();if(!e)throw{errMsg:"manualShare: title is required",code:"PARAM_MISSING"};if(!r)throw{errMsg:"manualShare: h5Url is required",code:"PARAM_MISSING"};if(!i)throw{errMsg:"manualShare: clientId is required",code:"PARAM_MISSING"};if(r&&!fi(r))throw{errMsg:"manualShare: h5Url must be a valid http(s) url",code:"PARAM_INVALID"};return{title:e,h5Url:r,clientId:i,isPublic:n,imageUrl:a,description:o,success:t.success,fail:t.fail,complete:t.complete}}function mi(t){return{type:"qsh_api_call",api:"manualShare",params:{title:t.title,h5Url:t.h5Url,clientId:t.clientId,isPublic:t.isPublic,imageUrl:t.imageUrl,description:t.description},timestamp:Date.now()}}function pi(t){return new Promise((e,r)=>{const i=mi(t);s.debug("Relay manualShare through wx.miniProgram.postMessage",i);try{window.wx.miniProgram.postMessage({data:i})}catch(n){s.error("Post manualShare message failed",n),r(n);return}window.wx.miniProgram.navigateBack({delta:1,success:n=>{const a=w(g({},n||{}),{success:!0,errMsg:(n==null?void 0:n.errMsg)||"manualShare:queued"});s.info("manualShare request queued in weixin web-view",{h5Url:t.h5Url,clientId:t.clientId,isPublic:t.isPublic}),e(a)},fail:n=>{s.error("Navigate back after posting manualShare message failed",n),r(n)}})})}function At(t={}){return l.safeExecute(()=>{var i,n,a,o,c,d;const e=V(!0);let r;try{r=hi(t)}catch(m){return(i=t.fail)==null||i.call(t,m),(n=t.complete)==null||n.call(t,m),Promise.reject(m)}if(!e.isWeixinMiniProgram){const m={errMsg:"manualShare only supports Weixin mini-program web-view environment",code:"ENV_NOT_SUPPORTED"};return(a=r.fail)==null||a.call(r,m),(o=r.complete)==null||o.call(r,m),Promise.reject(m)}if(!gi()){const m={errMsg:"wx.miniProgram.postMessage or wx.miniProgram.navigateBack is not available",code:"PLATFORM_NOT_SUPPORTED"};return(c=r.fail)==null||c.call(r,m),(d=r.complete)==null||d.call(r,m),Promise.reject(m)}return pi(r).then(m=>{var S,_;return(S=r.success)==null||S.call(r,m),(_=r.complete)==null||_.call(r,m),m}).catch(m=>{var S,_;return(S=r.fail)==null||S.call(r,m),(_=r.complete)==null||_.call(r,m),Promise.reject(m)})},{context:"manualShare",options:t})}function wi(t={}){return new Promise((e,r)=>{At(w(g({},t),{success:e,fail:r}))})}const Te={ALBUM:"album",CAMERA:"camera"},be={ORIGINAL:"original",COMPRESSED:"compressed"},Ei={count:9,sizeType:[be.ORIGINAL,be.COMPRESSED],sourceType:[Te.ALBUM,Te.CAMERA]};function yi(t={}){const e=g(g({},Ei),t);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=[be.COMPRESSED]),e.sourceType.length===0&&(e.sourceType=[Te.ALBUM]),e}function It(){return["weixin","webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function Pt(t){return l.safeExecute(()=>{var e;if(!window.wx){const r={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(e=t.fail)==null||e.call(t,r);return}if(!he()){s.info("等待微信配置完成"),ne().then(()=>Pt(t)).catch(r=>{var i;s.error("微信配置失败",r),(i=t.fail)==null||i.call(t,{errMsg:`微信配置失败: ${r.message}`})});return}s.debug("调用微信图片选择",t),window.wx.chooseImage({count:t.count,sizeType:t.sizeType,sourceType:t.sourceType,success:r=>{var i,n;s.info("微信图片选择成功",{count:((i=r.localIds)==null?void 0:i.length)||0}),(n=t.success)==null||n.call(t,r)},fail:r=>{var i;s.error("微信图片选择失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"chooseImageInWeixin",platform:"weixin"})}function Ai(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用图片选择",t),N("chooseImage",w(g({},t),{disableTimeout:!0}),{success:e=>{var r,i;s.info("UniApp 图片选择成功",{count:((r=e==null?void 0:e.tempFilePaths)==null?void 0:r.length)||0}),(i=t.success)==null||i.call(t,e)},fail:e=>{var r;s.error("UniApp 图片选择失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"chooseImageInUniApp",platform:"uniapp"})}function Ii(t={}){return l.safeExecute(()=>{var r;if(!It()){const i={errMsg:`当前环境 (${f.type}) 不支持图片选择功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持图片选择",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=yi(t);s.info("开始选择图片",{platform:f.type,count:e.count,sizeType:e.sizeType,sourceType:e.sourceType}),p()?Pt(e):Ai(e)},{context:"chooseImage",options:t})}function Pi(){return{supported:It(),environment:f.type,implementation:p()?"weixin":"webview",features:{multipleSelection:!0,sizeTypeSelection:!0,sourceTypeSelection:!0,asyncSupport:!0}}}const ce={QR_CODE:"qrCode",BAR_CODE:"barCode",DATA_MATRIX:"datamatrix",PDF417:"pdf417"},Mi={onlyFromCamera:!0,scanType:[ce.QR_CODE,ce.BAR_CODE]};function Ci(t={}){const e=g(g({},Mi),t);return Array.isArray(e.scanType)||(e.scanType=[e.scanType].filter(Boolean)),e.scanType.length===0&&(e.scanType=[ce.QR_CODE,ce.BAR_CODE]),e.onlyFromCamera=!!e.onlyFromCamera,e}function Mt(){return["weixin","webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function Ct(t){return l.safeExecute(()=>{var e;if(!window.wx){const r={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(e=t.fail)==null||e.call(t,r);return}if(!he()){s.info("等待微信配置完成"),ne().then(()=>Ct(t)).catch(r=>{var i;s.error("微信配置失败",r),(i=t.fail)==null||i.call(t,{errMsg:`微信配置失败: ${r.message}`})});return}s.debug("调用微信扫码",t),window.wx.scanQRCode({needResult:1,scanType:t.scanType,success:r=>{var n;s.info("微信扫码成功",{result:r.resultStr});const i={result:r.resultStr,scanType:_i(r.resultStr),charSet:"utf-8",errMsg:"scanCode:ok"};(n=t.success)==null||n.call(t,i)},fail:r=>{var i;s.error("微信扫码失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"scanCodeInWeixin",platform:"weixin"})}function _i(t){return t?t.length>50||/[^\d]/.test(t)?ce.QR_CODE:ce.BAR_CODE:"unknown"}function Ri(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用扫码",t),N("scanCode",w(g({},t),{disableTimeout:!0}),{success:e=>{var r;s.info("UniApp 扫码成功",{result:e==null?void 0:e.result,scanType:e==null?void 0:e.scanType}),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("UniApp 扫码失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"scanCodeInUniApp",platform:"uniapp"})}function Si(t={}){return l.safeExecute(()=>{var r;if(!Mt()){const i={errMsg:`当前环境 (${f.type}) 不支持扫码功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持扫码",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=Ci(t);s.info("开始扫码",{platform:f.type,onlyFromCamera:e.onlyFromCamera,scanType:e.scanType}),p()?Ct(e):Ri(e)},{context:"scanCode",options:t})}function Oi(){return{supported:Mt(),environment:f.type,implementation:p()?"weixin":"webview",features:{onlyFromCamera:!0,scanTypeSelection:!0,multipleTypes:!0,asyncSupport:!0}}}const v=3.141592653589793,ve=6378245,xe=.006693421622965943;function _t(t,e){t=+t,e=+e;let r=-100+2*t+3*e+.2*e*e+.1*t*e+.2*Math.sqrt(Math.abs(t));return r+=(20*Math.sin(6*t*v)+20*Math.sin(2*t*v))*2/3,r+=(20*Math.sin(e*v)+40*Math.sin(e/3*v))*2/3,r+=(160*Math.sin(e/12*v)+320*Math.sin(e*v/30))*2/3,r}function Rt(t,e){t=+t,e=+e;let r=300+t+2*e+.1*t*t+.1*t*e+.1*Math.sqrt(Math.abs(t));return r+=(20*Math.sin(6*t*v)+20*Math.sin(2*t*v))*2/3,r+=(20*Math.sin(t*v)+40*Math.sin(t/3*v))*2/3,r+=(150*Math.sin(t/12*v)+300*Math.sin(t/30*v))*2/3,r}function St(t,e){return t=+t,e=+e,!(t>73.66&&t<135.05&&e>3.86&&e<53.55)}function Ni(t,e){if(t=+t,e=+e,St(t,e))return[t,e];let r=_t(t-105,e-35),i=Rt(t-105,e-35);const n=e/180*v;let a=Math.sin(n);a=1-xe*a*a;const o=Math.sqrt(a);r=r*180/(ve*(1-xe)/(a*o)*v),i=i*180/(ve/o*Math.cos(n)*v);const c=e+r;return[t+i,c]}function Ti(t,e){if(t=+t,e=+e,St(t,e))return[t,e];let r=_t(t-105,e-35),i=Rt(t-105,e-35);const n=e/180*v;let a=Math.sin(n);a=1-xe*a*a;const o=Math.sqrt(a);r=r*180/(ve*(1-xe)/(a*o)*v),i=i*180/(ve/o*Math.cos(n)*v);const c=e+r,d=t+i;return[t*2-d,e*2-c]}const U={WGS84:"wgs84",GCJ02:"gcj02",BD09:"bd09"},bi={type:U.WGS84,altitude:!1},vi={type:U.WGS84,scale:12},xi=[U.WGS84,U.GCJ02];function Li(t={}){const e=g(g({},bi),t);return Object.values(U).includes(e.type)||(e.type=U.WGS84),e.altitude=!!e.altitude,e}function Di(t={}){const e=g({},t);return Object.values(U).includes(e.type)||(e.type=U.WGS84),e.needFullAccuracy=!!e.needFullAccuracy,e}function Ui(t={}){const e=g(g({},vi),t);if(xi.includes(e.type)||(e.type=U.WGS84),e.latitude===void 0||e.latitude===null)throw{errMsg:"缺少必需参数:latitude(纬度)",code:"PARAM_MISSING"};if(typeof e.latitude!="number")throw{errMsg:`latitude 参数类型错误:期望 number,实际 ${typeof e.latitude}`,code:"PARAM_TYPE_ERROR",details:{param:"latitude",expected:"number",actual:typeof e.latitude,value:e.latitude}};if(e.latitude<-90||e.latitude>90)throw{errMsg:`latitude 超出范围:有效范围 -90 ~ 90,实际值 ${e.latitude}`,code:"PARAM_INVALID",details:{param:"latitude",value:e.latitude,validRange:"-90 ~ 90"}};if(e.longitude===void 0||e.longitude===null)throw{errMsg:"缺少必需参数:longitude(经度)",code:"PARAM_MISSING"};if(typeof e.longitude!="number")throw{errMsg:`longitude 参数类型错误:期望 number,实际 ${typeof e.longitude}`,code:"PARAM_TYPE_ERROR",details:{param:"longitude",expected:"number",actual:typeof e.longitude,value:e.longitude}};if(e.longitude<-180||e.longitude>180)throw{errMsg:`longitude 超出范围:有效范围 -180 ~ 180,实际值 ${e.longitude}`,code:"PARAM_INVALID",details:{param:"longitude",value:e.longitude,validRange:"-180 ~ 180"}};if(e.scale!==void 0&&e.scale!==null){const r=Number(e.scale);isNaN(r)?(s.warn("scale 参数无效,使用默认值 12",{scale:e.scale}),e.scale=12):e.scale=Math.max(1,Math.min(28,Math.floor(r)))}return e}function Wi(t){if(t.type!==U.WGS84)return t;const[e,r]=Ni(t.longitude,t.latitude);return w(g({},t),{latitude:r,longitude:e,type:U.GCJ02})}function $i(t){if(t.type!==U.GCJ02)return t;const[e,r]=Ti(t.longitude,t.latitude);return w(g({},t),{latitude:r,longitude:e,type:U.WGS84})}function Be(){return["weixin","webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function Ot(t){return l.safeExecute(()=>{var e;if(!window.wx){const r={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(e=t.fail)==null||e.call(t,r);return}if(!he()){s.info("等待微信配置完成"),ne().then(()=>Ot(t)).catch(r=>{var i;s.error("微信配置失败",r),(i=t.fail)==null||i.call(t,{errMsg:`微信配置失败: ${r.message}`})});return}s.debug("调用微信定位",t),window.wx.getLocation({type:t.type,success:r=>{var i;s.info("微信定位成功",{latitude:r.latitude,longitude:r.longitude}),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;s.error("微信定位失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"getLocationInWeixin",platform:"weixin"})}function Nt(t){return l.safeExecute(()=>{var r;if(!window.wx){const i={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(r=t.fail)==null||r.call(t,i);return}if(!he()){s.info("等待微信配置完成"),ne().then(()=>Nt(t)).catch(i=>{var n;s.error("微信配置失败",i),(n=t.fail)==null||n.call(t,{errMsg:`微信配置失败: ${i.message}`})});return}const e=Wi(t);s.debug("调用微信查看位置",e),window.wx.openLocation({latitude:e.latitude,longitude:e.longitude,name:e.name||"",address:e.address||"",scale:e.scale||12,infoUrl:e.infoUrl||"",success:i=>{var n;s.info("微信查看位置成功"),(n=t.success)==null||n.call(t,i)},fail:i=>{var n;s.error("微信查看位置失败",i),(n=t.fail)==null||n.call(t,i)},complete:t.complete})},{context:"openLocationInWeixin",platform:"weixin"})}function Fi(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用获取位置",t),N("getLocation",t,{success:e=>{var r;s.info("UniApp 获取位置成功",{latitude:e==null?void 0:e.latitude,longitude:e==null?void 0:e.longitude}),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("UniApp 获取位置失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"getLocationInUniApp",platform:"uniapp"})}function ki(t){return l.safeExecute(()=>{const e=$i(t);s.debug("通过 WebView 桥接调用查看位置",e),N("openLocation",e,{success:r=>{var i;s.info("UniApp 查看位置成功"),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;s.error("UniApp 查看位置失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"openLocationInUniApp",platform:"uniapp"})}function Bi(t={}){return l.safeExecute(()=>{var r;if(!Be()){const i={errMsg:`当前环境 (${f.type}) 不支持定位功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持定位",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=Li(t);s.info("开始获取位置",{platform:f.type,type:e.type,altitude:e.altitude}),p()?Ot(e):Fi(e)},{context:"getLocation",options:t})}function Gi(t={}){return l.safeExecute(()=>{var r,i,n;if(!Be()){const a={errMsg:`当前环境 (${f.type}) 不支持查看位置功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持查看位置",{platform:f.type}),(r=t.fail)==null||r.call(t,a);return}let e;try{e=Ui(t)}catch(a){s.error("参数验证失败",a),(i=t.fail)==null||i.call(t,a),(n=t.complete)==null||n.call(t);return}s.info("开始查看位置",{platform:f.type,type:e.type,latitude:e.latitude,longitude:e.longitude,name:e.name}),p()?Nt(e):ki(e)},{context:"openLocation",options:t})}function Ki(){const t=p();return{supported:Be(),environment:f.type,implementation:t?"weixin":"webview",features:{getLocation:!0,openLocation:!0,coordinateTypes:!0,altitudeSupport:!0,asyncSupport:!0,onLocationChange:!t}}}const Q=new Set,ee=new Set;function Tt(t,e,r){t.forEach(i=>{if(typeof i=="function"){l.safeExecute(()=>i(e),{context:r});return}s.warn("监听回调不是函数,已跳过",{type:typeof i})})}function Vi(t={}){return l.safeExecute(()=>{var r,i;if(p()){const n={errMsg:`当前环境 (${f.type}) 不支持该接口`,code:"PLATFORM_NOT_SUPPORTED"};s.error("当前环境不支持此接口",{platform:f.type}),(r=t.fail)==null||r.call(t,n),(i=t.complete)==null||i.call(t,n);return}const e=Di(t);s.info("正在开启定位监听"),N("startLocationUpdate",{type:e.type,needFullAccuracy:e.needFullAccuracy},{success:n=>{var a;s.info("定位监听已启动"),(a=t.success)==null||a.call(t,n)},fail:n=>{var a;return(a=t.fail)==null?void 0:a.call(t,n)},complete:t.complete})},{context:"startLocationUpdate"})}function qi(t={}){return l.safeExecute(()=>{var e,r;if(p()){const i={errMsg:`当前环境 (${f.type}) 不支持该接口`,code:"PLATFORM_NOT_SUPPORTED"};s.error("当前环境不支持此接口",{platform:f.type}),(e=t.fail)==null||e.call(t,i),(r=t.complete)==null||r.call(t,i);return}s.info("正在停止定位监听"),N("stopLocationUpdate",t,{success:i=>{var n;s.info("定位监听已停止"),(n=t.success)==null||n.call(t,i)},fail:i=>{var n;return(n=t.fail)==null?void 0:n.call(t,i)},complete:t.complete})},{context:"stopLocationUpdate"})}function ji(t){return l.safeExecute(()=>{if(p()){s.warn("当前环境不支持此接口",{platform:f.type});return}if(typeof t!="function")throw s.error("onLocationChange 回调不是函数",{type:typeof t}),{errMsg:"onLocationChange 回调必须是函数",code:"INVALID_CALLBACK"};const e=Q.size>0;Q.add(t),e||(s.debug("注册实时位置变化监听器"),N("onLocationChange",{isPersistent:!0},{success:r=>{s.debug("收到实时位置推送",r),Tt(Q,r,"onLocationChange")},fail:r=>{s.warn("位置变化监听出错,请通过 onLocationChangeError 监听错误",r),Q.delete(t),Q.size===0&&pe("onLocationChange")}}))},{context:"onLocationChange"})}function Ji(t){return l.safeExecute(()=>{if(p()){s.warn("当前环境不支持此接口",{platform:f.type});return}if(t&&typeof t!="function")throw s.error("offLocationChange 回调不是函数",{type:typeof t}),{errMsg:"offLocationChange 回调必须是函数",code:"INVALID_CALLBACK"};t?Q.delete(t):Q.clear(),!(Q.size>0)&&(s.info("移除位置变化监听器"),N("offLocationChange",{},{success:()=>{s.info("位置变化监听已移除"),pe("onLocationChange")},fail:e=>{s.error("移除位置变化监听失败",e),pe("onLocationChange")}}))},{context:"offLocationChange"})}function Hi(t){return l.safeExecute(()=>{if(p()){s.warn("当前环境不支持此接口",{platform:f.type});return}if(typeof t!="function")throw s.error("onLocationChangeError 回调不是函数",{type:typeof t}),{errMsg:"onLocationChangeError 回调必须是函数",code:"INVALID_CALLBACK"};const e=ee.size>0;ee.add(t),e||(s.debug("注册位置更新错误监听器"),N("onLocationChangeError",{isPersistent:!0},{success:r=>{s.warn("持续定位发生异常",r),Tt(ee,r,"onLocationChangeError")},fail:r=>{s.warn("位置更新错误监听注册失败",r),ee.delete(t),ee.size===0&&pe("onLocationChangeError")}}))},{context:"onLocationChangeError"})}function zi(t){return l.safeExecute(()=>{if(p()){s.warn("当前环境不支持此接口",{platform:f.type});return}if(t&&typeof t!="function")throw s.error("offLocationChangeError 回调不是函数",{type:typeof t}),{errMsg:"offLocationChangeError 回调必须是函数",code:"INVALID_CALLBACK"};t?ee.delete(t):ee.clear(),!(ee.size>0)&&(s.info("移除定位错误监听器"),N("offLocationChangeError",{},{success:()=>{s.info("定位错误监听已移除"),pe("onLocationChangeError")},fail:e=>{s.error("移除定位错误监听失败",e),pe("onLocationChangeError")}}))},{context:"offLocationChangeError"})}const Yi={latitude:null,longitude:null};function Xi(t={}){const e=g(g({},Yi),t);return e.latitude!==null&&e.latitude!==void 0&&(typeof e.latitude!="number"?(s.warn("latitude 参数类型错误,已忽略",{latitude:e.latitude}),e.latitude=null):(e.latitude<-90||e.latitude>90)&&(s.warn("latitude 超出范围,已忽略",{latitude:e.latitude}),e.latitude=null)),e.longitude!==null&&e.longitude!==void 0&&(typeof e.longitude!="number"?(s.warn("longitude 参数类型错误,已忽略",{longitude:e.longitude}),e.longitude=null):(e.longitude<-180||e.longitude>180)&&(s.warn("longitude 超出范围,已忽略",{longitude:e.longitude}),e.longitude=null)),e}function bt(){return["webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function Zi(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用位置选择",t);const e={disableTimeout:!0,success:r=>{var i;s.info("UniApp 位置选择成功",{name:r==null?void 0:r.name,address:r==null?void 0:r.address,latitude:r==null?void 0:r.latitude,longitude:r==null?void 0:r.longitude}),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;s.error("UniApp 位置选择失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete};t.latitude!==null&&t.latitude!==void 0&&(e.latitude=t.latitude),t.longitude!==null&&t.longitude!==void 0&&(e.longitude=t.longitude),N("chooseLocation",e,{success:r=>{e.success(r)},fail:r=>{e.fail(r)},complete:e.complete})},{context:"chooseLocationInUniApp",platform:"uniapp"})}function Qi(t={}){return l.safeExecute(()=>{var r;if(!bt()){const i={errMsg:`当前环境 (${f.type}) 不支持位置选择功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持位置选择",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=Xi(t);s.info("开始选择位置",{platform:f.type,latitude:e.latitude,longitude:e.longitude}),p()||Zi(e)},{context:"chooseLocation",options:t})}function en(){return{supported:bt(),environment:f.type,implementation:p()?"weixin":"webview",features:{chooseLocation:!0,centerPoint:!0,asyncSupport:!0}}}const vt="https://iafs.xjy2.cn/img/bg.143351f0.jpg";function tn(t){return t==="timeline"||Number(t)===1?1:0}function Le(t="",e="targetPath"){if(!t||typeof t!="string")throw{errMsg:`share: ${e} 必须是最终小程序页面路径`,code:"PARAM_INVALID"};const r=t.trim(),[,i=""]=r.split("?");return{path:r,query:i}}function xt(t="",e="webTarget"){if(!t||typeof t!="string")throw{errMsg:`share: ${e} 必须是公网链接,例如 https://example.com/path?a=1`,code:"PARAM_INVALID"};const r=t.trim();if(!/^https?:\/\//.test(r))throw{errMsg:`share: ${e} 必须是公网链接,例如 https://example.com/path?a=1`,code:"PARAM_INVALID"};return r}function rn(){return new Promise((t,e)=>{var a,o;const r=typeof window!="undefined"?window:null;if(!r)return e({errMsg:"当前环境不支持 plus",code:"PLUS_UNAVAILABLE"});if(r.plus)return t(r.plus);const i=setTimeout(()=>{var c,d;(d=(c=r.document)==null?void 0:c.removeEventListener)==null||d.call(c,"plusready",n),e({errMsg:"等待 plusready 超时",code:"PLUS_READY_TIMEOUT"})},8e3);function n(){clearTimeout(i),t(r.plus)}(o=(a=r.document)==null?void 0:a.addEventListener)==null||o.call(a,"plusready",n,{once:!0})})}function nn(){return new Promise((t,e)=>{const r=typeof window!="undefined"?window.plus:null;if(!r||!r.share||typeof r.share.getServices!="function")return e({errMsg:"当前环境不支持 plus.share",code:"PLUS_SHARE_UNSUPPORTED"});r.share.getServices(i=>{const n=i.find(a=>a.id==="weixin");if(!n)return e({errMsg:"未找到微信分享服务",code:"WEIXIN_SERVICE_NOT_FOUND"});t(n)},i=>e(i||{errMsg:"获取分享服务失败",code:"GET_SHARE_SERVICES_FAILED"}))})}function an(t){return t.isWeixinMiniProgram?"已同步分享内容,请点击右上角“···”选择发送给朋友或分享到朋友圈。":"正在拉起微信分享面板,请选择聊天框或朋友圈。"}function sn(t={}){if(!t||typeof t!="object")throw{errMsg:"shareDirected 参数必须是对象",code:"PARAM_TYPE_ERROR"};const e=String(t.kind||"").trim(),r=t.payload||{},i=tn(t.scene);if(!["web","image","text"].includes(e))throw{errMsg:'shareDirected: kind 仅支持 "web"|"image"|"text"',code:"PARAM_INVALID"};if(![0,1].includes(i))throw{errMsg:"shareDirected: scene 仅支持 0|1",code:"PARAM_INVALID"};if(e==="web"&&(!r.title||!r.description||!r.imageUrl))throw{errMsg:"shareDirected(web): title/description/imageUrl 必填",code:"PARAM_MISSING"};if(e==="image"&&!r.imageUrl)throw{errMsg:"shareDirected(image): payload.imageUrl 必填",code:"PARAM_MISSING"};if(e==="text"&&!r.description)throw{errMsg:"shareDirected(text): payload.description 必填",code:"PARAM_MISSING"};return{kind:e,scene:i,payload:r,resolvedTargetPath:"",resolvedWebTarget:"",success:t.success,fail:t.fail,complete:t.complete}}function on(t,e){const{payload:r}=t;if(e.isWeixinMiniProgram)try{const i=Le(r.target,"target");return t.resolvedTargetPath=i.path,t}catch(i){throw{errMsg:(i==null?void 0:i.errMsg)||"shareDirected: 小程序环境下 payload.target 不合法",code:(i==null?void 0:i.code)||"PARAM_INVALID"}}if(e.isAppPlus){const i=(o,c)=>{try{return xt(o,c)}catch(d){return""}},n=i(r.target,"target");if(n)return t.resolvedWebTarget=n,t;const a=i(r.webTarget,"webTarget");if(a)return t.resolvedWebTarget=a,t;throw{errMsg:"shareDirected: App 环境下 payload.target 必须是公网链接;若 target 不存在或不合法,则 payload.webTarget 也必须是公网链接",code:"PARAM_INVALID"}}return t}function cn(t){const{kind:e,payload:r,resolvedTargetPath:i}=t,n=Le(i||r.target,"target"),a=r.imageUrl||vt;return{title:r.title||"分享",path:n.path,query:n.query,imageUrl:a,custom:{kind:e,target:n.path,webTarget:r.webTarget||"",description:r.description||""}}}function un(t){const{kind:e,scene:r,payload:i,resolvedWebTarget:n}=t,a=r===1?"WXSceneTimeline":"WXSceneSession",o=i.imageUrl||vt;return e==="image"?{message:{type:"image",pictures:[i.imageUrl],extra:{scene:a}},degradedFromText:!1}:{message:{type:"web",title:i.title||"分享",content:i.description||"",href:n,thumbs:[o],extra:{scene:a}},degradedFromText:e==="text"}}function ln(t){return I(this,null,function*(){yield rn();const e=yield nn(),{message:r,degradedFromText:i}=un(t);return new Promise((n,a)=>{e.send(r,()=>n({success:!0,data:{degradedFromText:i,hint:i?"纯文字已自动降级为图文分享,避免微信通道不支持纯文本":void 0}}),o=>a(o||{errMsg:"微信分享失败",code:"WEIXIN_SHARE_FAILED"}))})})}function Lt(t,e="share"){const r=typeof window!="undefined"&&window.wx&&window.wx.miniProgram;if(!r||typeof r.postMessage!="function")throw{errMsg:`当前微信小程序容器未注入 postMessage 能力,无法发起 ${e}`,code:"MINIPROGRAM_BRIDGE_UNAVAILABLE"};r.postMessage({data:t})}function fn(t,e){return{type:"qsh_api_call",api:"shareDirected",params:{miniProgramShare:cn(t),rowCustom:e},timestamp:Date.now()}}function dn(t={}){if(!t||typeof t!="object")throw{errMsg:"shareMiniProgramCard 参数必须是对象",code:"PARAM_TYPE_ERROR"};const e=t.payload||{};if(!e.title)throw{errMsg:"shareMiniProgramCard: payload.title 必填",code:"PARAM_MISSING"};if(!e.imageUrl)throw{errMsg:"shareMiniProgramCard: payload.imageUrl 必填",code:"PARAM_MISSING"};if(!e.targetPath)throw{errMsg:"shareMiniProgramCard: payload.targetPath 必填",code:"PARAM_MISSING"};return Le(e.targetPath,"targetPath"),{payload:e,success:t.success,fail:t.fail,complete:t.complete}}function gn(t){switch(String(t||"release").trim().toLowerCase()){case"develop":case"development":case"test":return"test";case"trial":case"preview":case"experience":return"preview";case"release":case"formal":case"production":return"release";default:throw{errMsg:'shareMiniProgramCard: payload.envVersion 仅支持 "develop"|"trial"|"release"',code:"PARAM_INVALID"}}}function hn(t){switch(String(t||"release").trim().toLowerCase()){case"develop":case"development":case"test":return 1;case"trial":case"preview":case"experience":return 2;case"release":case"formal":case"production":return 0;default:throw{errMsg:'shareMiniProgramCard: payload.envVersion 仅支持 "develop"|"trial"|"release"',code:"PARAM_INVALID"}}}function mn(t){const{payload:e}=t;if(!e.appid)throw{errMsg:"shareMiniProgramCard: App 环境下 payload.appid 必填",code:"PARAM_MISSING"};try{xt(e.webUrl,"webUrl")}catch(r){throw{errMsg:"shareMiniProgramCard: App 环境下 payload.webUrl 必填,且必须是公网链接",code:(r==null?void 0:r.code)||"PARAM_INVALID"}}return gn(e.envVersion),t}function pn(t){const{payload:e}=t,r=Le(e.targetPath,"targetPath");return{title:e.title,path:r.path,query:r.query,imageUrl:e.imageUrl}}function wn(t){const{payload:e}=t;return{provider:"weixin",scene:"WXSceneSession",type:5,title:e.title,imageUrl:e.imageUrl,miniProgram:{id:e.appid,path:e.targetPath,type:hn(e.envVersion),webUrl:e.webUrl}}}function En(t,e){return{type:"qsh_api_call",api:"shareMiniProgramCard",params:{miniProgramShare:pn(t),rowCustom:e},timestamp:Date.now()}}function yn(t){return I(this,null,function*(){return new Promise((e,r)=>{N("shareMiniProgramCard",{appShare:wn(t)},{success:i=>e(i||{}),fail:i=>r(i)})})})}function Dt(t={}){return l.safeExecute(()=>{var a,o,c,d,m,S,_,H,_e,O,z;let e;try{e=sn(t)}catch(A){return(a=t.fail)==null||a.call(t,A),Promise.reject(A)}const r=V(!0);try{e=on(e,r)}catch(A){return(o=e.fail)==null||o.call(e,A),(c=e.complete)==null||c.call(e,A),Promise.reject(A)}const i=an(r);if(r.isAppPlus)return ln(e).then(A=>{var Re,rr;const Y=w(g({},(A==null?void 0:A.data)||{}),{hint:i});return(Re=e.success)==null||Re.call(e,Y),(rr=e.complete)==null||rr.call(e,Y),Y}).catch(A=>{var Y,Re;return(Y=e.fail)==null||Y.call(e,A),(Re=e.complete)==null||Re.call(e,A),Promise.reject(A)});if(r.isWeixinMiniProgram)try{Lt(fn(e,t.rowCustom),"shareDirected");const A={success:!0,hint:i};return(d=e.success)==null||d.call(e,A),(m=e.complete)==null||m.call(e,A),Promise.resolve(A)}catch(A){return(S=e.fail)==null||S.call(e,A),(_=e.complete)==null||_.call(e,A),Promise.reject(A)}if(r.type==="h5"&&!r.isUniAppWebView&&!r.isOfflineWebview){const A={errMsg:"当前页面不在宿主 WebView 中,无法分享。请在 unified-platform-app 内打开该 H5 再重试。",code:"NOT_IN_CONTAINER"};return(H=e.fail)==null||H.call(e,A),(_e=e.complete)==null||_e.call(e,A),Promise.reject(A)}const n={errMsg:"当前环境暂不支持 shareDirected,请在 App 或微信小程序容器内使用。",code:"ENV_NOT_SUPPORTED"};return(O=e.fail)==null||O.call(e,n),(z=e.complete)==null||z.call(e,n),Promise.reject(n)},{context:"shareDirected",options:t})}function An(t={}){return new Promise((e,r)=>{Dt(w(g({},t),{success:e,fail:r}))})}function Ut(t={}){return l.safeExecute(()=>{var a,o,c,d,m,S,_,H,_e;let e;try{e=dn(t)}catch(O){return(a=t.fail)==null||a.call(t,O),Promise.reject(O)}const r=V(!0);if(r.isAppPlus)try{e=mn(e)}catch(O){return(o=e.fail)==null||o.call(e,O),(c=e.complete)==null||c.call(e,O),Promise.reject(O)}const i=r.isWeixinMiniProgram?"已同步小程序卡片内容,请点击右上角“···”后发送给朋友。":"正在拉起微信发送给朋友面板,请继续完成小程序卡片分享。";if(r.isAppPlus)return yn(e).then(O=>{var A,Y;const z=w(g({},O||{}),{hint:i});return(A=e.success)==null||A.call(e,z),(Y=e.complete)==null||Y.call(e,z),z}).catch(O=>{var z,A;return(z=e.fail)==null||z.call(e,O),(A=e.complete)==null||A.call(e,O),Promise.reject(O)});if(r.isWeixinMiniProgram)try{Lt(En(e,t.rowCustom),"shareMiniProgramCard");const O={success:!0,hint:i};return(d=e.success)==null||d.call(e,O),(m=e.complete)==null||m.call(e,O),Promise.resolve(O)}catch(O){return(S=e.fail)==null||S.call(e,O),(_=e.complete)==null||_.call(e,O),Promise.reject(O)}const n={errMsg:"当前环境暂不支持 shareMiniProgramCard,请在 App 或微信小程序容器内使用。",code:"ENV_NOT_SUPPORTED"};return(H=e.fail)==null||H.call(e,n),(_e=e.complete)==null||_e.call(e,n),Promise.reject(n)},{context:"shareMiniProgramCard",options:t})}function In(t={}){return new Promise((e,r)=>{Ut(w(g({},t),{success:e,fail:r}))})}const Pn={OFF:"off",ON:"on",UNAVAILABLE:"unavailable",UNAUTHORIZED:"unauthorized"},Mn={allowDuplicatesKey:!1,services:[]};function De(t={}){return g(g({},Mn),t)}function Ce(){return["weixin","webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function Cn(t){return l.safeExecute(()=>I(null,null,function*(){var e;if(!window.wx){const r={errMsg:"微信JS-SDK未加载",code:"WEIXIN_SDK_NOT_LOADED"};(e=t.fail)==null||e.call(t,r);return}he()||(s.info("等待微信配置完成"),yield ne()),wx.openBluetoothAdapter({success:()=>{s.info("微信蓝牙适配器已打开"),Wt(t)},fail:r=>{var i;s.error("蓝牙适配器打开失败",r),(i=t.fail)==null||i.call(t,r)}})}),{context:"openBluetoothAdapterInWeixin"})}function _n(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用蓝牙功能",t),N("bluetooth",t,{success:e=>{var r;s.info("UniApp 蓝牙调用成功",e),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("UniApp 蓝牙调用失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"bluetoothInUniApp"})}function Rn(t){return l.safeExecute(()=>{var e;s.debug("通过 WebView 桥接调用蓝牙设备搜索功能",t),N("bluetoothDevicesDiscovery",{action:"startBluetoothDevicesDiscovery",params:{services:t.services||[],allowDuplicatesKey:(e=t.allowDuplicatesKey)!=null?e:!1}},{success:r=>{var i;console.log("[Bluetooth] 设备开启搜索成功:",r),s.info("UniApp 蓝牙设备开启搜索成功",r),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;console.error("[Bluetooth] 设备开启搜索失败:",r),s.error("UniApp 蓝牙设备开启搜索失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"startBluetoothDevicesDiscoveryInUniApp"})}const Ue=new Set;function Sn(t,e={}){return l.safeExecute(()=>{var r;return Ue.add(t),Ue.size===1&&N("onBluetoothDeviceFound",{action:"onBluetoothDeviceFound",isPersistent:!0,params:{services:e.services||[],allowDuplicatesKey:(r=e.allowDuplicatesKey)!=null?r:!1}},{success:i=>{Ue.forEach(n=>{typeof n=="function"?l.safeExecute(()=>n(i),{context:"BluetoothDeviceCallback"}):console.warn("[BluetoothDeviceCallback] 不是函数:",n)})},fail:i=>{var n;console.error("[Bluetooth] 搜索失败:",i),(n=e.fail)==null||n.call(e,i)},complete:e.complete}),()=>Ue.delete(t)},{context:"qsh_onBluetoothDeviceFound"})}function On(t){return l.safeExecute(()=>{var e;s.debug("通过 WebView 桥接调用蓝牙连接功能",t),N("bluetoothConnection",{action:"createBLEConnection",params:{deviceId:t.deviceId,name:t.name,autoConnect:(e=t.autoConnect)!=null?e:!1}},{success:r=>{var i;console.log("[Bluetooth] 蓝牙连接成功:",r),s.info("UniApp 蓝牙连接成功",r),(i=t.success)==null||i.call(t,r)},fail:r=>{var i;console.error("[Bluetooth] 蓝牙连接失败:",r),s.error("UniApp 蓝牙连接失败",r),(i=t.fail)==null||i.call(t,r)},complete:t.complete})},{context:"createBLEConnectionInUniApp"})}function Nn(t={}){return l.safeExecute(()=>{var r;if(!Ce()){const i={errMsg:`当前环境 (${f.type}) 不支持蓝牙功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持蓝牙",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=De(t);s.info("开始蓝牙操作",{platform:f.type,services:e.services,allowDuplicatesKey:e.allowDuplicatesKey}),p()?Cn(e):_n(e)},{context:"openBluetoothAdapter",options:t})}function Tn(t={}){return l.safeExecute(()=>{var r,i;if(!Ce()){const n={errMsg:`当前环境 (${f.type}) 不支持蓝牙功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持蓝牙",{platform:f.type}),(r=t.fail)==null||r.call(t,n),(i=t.complete)==null||i.call(t,n);return}const e=De(t);s.info("开始搜索蓝牙设备",{platform:f.type,services:e.services,allowDuplicatesKey:e.allowDuplicatesKey}),p()?startBluetoothDevicesDiscoveryInWeixin(e):Rn(e)},{context:"startBluetoothDevicesDiscovery",options:t})}function Wt(t,e={}){return l.safeExecute(()=>{var i,n;if(!Ce()){const a={errMsg:`当前环境 (${f.type}) 不支持蓝牙功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持蓝牙",{platform:f.type}),(i=e.fail)==null||i.call(e,a),(n=e.complete)==null||n.call(e,a);return}const r=De(e);s.info("注册蓝牙设备发现监听",{platform:f.type}),p()?onBluetoothDeviceFoundInWeixin(r):Sn(t,r)},{context:"onBluetoothDeviceFound",options:e})}function bn(t={}){return l.safeExecute(()=>{var a,o,c,d;if(!Ce()){const m={errMsg:`当前环境 (${f.type}) 不支持蓝牙功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持蓝牙连接",{platform:f.type}),(a=t.fail)==null||a.call(t,m),(o=t.complete)==null||o.call(t,m);return}const e=De(t),{name:r,deviceId:i,autoConnect:n=!1}=e;if(!i){const m={errMsg:"缺少 deviceId 参数",code:"INVALID_PARAMS"};(c=t.fail)==null||c.call(t,m),(d=t.complete)==null||d.call(t,m);return}s.info("创建蓝牙连接",{deviceId:i,autoConnect:n,platform:f.type}),p()?uni.createBLEConnection({deviceId:i,autoConnect:n,success:t.success,fail:t.fail,complete:t.complete}):On(e)},{context:"createBLEConnection",options:t})}function vn(){return{supported:Ce(),environment:f.type,implementation:p()?"weixin":"webview",features:{discovery:!0,connect:!0,readWrite:!0,notify:!0,asyncSupport:!0}}}const xn={};function Ln(t={}){return g(g({},xn),t)}function $t(){return["webview","UniApp","plus","nvue","uvue","offline"].includes(f.type)}function Dn(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用打印PDF",t),N("printPdf",w(g({},t),{isPersistent:!0}),{success:e=>{var r;s.info("UniApp 打印PDF成功",e),(r=t.success)==null||r.call(t,e)},fail:e=>{var r;s.error("UniApp 打印PDF失败",e),(r=t.fail)==null||r.call(t,e)},complete:t.complete})},{context:"printPdfInUniApp",platform:"uniapp"})}function Un(t={}){return l.safeExecute(()=>{var r;if(!$t()){const i={errMsg:`当前环境 (${f.type}) 不支持打印PDF功能`,code:"PLATFORM_NOT_SUPPORTED"};s.error("平台不支持打印PDF",{platform:f.type}),(r=t.fail)==null||r.call(t,i);return}const e=Ln(t);s.info("开始打印PDF",{platform:f.type}),Dn(e)},{context:"printPdf",options:t})}function Wn(){return{supported:$t(),environment:f.type,implementation:"uniapp",features:{asyncSupport:!0}}}const Ge="/pages/face/index";function $n(t={}){const e=g({},t);if(!e.name||typeof e.name!="string"||!e.name.trim())throw{errMsg:"缺少必需参数:name(姓名)",code:"PARAM_MISSING"};if(e.name=e.name.trim(),!e.idCardNumber||typeof e.idCardNumber!="string"||!e.idCardNumber.trim())throw{errMsg:"缺少必需参数:idCardNumber(身份证号)",code:"PARAM_MISSING"};return e.idCardNumber=e.idCardNumber.trim(),e}function Ft(){return["weixin","webview","UniApp","plus","nvue","uvue"].includes(f.type)}function Fn(){return typeof window!="undefined"&&window.wx&&window.wx.miniProgram&&typeof window.wx.miniProgram.navigateTo=="function"}function kn(t){const e=w(g({},t),{title:document.title||"",url:window.location.href||""}),r=Object.entries(e).filter(([,i])=>i!=null&&i!=="").map(([i,n])=>`${encodeURIComponent(i)}=${encodeURIComponent(String(n))}`).join("&");return r?`${Ge}?${r}`:Ge}function Bn(t){return l.safeExecute(()=>{if(!Fn()){s.error("微信小程序导航API不可用");return}const e=kn(t);s.debug("跳转宿主人脸识别页面",{name:t.name,targetUrl:e}),window.wx.miniProgram.navigateTo({url:e,success:()=>{s.info("已跳转到宿主人脸识别页面",{targetUrl:e})},fail:r=>{s.error("跳转宿主人脸识别页面失败",r)}})},{context:"faceVerifyInWeixin",platform:"weixin"})}function Gn(t){return l.safeExecute(()=>{s.debug("通过 WebView 桥接调用人脸识别",{platform:f.type,name:t.name}),N("faceVerify",g({},t),{success:e=>{s.info("UniApp 人脸识别调用成功",e)},fail:e=>{s.error("UniApp 人脸识别调用失败",e)}})},{context:"faceVerifyInUniApp",platform:"uniapp"})}function Kn(t={}){return l.safeExecute(()=>{if(!Ft()){s.error("平台不支持人脸识别",{platform:f.type});return}let e;try{e=$n(t)}catch(r){s.error("人脸识别参数校验失败",r);return}if(s.info("开始人脸识别",{platform:f.type,name:e.name,pagePath:Ge}),p()){Bn(e);return}Gn(e)},{context:"faceVerify",options:t})}function Vn(){let t="weixin";return f.type==="UniApp"&&(t="uniapp"),{supported:Ft(),environment:f.type,implementation:t,features:{asyncSupport:!0,hostPageNavigation:p(),hostBridge:f.type==="UniApp"}}}const kt=V();function qn(){if(typeof window=="undefined"||!V(!0).isWeixinMiniProgram)return!1;const e=Fe().getRuntimeConfig();return typeof e.clientId=="string"&&e.clientId.length>0}function jn(){return I(this,null,function*(){yield gr(),qn()&&(yield ne())})}ae.useResponse(ot.response,{priority:1e3});let Bt=!1;function Gt(){if(Bt)return;Bt=!0,Lr([{name:"load-weixin-sdk",run:tt,timeoutMs:8e3},{name:"init-bridge",run:Qe,timeoutMs:8e3}],{onError:(e,r)=>{console.error(`[QSH-SDK] 初始化失败(${(r==null?void 0:r.name)||"unknown"}):`,e)}})}typeof window!="undefined"&&(document.readyState==="complete"||document.readyState==="interactive"?setTimeout(Gt,0):document.addEventListener("DOMContentLoaded",Gt));function y(t,{apiName:e}={}){return function(r={},...i){const n=r&&typeof r=="object"&&(typeof r.success=="function"||typeof r.fail=="function"||typeof r.complete=="function"),a=r&&typeof r=="object"?r:{},o=()=>n?t(a,...i):new Promise((d,m)=>{const S=w(g({},a),{success:_=>{typeof a.success=="function"&&a.success(_),d(_)},fail:_=>{typeof a.fail=="function"&&a.fail(_),m(_)},complete:a.complete});t(S,...i)});return(typeof window=="undefined"?Promise.resolve():Ze()).then(()=>o()).catch(d=>{throw console.error(`[QSH-SDK] ${e||"API"} call failed:`,d),d})}}function We(t){return typeof t=="function"?{success:t}:t&&typeof t=="object"?t:{}}const Kt=y(Gr),Vt=y(Kr),qt=y(Vr),jt=y(qr),Jt=y(jr),Ht=y(Jr);function zt(t){const e=()=>Hr(t);return(typeof window=="undefined"?Promise.resolve():Ze()).then(()=>e())}const Ke=y(ei,{apiName:"getCode"});function Jn(t={}){return new Promise((e,r)=>{Ke(w(g({},t),{success:e,fail:r}))})}const Ve=y(ai,{apiName:"navigateToMiniProgram"});function Hn(t={}){return new Promise((e,r)=>{Ve(w(g({},t),{success:e,fail:r}))})}const qe=y(li,{apiName:"filePreview"});function zn(t={}){return new Promise((e,r)=>{qe(w(g({},t),{success:e,fail:r}))})}const je=y(Ii);function Yn(t={}){return new Promise((e,r)=>{je(w(g({},t),{success:e,fail:r}))})}const Yt=y(Un);function Xn(t={}){return new Promise((e,r)=>{Yt(w(g({},t),{success:e,fail:r}))})}const Je=y(Si),Zn=y(Kn);function Qn(t={}){return new Promise((e,r)=>{Je(w(g({},t),{success:e,fail:r}))})}const ea=y(Dt,{apiName:"shareDirected"}),ta=y(An,{apiName:"shareDirectedAsync"}),ra=y(At,{apiName:"manualShare"}),ia=y(wi,{apiName:"manualShareAsync"}),He=y(Bi);function na(t={}){return new Promise((e,r)=>{He(w(g({},t),{success:e,fail:r}))})}const ze=y(Gi);function aa(t={}){return new Promise((e,r)=>{ze(w(g({},t),{success:e,fail:r}))})}const Ye=y(Qi);function sa(t={}){return new Promise((e,r)=>{Ye(w(g({},t),{success:e,fail:r}))})}const Xt=y(Nn);function oa(t={}){return new Promise((e,r)=>{Xt(w(g({},t),{success:e,fail:r}))})}const Zt=y(Tn);function ca(t={}){return new Promise((e,r)=>{Zt(w(g({},t),{success:e,fail:r}))})}const Qt=y(Wt);function ua(t={}){return new Promise((e,r)=>{Qt(w(g({},t),{success:e,fail:r}))})}const er=y(bn);function la(t={}){return new Promise((e,r)=>{er(w(g({},t),{success:e,fail:r}))})}const fa=y(Ut,{apiName:"shareMiniProgramCard"}),da=y(In,{apiName:"shareMiniProgramCardAsync"}),ue={navigateTo:Kt,navigateBack:Vt,switchTab:qt,reLaunch:jt,redirectTo:Jt,postMessage:Ht,getEnv:zt,getCode:Ke,getCodeAsync:Jn,navigateToMiniProgram:Ve,navigateToMiniProgramAsync:Hn,filePreview:qe,filePreviewAsync:zn,chooseImage:je,chooseImageAsync:Yn,scanCode:Je,scanCodeAsync:Qn,getLocation:He,getLocationAsync:na,openLocation:ze,openLocationAsync:aa,chooseLocation:Ye,chooseLocationAsync:sa,onLocationChange:t=>y((e={})=>ji(e.success),{apiName:"onLocationChange"})(We(t)),offLocationChange:t=>y((e={})=>Ji(e.success),{apiName:"offLocationChange"})(We(t)),onLocationChangeError:t=>y((e={})=>Hi(e.success),{apiName:"onLocationChangeError"})(We(t)),offLocationChangeError:t=>y((e={})=>zi(e.success),{apiName:"offLocationChangeError"})(We(t)),startLocationUpdate:y(Vi,{apiName:"startLocationUpdate"}),stopLocationUpdate:y(qi,{apiName:"stopLocationUpdate"}),environment:kt,ready:jn,init:Qe,isReady:sr,getState:or,config:rt,weixin:{config:rt,waitForConfig:ne,isConfigReady:he,getConfigState:Er,retryConfig:yr},webView:null,ImageSourceTypes:Te,ImageSizeTypes:be,getImageCapabilities:Pi,ScanTypes:ce,getScanCapabilities:Oi,CoordinateTypes:U,getLocationCapabilities:Ki,getChooseLocationCapabilities:en,openBluetoothAdapter:Xt,openBluetoothAdapterAsync:oa,startBluetoothDevicesDiscovery:Zt,startBluetoothDevicesDiscoveryAsync:ca,onBluetoothDeviceFound:Qt,onBluetoothDeviceFoundAsync:ua,createBLEConnection:er,createBLEConnectionAsync:la,BluetoothStates:Pn,shareDirected:ea,shareDirectedAsync:ta,manualShare:ra,manualShareAsync:ia,shareMiniProgramCard:fa,shareMiniProgramCardAsync:da,getBluetoothCapabilities:vn,printPdf:Yt,printPdfAsync:Xn,getPrintCapabilities:Wn,faceVerify:Zn,getFaceCapabilities:Vn,plugins:{manager:Ae,register:t=>Ae.register(t),install:t=>Ae.install(t,ue),list:()=>Ae.getPluginList()},interceptors:{chain:ae,useRequest:(t,e)=>ae.useRequest(t,e),useResponse:(t,e)=>ae.useResponse(t,e),builtin:{logging:Pr,performance:Z,createRetry:Mr,createValidation:Cr,errorNormalizer:ot}},metrics:{getPerformanceReport:()=>Z.getReport(),clearPerformanceMetrics:()=>Z.clearMetrics()},errors:{codes:u,messages:ke,categories:K,normalize:st,create:br,isStandard:vr},store:{instance:j,get:t=>j.get(t),set:(t,e)=>j.set(t,e),subscribe:(t,e)=>j.subscribe(t,e),getSnapshot:()=>j.getSnapshot()},debug:{logger:W,setLogReporter:t=>W.setReporter(t),errorHandler:l,stateManager:ie,enableDevMode:()=>W.enableDevMode(),getLogs:t=>W.getHistory(t),getStats:()=>({logger:W.getStats(),state:ie.getStats(),weixinConfig:Fe().getStats(),plugins:Ae.getStats(),interceptors:ae.getStats(),store:j.getStats()}),getWeixinConfigManager:Fe,exportDebugInfo:()=>W.exportToJSON()}};kt.isWeixinMiniProgram?ue.webView=window.wx&&window.wx.miniProgram:ue.webView={navigateTo:Kt,navigateBack:Vt,switchTab:qt,reLaunch:jt,redirectTo:Jt,postMessage:Ht,getEnv:zt,getCode:Ke,navigateToMiniProgram:Ve,filePreview:qe,chooseImage:je,scanCode:Je,getLocation:He,openLocation:ze,chooseLocation:Ye};const tr=typeof window.uni!="undefined"?window.uni:{};return Object.keys(tr).forEach(t=>{ue.hasOwnProperty(t)||(ue[t]=tr[t])}),typeof window!="undefined"&&(window.qsh=ue),ue});
|
|
2
2
|
//# sourceMappingURL=qsh-webview-sdk.umd.js.map
|