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