qsh-webview-sdk 2.2.0 → 2.2.2

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