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