@xybplugins/xyb-agent 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1 +1 @@
1
- const e=(e="",t="",i="log",n="")=>{const o={error:"错误",warn:"警告",info:"提示",log:"日志"}[i]||"日志",a=JSON.stringify(n);console.log(`\n=============🚀START - V${f} 🚀=============\n【事件名称】:${e} \n【日志类型】:${o} \n【日志信息】:${t} ${"error"===i?`【错误信息】:${JSON.stringify(a)}`:""} \n==============🚀END🚀==============`),console.log("")},t=(t={})=>{if("function"==typeof t)return e("deepClone","数据类型为function,无法执行深拷贝,请检查","error"),t;try{return JSON.parse(JSON.stringify(t))}catch(i){return e("deepClone","执行数据深拷贝异常","error",i),t}},i=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}),n=(e={},t={})=>{for(let i in e)t[i]=e[i]};let o={finished:!1,result:!1},a={finished:!1,result:!1},r={finished:!1,result:!1},s={finished:!1,result:!1};const c=()=>l()?navigator.userAgent.toLowerCase():"",d=()=>uni?.getSystemInfoSync()?.platform||!1,l=()=>window&&document,m=()=>{if(r.finished)return r.result;if(r.finished=!0,!l())return r.result=!1,!1;const t=c();return r.result=t.includes("xybwebcomponent"),e("checkIsXybBrowserEnv",`当前是否为湘易办浏览器环境:${r.result}`),r.result},u=()=>{const{finished:t,result:i}=o;return t?i:(o.result=m()||(()=>{if(s.finished)return s.result;if(s.finished=!0,!l())return s.result=!1,!1;const t=c();return s.result=t.includes("uni-app")&&!t.includes("xybwebcomponent"),e("checkIsMiniAppBrowserEnv",`当前是否为小程序的浏览器环境:${s.result}`),s.result})(),o.finished=!0,e("checkIsWebviewEnv",`当前是否为Webview环境:${o.result}`),o.result)},g=()=>{const{finished:t,result:i}=a;if(t)return i;if(a.finished=!0,!l())return a.result=!1,!1;const n=c();return a.result=m()&&!n.includes("uniminiapp"),e("checkIsAppWebviewEnv",`当前是否为APP的Webview环境:${a.result}`),a.result},v=()=>l()?c().includes("micromessenger"):"mp-weixin"===d(),p=t=>{const{dinateType:i}=t;return e("replaceCoordinate",`坐标转换开始:${i}`,"log"),(e=>{const{lat:t,lng:i,address:n}=e,o=52.35987755982988,a=i-.0065,r=t-.006,s=Math.sqrt(a*a+r*r)-2e-5*Math.sin(r*o),c=Math.atan2(r,a)-3e-6*Math.cos(a*o);return{destinationName:n,destinationLongitude:s*Math.cos(c).toFixed(6),destinationLatitude:s*Math.sin(c).toFixed(6)}})(t)},h=[{isCustomEv:!0,eventName:"authFace",uniEvName:"Auth_face",description:"人脸识别功能",nativeEvName:"faceAuth",reqDataFormat:t=>{e("authFace",`执行人脸验证,参数信息:${JSON.stringify(t)}`);const{name:i,certNo:n,appId:o,sign:a,created:r,nonce:s}=t;return i&&n&&o&&a&&r&&s?t:(e("authFace","缺少必要参数:name, certNo, appId, sign, created, nonce","error","缺少必要参数"),!1)},resDataFormat:e=>({isSuccess:Boolean(e),certifyId:e}),resErrorFormat:e=>"harmony"===d().toLowerCase()?{isSuccess:!1,errorMsg:e}:e},{isCustomEv:!0,eventName:"startNavigation",uniEvName:"Start_navigation",description:"目的地导航",nativeEvName:"start_navigation",reqDataFormat:t=>{let i={};const{dinateType:n,lat:o,lng:a,address:r}=t;return e("replaceCoordinate",`坐标系值:LAT:${o},LNG:${a}`,"log"),i=n&&"GCJ02"!==n?p(t):{destinationLatitude:o,destinationLongitude:a,destinationName:r},e("replaceCoordinate",`转换后值:LAT:${i.destinationLatitude},LNG:${i.destinationLongitude}`,"log"),i}},{isWindowEv:!0,eventName:"getLoginStatus",uniEvName:"Auth_checkLogin",description:"获取登录状态",nativeEvName:"CallNativeMethodGetUserInfo",resDataFormat:e=>{const i=t(e);return{logined:1===Number(i?.isLogin)}},resErrorFormat:()=>({logined:!1})},{isWindowEv:!0,eventName:"getLoginUserInfo",uniEvName:"Auth_getUserInfo",description:"获取登录用户数据信息",nativeEvName:"CallNativeMethodGetUserInfo",resDataFormat:e=>t(e),resErrorFormat:()=>({isSuccess:!1})},{isCustomEv:!0,eventName:"getAuthToken",uniEvName:"Auth_getToken",description:"获取授权token",nativeEvName:"get_token",resDataFormat:e=>{try{const i=t(e);return{token:i?.token,isSuccess:Boolean(i?.token)}}catch(t){return{token:e?.token,isSuccess:Boolean(e?.token)}}},resErrorFormat:()=>({isSuccess:!1})},{isWindowEv:!0,eventName:"getAccessLink",uniEvName:"Auth_getAccessLink",nativeEvName:"CallNativeMethodGetAccessLink",description:"获取授权链接",resDataFormat:e=>"ios"===d().toLowerCase()?{isSuccess:!0,accessLink:e}:t(e),resErrorFormat:()=>({isSuccess:!1})},{moduleName:"image",eventName:"chooseImg",uniEvName:"Image_choose",nativeEvName:"chooseImage",description:"选择本地图片",reqDataFormat:e=>{const{count:t,sizeType:i,sourceType:n,isCircleCrop:o}=e||{};return{count:t||9,sizeType:i||["original","compressed"],sourceType:n||["album"],isCircleCrop:o||!1}},resDataFormat:e=>t(e)},{moduleName:"image",eventName:"imgPreview",uniEvName:"Image_preview",nativeEvName:"previewImage",description:"执行图片预览"},{moduleName:"image",eventName:"imgUpload",uniEvName:"Image_upload",nativeEvName:"uploadImage",description:"执行图片上传",resDataFormat:e=>t(e),resErrorFormat:e=>e},{eventName:"imgDownload",uniEvName:"Image_download",nativeEvName:"",description:"执行图片下载"},{eventName:"fileUpload",uniEvName:"File_upload",nativeEvName:"",description:"执行文件上传"},{moduleName:"file",eventName:"fileDownload",uniEvName:"File_download",nativeEvName:"downloadFile",description:"执行文件下载",resDataFormat:e=>({isSuccess:Boolean(e),resultObj:{path:e}})},{moduleName:"file",eventName:"filePreview",uniEvName:"File_preview",nativeEvName:"previewFile",description:"执行文件预览"},{moduleName:"file",eventName:"openLocalFile",uniEvName:"File_openLocal",nativeEvName:"openLocalFile",description:"执行打开本地文件"},{moduleName:"file",eventName:"chooseLocalFile",uniEvName:"File_chooseLocal",nativeEvName:"chooseLocalFile",description:"选择本地文件",resDataFormat:e=>t(e)},{moduleName:"file",eventName:"openThirdFile",uniEvName:"File_openThirdParty",nativeEvName:"openFileWithThirdParty",description:"执行打开第三方文件"},{eventName:"openApp",uniEvName:"Util_openApp",nativeEvName:"",description:"打开APP"},{isCustomEv:!0,eventName:"openXybApp",uniEvName:"Util_openXYBMiniApp",nativeEvName:"jumpToMiniApp",description:"打开湘易办融合APP小程序",reqDataFormat:e=>{if(g()){const{pageUrl:t}=e;return{...e,path:t}}return e}},{eventName:"postMsgToOtherApp",uniEvName:"Util_postMessageToXYBMiniApp",nativeEvName:"",description:"发送消息给其他小程序"},{isWindowEv:!0,eventName:"scanCode",uniEvName:"Scan_code",description:"扫描二维码",nativeEvName:"CallNativeMethodScanQRCode",resDataFormat:e=>({text:e})},{moduleName:"system",eventName:"getAppInfo",nativeEvName:"getAppInfo",description:"获取应用信息",uniEvName:"System_getAppInfo",resDataFormat:e=>t(e)},{moduleName:"util",eventName:"copyToClipboard",uniEvName:"Util_clipboardData",nativeEvName:"clipboardData",description:"复制内容到剪切板",reqDataFormat:e=>({text:e}),resDataFormat:e=>g()?{isSuccess:Boolean(e)}:{isSuccess:!0}},{moduleName:"util",eventName:"getCacheSize",uniEvName:"Util_getCacheSize",nativeEvName:"getCacheSize",description:"获取缓存大小",resDataFormat:e=>t(e)},{moduleName:"util",eventName:"clearCache",uniEvName:"Util_clearCache",nativeEvName:"clearCache",description:"执行缓存清除",resDataFormat:()=>({isSuccess:!0}),resErrorFormat:()=>({isSuccess:!1})},{moduleName:"telephone",eventName:"callPhone",uniEvName:"Util_callDesignateNumber",nativeEvName:"call",description:"拨打电话",reqDataFormat:e=>g()?{phoneCode:"+86",phoneNumber:String(e).replace("+86","")}:{text:e}},{eventName:"forbidScreenShot",uniEvName:"Util_forbidScreenShot",nativeEvName:"",description:"执行禁止截屏"},{eventName:"setScreenLight",uniEvName:"Util_setScreenLight",nativeEvName:"",description:"设置屏幕是否常亮",reqDataFormat:e=>({idleTimerValue:e})},{eventName:"sendMatterId",uniEvName:"Param_MatterID",nativeEvName:"",description:"执行页面事件ID上报",reqDataFormat:e=>({matterID:e})},{isWindowEv:!0,description:"获取位置信息",eventName:"getLocationInfo",uniEvName:"Util_getLocationInformation",nativeEvName:"CallNativeMethodGetLocationInformation",resDataFormat:e=>({isSuccess:!0,location:t(e)}),resErrorFormat:()=>({isSuccess:!1,location:{}})},{eventName:"checkPermission",uniEvName:"Auth_matterHandleAuthority",nativeEvName:"",description:"检查事项权限",reqDataFormat:e=>({matterCode:e})},{eventName:"showComment",uniEvName:"Util_jumpToComment",nativeEvName:"",description:"打开评价弹窗"},{isWindowEv:!0,description:"打开微信小程序",eventName:"openWechatMiniApp",uniEvName:"Util_openWechatMiniProgram",nativeEvName:"CallNativeMethodJumpToWechatMiniProgram",reqDataFormat:e=>{if(g()){const t={};for(let i in e)t[i]=String(e[i]);return JSON.stringify(t)}return e}},{isWindowEv:!0,description:"打开支付宝小程序",eventName:"openAliPayMiniApp",uniEvName:"Util_openAlipayMiniProgram",nativeEvName:"CallNativeMethodJumpToAliPay",reqDataFormat:e=>g()?JSON.stringify(e):e},{eventName:"showMenuPanel",uniEvName:"menu_present",nativeEvName:"",description:"显示菜单面板"}],f="0.0.2",N=e=>Number(e)>9?e:`0${e}`,w=()=>{const e=new Date;return`${e.getFullYear()}-${N(e.getMonth()+1)}-${N(e.getDate())} ${N(e.getHours())}:${N(e.getMinutes())}:${N(e.getSeconds())}`},S={trackStack:[],anaSDKLoadTimes:0,locationInfo:{},isProdEnv:!1,track(t="",n={}){if(t){if(n)return l()&&!this.anaSDKInit?(this.trackStack.push({id:i(),eventID:t,eventPro:n}),void e("track","埋点上报插件初始化未完成,本次数据在插件初始化后自动上报","log")):void this.executeTrack(t,n);e("track","埋点数据上报失败","error","请传入埋点数据")}else e("track","埋点数据上报失败","error","请传入埋点事件")},async executeTrack(t="",i={}){if("object"==typeof t)return void await this.track(t?.eventID,t?.eventPro);const n=await this.initTrackParams(i);if(e("track",`执行埋点数据上报,事件名称:${t},事项编码:${n.code},完整埋点数据:${JSON.stringify(n)}`,"log"),l()&&xybAgent?.AnalysysAgent)return e("track","通过浏览器插件执行埋点数据上报","log"),void window.xybAgent.AnalysysAgent.track(t,n);if("undefined"!=typeof uni&&Object.prototype.hasOwnProperty.call(uni,"sendNativeEvent"))try{e("track",`埋点数据:${JSON.stringify(n)},埋点ID:${t}`,"log"),uni.sendNativeEvent("Analysis_common",{eventID:t,eventPro:n})}catch(t){e("track","执行数据埋点功能异常","error",t)}},loadAnaSDK:()=>new Promise(e=>{const t=document.createElement("script");t.src="https://mobile.zwfw.hunan.gov.cn:8088/AnalysysAgent_JS_SDK.min.js",t.onload=e,document.head.appendChild(t)}),trackSDKInit(t){return new Promise((i,n)=>{l()||(e("initTrack","非浏览器环境无需使用init执行初","error"),i(!0)),this.anaSDKInsert?this.configAnaSDK(t,i):this.loadAnaSDK().then(()=>{window.AnalysysAgent&&(xybAgent.AnalysysAgent=window.AnalysysAgent,this.anaSDKInsert=!0,this.configAnaSDK(t,i))})})},configAnaSDK(t,i){const n="800c298f0c42c94c",o="40d556c15f872084";let a=location?.host?.includes("hunan.gov.cn")?n:o;if("object"==typeof t)a=o;else{const e={production:n,development:o},i=[n,o];(e[t]||i.includes(t))&&(a=e[t]?e[t]:t)}this.isProdEnv=a===n,l()?(window.xybAgent.AnalysysAgent&&(window.xybAgent.AnalysysAgent.init({appkey:a,uploadURL:"https://mobile.zwfw.hunan.gov.cn:8088/aurora-api"}),e("_initSDK","xybAgent已初始化完成,可正常执行埋点操作","log"),this.anaSDKInit=!0,this.isInit=!0,this.checkTrackStack(),i(!0)),!Boolean(window.xybAgent.AnalysysAgent)&&this.anaSDKLoadTimes<10&&setTimeout(()=>this.trackSDKInit(i),300),!Boolean(window.xybAgent.AnalysysAgent)&&this.anaSDKLoadTimes>=10&&(e("_initSDK","xybAgent初始化失败","error","请检查app key、uploadURL是否正确"),i(!1))):i(!1)},async initTrackParams(e={}){const{code:t,name:i,aff_city_code:n,aff_city_name:o,unit_code:a,area_code:r,unit_name:s,is_finish:c,category:d,user_id:l,miniAppCode:m,$url_domain:u}=e,g=this.getVisitSource(),v=this.getPageSource(),p=await this.getPositionInfo();return{code:t||void 0,name:i||void 0,aff_city_code:n||void 0,aff_city_name:o||void 0,unit_code:a||void 0,area_code:r||void 0,unit_name:s||void 0,is_finish:c||void 0,category:d||void 0,user_id:l||void 0,miniAppCode:m||void 0,$url_domain:u||void 0,curr_time:w(),source:g,page_source:v,location:p}},getVisitSource(){if(!l()){const e=uni?.getSystemInfoSync(),{uniPlatform:t}=e||{};return"mp-weixin"===t?"wx":"mp-alipay"===t?"alipay":"app"}return v()?"wx":(l()?c().includes("alipay"):"mp-alipay"===d())?"alipay":"app"},checkTrackStack(){e("checkTrackStack","xybAgent已初始化完成,执行埋点数据堆栈检测","log");t(this.trackStack).forEach(t=>{const{eventID:i,eventPro:n,id:o}=t;e("checkTrackStack",`执行id值为${o} 的埋点数据再次上报`,"log"),this.track(i,n);const a=this.trackStack.findIndex(e=>e.id===o);a>-1&&this.trackStack.splice(a,1)})},getPageSource(){let t=null;t=l()?location.href:decodeURIComponent(((t=!1)=>{let i="";try{const n="function"==typeof getCurrentPages?getCurrentPages():[];e("getCurrentPagePath",`路径清单::${n}`,"log");const o=n?.length||0;o&&(e("getCurrentPagePath",`获取当前页面路径 -1 :${n[n.length-1]?.route}`,"log"),e("getCurrentPagePath",`获取当前页面路径 -2 :${n[n.length-2]?.route}`,"log"),i=n[o-(t?2:1)]?.route||"")}catch(t){e("getCurrentPagePath","获取当前页面路径时发生异常","error",t)}return i})());const i=t?.includes("source=");if(!i)return"click";const n=t.split("source=")[1];let o="click";return o=n.includes("&")?n.split("&")[0]:n,["copy","share","click","search"].includes(o)?o:"click"},async getPositionInfo(){if(!this.locationInfo?.province)try{const{location:e}=await this.getLocationInfo()||{};this.locationInfo=e||""}catch(e){this.locationInfo={}}return JSON.stringify(this.locationInfo)}},y={initMobileBridgeGlobalConfig(){const t=d();e("initMobileBridgeGlobalConfig",`开始初始化移动端桥链接配置,访问设备类型:${t}`),window.c2={},"ios"===t&&this.initIOSCallbackEvConfig(),"android"===t&&this.initAndroidCallbackEvConfig(),e("initMobileBridgeGlobalConfig","初始化移动端桥链接配置完成"),window.CreatorJsBridge=window.c2},initIOSCallbackEvConfig(){try{const t=this;window.c2.iOS={},window.c2.iOS.callJS=function(){window?.c2.iOS?.callJSCallback||(window.c2.iOS.callJSCallback={}),e("initIOSCallbackEvConfig",`开始处理IOS设备回调事件,回调数据:${JSON.stringify(arguments)}`),t.IOSCallbackEvFormat(arguments[0])}}catch(t){e("initIOSCallbackEvConfig","初始化IOS回调事件配置异常","error",t)}},initAndroidCallbackEvConfig(){window.c2.sendDataWarpToWeb=(e,t,i)=>{e(i)}},IOSCallbackEvFormat(i){const{returnValue:n,funcName:o}=i;let a=this.base64Decode(n);a.startsWith("{")&&a.endsWith("}")&&(a=JSON.parse(a)),e("IOSCallbackEvFormat",`IOS设备回调事件处理开始,回调数据:${JSON.stringify(a)}, 格式:${typeof a}`);const r=o.split("_a")[0],s=o.replace(r,""),c=this.iosCallBackList.find(e=>e.id===r);if(!c)return;const{resolveInfo:d,configInfo:l}=c,{resDataFormat:m,resErrorFormat:u}=l;if(s.includes("onFail")&&u)return a=u({isSuccess:!1,errorMsg:t(n)}),void d(a);m&&(a=m(a)),e("IOSCallbackEvFormat",`IOS设备回调事件处理完成,返回数据:${JSON.stringify(a)}`),d(a);const g=this.iosCallBackList.findIndex(e=>e.id===r);this.iosCallBackList.splice(g,1)},base64Decode(e){let t,i,n,o,a,r,s,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",d="",l=0;for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");l<e.length;)o=c.indexOf(e.charAt(l++)),a=c.indexOf(e.charAt(l++)),r=c.indexOf(e.charAt(l++)),s=c.indexOf(e.charAt(l++)),t=o<<2|a>>4,i=(15&a)<<4|r>>2,n=(3&r)<<6|s,d+=String.fromCharCode(t),64!=r&&(d+=String.fromCharCode(i)),64!=s&&(d+=String.fromCharCode(n));return d=this._utf8_decode(d),d},_utf8_decode(e){let t="",i=0,n=0,o=0,a=0;for(;i<e.length;)n=e.charCodeAt(i),n<128?(t+=String.fromCharCode(n),i++):n>191&&n<224?(a=e.charCodeAt(i+1),t+=String.fromCharCode((31&n)<<6|63&a),i+=2):(a=e.charCodeAt(i+1),o=e.charCodeAt(i+2),t+=String.fromCharCode((15&n)<<12|(63&a)<<6|63&o),i+=3);return t},checkMobileModuleBack(e,t,i){const n=i?"custom":e,o=`${i?"call":t}Callback`;window.c2.hasOwnProperty(n)||(window.c2[n]={}),window.c2[n].hasOwnProperty(o)||(window.c2[n][o]={})}},A={defaults:{headers:{},baseURL:""},interceptor:{request:null,response:null},request(i={}){if(uni?.request)return new Promise((e,n)=>{let o=t(i);o?("function"!=typeof this.interceptor?.request||i.ignore||(o=this.interceptor.request(i)),g()||this.executeNormalRequest(o,e,n)):e(!1)});e("request","当前环境非UNI编译的项目,无法执行请求操作,请自行使用接口请求插件实现","warn")},executeNormalRequest(e,t,i){uni.request({url:`${this.defaults.baseURL}${e.url}`,header:e?.header||{},data:e?.data||{},method:e?.method||"GET",success:e=>{if("function"==typeof this.interceptor.response){const i=this.interceptor.response(e);return void t(i)}t(e)},fail:e=>{i(e)}})},executeCloudRequest(e,t,i){}},M={menuBtnConfig(t={}){return!(!l()&&v)&&new Promise((i,n)=>{e("menuBtnConfig",`配置APP胶囊按钮清单显示,配置信息:${JSON.stringify(t)}`,"log");let o=!0;for(let i in t){if("object"!=typeof t[i]){o=!1,e("menuBtnConfig","配置参数错误","error","请传入一个Object配置数据");break}}if(o)if(u())this.miniAppH5SendMsgToApp(i,"menuBtnConfig",t,"配置APP的胶囊按钮清单显示");else{if(l()||!uni||!uni?.sendNativeEvent)return e("menuBtnConfig","配置APP胶囊按钮清单显示功能无法在非UNI环境运行","log"),void i(!1);try{e("menuBtnConfig","开始执行配置APP胶囊按钮清单显示","log"),uni?.sendNativeEvent("Util_MiniAppConfigMenu",t)}catch(t){e("menuBtnConfig","配置APP的胶囊按钮清单显示时发生异常","error",t)}}})}},E={initMessage(...t){e("initMessage",`初始化消息模块,当前环境为:${l()?"浏览器":"APP"},初始化消息模块:参数个数:${t.length}`,"log");const i=t[0];try{e("initMessage",`初始化消息模块,事件信息:${JSON.stringify(i)}`)}catch(t){e("initMessage","初始化消息模块,事件信息:"+typeof i,"error","序列化失败")}try{this.wvInfo=t[2],t[2]?.$scope?.$getAppWebview()&&(this.wvInfo=t[2].$scope.$getAppWebview().children()[0])}catch(t){e("initMessage","初始化消息模块,是否包含wvInfo:"+typeof this.wvInfo?.evalJS)}l()?window.addEventListener("message",t=>{e("initMessage",`浏览器webview接收到的消息内容,${JSON.stringify(t)}`,"log"),this.getMsgFromH5(t)}):(e("initMessage",`非浏览器中的webview接收到的消息内容,${JSON.stringify(i)}`,"log"),this.getMsgFromH5(i))},getMsgFromH5(t={}){let i=this.getMsgDataFromH5(t);const{origin:n}=t||{},{href:o}=location||{};if(l()&&o?.includes(n))return!1;const{isH5Send:a,methodName:r,methodData:s}=i||{};return!!a&&(r?null==s?(e("getMsgFromH5","请传入需要执行的事件数据","warn"),!1):(e("getMsgFromH5",`需要执行的事件名称【${r}】,需要执行的事件数据【${JSON.stringify(s)}】,是否为H5发送的消息【${a}】`,"log"),void(this[r]?this.executeH5MethodName(r,i):e("getMsgFromH5",`【${r}】事件不存在`,"warn"))):(e("getMsgFromH5","请传入需要执行的事件名称","warn"),!1))},executeH5MethodName(t,i){const{msgId:n,methodData:o}=i;try{const i=this[t].toString();if(e("executeH5MethodName",`【${t}】方法定义:${i}`,"log"),i.includes("Promise"))return void this[t](o).then(i=>{e("executeH5MethodName",`${t}方法执行结果:${JSON.stringify(i)}`,"log");let o=i;try{o=JSON.parse(i)}catch(t){e("executeH5MethodName","强制给数据进行序列化失败","error",t)}this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:o,isWebviewSend:!0,resultMessage:`执行${t}方法完成`})}).catch(i=>{e("executeH5MethodName",`${t}方法执行失败`,"error",i),this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:null,isWebviewSend:!0,resultMessage:`执行${t}方法失败,具体错误信息,请查看控制台`})});this[t](o),this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:null,isWebviewSend:!0,resultMessage:`执行${t}方法完成`})}catch(i){e("getMsgFromH5",`${t}方法执行失败`,"error",i)}},postMsgToH5(t){const i=JSON.stringify(t);if(e("postMsgToH5",`消息内容:${i}`,"log"),l()){e("postMsgToH5","父页面运行在浏览器","log");document.querySelector("iframe").contentWindow.postMessage(JSON.stringify(i),"*")}else try{e("postMsgToH5","父页面运行在非浏览器","log"),this.wvInfo.evalJS(`getMessageFromWebview('${i}')`)}catch(t){e("postMsgToH5","执行浏览器的webview回传异常","error",t)}},getMsgDataFromH5(t){let i=null;const{data:n}=t;try{i=l()?n?.data?.arg?n?.data?.arg:n?.data?n.data:n:t.detail?.data[0]}catch(t){return e("getMsgDataFromH5","处理消息内容时发生异常","error",t),!1}return e("getMsgDataFromH5",`获取到的消息内容:${JSON.stringify(i)}`,"log"),i}},b=(t,i,n)=>{if(e("_parseFunction",`${JSON.stringify(t)}`),"function"==typeof t)return n[i]=t,void(t="[Function]::"+i);if("object"!=typeof t)return;let o=null;for(let e in t)switch(typeof t[e]){case"object":o=i?i+"_"+e:e,b(t[e],o,n);break;case"function":o=i?i+"_"+e:e,n[o]=t[e],t[e]="[Function]::"+o}},I=e=>{let t=0;return"string"==typeof e?t=1:"number"==typeof e?t=2:"boolean"==typeof e?t=3:"function"==typeof e?t=4:e instanceof Array?t=6:"object"==typeof e&&(t=5),t},$={appH5SendMsgToApp(i,n={},o={}){const{isWindowEv:a,description:r,moduleName:s,nativeEvName:c,isCustomEv:l}=n;if(a)return void this.h5SendMsgToAppByWindow(i,n,o);const m=l?"custom":s,u=l?"call":c,g=this;try{let a={};if(("object"==typeof o?Object.keys(o):[]).length>0&&(a=t(o)),l){const i=t(a);e("webviewSendMsgToApp",`${r}功能在是通过custom.call的方式调用,需要重新处理入参`),a.params=i,a.action=c}e("webviewSendMsgToApp",`${r}的完整参数:${JSON.stringify(a)}`),this.initEventCallbackEv(i,a,n);const s=function(){return g.formatBridgeData(window.c2[m][`${u}Callback`],arguments)}(a);e("webviewSendMsgToApp",`${r}功能在${d()}的Webview环境下执行,调用参数:${JSON.stringify(s)}`),this.h5SendMsgToAppByBrowser(i,n,s)}catch(t){console.log(`🚀发送消息给APP出现错误,错误信息:${t},${JSON.stringify(t)}`),e("webviewSendMsgToApp",`${r}执行数据处理失败`,"error",t)}},initEventCallbackEv(i,n,o={}){const{description:a,resDataFormat:r,resErrorFormat:s}=o;n.onSuccess=function(t){e("webviewSendMsgToApp",`${a}功能在App的Webview环境下执行完成`),i(r?r(t):t)},n.onFail=function(n){const o=t(n);e("webviewSendMsgToApp",`${a}功能在App的Webview环境下执行失败,收到的回调数据:::${JSON.stringify(o)}`),i(s?s(o):r?r(o):o)}},formatBridgeData(t,i){try{const n=Math.random().toString(32).slice(2),o=[];for(let e in i){const a=n+"_a"+e,r=i[e],s={};!1===/OpenHarmony ([5-9])|OpenHarmony (\d{2})/i.test(navigator.userAgent)&&b(r,a,s);for(let e in s)t[e]=s[e],this.C2ReceiveQueue.push(t);o.push({type:I(r),name:a,value:r})}return e("formatBridgeData",`格式化后的参数:${JSON.stringify(o)}`),{params:o,id:n}}catch(t){e("formatBridgeData","消息通讯数据格式化异常","error",t)}},h5SendMsgToAppByWindow(t,i={},n={}){const{nativeEvName:o,description:a,resDataFormat:r}=i,s=d(),c=`${o}Back`;let l=n;e("h5SendMsgToAppByWindow",`给【${s}】APP发送【${a}】-【${o}】事件调用,回调函数名称:【${c}】`,"log"),window[c]=i=>{let n=i;if(e("h5SendMsgToAppByWindow",`收到【${s}】APP发送的${a}事件调用的回调值:${JSON.stringify(n)},回调数据类型::${typeof n}`,"log"),"string"==typeof n&&n.startsWith("{")&&n.endsWith("}"))try{n=JSON.parse(n)}catch(t){e("h5SendMsgToAppByWindow","数据格式化异常","error",t)}t(r?r(n):n)},setTimeout(()=>{"ios"!==s.toLowerCase()?"android"!==s.toLowerCase()?window.harmony[o](l):window.android[o](l):window.webkit.messageHandlers[o].postMessage(l)},100)},h5SendMsgToAppByBrowser(t,i={},n={}){const o=d();e("h5SendMsgToAppByBrowser",`给【${o}】APP发送【${i.nativeEvName}】事件调用,入参:${JSON.stringify(n)}`,"log");const{nativeEvName:a,moduleName:r,isCustomEv:s}=i,{id:c,params:l}=n;if("android"!==o)return"ios"===o?(this.iosCallBackList.push({id:c,resolveInfo:t,configInfo:i}),void this.h5SendMsgToIOS(c,r,a,l,s)):void("harmony"===o&&this.h5SendMsgToHarmony(c,r,a,l,s));this.h5SendMsgToAndroid(c,r,a,l,s)},h5SendMsgToAndroid(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToAndroid",`发送给安卓APP的消息:${JSON.stringify(r)}`),JSON.parse(window.AndroidFunction.callAndroidFun(JSON.stringify(r)))},h5SendMsgToIOS(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToIOS",`发送给IOS APP的消息:${JSON.stringify(r)}`),JSON.parse(prompt(JSON.stringify(r)))},h5SendMsgToHarmony(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToHarmony",`发送给鸿蒙APP的消息:${JSON.stringify(r)}`),JSON.parse(window.harmonyFunction.callHarmonyFun(r))}},C={msgList:[],msgStack:[],async miniAppH5SendMsgToApp(t,i,n){try{e("miniAppH5SendMsgToApp",`发送消息给webview:${i}`,"log");const o=await this.sendMsgToMiniApp({methodName:i,methodData:n});t(o?.resultInfo)}catch(n){e("miniAppH5SendMsgToApp",`执行${i}失败`,"error",n),t({isSuccess:!1,message:"执行事件失败,详情查看控制台"})}},sendMsgToMiniApp(t){return new Promise((n,o)=>{e("postMsgToWebview",`消息内容:${JSON.stringify(t)}`,"log");const{methodName:a,methodData:r}=t||{};if(!a)return void e("postMsgToWebview","请传入要调用的事件名称","warn");if(!r)return void e("postMsgToWebview","请传入要调用事件的数据信息","warn");const s=i(),c={data:{msgId:s,isH5Send:!0,...t}};if(this.msgList.push({id:s,resolveInfo:n,rejectInfo:o}),e("postMsgToWebview",`发送消息给父容器页面:${JSON.stringify(c)}`,"log"),!this.uniSDKInit)return e("postMsgToWebview","SDK尚未初始化完成,先行执行堆栈","log"),void this.msgStack.push({id:i(),msgContent:c,resolve:n,reject:o});uni?.webView?.postMessage?uni.webView.postMessage(c):uni?.postMessage(c)}).catch(t=>{e("postMsgToWebview","发生异常","error",t)})}},D={getMessageFromWebview(t,i=!1){let n={};try{n=i?t:t?.data||"{}","string"==typeof n&&n?.startsWith("{")&&n.endsWith("}")&&(n=JSON.parse(n))}catch(t){e("getMessageFromWebview","解析数据异常","error",t)}if(e("getMessageFromWebview",`是否为webview发送的消息内容:${n?.isWebviewSend},消息内容:${JSON.stringify(n)}`,"log"),!n?.isWebviewSend)return;const{msgId:o}=n,a=this.msgList.findIndex(e=>e.id===o);if(-1===a)return;const r=this.msgList[a],{resolveInfo:s}=r;s(n),this.msgList.splice(a,1)}},k=["getLoginUserInfo","getAuthToken"];let F=new class{version="";isInit=!1;isWebviewPage=!1;anaSDKInit=!1;uniSDKInit=!1;iosCallBackList=[];C2ReceiveQueue=[];constructor(e,t){this.version=e,this.isInit=!1,this.isWebviewPage=t,this.iosCallBackList=[],this.initModuleMethod(),this.initSDKAPI()}initModuleMethod(){n(S,this),n(y,this),n(A,this),n(M,this),n(E,this),n($,this),n(C,this),n(D,this)}init(t){l()?(u()&&this.initWebviewMsgFormat(),this.initUNISDK(),this.trackSDKInit(t)):e("init","当前环境非浏览器环境,无需执行初始化动作","warn")}initWebviewMsgFormat(){e("initWebviewMsgFormat","初始化被嵌套的页面消息通讯","log"),l()?(window.addEventListener("message",t=>{e("initWebviewMsgFormat","浏览器消息处理","log"),this.getMessageFromWebview(t)}),window.getMessageFromWebview=t=>{e("initWebviewMsgFormat","事件注入消息处理","log"),this.getMessageFromWebview(t,!0)}):e("initWebviewMsgFormat","该API仅支持在被webview嵌套的H5页面中使用","error","")}initUNISDK(){l()&&this.loadUniWebviewSDK().then(()=>{window?.uni&&"function"==typeof window?.uni?.webView?.postMessage&&(this.uniSDKInit=!0,e("initUNISDK","UNI Webview SDK 挂载完成"))})}loadUniWebviewSDK(){return e("loadUniWebviewSDK","开始挂载UNI-WEBVIEW SDK文件","log"),new Promise(e=>{const t=document.createElement("script");t.src="https://mobile.zwfw.hunan.gov.cn:8088/uni.webview.1.5.6.js",t.onload=e,document.head.appendChild(t)}).catch(t=>(e("loadUniWebviewSDK","加载uni-webview SDK异常","error",t),!1))}initSDKAPI(){g()&&(e("initSDKAPI","App的Webview环境,初始化C2调用链的回调函数"),this.initMobileBridgeGlobalConfig()),e("initSDKAPI","开始初始化SDK API"),h.forEach(t=>{const{eventName:i,moduleName:n,nativeEvName:o,isCustomEv:a}=t;if((n&&o||a)&&g()&&(e("initSDKAPI",`初始化C2调用链的回调函数:${i}`),this.checkMobileModuleBack(n,o,a)),!k?.includes(i))try{this[i]=e=>new Promise(i=>{this.normalEvDataTransition(i,e,t)})}catch(t){e("initSDKAPI","执行API初始化挂载异常","error",t)}})}normalEvDataTransition(t,i={},n={}){const{eventName:o,description:a,reqDataFormat:r}=n||{},s=d();if(l()&&!m())return t({code:-1,isSuccess:!1,data:{},msg:"当前环境不支持该功能"}),void e(o,`${a}功能在浏览器环境执行失败,请检查是否为湘易办相关环境`,"warn");let c=i;if(r&&(c=r(i)),c){if(g())return e("normalEvDataTransition",`开始调用APP的嵌套H5能力,事件名称:${o},入参:${JSON.stringify(c)}`),void this.appH5SendMsgToApp(t,n,c);if(u())return e("normalEvDataTransition",`开始调用小程序/H5嵌套的H5能力,事件名称:${o},入参:${JSON.stringify(c)}`),void this.miniAppH5SendMsgToApp(t,o,c,a);e("normalEvDataTransition",`开始小程序调用原生能力,事件名称:${o},入参:${JSON.stringify(c)}`),this.executeEvByNative(t,c,n)}else e(o,`给【${s}】APP发送【${a}】-【${o}】事件失败,请检查数据格式是否正确`,"error")}executeEvByNative(t,i,n){const{description:o,uniEvName:a}=n;try{e("executeEvByNative",`开始调用原生${o}的能力,API名称:${a},格式化前的参数信息:${JSON.stringify(i)}`),uni.sendNativeEvent(a,i,i=>{e("executeEvByNative",`调用原生${o}的能力完成,结果:${JSON.stringify(i)}`,"log"),((t={},i={})=>{let n=i;try{"string"==typeof n&&n?.startsWith("{")&&n.endsWith("}")&&(n=JSON.parse(i))}catch(t){e("formatResponseData","格式化失败","error",t),n=i}t(n)})(t,i)})}catch(t){e("executeEvByNative",`${o}API执行异常`,"error",t)}}}(f,u());l()&&(window.xybAgent=F);export{F as default};
1
+ const e=(e="",t="",i="log",n="")=>{const o={error:"错误",warn:"警告",info:"提示",log:"日志"}[i]||"日志",a=JSON.stringify(n);console.log(`\n=============🚀START - V${N} 🚀=============\n【事件名称】:${e} \n【日志类型】:${o} \n【日志信息】:${t} ${"error"===i?`【错误信息】:${JSON.stringify(a)}`:""} \n==============🚀END🚀==============`),console.log("")},t=(t={})=>{if("function"==typeof t)return e("deepClone","数据类型为function,无法执行深拷贝,请检查","error"),t;try{return JSON.parse(JSON.stringify(t))}catch(i){return e("deepClone","执行数据深拷贝异常","error",i),t}},i=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}),n=(e={},t={})=>{for(let i in e)t[i]=e[i]},o=e=>{try{return JSON.parse(e)}catch(t){return e}};let a={finished:!1,result:!1},r={finished:!1,result:!1},s={finished:!1,result:!1},c={finished:!1,result:!1};const d=()=>m()?navigator.userAgent.toLowerCase():"",l=()=>{const e=d();return/android/i.test(e)?"android":/iphone|ipad|ipod|mac/i.test(e)&&!window.MSStream?"ios":/windows phone/i.test(e)?"windows":"harmony"},m=()=>window&&document,u=()=>{if(s.finished)return s.result;if(s.finished=!0,!m())return s.result=!1,!1;const t=d();return s.result=t.includes("xybwebcomponent")||t.includes("uni-app"),e("checkIsXybBrowserEnv",`当前是否为湘易办浏览器环境:${s.result}`),s.result},g=()=>{if(c.finished)return c.result;if(c.finished=!0,!m())return c.result=!1,!1;const t=d();return c.result=t.includes("uni-app"),e("checkIsMiniAppBrowserEnv",`当前是否为小程序的浏览器环境:${c.result}`),c.result},v=()=>{const{finished:t,result:i}=a;return t?i:(a.result=u()||g(),a.finished=!0,e("checkIsWebviewEnv",`当前是否为Webview环境:${a.result}`),a.result)},p=()=>{const{finished:t,result:i}=r;if(t)return i;if(r.finished=!0,!m())return r.result=!1,!1;const n=d();return r.result=n.includes("xybwebcomponent")&&!n.includes("uniminiapp"),e("checkIsAppWebviewEnv",`当前是否为APP的Webview环境:${r.result}`),r.result},h=()=>m()?d().includes("micromessenger"):"mp-weixin"===l(),f=t=>{const{dinateType:i}=t;return e("replaceCoordinate",`坐标转换开始:${i}`,"log"),(e=>{const{lat:t,lng:i,address:n}=e,o=52.35987755982988,a=i-.0065,r=t-.006,s=Math.sqrt(a*a+r*r)-2e-5*Math.sin(r*o),c=Math.atan2(r,a)-3e-6*Math.cos(a*o);return{destinationName:n,destinationLongitude:s*Math.cos(c).toFixed(6),destinationLatitude:s*Math.sin(c).toFixed(6)}})(t)},w=[{isCustomEv:!0,eventName:"authFace",uniEvName:"Auth_face",description:"人脸识别功能",nativeEvName:"faceAuth",reqDataFormat:t=>{e("authFace",`执行人脸验证,参数信息:${JSON.stringify(t)}`);const{name:i,certNo:n,appId:o,sign:a,created:r,nonce:s}=t;return i&&n&&o&&a&&r&&s?t:(e("authFace","缺少必要参数:name, certNo, appId, sign, created, nonce","error","缺少必要参数"),!1)},resDataFormat:e=>({isSuccess:Boolean(e),certifyId:e}),resErrorFormat:e=>"harmony"===l().toLowerCase()?{isSuccess:!1,errorMsg:e}:e},{isCustomEv:!0,eventName:"startNavigation",uniEvName:"Start_navigation",description:"目的地导航",nativeEvName:"start_navigation",reqDataFormat:t=>{let i={};const{dinateType:n,lat:o,lng:a,address:r}=t;return e("replaceCoordinate",`坐标系值:LAT:${o},LNG:${a}`,"log"),i=n&&"GCJ02"!==n?f(t):{destinationLatitude:o,destinationLongitude:a,destinationName:r},e("replaceCoordinate",`转换后值:LAT:${i.destinationLatitude},LNG:${i.destinationLongitude}`,"log"),i}},{isWindowEv:!0,eventName:"getLoginStatus",uniEvName:"Auth_checkLogin",description:"获取登录状态",nativeEvName:"CallNativeMethodGetUserInfo",resDataFormat:e=>{const i=t(e);return{logined:1===Number(i?.isLogin)}},resErrorFormat:()=>({logined:!1})},{isWindowEv:!0,eventName:"getLoginUserInfo",uniEvName:"Auth_getUserInfo",description:"获取登录用户数据信息",nativeEvName:"CallNativeMethodGetUserInfo",resDataFormat:e=>t(e),resErrorFormat:()=>({isSuccess:!1})},{isCustomEv:!0,eventName:"getAuthToken",uniEvName:"Auth_getToken",description:"获取授权token",nativeEvName:"get_token",resDataFormat:e=>{try{const i=t(e);return{token:i?.token,isSuccess:Boolean(i?.token)}}catch(t){return{token:e?.token,isSuccess:Boolean(e?.token)}}},resErrorFormat:()=>({isSuccess:!1})},{isWindowEv:!0,eventName:"getAccessLink",uniEvName:"Auth_getAccessLink",nativeEvName:"CallNativeMethodGetAccessLink",description:"获取授权链接",resDataFormat:e=>"ios"===l().toLowerCase()?{isSuccess:!0,accessLink:e}:t(e),resErrorFormat:()=>({isSuccess:!1})},{moduleName:"image",eventName:"chooseImg",uniEvName:"Image_choose",nativeEvName:"chooseImage",description:"选择本地图片",reqDataFormat:e=>{const{count:t,sizeType:i,sourceType:n,isCircleCrop:o}=e||{};return{count:t||9,sizeType:i||["original","compressed"],sourceType:n||["album"],isCircleCrop:o||!1}},resDataFormat:e=>t(e)},{moduleName:"image",eventName:"imgPreview",uniEvName:"Image_preview",nativeEvName:"previewImage",description:"执行图片预览"},{moduleName:"image",eventName:"imgUpload",uniEvName:"Image_upload",nativeEvName:"uploadImage",description:"执行图片上传",resDataFormat:e=>t(e),resErrorFormat:e=>e},{eventName:"imgDownload",uniEvName:"Image_download",nativeEvName:"",description:"执行图片下载"},{eventName:"fileUpload",uniEvName:"File_upload",nativeEvName:"",description:"执行文件上传"},{moduleName:"file",eventName:"fileDownload",uniEvName:"File_download",nativeEvName:"downloadFile",description:"执行文件下载",resDataFormat:e=>({isSuccess:Boolean(e),resultObj:{path:e}})},{moduleName:"file",eventName:"filePreview",uniEvName:"File_preview",nativeEvName:"previewFile",description:"执行文件预览"},{moduleName:"file",eventName:"openLocalFile",uniEvName:"File_openLocal",nativeEvName:"openLocalFile",description:"执行打开本地文件"},{moduleName:"file",eventName:"chooseLocalFile",uniEvName:"File_chooseLocal",nativeEvName:"chooseLocalFile",description:"选择本地文件",resDataFormat:e=>t(e)},{moduleName:"file",eventName:"openThirdFile",uniEvName:"File_openThirdParty",nativeEvName:"openFileWithThirdParty",description:"执行打开第三方文件"},{eventName:"openApp",uniEvName:"Util_openApp",nativeEvName:"",description:"打开APP"},{isCustomEv:!0,eventName:"openXybApp",uniEvName:"Util_openXYBMiniApp",nativeEvName:"jumpToMiniApp",description:"打开湘易办融合APP小程序",reqDataFormat:e=>{if(p()){const{pageUrl:t}=e;return{...e,path:t}}return e}},{eventName:"postMsgToOtherApp",uniEvName:"Util_postMessageToXYBMiniApp",nativeEvName:"",description:"发送消息给其他小程序"},{isWindowEv:!0,eventName:"scanCode",uniEvName:"Scan_code",description:"扫描二维码",nativeEvName:"CallNativeMethodScanQRCode",resDataFormat:e=>({text:e})},{moduleName:"system",eventName:"getAppInfo",nativeEvName:"getAppInfo",description:"获取应用信息",uniEvName:"System_getAppInfo",resDataFormat:e=>t(e)},{moduleName:"util",eventName:"copyToClipboard",uniEvName:"Util_clipboardData",nativeEvName:"clipboardData",description:"复制内容到剪切板",reqDataFormat:e=>({text:e}),resDataFormat:e=>p()?{isSuccess:Boolean(e)}:{isSuccess:!0}},{moduleName:"util",eventName:"getCacheSize",uniEvName:"Util_getCacheSize",nativeEvName:"getCacheSize",description:"获取缓存大小",resDataFormat:e=>t(e)},{moduleName:"util",eventName:"clearCache",uniEvName:"Util_clearCache",nativeEvName:"clearCache",description:"执行缓存清除",resDataFormat:()=>({isSuccess:!0}),resErrorFormat:()=>({isSuccess:!1})},{moduleName:"telephone",eventName:"callPhone",uniEvName:"Util_callDesignateNumber",nativeEvName:"call",description:"拨打电话",reqDataFormat:e=>"object"==typeof o(e)?o(e):p()?{phoneCode:"+86",phoneNumber:String(e).replace("+86","")}:{text:e}},{eventName:"forbidScreenShot",uniEvName:"Util_forbidScreenShot",nativeEvName:"",description:"执行禁止截屏"},{eventName:"setScreenLight",uniEvName:"Util_setScreenLight",nativeEvName:"",description:"设置屏幕是否常亮",reqDataFormat:e=>({idleTimerValue:e})},{eventName:"sendMatterId",uniEvName:"Param_MatterID",nativeEvName:"",description:"执行页面事件ID上报",reqDataFormat:e=>({matterID:e})},{isWindowEv:!0,description:"获取位置信息",eventName:"getLocationInfo",uniEvName:"Util_getLocationInformation",nativeEvName:"CallNativeMethodGetLocationInformation",resDataFormat:e=>({isSuccess:!0,location:t(e)}),resErrorFormat:()=>({isSuccess:!1,location:{}})},{eventName:"checkPermission",uniEvName:"Auth_matterHandleAuthority",nativeEvName:"",description:"检查事项权限",reqDataFormat:e=>({matterCode:e})},{eventName:"showComment",uniEvName:"Util_jumpToComment",nativeEvName:"",description:"打开评价弹窗"},{isWindowEv:!0,description:"打开微信小程序",eventName:"openWechatMiniApp",uniEvName:"Util_openWechatMiniProgram",nativeEvName:"CallNativeMethodJumpToWechatMiniProgram",reqDataFormat:e=>{if(p()){const t={};for(let i in e)t[i]=String(e[i]);return JSON.stringify(t)}return e}},{isWindowEv:!0,description:"打开支付宝小程序",eventName:"openAliPayMiniApp",uniEvName:"Util_openAlipayMiniProgram",nativeEvName:"CallNativeMethodJumpToAliPay",reqDataFormat:e=>p()?JSON.stringify(e):e},{eventName:"showMenuPanel",uniEvName:"menu_present",nativeEvName:"",description:"显示菜单面板"}],N="0.0.3",S=e=>Number(e)>9?e:`0${e}`,y=()=>{const e=new Date;return`${e.getFullYear()}-${S(e.getMonth()+1)}-${S(e.getDate())} ${S(e.getHours())}:${S(e.getMinutes())}:${S(e.getSeconds())}`},A={trackStack:[],anaSDKLoadTimes:0,locationInfo:{},isProdEnv:!1,track(t="",n={}){if(t){if(n)return m()&&!this.anaSDKInit?(this.trackStack.push({id:i(),eventID:t,eventPro:n}),void e("track","埋点上报插件初始化未完成,本次数据在插件初始化后自动上报","log")):void this.executeTrack(t,n);e("track","埋点数据上报失败","error","请传入埋点数据")}else e("track","埋点数据上报失败","error","请传入埋点事件")},async executeTrack(t="",i={}){if("object"==typeof t)return void await this.track(t?.eventID,t?.eventPro);const n=await this.initTrackParams(i);if(e("track",`执行埋点数据上报,事件名称:${t},事项编码:${n.code},完整埋点数据:${JSON.stringify(n)}`,"log"),m()&&xybAgent?.AnalysysAgent)return e("track","通过浏览器插件执行埋点数据上报","log"),void window.xybAgent.AnalysysAgent.track(t,n);if("undefined"!=typeof uni&&Object.prototype.hasOwnProperty.call(uni,"sendNativeEvent"))try{e("track",`埋点数据:${JSON.stringify(n)},埋点ID:${t}`,"log"),uni.sendNativeEvent("Analysis_common",{eventID:t,eventPro:n})}catch(t){e("track","执行数据埋点功能异常","error",t)}},loadAnaSDK:()=>new Promise(e=>{const t=document.createElement("script");t.src="https://mobile.zwfw.hunan.gov.cn:8088/AnalysysAgent_JS_SDK.min.js",t.onload=e,document.head.appendChild(t)}),trackSDKInit(t){return new Promise((i,n)=>{m()||(e("initTrack","非浏览器环境无需使用init执行初","error"),i(!0)),this.anaSDKInsert?this.configAnaSDK(t,i):this.loadAnaSDK().then(()=>{window.AnalysysAgent&&(xybAgent.AnalysysAgent=window.AnalysysAgent,this.anaSDKInsert=!0,this.configAnaSDK(t,i))})})},configAnaSDK(t,i){const n="800c298f0c42c94c",o="40d556c15f872084";let a=location?.host?.includes("hunan.gov.cn")?n:o;if("object"==typeof t)a=o;else{const e={production:n,development:o},i=[n,o];(e[t]||i.includes(t))&&(a=e[t]?e[t]:t)}this.isProdEnv=a===n,m()?(window.xybAgent.AnalysysAgent&&(window.xybAgent.AnalysysAgent.init({appkey:a,uploadURL:"https://mobile.zwfw.hunan.gov.cn:8088/aurora-api"}),e("_initSDK","xybAgent已初始化完成,可正常执行埋点操作","log"),this.anaSDKInit=!0,this.isInit=!0,this.checkTrackStack(),i(!0)),!Boolean(window.xybAgent.AnalysysAgent)&&this.anaSDKLoadTimes<10&&setTimeout(()=>this.trackSDKInit(i),300),!Boolean(window.xybAgent.AnalysysAgent)&&this.anaSDKLoadTimes>=10&&(e("_initSDK","xybAgent初始化失败","error","请检查app key、uploadURL是否正确"),i(!1))):i(!1)},async initTrackParams(e={}){const{code:t,name:i,aff_city_code:n,aff_city_name:o,unit_code:a,area_code:r,unit_name:s,is_finish:c,category:d,user_id:l,miniAppCode:m,$url_domain:u}=e,g=this.getVisitSource(),v=this.getPageSource(),p=await this.getPositionInfo();return{code:t||void 0,name:i||void 0,aff_city_code:n||void 0,aff_city_name:o||void 0,unit_code:a||void 0,area_code:r||void 0,unit_name:s||void 0,is_finish:c||void 0,category:d||void 0,user_id:l||void 0,miniAppCode:m||void 0,$url_domain:u||void 0,curr_time:y(),source:g,page_source:v,location:p}},getVisitSource(){if(!m()){const e=uni?.getSystemInfoSync(),{uniPlatform:t}=e||{};return"mp-weixin"===t?"wx":"mp-alipay"===t?"alipay":"app"}return h()?"wx":(m()?d().includes("alipay"):"mp-alipay"===l())?"alipay":"app"},checkTrackStack(){e("checkTrackStack","xybAgent已初始化完成,执行埋点数据堆栈检测","log");t(this.trackStack).forEach(t=>{const{eventID:i,eventPro:n,id:o}=t;e("checkTrackStack",`执行id值为${o} 的埋点数据再次上报`,"log"),this.track(i,n);const a=this.trackStack.findIndex(e=>e.id===o);a>-1&&this.trackStack.splice(a,1)})},getPageSource(){let t=null;t=m()?location.href:decodeURIComponent(((t=!1)=>{let i="";try{const n="function"==typeof getCurrentPages?getCurrentPages():[];e("getCurrentPagePath",`路径清单::${n}`,"log");const o=n?.length||0;o&&(e("getCurrentPagePath",`获取当前页面路径 -1 :${n[n.length-1]?.route}`,"log"),e("getCurrentPagePath",`获取当前页面路径 -2 :${n[n.length-2]?.route}`,"log"),i=n[o-(t?2:1)]?.route||"")}catch(t){e("getCurrentPagePath","获取当前页面路径时发生异常","error",t)}return i})());const i=t?.includes("source=");if(!i)return"click";const n=t.split("source=")[1];let o="click";return o=n.includes("&")?n.split("&")[0]:n,["copy","share","click","search"].includes(o)?o:"click"},async getPositionInfo(){if(!this.locationInfo?.province)try{const{location:e}=await this.getLocationInfo()||{};this.locationInfo=e||""}catch(e){this.locationInfo={}}return JSON.stringify(this.locationInfo)}},E={initMobileBridgeGlobalConfig(){const t=l();e("initMobileBridgeGlobalConfig",`开始初始化移动端桥链接配置,访问设备类型:${t}`),window.c2={},"ios"===t&&this.initIOSCallbackEvConfig(),"android"===t&&this.initAndroidCallbackEvConfig(),e("initMobileBridgeGlobalConfig","初始化移动端桥链接配置完成"),window.CreatorJsBridge=window.c2},initIOSCallbackEvConfig(){try{const t=this;window.c2.iOS={},window.c2.iOS.callJS=function(){window?.c2.iOS?.callJSCallback||(window.c2.iOS.callJSCallback={}),e("initIOSCallbackEvConfig",`开始处理IOS设备回调事件,回调数据:${JSON.stringify(arguments)}`),t.IOSCallbackEvFormat(arguments[0])}}catch(t){e("initIOSCallbackEvConfig","初始化IOS回调事件配置异常","error",t)}},initAndroidCallbackEvConfig(){window.c2.sendDataWarpToWeb=(e,t,i)=>{e(i)}},IOSCallbackEvFormat(i){const{returnValue:n,funcName:a}=i;let r=this.base64Decode(n);r=o(r),e("IOSCallbackEvFormat",`IOS设备回调事件处理开始,回调数据:${JSON.stringify(r)}, 格式:${typeof r}`);const s=a.split("_a")[0],c=a.replace(s,""),d=this.iosCallBackList.find(e=>e.id===s);if(!d)return;const{resolveInfo:l,configInfo:m}=d,{resDataFormat:u,resErrorFormat:g}=m;if(c.includes("onFail")&&g)return r=g({isSuccess:!1,errorMsg:t(n)}),void l(r);u&&(r=u(r)),e("IOSCallbackEvFormat",`IOS设备回调事件处理完成,返回数据:${JSON.stringify(r)}`),l(r);const v=this.iosCallBackList.findIndex(e=>e.id===s);this.iosCallBackList.splice(v,1)},base64Decode(e){let t,i,n,o,a,r,s,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",d="",l=0;for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");l<e.length;)o=c.indexOf(e.charAt(l++)),a=c.indexOf(e.charAt(l++)),r=c.indexOf(e.charAt(l++)),s=c.indexOf(e.charAt(l++)),t=o<<2|a>>4,i=(15&a)<<4|r>>2,n=(3&r)<<6|s,d+=String.fromCharCode(t),64!=r&&(d+=String.fromCharCode(i)),64!=s&&(d+=String.fromCharCode(n));return d=this._utf8_decode(d),d},_utf8_decode(e){let t="",i=0,n=0,o=0,a=0;for(;i<e.length;)n=e.charCodeAt(i),n<128?(t+=String.fromCharCode(n),i++):n>191&&n<224?(a=e.charCodeAt(i+1),t+=String.fromCharCode((31&n)<<6|63&a),i+=2):(a=e.charCodeAt(i+1),o=e.charCodeAt(i+2),t+=String.fromCharCode((15&n)<<12|(63&a)<<6|63&o),i+=3);return t},checkMobileModuleBack(e,t,i){const n=i?"custom":e,o=`${i?"call":t}Callback`;window.c2.hasOwnProperty(n)||(window.c2[n]={}),window.c2[n].hasOwnProperty(o)||(window.c2[n][o]={})}},M={defaults:{headers:{},baseURL:""},interceptor:{request:null,response:null},request(i={}){if(uni?.request)return new Promise((e,n)=>{let o=t(i);o?("function"!=typeof this.interceptor?.request||i.ignore||(o=this.interceptor.request(i)),p()||this.executeNormalRequest(o,e,n)):e(!1)});e("request","当前环境非UNI编译的项目,无法执行请求操作,请自行使用接口请求插件实现","warn")},executeNormalRequest(e,t,i){uni.request({url:`${this.defaults.baseURL}${e.url}`,header:e?.header||{},data:e?.data||{},method:e?.method||"GET",success:e=>{if("function"==typeof this.interceptor.response){const i=this.interceptor.response(e);return void t(i)}t(e)},fail:e=>{i(e)}})},executeCloudRequest(e,t,i){}},b={menuBtnConfig(t={}){return!(!m()&&h)&&new Promise((i,n)=>{e("menuBtnConfig",`配置APP胶囊按钮清单显示,配置信息:${JSON.stringify(t)}`,"log");let o=!0;for(let i in t){if("object"!=typeof t[i]){o=!1,e("menuBtnConfig","配置参数错误","error","请传入一个Object配置数据");break}}if(o)if(v())this.miniAppH5SendMsgToApp(i,"menuBtnConfig",t,"配置APP的胶囊按钮清单显示");else{if(m()||!uni||!uni?.sendNativeEvent)return e("menuBtnConfig","配置APP胶囊按钮清单显示功能无法在非UNI环境运行","log"),void i(!1);try{e("menuBtnConfig","开始执行配置APP胶囊按钮清单显示","log"),uni?.sendNativeEvent("Util_MiniAppConfigMenu",t)}catch(t){e("menuBtnConfig","配置APP的胶囊按钮清单显示时发生异常","error",t)}}})}},I={wvInfo:null,isHarmony:!1,isCheckDevice:!1,async initMessage(...t){const i=t[0];await this.checkDeviceInfo(),await this.initVMInfo(t[2]),m()?window.addEventListener("message",t=>{e("initMessage",`浏览器webview接收到的消息内容,${JSON.stringify(t)}`,"log"),this.getMsgFromH5(t)}):(e("initMessage",`非浏览器中的webview接收到的消息内容,${JSON.stringify(i)}`,"log"),this.getMsgFromH5(i))},checkDeviceInfo(){this.isCheckDevice||(this.isCheckDevice=!0,uni.sendNativeEvent("System_getAppInfo",{},e=>{this.isHarmony=e?.platform?.toLowerCase().includes("harmony")}))},initVMInfo(t){if(!this.wvInfo)if(this.isHarmony)this.wvInfo=uni.createWebviewContext("webview",t);else try{this.wvInfo=t,t?.$scope?.$getAppWebview()&&(this.wvInfo=t.$scope.$getAppWebview().children()[0])}catch(t){e("initMessage","初始化消息模块,是否包含wvInfo:"+typeof this.wvInfo?.evalJS)}},getMsgFromH5(t={}){let i=this.getMsgDataFromH5(t);const{origin:n}=t||{},{href:o}=location||{};if(m()&&o?.includes(n))return!1;const{isH5Send:a,methodName:r,methodData:s}=i||{};return!!a&&(r?null==s?(e("getMsgFromH5","请传入需要执行的事件数据","warn"),!1):(e("getMsgFromH5",`需要执行的事件名称【${r}】,需要执行的事件数据【${JSON.stringify(s)}】,是否为H5发送的消息【${a}】`,"log"),void(this[r]?this.executeH5MethodName(r,i):e("getMsgFromH5",`【${r}】事件不存在`,"warn"))):(e("getMsgFromH5","请传入需要执行的事件名称","warn"),!1))},executeH5MethodName(t,i){const{msgId:n,methodData:o}=i;try{const i=this[t].toString();if(e("executeH5MethodName",`【${t}】方法定义:${i}`,"log"),i.includes("Promise"))return void this[t](o).then(i=>{e("executeH5MethodName",`${t}方法执行结果:${JSON.stringify(i)}`,"log");let o=i;try{o=JSON.parse(i)}catch(t){e("executeH5MethodName","强制给数据进行序列化失败","error",t)}this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:o,isWebviewSend:!0,resultMessage:`执行${t}方法完成`})}).catch(i=>{e("executeH5MethodName",`${t}方法执行失败`,"error",i),this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:null,isWebviewSend:!0,resultMessage:`执行${t}方法失败,具体错误信息,请查看控制台`})});this[t](o),this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:null,isWebviewSend:!0,resultMessage:`执行${t}方法完成`})}catch(i){e("getMsgFromH5",`${t}方法执行失败`,"error",i)}},postMsgToH5(t){const i=JSON.stringify(t);if(e("postMsgToH5",`消息内容:${i}`,"log"),m()){e("postMsgToH5","父页面运行在浏览器","log");document.querySelector("iframe").contentWindow.postMessage(JSON.stringify(i),"*")}else try{e("postMsgToH5","父页面运行在非浏览器","log"),this.wvInfo.evalJS(`getMessageFromWebview('${i}')`)}catch(t){e("postMsgToH5","执行浏览器的webview回传异常","error",t)}},getMsgDataFromH5(t){let i=null;const{data:n}=t;try{i=m()?n?.data?.arg?n?.data?.arg:n?.data?n.data:n:t.detail?.data[0]}catch(t){return e("getMsgDataFromH5","处理消息内容时发生异常","error",t),!1}return e("getMsgDataFromH5",`获取到的消息内容:${JSON.stringify(i)}`,"log"),i}},C=(t,i,n)=>{if(e("_parseFunction",`${JSON.stringify(t)}`),"function"==typeof t)return n[i]=t,void(t="[Function]::"+i);if("object"!=typeof t)return;let o=null;for(let e in t)switch(typeof t[e]){case"object":o=i?i+"_"+e:e,C(t[e],o,n);break;case"function":o=i?i+"_"+e:e,n[o]=t[e],t[e]="[Function]::"+o}},$=e=>{let t=0;return"string"==typeof e?t=1:"number"==typeof e?t=2:"boolean"==typeof e?t=3:"function"==typeof e?t=4:e instanceof Array?t=6:"object"==typeof e&&(t=5),t},D={appH5SendMsgToApp(i,n={},o={}){const{isWindowEv:a,description:r,moduleName:s,nativeEvName:c,isCustomEv:d}=n;if(a)return void this.h5SendMsgToAppByWindow(i,n,o);const m=d?"custom":s,u=d?"call":c,g=this;try{let a={};if(("object"==typeof o?Object.keys(o):[]).length>0&&(a=t(o)),d){const i=t(a);e("webviewSendMsgToApp",`${r}功能在是通过custom.call的方式调用,需要重新处理入参`),a.params=i,a.action=c}e("webviewSendMsgToApp",`${r}的完整参数:${JSON.stringify(a)}`),this.initEventCallbackEv(i,a,n);const s=function(){return g.formatBridgeData(window.c2[m][`${u}Callback`],arguments)}(a);e("webviewSendMsgToApp",`${r}功能在${l()}的Webview环境下执行,调用参数:${JSON.stringify(s)}`),this.h5SendMsgToAppByBrowser(i,n,s)}catch(t){console.log(`🚀发送消息给APP出现错误,错误信息:${t},${JSON.stringify(t)}`),e("webviewSendMsgToApp",`${r}执行数据处理失败`,"error",t)}},initEventCallbackEv(i,n,o={}){const{description:a,resDataFormat:r,resErrorFormat:s}=o;n.onSuccess=function(t){e("webviewSendMsgToApp",`${a}功能在App的Webview环境下执行完成`),i(r?r(t):t)},n.onFail=function(n){const o=t(n);e("webviewSendMsgToApp",`${a}功能在App的Webview环境下执行失败,收到的回调数据:::${JSON.stringify(o)}`),i(s?s(o):r?r(o):o)}},formatBridgeData(t,i){try{const n=Math.random().toString(32).slice(2),o=[];for(let e in i){const a=n+"_a"+e,r=i[e],s={};!1===/OpenHarmony ([5-9])|OpenHarmony (\d{2})/i.test(navigator.userAgent)&&C(r,a,s);for(let e in s)t[e]=s[e],this.C2ReceiveQueue.push(t);o.push({type:$(r),name:a,value:r})}return e("formatBridgeData",`格式化后的参数:${JSON.stringify(o)}`),{params:o,id:n}}catch(t){e("formatBridgeData","消息通讯数据格式化异常","error",t)}},h5SendMsgToAppByWindow(t,i={},n={}){const{nativeEvName:a,description:r,resDataFormat:s}=i,c=l(),d=`${a}Back`;let m=n;e("h5SendMsgToAppByWindow",`给【${c}】APP发送【${r}】-【${a}】事件调用,回调函数名称:【${d}】`,"log"),window[d]=i=>{let n=i;e("h5SendMsgToAppByWindow",`收到【${c}】APP发送的${r}事件调用的回调值:${JSON.stringify(n)},回调数据类型::${typeof n}`,"log"),n=o(n),t(s?s(n):n)},setTimeout(()=>{"ios"!==c.toLowerCase()?"android"!==c.toLowerCase()?window.harmony[a](m):window.android[a](m):window.webkit.messageHandlers[a].postMessage(m)},100)},h5SendMsgToAppByBrowser(t,i={},n={}){const o=l();e("h5SendMsgToAppByBrowser",`给【${o}】APP发送【${i.nativeEvName}】事件调用,入参:${JSON.stringify(n)}`,"log");const{nativeEvName:a,moduleName:r,isCustomEv:s}=i,{id:c,params:d}=n;if("android"!==o)return"ios"===o?(this.iosCallBackList.push({id:c,resolveInfo:t,configInfo:i}),void this.h5SendMsgToIOS(c,r,a,d,s)):void("harmony"===o&&this.h5SendMsgToHarmony(c,r,a,d,s));this.h5SendMsgToAndroid(c,r,a,d,s)},h5SendMsgToAndroid(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToAndroid",`发送给安卓APP的消息:${JSON.stringify(r)}`),JSON.parse(window.AndroidFunction.callAndroidFun(JSON.stringify(r)))},h5SendMsgToIOS(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToIOS",`发送给IOS APP的消息:${JSON.stringify(r)}`),JSON.parse(prompt(JSON.stringify(r)))},h5SendMsgToHarmony(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToHarmony",`发送给鸿蒙APP的消息:${JSON.stringify(r)}`),JSON.parse(window.harmonyFunction.callHarmonyFun(r))}},k={msgList:[],msgStack:[],async miniAppH5SendMsgToApp(t,i,n){try{e("miniAppH5SendMsgToApp",`发送消息给webview:${i}`,"log");const o=await this.sendMsgToMiniApp({methodName:i,methodData:n});t(o?.resultInfo)}catch(n){e("miniAppH5SendMsgToApp",`执行${i}失败`,"error",n),t({isSuccess:!1,message:"执行事件失败,详情查看控制台"})}},sendMsgToMiniApp(t){return new Promise((n,o)=>{e("postMsgToWebview",`消息内容:${JSON.stringify(t)}`,"log");const{methodName:a,methodData:r}=t||{};if(!a)return void e("postMsgToWebview","请传入要调用的事件名称","warn");if(!r)return void e("postMsgToWebview","请传入要调用事件的数据信息","warn");const s=i(),c={data:{msgId:s,isH5Send:!0,...t}};if(this.msgList.push({id:s,resolveInfo:n,rejectInfo:o}),e("postMsgToWebview",`发送消息给父容器页面:${JSON.stringify(c)}`,"log"),!this.uniSDKInit)return e("postMsgToWebview","SDK尚未初始化完成,先行执行堆栈","log"),void this.msgStack.push({id:i(),msgContent:c,resolve:n,reject:o});uni?.webView?.postMessage?uni.webView.postMessage(c):uni?.postMessage(c)}).catch(t=>{e("postMsgToWebview","发生异常","error",t)})}},F={getMessageFromWebview(t,i=!1){let n={};try{n=i?t:t?.data||"{}",n=o(n)}catch(t){e("getMessageFromWebview","解析数据异常","error",t)}if(e("getMessageFromWebview",`是否为webview发送的消息内容:${n?.isWebviewSend},消息内容:${JSON.stringify(n)}`,"log"),!n?.isWebviewSend)return;const{msgId:a}=n,r=this.msgList.findIndex(e=>e.id===a);if(-1===r)return;const s=this.msgList[r],{resolveInfo:c}=s;c(n),this.msgList.splice(r,1)}},P=["getLoginUserInfo","getAuthToken"];let T=new class{version="";isInit=!1;isWebviewPage=!1;anaSDKInit=!1;uniSDKInit=!1;iosCallBackList=[];C2ReceiveQueue=[];constructor(e,t){this.version=e,this.isInit=!1,this.isWebviewPage=t,this.iosCallBackList=[],this.initModuleMethod(),this.initSDKAPI()}initModuleMethod(){n(A,this),n(E,this),n(M,this),n(b,this),n(I,this),n(D,this),n(k,this),n(F,this)}init(t){m()?(v()&&this.initWebviewMsgFormat(),this.initUNISDK(),this.trackSDKInit(t)):e("init","当前环境非浏览器环境,无需执行初始化动作","warn")}initWebviewMsgFormat(){e("initWebviewMsgFormat","初始化被嵌套的页面消息通讯","log"),m()?(window.addEventListener("message",t=>{e("initWebviewMsgFormat","浏览器消息处理","log"),this.getMessageFromWebview(t)}),window.getMessageFromWebview=t=>{e("initWebviewMsgFormat","事件注入消息处理","log"),this.getMessageFromWebview(t,!0)}):e("initWebviewMsgFormat","该API仅支持在被webview嵌套的H5页面中使用","error","")}initUNISDK(){m()&&this.loadUniWebviewSDK().then(()=>{window?.uni&&"function"==typeof window?.uni?.webView?.postMessage&&(this.uniSDKInit=!0,e("initUNISDK","UNI Webview SDK 挂载完成"))})}loadUniWebviewSDK(){return e("loadUniWebviewSDK","开始挂载UNI-WEBVIEW SDK文件","log"),new Promise(e=>{const t=document.createElement("script");t.src="https://mobile.zwfw.hunan.gov.cn:8088/uni.webview.1.5.6.js",t.onload=e,document.head.appendChild(t)}).catch(t=>(e("loadUniWebviewSDK","加载uni-webview SDK异常","error",t),!1))}initSDKAPI(){p()&&(e("initSDKAPI","App的Webview环境,初始化C2调用链的回调函数"),this.initMobileBridgeGlobalConfig()),e("initSDKAPI","开始初始化SDK API"),w.forEach(t=>{const{eventName:i,moduleName:n,nativeEvName:o,isCustomEv:a}=t;if((n&&o||a)&&p()&&(e("initSDKAPI",`初始化C2调用链的回调函数:${i}`),this.checkMobileModuleBack(n,o,a)),!P?.includes(i))try{this[i]=e=>new Promise(i=>{this.normalEvDataTransition(i,e,t)})}catch(t){e("initSDKAPI","执行API初始化挂载异常","error",t)}})}normalEvDataTransition(t,i={},n={}){const{eventName:o,description:a,reqDataFormat:r}=n||{},s=l();if(m()&&!u())return t({code:-1,isSuccess:!1,data:{},msg:"当前环境不支持该功能"}),void e(o,`${a}功能在浏览器环境执行失败,请检查是否为湘易办相关环境`,"warn");let c=i;if(r&&(c=r(i)),c){if(p())return e("normalEvDataTransition",`开始调用APP的嵌套H5能力,事件名称:${o},入参:${JSON.stringify(c)}`),void this.appH5SendMsgToApp(t,n,c);if(g())return e("normalEvDataTransition",`开始调用小程序/H5嵌套的H5能力,事件名称:${o},入参:${JSON.stringify(c)}`),void this.miniAppH5SendMsgToApp(t,o,c,a);e("normalEvDataTransition",`开始小程序调用原生能力,事件名称:${o},入参:${JSON.stringify(c)}`),this.executeEvByNative(t,c,n)}else e(o,`给【${s}】APP发送【${a}】-【${o}】事件失败,请检查数据格式是否正确`,"error")}executeEvByNative(t,i,n){const{description:a,uniEvName:r}=n;try{e("executeEvByNative",`开始调用原生${a}的能力,API名称:${r},格式化前的参数信息:${JSON.stringify(i)}`),uni.sendNativeEvent(r,i,i=>{e("executeEvByNative",`调用原生${a}的能力完成,结果:${JSON.stringify(i)}`,"log"),((t={},i={})=>{let n=i;try{n=o(i)}catch(t){e("formatResponseData","格式化失败","error",t),n=i}t(n)})(t,i)})}catch(t){e("executeEvByNative",`${a}API执行异常`,"error",t)}}}(N,v());m()&&(window.xybAgent=T);export{T as default};
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).xybAgent=t()}(this,function(){"use strict";const e=(e="",t="",i="log",n="")=>{const o={error:"错误",warn:"警告",info:"提示",log:"日志"}[i]||"日志",a=JSON.stringify(n);console.log(`\n=============🚀START - V${f} 🚀=============\n【事件名称】:${e} \n【日志类型】:${o} \n【日志信息】:${t} ${"error"===i?`【错误信息】:${JSON.stringify(a)}`:""} \n==============🚀END🚀==============`),console.log("")},t=(t={})=>{if("function"==typeof t)return e("deepClone","数据类型为function,无法执行深拷贝,请检查","error"),t;try{return JSON.parse(JSON.stringify(t))}catch(i){return e("deepClone","执行数据深拷贝异常","error",i),t}},i=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}),n=(e={},t={})=>{for(let i in e)t[i]=e[i]};let o={finished:!1,result:!1},a={finished:!1,result:!1},r={finished:!1,result:!1},s={finished:!1,result:!1};const c=()=>l()?navigator.userAgent.toLowerCase():"",d=()=>uni?.getSystemInfoSync()?.platform||!1,l=()=>window&&document,m=()=>{if(r.finished)return r.result;if(r.finished=!0,!l())return r.result=!1,!1;const t=c();return r.result=t.includes("xybwebcomponent"),e("checkIsXybBrowserEnv",`当前是否为湘易办浏览器环境:${r.result}`),r.result},u=()=>{const{finished:t,result:i}=o;return t?i:(o.result=m()||(()=>{if(s.finished)return s.result;if(s.finished=!0,!l())return s.result=!1,!1;const t=c();return s.result=t.includes("uni-app")&&!t.includes("xybwebcomponent"),e("checkIsMiniAppBrowserEnv",`当前是否为小程序的浏览器环境:${s.result}`),s.result})(),o.finished=!0,e("checkIsWebviewEnv",`当前是否为Webview环境:${o.result}`),o.result)},g=()=>{const{finished:t,result:i}=a;if(t)return i;if(a.finished=!0,!l())return a.result=!1,!1;const n=c();return a.result=m()&&!n.includes("uniminiapp"),e("checkIsAppWebviewEnv",`当前是否为APP的Webview环境:${a.result}`),a.result},p=()=>l()?c().includes("micromessenger"):"mp-weixin"===d(),v=t=>{const{dinateType:i}=t;return e("replaceCoordinate",`坐标转换开始:${i}`,"log"),(e=>{const{lat:t,lng:i,address:n}=e,o=52.35987755982988,a=i-.0065,r=t-.006,s=Math.sqrt(a*a+r*r)-2e-5*Math.sin(r*o),c=Math.atan2(r,a)-3e-6*Math.cos(a*o);return{destinationName:n,destinationLongitude:s*Math.cos(c).toFixed(6),destinationLatitude:s*Math.sin(c).toFixed(6)}})(t)},h=[{isCustomEv:!0,eventName:"authFace",uniEvName:"Auth_face",description:"人脸识别功能",nativeEvName:"faceAuth",reqDataFormat:t=>{e("authFace",`执行人脸验证,参数信息:${JSON.stringify(t)}`);const{name:i,certNo:n,appId:o,sign:a,created:r,nonce:s}=t;return i&&n&&o&&a&&r&&s?t:(e("authFace","缺少必要参数:name, certNo, appId, sign, created, nonce","error","缺少必要参数"),!1)},resDataFormat:e=>({isSuccess:Boolean(e),certifyId:e}),resErrorFormat:e=>"harmony"===d().toLowerCase()?{isSuccess:!1,errorMsg:e}:e},{isCustomEv:!0,eventName:"startNavigation",uniEvName:"Start_navigation",description:"目的地导航",nativeEvName:"start_navigation",reqDataFormat:t=>{let i={};const{dinateType:n,lat:o,lng:a,address:r}=t;return e("replaceCoordinate",`坐标系值:LAT:${o},LNG:${a}`,"log"),i=n&&"GCJ02"!==n?v(t):{destinationLatitude:o,destinationLongitude:a,destinationName:r},e("replaceCoordinate",`转换后值:LAT:${i.destinationLatitude},LNG:${i.destinationLongitude}`,"log"),i}},{isWindowEv:!0,eventName:"getLoginStatus",uniEvName:"Auth_checkLogin",description:"获取登录状态",nativeEvName:"CallNativeMethodGetUserInfo",resDataFormat:e=>{const i=t(e);return{logined:1===Number(i?.isLogin)}},resErrorFormat:()=>({logined:!1})},{isWindowEv:!0,eventName:"getLoginUserInfo",uniEvName:"Auth_getUserInfo",description:"获取登录用户数据信息",nativeEvName:"CallNativeMethodGetUserInfo",resDataFormat:e=>t(e),resErrorFormat:()=>({isSuccess:!1})},{isCustomEv:!0,eventName:"getAuthToken",uniEvName:"Auth_getToken",description:"获取授权token",nativeEvName:"get_token",resDataFormat:e=>{try{const i=t(e);return{token:i?.token,isSuccess:Boolean(i?.token)}}catch(t){return{token:e?.token,isSuccess:Boolean(e?.token)}}},resErrorFormat:()=>({isSuccess:!1})},{isWindowEv:!0,eventName:"getAccessLink",uniEvName:"Auth_getAccessLink",nativeEvName:"CallNativeMethodGetAccessLink",description:"获取授权链接",resDataFormat:e=>"ios"===d().toLowerCase()?{isSuccess:!0,accessLink:e}:t(e),resErrorFormat:()=>({isSuccess:!1})},{moduleName:"image",eventName:"chooseImg",uniEvName:"Image_choose",nativeEvName:"chooseImage",description:"选择本地图片",reqDataFormat:e=>{const{count:t,sizeType:i,sourceType:n,isCircleCrop:o}=e||{};return{count:t||9,sizeType:i||["original","compressed"],sourceType:n||["album"],isCircleCrop:o||!1}},resDataFormat:e=>t(e)},{moduleName:"image",eventName:"imgPreview",uniEvName:"Image_preview",nativeEvName:"previewImage",description:"执行图片预览"},{moduleName:"image",eventName:"imgUpload",uniEvName:"Image_upload",nativeEvName:"uploadImage",description:"执行图片上传",resDataFormat:e=>t(e),resErrorFormat:e=>e},{eventName:"imgDownload",uniEvName:"Image_download",nativeEvName:"",description:"执行图片下载"},{eventName:"fileUpload",uniEvName:"File_upload",nativeEvName:"",description:"执行文件上传"},{moduleName:"file",eventName:"fileDownload",uniEvName:"File_download",nativeEvName:"downloadFile",description:"执行文件下载",resDataFormat:e=>({isSuccess:Boolean(e),resultObj:{path:e}})},{moduleName:"file",eventName:"filePreview",uniEvName:"File_preview",nativeEvName:"previewFile",description:"执行文件预览"},{moduleName:"file",eventName:"openLocalFile",uniEvName:"File_openLocal",nativeEvName:"openLocalFile",description:"执行打开本地文件"},{moduleName:"file",eventName:"chooseLocalFile",uniEvName:"File_chooseLocal",nativeEvName:"chooseLocalFile",description:"选择本地文件",resDataFormat:e=>t(e)},{moduleName:"file",eventName:"openThirdFile",uniEvName:"File_openThirdParty",nativeEvName:"openFileWithThirdParty",description:"执行打开第三方文件"},{eventName:"openApp",uniEvName:"Util_openApp",nativeEvName:"",description:"打开APP"},{isCustomEv:!0,eventName:"openXybApp",uniEvName:"Util_openXYBMiniApp",nativeEvName:"jumpToMiniApp",description:"打开湘易办融合APP小程序",reqDataFormat:e=>{if(g()){const{pageUrl:t}=e;return{...e,path:t}}return e}},{eventName:"postMsgToOtherApp",uniEvName:"Util_postMessageToXYBMiniApp",nativeEvName:"",description:"发送消息给其他小程序"},{isWindowEv:!0,eventName:"scanCode",uniEvName:"Scan_code",description:"扫描二维码",nativeEvName:"CallNativeMethodScanQRCode",resDataFormat:e=>({text:e})},{moduleName:"system",eventName:"getAppInfo",nativeEvName:"getAppInfo",description:"获取应用信息",uniEvName:"System_getAppInfo",resDataFormat:e=>t(e)},{moduleName:"util",eventName:"copyToClipboard",uniEvName:"Util_clipboardData",nativeEvName:"clipboardData",description:"复制内容到剪切板",reqDataFormat:e=>({text:e}),resDataFormat:e=>g()?{isSuccess:Boolean(e)}:{isSuccess:!0}},{moduleName:"util",eventName:"getCacheSize",uniEvName:"Util_getCacheSize",nativeEvName:"getCacheSize",description:"获取缓存大小",resDataFormat:e=>t(e)},{moduleName:"util",eventName:"clearCache",uniEvName:"Util_clearCache",nativeEvName:"clearCache",description:"执行缓存清除",resDataFormat:()=>({isSuccess:!0}),resErrorFormat:()=>({isSuccess:!1})},{moduleName:"telephone",eventName:"callPhone",uniEvName:"Util_callDesignateNumber",nativeEvName:"call",description:"拨打电话",reqDataFormat:e=>g()?{phoneCode:"+86",phoneNumber:String(e).replace("+86","")}:{text:e}},{eventName:"forbidScreenShot",uniEvName:"Util_forbidScreenShot",nativeEvName:"",description:"执行禁止截屏"},{eventName:"setScreenLight",uniEvName:"Util_setScreenLight",nativeEvName:"",description:"设置屏幕是否常亮",reqDataFormat:e=>({idleTimerValue:e})},{eventName:"sendMatterId",uniEvName:"Param_MatterID",nativeEvName:"",description:"执行页面事件ID上报",reqDataFormat:e=>({matterID:e})},{isWindowEv:!0,description:"获取位置信息",eventName:"getLocationInfo",uniEvName:"Util_getLocationInformation",nativeEvName:"CallNativeMethodGetLocationInformation",resDataFormat:e=>({isSuccess:!0,location:t(e)}),resErrorFormat:()=>({isSuccess:!1,location:{}})},{eventName:"checkPermission",uniEvName:"Auth_matterHandleAuthority",nativeEvName:"",description:"检查事项权限",reqDataFormat:e=>({matterCode:e})},{eventName:"showComment",uniEvName:"Util_jumpToComment",nativeEvName:"",description:"打开评价弹窗"},{isWindowEv:!0,description:"打开微信小程序",eventName:"openWechatMiniApp",uniEvName:"Util_openWechatMiniProgram",nativeEvName:"CallNativeMethodJumpToWechatMiniProgram",reqDataFormat:e=>{if(g()){const t={};for(let i in e)t[i]=String(e[i]);return JSON.stringify(t)}return e}},{isWindowEv:!0,description:"打开支付宝小程序",eventName:"openAliPayMiniApp",uniEvName:"Util_openAlipayMiniProgram",nativeEvName:"CallNativeMethodJumpToAliPay",reqDataFormat:e=>g()?JSON.stringify(e):e},{eventName:"showMenuPanel",uniEvName:"menu_present",nativeEvName:"",description:"显示菜单面板"}],f="0.0.2",N=e=>Number(e)>9?e:`0${e}`,w=()=>{const e=new Date;return`${e.getFullYear()}-${N(e.getMonth()+1)}-${N(e.getDate())} ${N(e.getHours())}:${N(e.getMinutes())}:${N(e.getSeconds())}`},S={trackStack:[],anaSDKLoadTimes:0,locationInfo:{},isProdEnv:!1,track(t="",n={}){if(t){if(n)return l()&&!this.anaSDKInit?(this.trackStack.push({id:i(),eventID:t,eventPro:n}),void e("track","埋点上报插件初始化未完成,本次数据在插件初始化后自动上报","log")):void this.executeTrack(t,n);e("track","埋点数据上报失败","error","请传入埋点数据")}else e("track","埋点数据上报失败","error","请传入埋点事件")},async executeTrack(t="",i={}){if("object"==typeof t)return void await this.track(t?.eventID,t?.eventPro);const n=await this.initTrackParams(i);if(e("track",`执行埋点数据上报,事件名称:${t},事项编码:${n.code},完整埋点数据:${JSON.stringify(n)}`,"log"),l()&&xybAgent?.AnalysysAgent)return e("track","通过浏览器插件执行埋点数据上报","log"),void window.xybAgent.AnalysysAgent.track(t,n);if("undefined"!=typeof uni&&Object.prototype.hasOwnProperty.call(uni,"sendNativeEvent"))try{e("track",`埋点数据:${JSON.stringify(n)},埋点ID:${t}`,"log"),uni.sendNativeEvent("Analysis_common",{eventID:t,eventPro:n})}catch(t){e("track","执行数据埋点功能异常","error",t)}},loadAnaSDK:()=>new Promise(e=>{const t=document.createElement("script");t.src="https://mobile.zwfw.hunan.gov.cn:8088/AnalysysAgent_JS_SDK.min.js",t.onload=e,document.head.appendChild(t)}),trackSDKInit(t){return new Promise((i,n)=>{l()||(e("initTrack","非浏览器环境无需使用init执行初","error"),i(!0)),this.anaSDKInsert?this.configAnaSDK(t,i):this.loadAnaSDK().then(()=>{window.AnalysysAgent&&(xybAgent.AnalysysAgent=window.AnalysysAgent,this.anaSDKInsert=!0,this.configAnaSDK(t,i))})})},configAnaSDK(t,i){const n="800c298f0c42c94c",o="40d556c15f872084";let a=location?.host?.includes("hunan.gov.cn")?n:o;if("object"==typeof t)a=o;else{const e={production:n,development:o},i=[n,o];(e[t]||i.includes(t))&&(a=e[t]?e[t]:t)}this.isProdEnv=a===n,l()?(window.xybAgent.AnalysysAgent&&(window.xybAgent.AnalysysAgent.init({appkey:a,uploadURL:"https://mobile.zwfw.hunan.gov.cn:8088/aurora-api"}),e("_initSDK","xybAgent已初始化完成,可正常执行埋点操作","log"),this.anaSDKInit=!0,this.isInit=!0,this.checkTrackStack(),i(!0)),!Boolean(window.xybAgent.AnalysysAgent)&&this.anaSDKLoadTimes<10&&setTimeout(()=>this.trackSDKInit(i),300),!Boolean(window.xybAgent.AnalysysAgent)&&this.anaSDKLoadTimes>=10&&(e("_initSDK","xybAgent初始化失败","error","请检查app key、uploadURL是否正确"),i(!1))):i(!1)},async initTrackParams(e={}){const{code:t,name:i,aff_city_code:n,aff_city_name:o,unit_code:a,area_code:r,unit_name:s,is_finish:c,category:d,user_id:l,miniAppCode:m,$url_domain:u}=e,g=this.getVisitSource(),p=this.getPageSource(),v=await this.getPositionInfo();return{code:t||void 0,name:i||void 0,aff_city_code:n||void 0,aff_city_name:o||void 0,unit_code:a||void 0,area_code:r||void 0,unit_name:s||void 0,is_finish:c||void 0,category:d||void 0,user_id:l||void 0,miniAppCode:m||void 0,$url_domain:u||void 0,curr_time:w(),source:g,page_source:p,location:v}},getVisitSource(){if(!l()){const e=uni?.getSystemInfoSync(),{uniPlatform:t}=e||{};return"mp-weixin"===t?"wx":"mp-alipay"===t?"alipay":"app"}return p()?"wx":(l()?c().includes("alipay"):"mp-alipay"===d())?"alipay":"app"},checkTrackStack(){e("checkTrackStack","xybAgent已初始化完成,执行埋点数据堆栈检测","log");t(this.trackStack).forEach(t=>{const{eventID:i,eventPro:n,id:o}=t;e("checkTrackStack",`执行id值为${o} 的埋点数据再次上报`,"log"),this.track(i,n);const a=this.trackStack.findIndex(e=>e.id===o);a>-1&&this.trackStack.splice(a,1)})},getPageSource(){let t=null;t=l()?location.href:decodeURIComponent(((t=!1)=>{let i="";try{const n="function"==typeof getCurrentPages?getCurrentPages():[];e("getCurrentPagePath",`路径清单::${n}`,"log");const o=n?.length||0;o&&(e("getCurrentPagePath",`获取当前页面路径 -1 :${n[n.length-1]?.route}`,"log"),e("getCurrentPagePath",`获取当前页面路径 -2 :${n[n.length-2]?.route}`,"log"),i=n[o-(t?2:1)]?.route||"")}catch(t){e("getCurrentPagePath","获取当前页面路径时发生异常","error",t)}return i})());const i=t?.includes("source=");if(!i)return"click";const n=t.split("source=")[1];let o="click";return o=n.includes("&")?n.split("&")[0]:n,["copy","share","click","search"].includes(o)?o:"click"},async getPositionInfo(){if(!this.locationInfo?.province)try{const{location:e}=await this.getLocationInfo()||{};this.locationInfo=e||""}catch(e){this.locationInfo={}}return JSON.stringify(this.locationInfo)}},y={initMobileBridgeGlobalConfig(){const t=d();e("initMobileBridgeGlobalConfig",`开始初始化移动端桥链接配置,访问设备类型:${t}`),window.c2={},"ios"===t&&this.initIOSCallbackEvConfig(),"android"===t&&this.initAndroidCallbackEvConfig(),e("initMobileBridgeGlobalConfig","初始化移动端桥链接配置完成"),window.CreatorJsBridge=window.c2},initIOSCallbackEvConfig(){try{const t=this;window.c2.iOS={},window.c2.iOS.callJS=function(){window?.c2.iOS?.callJSCallback||(window.c2.iOS.callJSCallback={}),e("initIOSCallbackEvConfig",`开始处理IOS设备回调事件,回调数据:${JSON.stringify(arguments)}`),t.IOSCallbackEvFormat(arguments[0])}}catch(t){e("initIOSCallbackEvConfig","初始化IOS回调事件配置异常","error",t)}},initAndroidCallbackEvConfig(){window.c2.sendDataWarpToWeb=(e,t,i)=>{e(i)}},IOSCallbackEvFormat(i){const{returnValue:n,funcName:o}=i;let a=this.base64Decode(n);a.startsWith("{")&&a.endsWith("}")&&(a=JSON.parse(a)),e("IOSCallbackEvFormat",`IOS设备回调事件处理开始,回调数据:${JSON.stringify(a)}, 格式:${typeof a}`);const r=o.split("_a")[0],s=o.replace(r,""),c=this.iosCallBackList.find(e=>e.id===r);if(!c)return;const{resolveInfo:d,configInfo:l}=c,{resDataFormat:m,resErrorFormat:u}=l;if(s.includes("onFail")&&u)return a=u({isSuccess:!1,errorMsg:t(n)}),void d(a);m&&(a=m(a)),e("IOSCallbackEvFormat",`IOS设备回调事件处理完成,返回数据:${JSON.stringify(a)}`),d(a);const g=this.iosCallBackList.findIndex(e=>e.id===r);this.iosCallBackList.splice(g,1)},base64Decode(e){let t,i,n,o,a,r,s,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",d="",l=0;for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");l<e.length;)o=c.indexOf(e.charAt(l++)),a=c.indexOf(e.charAt(l++)),r=c.indexOf(e.charAt(l++)),s=c.indexOf(e.charAt(l++)),t=o<<2|a>>4,i=(15&a)<<4|r>>2,n=(3&r)<<6|s,d+=String.fromCharCode(t),64!=r&&(d+=String.fromCharCode(i)),64!=s&&(d+=String.fromCharCode(n));return d=this._utf8_decode(d),d},_utf8_decode(e){let t="",i=0,n=0,o=0,a=0;for(;i<e.length;)n=e.charCodeAt(i),n<128?(t+=String.fromCharCode(n),i++):n>191&&n<224?(a=e.charCodeAt(i+1),t+=String.fromCharCode((31&n)<<6|63&a),i+=2):(a=e.charCodeAt(i+1),o=e.charCodeAt(i+2),t+=String.fromCharCode((15&n)<<12|(63&a)<<6|63&o),i+=3);return t},checkMobileModuleBack(e,t,i){const n=i?"custom":e,o=`${i?"call":t}Callback`;window.c2.hasOwnProperty(n)||(window.c2[n]={}),window.c2[n].hasOwnProperty(o)||(window.c2[n][o]={})}},A={defaults:{headers:{},baseURL:""},interceptor:{request:null,response:null},request(i={}){if(uni?.request)return new Promise((e,n)=>{let o=t(i);o?("function"!=typeof this.interceptor?.request||i.ignore||(o=this.interceptor.request(i)),g()||this.executeNormalRequest(o,e,n)):e(!1)});e("request","当前环境非UNI编译的项目,无法执行请求操作,请自行使用接口请求插件实现","warn")},executeNormalRequest(e,t,i){uni.request({url:`${this.defaults.baseURL}${e.url}`,header:e?.header||{},data:e?.data||{},method:e?.method||"GET",success:e=>{if("function"==typeof this.interceptor.response){const i=this.interceptor.response(e);return void t(i)}t(e)},fail:e=>{i(e)}})},executeCloudRequest(e,t,i){}},M={menuBtnConfig(t={}){return!(!l()&&p)&&new Promise((i,n)=>{e("menuBtnConfig",`配置APP胶囊按钮清单显示,配置信息:${JSON.stringify(t)}`,"log");let o=!0;for(let i in t){if("object"!=typeof t[i]){o=!1,e("menuBtnConfig","配置参数错误","error","请传入一个Object配置数据");break}}if(o)if(u())this.miniAppH5SendMsgToApp(i,"menuBtnConfig",t,"配置APP的胶囊按钮清单显示");else{if(l()||!uni||!uni?.sendNativeEvent)return e("menuBtnConfig","配置APP胶囊按钮清单显示功能无法在非UNI环境运行","log"),void i(!1);try{e("menuBtnConfig","开始执行配置APP胶囊按钮清单显示","log"),uni?.sendNativeEvent("Util_MiniAppConfigMenu",t)}catch(t){e("menuBtnConfig","配置APP的胶囊按钮清单显示时发生异常","error",t)}}})}},E={initMessage(...t){e("initMessage",`初始化消息模块,当前环境为:${l()?"浏览器":"APP"},初始化消息模块:参数个数:${t.length}`,"log");const i=t[0];try{e("initMessage",`初始化消息模块,事件信息:${JSON.stringify(i)}`)}catch(t){e("initMessage","初始化消息模块,事件信息:"+typeof i,"error","序列化失败")}try{this.wvInfo=t[2],t[2]?.$scope?.$getAppWebview()&&(this.wvInfo=t[2].$scope.$getAppWebview().children()[0])}catch(t){e("initMessage","初始化消息模块,是否包含wvInfo:"+typeof this.wvInfo?.evalJS)}l()?window.addEventListener("message",t=>{e("initMessage",`浏览器webview接收到的消息内容,${JSON.stringify(t)}`,"log"),this.getMsgFromH5(t)}):(e("initMessage",`非浏览器中的webview接收到的消息内容,${JSON.stringify(i)}`,"log"),this.getMsgFromH5(i))},getMsgFromH5(t={}){let i=this.getMsgDataFromH5(t);const{origin:n}=t||{},{href:o}=location||{};if(l()&&o?.includes(n))return!1;const{isH5Send:a,methodName:r,methodData:s}=i||{};return!!a&&(r?null==s?(e("getMsgFromH5","请传入需要执行的事件数据","warn"),!1):(e("getMsgFromH5",`需要执行的事件名称【${r}】,需要执行的事件数据【${JSON.stringify(s)}】,是否为H5发送的消息【${a}】`,"log"),void(this[r]?this.executeH5MethodName(r,i):e("getMsgFromH5",`【${r}】事件不存在`,"warn"))):(e("getMsgFromH5","请传入需要执行的事件名称","warn"),!1))},executeH5MethodName(t,i){const{msgId:n,methodData:o}=i;try{const i=this[t].toString();if(e("executeH5MethodName",`【${t}】方法定义:${i}`,"log"),i.includes("Promise"))return void this[t](o).then(i=>{e("executeH5MethodName",`${t}方法执行结果:${JSON.stringify(i)}`,"log");let o=i;try{o=JSON.parse(i)}catch(t){e("executeH5MethodName","强制给数据进行序列化失败","error",t)}this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:o,isWebviewSend:!0,resultMessage:`执行${t}方法完成`})}).catch(i=>{e("executeH5MethodName",`${t}方法执行失败`,"error",i),this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:null,isWebviewSend:!0,resultMessage:`执行${t}方法失败,具体错误信息,请查看控制台`})});this[t](o),this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:null,isWebviewSend:!0,resultMessage:`执行${t}方法完成`})}catch(i){e("getMsgFromH5",`${t}方法执行失败`,"error",i)}},postMsgToH5(t){const i=JSON.stringify(t);if(e("postMsgToH5",`消息内容:${i}`,"log"),l()){e("postMsgToH5","父页面运行在浏览器","log");document.querySelector("iframe").contentWindow.postMessage(JSON.stringify(i),"*")}else try{e("postMsgToH5","父页面运行在非浏览器","log"),this.wvInfo.evalJS(`getMessageFromWebview('${i}')`)}catch(t){e("postMsgToH5","执行浏览器的webview回传异常","error",t)}},getMsgDataFromH5(t){let i=null;const{data:n}=t;try{i=l()?n?.data?.arg?n?.data?.arg:n?.data?n.data:n:t.detail?.data[0]}catch(t){return e("getMsgDataFromH5","处理消息内容时发生异常","error",t),!1}return e("getMsgDataFromH5",`获取到的消息内容:${JSON.stringify(i)}`,"log"),i}},b=(t,i,n)=>{if(e("_parseFunction",`${JSON.stringify(t)}`),"function"==typeof t)return n[i]=t,void(t="[Function]::"+i);if("object"!=typeof t)return;let o=null;for(let e in t)switch(typeof t[e]){case"object":o=i?i+"_"+e:e,b(t[e],o,n);break;case"function":o=i?i+"_"+e:e,n[o]=t[e],t[e]="[Function]::"+o}},I=e=>{let t=0;return"string"==typeof e?t=1:"number"==typeof e?t=2:"boolean"==typeof e?t=3:"function"==typeof e?t=4:e instanceof Array?t=6:"object"==typeof e&&(t=5),t},$={appH5SendMsgToApp(i,n={},o={}){const{isWindowEv:a,description:r,moduleName:s,nativeEvName:c,isCustomEv:l}=n;if(a)return void this.h5SendMsgToAppByWindow(i,n,o);const m=l?"custom":s,u=l?"call":c,g=this;try{let a={};if(("object"==typeof o?Object.keys(o):[]).length>0&&(a=t(o)),l){const i=t(a);e("webviewSendMsgToApp",`${r}功能在是通过custom.call的方式调用,需要重新处理入参`),a.params=i,a.action=c}e("webviewSendMsgToApp",`${r}的完整参数:${JSON.stringify(a)}`),this.initEventCallbackEv(i,a,n);const s=function(){return g.formatBridgeData(window.c2[m][`${u}Callback`],arguments)}(a);e("webviewSendMsgToApp",`${r}功能在${d()}的Webview环境下执行,调用参数:${JSON.stringify(s)}`),this.h5SendMsgToAppByBrowser(i,n,s)}catch(t){console.log(`🚀发送消息给APP出现错误,错误信息:${t},${JSON.stringify(t)}`),e("webviewSendMsgToApp",`${r}执行数据处理失败`,"error",t)}},initEventCallbackEv(i,n,o={}){const{description:a,resDataFormat:r,resErrorFormat:s}=o;n.onSuccess=function(t){e("webviewSendMsgToApp",`${a}功能在App的Webview环境下执行完成`),i(r?r(t):t)},n.onFail=function(n){const o=t(n);e("webviewSendMsgToApp",`${a}功能在App的Webview环境下执行失败,收到的回调数据:::${JSON.stringify(o)}`),i(s?s(o):r?r(o):o)}},formatBridgeData(t,i){try{const n=Math.random().toString(32).slice(2),o=[];for(let e in i){const a=n+"_a"+e,r=i[e],s={};!1===/OpenHarmony ([5-9])|OpenHarmony (\d{2})/i.test(navigator.userAgent)&&b(r,a,s);for(let e in s)t[e]=s[e],this.C2ReceiveQueue.push(t);o.push({type:I(r),name:a,value:r})}return e("formatBridgeData",`格式化后的参数:${JSON.stringify(o)}`),{params:o,id:n}}catch(t){e("formatBridgeData","消息通讯数据格式化异常","error",t)}},h5SendMsgToAppByWindow(t,i={},n={}){const{nativeEvName:o,description:a,resDataFormat:r}=i,s=d(),c=`${o}Back`;let l=n;e("h5SendMsgToAppByWindow",`给【${s}】APP发送【${a}】-【${o}】事件调用,回调函数名称:【${c}】`,"log"),window[c]=i=>{let n=i;if(e("h5SendMsgToAppByWindow",`收到【${s}】APP发送的${a}事件调用的回调值:${JSON.stringify(n)},回调数据类型::${typeof n}`,"log"),"string"==typeof n&&n.startsWith("{")&&n.endsWith("}"))try{n=JSON.parse(n)}catch(t){e("h5SendMsgToAppByWindow","数据格式化异常","error",t)}t(r?r(n):n)},setTimeout(()=>{"ios"!==s.toLowerCase()?"android"!==s.toLowerCase()?window.harmony[o](l):window.android[o](l):window.webkit.messageHandlers[o].postMessage(l)},100)},h5SendMsgToAppByBrowser(t,i={},n={}){const o=d();e("h5SendMsgToAppByBrowser",`给【${o}】APP发送【${i.nativeEvName}】事件调用,入参:${JSON.stringify(n)}`,"log");const{nativeEvName:a,moduleName:r,isCustomEv:s}=i,{id:c,params:l}=n;if("android"!==o)return"ios"===o?(this.iosCallBackList.push({id:c,resolveInfo:t,configInfo:i}),void this.h5SendMsgToIOS(c,r,a,l,s)):void("harmony"===o&&this.h5SendMsgToHarmony(c,r,a,l,s));this.h5SendMsgToAndroid(c,r,a,l,s)},h5SendMsgToAndroid(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToAndroid",`发送给安卓APP的消息:${JSON.stringify(r)}`),JSON.parse(window.AndroidFunction.callAndroidFun(JSON.stringify(r)))},h5SendMsgToIOS(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToIOS",`发送给IOS APP的消息:${JSON.stringify(r)}`),JSON.parse(prompt(JSON.stringify(r)))},h5SendMsgToHarmony(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToHarmony",`发送给鸿蒙APP的消息:${JSON.stringify(r)}`),JSON.parse(window.harmonyFunction.callHarmonyFun(r))}},C={msgList:[],msgStack:[],async miniAppH5SendMsgToApp(t,i,n){try{e("miniAppH5SendMsgToApp",`发送消息给webview:${i}`,"log");const o=await this.sendMsgToMiniApp({methodName:i,methodData:n});t(o?.resultInfo)}catch(n){e("miniAppH5SendMsgToApp",`执行${i}失败`,"error",n),t({isSuccess:!1,message:"执行事件失败,详情查看控制台"})}},sendMsgToMiniApp(t){return new Promise((n,o)=>{e("postMsgToWebview",`消息内容:${JSON.stringify(t)}`,"log");const{methodName:a,methodData:r}=t||{};if(!a)return void e("postMsgToWebview","请传入要调用的事件名称","warn");if(!r)return void e("postMsgToWebview","请传入要调用事件的数据信息","warn");const s=i(),c={data:{msgId:s,isH5Send:!0,...t}};if(this.msgList.push({id:s,resolveInfo:n,rejectInfo:o}),e("postMsgToWebview",`发送消息给父容器页面:${JSON.stringify(c)}`,"log"),!this.uniSDKInit)return e("postMsgToWebview","SDK尚未初始化完成,先行执行堆栈","log"),void this.msgStack.push({id:i(),msgContent:c,resolve:n,reject:o});uni?.webView?.postMessage?uni.webView.postMessage(c):uni?.postMessage(c)}).catch(t=>{e("postMsgToWebview","发生异常","error",t)})}},D={getMessageFromWebview(t,i=!1){let n={};try{n=i?t:t?.data||"{}","string"==typeof n&&n?.startsWith("{")&&n.endsWith("}")&&(n=JSON.parse(n))}catch(t){e("getMessageFromWebview","解析数据异常","error",t)}if(e("getMessageFromWebview",`是否为webview发送的消息内容:${n?.isWebviewSend},消息内容:${JSON.stringify(n)}`,"log"),!n?.isWebviewSend)return;const{msgId:o}=n,a=this.msgList.findIndex(e=>e.id===o);if(-1===a)return;const r=this.msgList[a],{resolveInfo:s}=r;s(n),this.msgList.splice(a,1)}},k=["getLoginUserInfo","getAuthToken"];let F=new class{version="";isInit=!1;isWebviewPage=!1;anaSDKInit=!1;uniSDKInit=!1;iosCallBackList=[];C2ReceiveQueue=[];constructor(e,t){this.version=e,this.isInit=!1,this.isWebviewPage=t,this.iosCallBackList=[],this.initModuleMethod(),this.initSDKAPI()}initModuleMethod(){n(S,this),n(y,this),n(A,this),n(M,this),n(E,this),n($,this),n(C,this),n(D,this)}init(t){l()?(u()&&this.initWebviewMsgFormat(),this.initUNISDK(),this.trackSDKInit(t)):e("init","当前环境非浏览器环境,无需执行初始化动作","warn")}initWebviewMsgFormat(){e("initWebviewMsgFormat","初始化被嵌套的页面消息通讯","log"),l()?(window.addEventListener("message",t=>{e("initWebviewMsgFormat","浏览器消息处理","log"),this.getMessageFromWebview(t)}),window.getMessageFromWebview=t=>{e("initWebviewMsgFormat","事件注入消息处理","log"),this.getMessageFromWebview(t,!0)}):e("initWebviewMsgFormat","该API仅支持在被webview嵌套的H5页面中使用","error","")}initUNISDK(){l()&&this.loadUniWebviewSDK().then(()=>{window?.uni&&"function"==typeof window?.uni?.webView?.postMessage&&(this.uniSDKInit=!0,e("initUNISDK","UNI Webview SDK 挂载完成"))})}loadUniWebviewSDK(){return e("loadUniWebviewSDK","开始挂载UNI-WEBVIEW SDK文件","log"),new Promise(e=>{const t=document.createElement("script");t.src="https://mobile.zwfw.hunan.gov.cn:8088/uni.webview.1.5.6.js",t.onload=e,document.head.appendChild(t)}).catch(t=>(e("loadUniWebviewSDK","加载uni-webview SDK异常","error",t),!1))}initSDKAPI(){g()&&(e("initSDKAPI","App的Webview环境,初始化C2调用链的回调函数"),this.initMobileBridgeGlobalConfig()),e("initSDKAPI","开始初始化SDK API"),h.forEach(t=>{const{eventName:i,moduleName:n,nativeEvName:o,isCustomEv:a}=t;if((n&&o||a)&&g()&&(e("initSDKAPI",`初始化C2调用链的回调函数:${i}`),this.checkMobileModuleBack(n,o,a)),!k?.includes(i))try{this[i]=e=>new Promise(i=>{this.normalEvDataTransition(i,e,t)})}catch(t){e("initSDKAPI","执行API初始化挂载异常","error",t)}})}normalEvDataTransition(t,i={},n={}){const{eventName:o,description:a,reqDataFormat:r}=n||{},s=d();if(l()&&!m())return t({code:-1,isSuccess:!1,data:{},msg:"当前环境不支持该功能"}),void e(o,`${a}功能在浏览器环境执行失败,请检查是否为湘易办相关环境`,"warn");let c=i;if(r&&(c=r(i)),c){if(g())return e("normalEvDataTransition",`开始调用APP的嵌套H5能力,事件名称:${o},入参:${JSON.stringify(c)}`),void this.appH5SendMsgToApp(t,n,c);if(u())return e("normalEvDataTransition",`开始调用小程序/H5嵌套的H5能力,事件名称:${o},入参:${JSON.stringify(c)}`),void this.miniAppH5SendMsgToApp(t,o,c,a);e("normalEvDataTransition",`开始小程序调用原生能力,事件名称:${o},入参:${JSON.stringify(c)}`),this.executeEvByNative(t,c,n)}else e(o,`给【${s}】APP发送【${a}】-【${o}】事件失败,请检查数据格式是否正确`,"error")}executeEvByNative(t,i,n){const{description:o,uniEvName:a}=n;try{e("executeEvByNative",`开始调用原生${o}的能力,API名称:${a},格式化前的参数信息:${JSON.stringify(i)}`),uni.sendNativeEvent(a,i,i=>{e("executeEvByNative",`调用原生${o}的能力完成,结果:${JSON.stringify(i)}`,"log"),((t={},i={})=>{let n=i;try{"string"==typeof n&&n?.startsWith("{")&&n.endsWith("}")&&(n=JSON.parse(i))}catch(t){e("formatResponseData","格式化失败","error",t),n=i}t(n)})(t,i)})}catch(t){e("executeEvByNative",`${o}API执行异常`,"error",t)}}}(f,u());return l()&&(window.xybAgent=F),F});
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).xybAgent=t()}(this,function(){"use strict";const e=(e="",t="",i="log",n="")=>{const o={error:"错误",warn:"警告",info:"提示",log:"日志"}[i]||"日志",a=JSON.stringify(n);console.log(`\n=============🚀START - V${N} 🚀=============\n【事件名称】:${e} \n【日志类型】:${o} \n【日志信息】:${t} ${"error"===i?`【错误信息】:${JSON.stringify(a)}`:""} \n==============🚀END🚀==============`),console.log("")},t=(t={})=>{if("function"==typeof t)return e("deepClone","数据类型为function,无法执行深拷贝,请检查","error"),t;try{return JSON.parse(JSON.stringify(t))}catch(i){return e("deepClone","执行数据深拷贝异常","error",i),t}},i=()=>"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var t=16*Math.random()|0;return("x"==e?t:3&t|8).toString(16)}),n=(e={},t={})=>{for(let i in e)t[i]=e[i]},o=e=>{try{return JSON.parse(e)}catch(t){return e}};let a={finished:!1,result:!1},r={finished:!1,result:!1},s={finished:!1,result:!1},c={finished:!1,result:!1};const d=()=>m()?navigator.userAgent.toLowerCase():"",l=()=>{const e=d();return/android/i.test(e)?"android":/iphone|ipad|ipod|mac/i.test(e)&&!window.MSStream?"ios":/windows phone/i.test(e)?"windows":"harmony"},m=()=>window&&document,u=()=>{if(s.finished)return s.result;if(s.finished=!0,!m())return s.result=!1,!1;const t=d();return s.result=t.includes("xybwebcomponent")||t.includes("uni-app"),e("checkIsXybBrowserEnv",`当前是否为湘易办浏览器环境:${s.result}`),s.result},g=()=>{if(c.finished)return c.result;if(c.finished=!0,!m())return c.result=!1,!1;const t=d();return c.result=t.includes("uni-app"),e("checkIsMiniAppBrowserEnv",`当前是否为小程序的浏览器环境:${c.result}`),c.result},v=()=>{const{finished:t,result:i}=a;return t?i:(a.result=u()||g(),a.finished=!0,e("checkIsWebviewEnv",`当前是否为Webview环境:${a.result}`),a.result)},p=()=>{const{finished:t,result:i}=r;if(t)return i;if(r.finished=!0,!m())return r.result=!1,!1;const n=d();return r.result=n.includes("xybwebcomponent")&&!n.includes("uniminiapp"),e("checkIsAppWebviewEnv",`当前是否为APP的Webview环境:${r.result}`),r.result},h=()=>m()?d().includes("micromessenger"):"mp-weixin"===l(),f=t=>{const{dinateType:i}=t;return e("replaceCoordinate",`坐标转换开始:${i}`,"log"),(e=>{const{lat:t,lng:i,address:n}=e,o=52.35987755982988,a=i-.0065,r=t-.006,s=Math.sqrt(a*a+r*r)-2e-5*Math.sin(r*o),c=Math.atan2(r,a)-3e-6*Math.cos(a*o);return{destinationName:n,destinationLongitude:s*Math.cos(c).toFixed(6),destinationLatitude:s*Math.sin(c).toFixed(6)}})(t)},w=[{isCustomEv:!0,eventName:"authFace",uniEvName:"Auth_face",description:"人脸识别功能",nativeEvName:"faceAuth",reqDataFormat:t=>{e("authFace",`执行人脸验证,参数信息:${JSON.stringify(t)}`);const{name:i,certNo:n,appId:o,sign:a,created:r,nonce:s}=t;return i&&n&&o&&a&&r&&s?t:(e("authFace","缺少必要参数:name, certNo, appId, sign, created, nonce","error","缺少必要参数"),!1)},resDataFormat:e=>({isSuccess:Boolean(e),certifyId:e}),resErrorFormat:e=>"harmony"===l().toLowerCase()?{isSuccess:!1,errorMsg:e}:e},{isCustomEv:!0,eventName:"startNavigation",uniEvName:"Start_navigation",description:"目的地导航",nativeEvName:"start_navigation",reqDataFormat:t=>{let i={};const{dinateType:n,lat:o,lng:a,address:r}=t;return e("replaceCoordinate",`坐标系值:LAT:${o},LNG:${a}`,"log"),i=n&&"GCJ02"!==n?f(t):{destinationLatitude:o,destinationLongitude:a,destinationName:r},e("replaceCoordinate",`转换后值:LAT:${i.destinationLatitude},LNG:${i.destinationLongitude}`,"log"),i}},{isWindowEv:!0,eventName:"getLoginStatus",uniEvName:"Auth_checkLogin",description:"获取登录状态",nativeEvName:"CallNativeMethodGetUserInfo",resDataFormat:e=>{const i=t(e);return{logined:1===Number(i?.isLogin)}},resErrorFormat:()=>({logined:!1})},{isWindowEv:!0,eventName:"getLoginUserInfo",uniEvName:"Auth_getUserInfo",description:"获取登录用户数据信息",nativeEvName:"CallNativeMethodGetUserInfo",resDataFormat:e=>t(e),resErrorFormat:()=>({isSuccess:!1})},{isCustomEv:!0,eventName:"getAuthToken",uniEvName:"Auth_getToken",description:"获取授权token",nativeEvName:"get_token",resDataFormat:e=>{try{const i=t(e);return{token:i?.token,isSuccess:Boolean(i?.token)}}catch(t){return{token:e?.token,isSuccess:Boolean(e?.token)}}},resErrorFormat:()=>({isSuccess:!1})},{isWindowEv:!0,eventName:"getAccessLink",uniEvName:"Auth_getAccessLink",nativeEvName:"CallNativeMethodGetAccessLink",description:"获取授权链接",resDataFormat:e=>"ios"===l().toLowerCase()?{isSuccess:!0,accessLink:e}:t(e),resErrorFormat:()=>({isSuccess:!1})},{moduleName:"image",eventName:"chooseImg",uniEvName:"Image_choose",nativeEvName:"chooseImage",description:"选择本地图片",reqDataFormat:e=>{const{count:t,sizeType:i,sourceType:n,isCircleCrop:o}=e||{};return{count:t||9,sizeType:i||["original","compressed"],sourceType:n||["album"],isCircleCrop:o||!1}},resDataFormat:e=>t(e)},{moduleName:"image",eventName:"imgPreview",uniEvName:"Image_preview",nativeEvName:"previewImage",description:"执行图片预览"},{moduleName:"image",eventName:"imgUpload",uniEvName:"Image_upload",nativeEvName:"uploadImage",description:"执行图片上传",resDataFormat:e=>t(e),resErrorFormat:e=>e},{eventName:"imgDownload",uniEvName:"Image_download",nativeEvName:"",description:"执行图片下载"},{eventName:"fileUpload",uniEvName:"File_upload",nativeEvName:"",description:"执行文件上传"},{moduleName:"file",eventName:"fileDownload",uniEvName:"File_download",nativeEvName:"downloadFile",description:"执行文件下载",resDataFormat:e=>({isSuccess:Boolean(e),resultObj:{path:e}})},{moduleName:"file",eventName:"filePreview",uniEvName:"File_preview",nativeEvName:"previewFile",description:"执行文件预览"},{moduleName:"file",eventName:"openLocalFile",uniEvName:"File_openLocal",nativeEvName:"openLocalFile",description:"执行打开本地文件"},{moduleName:"file",eventName:"chooseLocalFile",uniEvName:"File_chooseLocal",nativeEvName:"chooseLocalFile",description:"选择本地文件",resDataFormat:e=>t(e)},{moduleName:"file",eventName:"openThirdFile",uniEvName:"File_openThirdParty",nativeEvName:"openFileWithThirdParty",description:"执行打开第三方文件"},{eventName:"openApp",uniEvName:"Util_openApp",nativeEvName:"",description:"打开APP"},{isCustomEv:!0,eventName:"openXybApp",uniEvName:"Util_openXYBMiniApp",nativeEvName:"jumpToMiniApp",description:"打开湘易办融合APP小程序",reqDataFormat:e=>{if(p()){const{pageUrl:t}=e;return{...e,path:t}}return e}},{eventName:"postMsgToOtherApp",uniEvName:"Util_postMessageToXYBMiniApp",nativeEvName:"",description:"发送消息给其他小程序"},{isWindowEv:!0,eventName:"scanCode",uniEvName:"Scan_code",description:"扫描二维码",nativeEvName:"CallNativeMethodScanQRCode",resDataFormat:e=>({text:e})},{moduleName:"system",eventName:"getAppInfo",nativeEvName:"getAppInfo",description:"获取应用信息",uniEvName:"System_getAppInfo",resDataFormat:e=>t(e)},{moduleName:"util",eventName:"copyToClipboard",uniEvName:"Util_clipboardData",nativeEvName:"clipboardData",description:"复制内容到剪切板",reqDataFormat:e=>({text:e}),resDataFormat:e=>p()?{isSuccess:Boolean(e)}:{isSuccess:!0}},{moduleName:"util",eventName:"getCacheSize",uniEvName:"Util_getCacheSize",nativeEvName:"getCacheSize",description:"获取缓存大小",resDataFormat:e=>t(e)},{moduleName:"util",eventName:"clearCache",uniEvName:"Util_clearCache",nativeEvName:"clearCache",description:"执行缓存清除",resDataFormat:()=>({isSuccess:!0}),resErrorFormat:()=>({isSuccess:!1})},{moduleName:"telephone",eventName:"callPhone",uniEvName:"Util_callDesignateNumber",nativeEvName:"call",description:"拨打电话",reqDataFormat:e=>"object"==typeof o(e)?o(e):p()?{phoneCode:"+86",phoneNumber:String(e).replace("+86","")}:{text:e}},{eventName:"forbidScreenShot",uniEvName:"Util_forbidScreenShot",nativeEvName:"",description:"执行禁止截屏"},{eventName:"setScreenLight",uniEvName:"Util_setScreenLight",nativeEvName:"",description:"设置屏幕是否常亮",reqDataFormat:e=>({idleTimerValue:e})},{eventName:"sendMatterId",uniEvName:"Param_MatterID",nativeEvName:"",description:"执行页面事件ID上报",reqDataFormat:e=>({matterID:e})},{isWindowEv:!0,description:"获取位置信息",eventName:"getLocationInfo",uniEvName:"Util_getLocationInformation",nativeEvName:"CallNativeMethodGetLocationInformation",resDataFormat:e=>({isSuccess:!0,location:t(e)}),resErrorFormat:()=>({isSuccess:!1,location:{}})},{eventName:"checkPermission",uniEvName:"Auth_matterHandleAuthority",nativeEvName:"",description:"检查事项权限",reqDataFormat:e=>({matterCode:e})},{eventName:"showComment",uniEvName:"Util_jumpToComment",nativeEvName:"",description:"打开评价弹窗"},{isWindowEv:!0,description:"打开微信小程序",eventName:"openWechatMiniApp",uniEvName:"Util_openWechatMiniProgram",nativeEvName:"CallNativeMethodJumpToWechatMiniProgram",reqDataFormat:e=>{if(p()){const t={};for(let i in e)t[i]=String(e[i]);return JSON.stringify(t)}return e}},{isWindowEv:!0,description:"打开支付宝小程序",eventName:"openAliPayMiniApp",uniEvName:"Util_openAlipayMiniProgram",nativeEvName:"CallNativeMethodJumpToAliPay",reqDataFormat:e=>p()?JSON.stringify(e):e},{eventName:"showMenuPanel",uniEvName:"menu_present",nativeEvName:"",description:"显示菜单面板"}],N="0.0.3",S=e=>Number(e)>9?e:`0${e}`,y=()=>{const e=new Date;return`${e.getFullYear()}-${S(e.getMonth()+1)}-${S(e.getDate())} ${S(e.getHours())}:${S(e.getMinutes())}:${S(e.getSeconds())}`},A={trackStack:[],anaSDKLoadTimes:0,locationInfo:{},isProdEnv:!1,track(t="",n={}){if(t){if(n)return m()&&!this.anaSDKInit?(this.trackStack.push({id:i(),eventID:t,eventPro:n}),void e("track","埋点上报插件初始化未完成,本次数据在插件初始化后自动上报","log")):void this.executeTrack(t,n);e("track","埋点数据上报失败","error","请传入埋点数据")}else e("track","埋点数据上报失败","error","请传入埋点事件")},async executeTrack(t="",i={}){if("object"==typeof t)return void await this.track(t?.eventID,t?.eventPro);const n=await this.initTrackParams(i);if(e("track",`执行埋点数据上报,事件名称:${t},事项编码:${n.code},完整埋点数据:${JSON.stringify(n)}`,"log"),m()&&xybAgent?.AnalysysAgent)return e("track","通过浏览器插件执行埋点数据上报","log"),void window.xybAgent.AnalysysAgent.track(t,n);if("undefined"!=typeof uni&&Object.prototype.hasOwnProperty.call(uni,"sendNativeEvent"))try{e("track",`埋点数据:${JSON.stringify(n)},埋点ID:${t}`,"log"),uni.sendNativeEvent("Analysis_common",{eventID:t,eventPro:n})}catch(t){e("track","执行数据埋点功能异常","error",t)}},loadAnaSDK:()=>new Promise(e=>{const t=document.createElement("script");t.src="https://mobile.zwfw.hunan.gov.cn:8088/AnalysysAgent_JS_SDK.min.js",t.onload=e,document.head.appendChild(t)}),trackSDKInit(t){return new Promise((i,n)=>{m()||(e("initTrack","非浏览器环境无需使用init执行初","error"),i(!0)),this.anaSDKInsert?this.configAnaSDK(t,i):this.loadAnaSDK().then(()=>{window.AnalysysAgent&&(xybAgent.AnalysysAgent=window.AnalysysAgent,this.anaSDKInsert=!0,this.configAnaSDK(t,i))})})},configAnaSDK(t,i){const n="800c298f0c42c94c",o="40d556c15f872084";let a=location?.host?.includes("hunan.gov.cn")?n:o;if("object"==typeof t)a=o;else{const e={production:n,development:o},i=[n,o];(e[t]||i.includes(t))&&(a=e[t]?e[t]:t)}this.isProdEnv=a===n,m()?(window.xybAgent.AnalysysAgent&&(window.xybAgent.AnalysysAgent.init({appkey:a,uploadURL:"https://mobile.zwfw.hunan.gov.cn:8088/aurora-api"}),e("_initSDK","xybAgent已初始化完成,可正常执行埋点操作","log"),this.anaSDKInit=!0,this.isInit=!0,this.checkTrackStack(),i(!0)),!Boolean(window.xybAgent.AnalysysAgent)&&this.anaSDKLoadTimes<10&&setTimeout(()=>this.trackSDKInit(i),300),!Boolean(window.xybAgent.AnalysysAgent)&&this.anaSDKLoadTimes>=10&&(e("_initSDK","xybAgent初始化失败","error","请检查app key、uploadURL是否正确"),i(!1))):i(!1)},async initTrackParams(e={}){const{code:t,name:i,aff_city_code:n,aff_city_name:o,unit_code:a,area_code:r,unit_name:s,is_finish:c,category:d,user_id:l,miniAppCode:m,$url_domain:u}=e,g=this.getVisitSource(),v=this.getPageSource(),p=await this.getPositionInfo();return{code:t||void 0,name:i||void 0,aff_city_code:n||void 0,aff_city_name:o||void 0,unit_code:a||void 0,area_code:r||void 0,unit_name:s||void 0,is_finish:c||void 0,category:d||void 0,user_id:l||void 0,miniAppCode:m||void 0,$url_domain:u||void 0,curr_time:y(),source:g,page_source:v,location:p}},getVisitSource(){if(!m()){const e=uni?.getSystemInfoSync(),{uniPlatform:t}=e||{};return"mp-weixin"===t?"wx":"mp-alipay"===t?"alipay":"app"}return h()?"wx":(m()?d().includes("alipay"):"mp-alipay"===l())?"alipay":"app"},checkTrackStack(){e("checkTrackStack","xybAgent已初始化完成,执行埋点数据堆栈检测","log");t(this.trackStack).forEach(t=>{const{eventID:i,eventPro:n,id:o}=t;e("checkTrackStack",`执行id值为${o} 的埋点数据再次上报`,"log"),this.track(i,n);const a=this.trackStack.findIndex(e=>e.id===o);a>-1&&this.trackStack.splice(a,1)})},getPageSource(){let t=null;t=m()?location.href:decodeURIComponent(((t=!1)=>{let i="";try{const n="function"==typeof getCurrentPages?getCurrentPages():[];e("getCurrentPagePath",`路径清单::${n}`,"log");const o=n?.length||0;o&&(e("getCurrentPagePath",`获取当前页面路径 -1 :${n[n.length-1]?.route}`,"log"),e("getCurrentPagePath",`获取当前页面路径 -2 :${n[n.length-2]?.route}`,"log"),i=n[o-(t?2:1)]?.route||"")}catch(t){e("getCurrentPagePath","获取当前页面路径时发生异常","error",t)}return i})());const i=t?.includes("source=");if(!i)return"click";const n=t.split("source=")[1];let o="click";return o=n.includes("&")?n.split("&")[0]:n,["copy","share","click","search"].includes(o)?o:"click"},async getPositionInfo(){if(!this.locationInfo?.province)try{const{location:e}=await this.getLocationInfo()||{};this.locationInfo=e||""}catch(e){this.locationInfo={}}return JSON.stringify(this.locationInfo)}},E={initMobileBridgeGlobalConfig(){const t=l();e("initMobileBridgeGlobalConfig",`开始初始化移动端桥链接配置,访问设备类型:${t}`),window.c2={},"ios"===t&&this.initIOSCallbackEvConfig(),"android"===t&&this.initAndroidCallbackEvConfig(),e("initMobileBridgeGlobalConfig","初始化移动端桥链接配置完成"),window.CreatorJsBridge=window.c2},initIOSCallbackEvConfig(){try{const t=this;window.c2.iOS={},window.c2.iOS.callJS=function(){window?.c2.iOS?.callJSCallback||(window.c2.iOS.callJSCallback={}),e("initIOSCallbackEvConfig",`开始处理IOS设备回调事件,回调数据:${JSON.stringify(arguments)}`),t.IOSCallbackEvFormat(arguments[0])}}catch(t){e("initIOSCallbackEvConfig","初始化IOS回调事件配置异常","error",t)}},initAndroidCallbackEvConfig(){window.c2.sendDataWarpToWeb=(e,t,i)=>{e(i)}},IOSCallbackEvFormat(i){const{returnValue:n,funcName:a}=i;let r=this.base64Decode(n);r=o(r),e("IOSCallbackEvFormat",`IOS设备回调事件处理开始,回调数据:${JSON.stringify(r)}, 格式:${typeof r}`);const s=a.split("_a")[0],c=a.replace(s,""),d=this.iosCallBackList.find(e=>e.id===s);if(!d)return;const{resolveInfo:l,configInfo:m}=d,{resDataFormat:u,resErrorFormat:g}=m;if(c.includes("onFail")&&g)return r=g({isSuccess:!1,errorMsg:t(n)}),void l(r);u&&(r=u(r)),e("IOSCallbackEvFormat",`IOS设备回调事件处理完成,返回数据:${JSON.stringify(r)}`),l(r);const v=this.iosCallBackList.findIndex(e=>e.id===s);this.iosCallBackList.splice(v,1)},base64Decode(e){let t,i,n,o,a,r,s,c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",d="",l=0;for(e=e.replace(/[^A-Za-z0-9\+\/\=]/g,"");l<e.length;)o=c.indexOf(e.charAt(l++)),a=c.indexOf(e.charAt(l++)),r=c.indexOf(e.charAt(l++)),s=c.indexOf(e.charAt(l++)),t=o<<2|a>>4,i=(15&a)<<4|r>>2,n=(3&r)<<6|s,d+=String.fromCharCode(t),64!=r&&(d+=String.fromCharCode(i)),64!=s&&(d+=String.fromCharCode(n));return d=this._utf8_decode(d),d},_utf8_decode(e){let t="",i=0,n=0,o=0,a=0;for(;i<e.length;)n=e.charCodeAt(i),n<128?(t+=String.fromCharCode(n),i++):n>191&&n<224?(a=e.charCodeAt(i+1),t+=String.fromCharCode((31&n)<<6|63&a),i+=2):(a=e.charCodeAt(i+1),o=e.charCodeAt(i+2),t+=String.fromCharCode((15&n)<<12|(63&a)<<6|63&o),i+=3);return t},checkMobileModuleBack(e,t,i){const n=i?"custom":e,o=`${i?"call":t}Callback`;window.c2.hasOwnProperty(n)||(window.c2[n]={}),window.c2[n].hasOwnProperty(o)||(window.c2[n][o]={})}},M={defaults:{headers:{},baseURL:""},interceptor:{request:null,response:null},request(i={}){if(uni?.request)return new Promise((e,n)=>{let o=t(i);o?("function"!=typeof this.interceptor?.request||i.ignore||(o=this.interceptor.request(i)),p()||this.executeNormalRequest(o,e,n)):e(!1)});e("request","当前环境非UNI编译的项目,无法执行请求操作,请自行使用接口请求插件实现","warn")},executeNormalRequest(e,t,i){uni.request({url:`${this.defaults.baseURL}${e.url}`,header:e?.header||{},data:e?.data||{},method:e?.method||"GET",success:e=>{if("function"==typeof this.interceptor.response){const i=this.interceptor.response(e);return void t(i)}t(e)},fail:e=>{i(e)}})},executeCloudRequest(e,t,i){}},b={menuBtnConfig(t={}){return!(!m()&&h)&&new Promise((i,n)=>{e("menuBtnConfig",`配置APP胶囊按钮清单显示,配置信息:${JSON.stringify(t)}`,"log");let o=!0;for(let i in t){if("object"!=typeof t[i]){o=!1,e("menuBtnConfig","配置参数错误","error","请传入一个Object配置数据");break}}if(o)if(v())this.miniAppH5SendMsgToApp(i,"menuBtnConfig",t,"配置APP的胶囊按钮清单显示");else{if(m()||!uni||!uni?.sendNativeEvent)return e("menuBtnConfig","配置APP胶囊按钮清单显示功能无法在非UNI环境运行","log"),void i(!1);try{e("menuBtnConfig","开始执行配置APP胶囊按钮清单显示","log"),uni?.sendNativeEvent("Util_MiniAppConfigMenu",t)}catch(t){e("menuBtnConfig","配置APP的胶囊按钮清单显示时发生异常","error",t)}}})}},I={wvInfo:null,isHarmony:!1,isCheckDevice:!1,async initMessage(...t){const i=t[0];await this.checkDeviceInfo(),await this.initVMInfo(t[2]),m()?window.addEventListener("message",t=>{e("initMessage",`浏览器webview接收到的消息内容,${JSON.stringify(t)}`,"log"),this.getMsgFromH5(t)}):(e("initMessage",`非浏览器中的webview接收到的消息内容,${JSON.stringify(i)}`,"log"),this.getMsgFromH5(i))},checkDeviceInfo(){this.isCheckDevice||(this.isCheckDevice=!0,uni.sendNativeEvent("System_getAppInfo",{},e=>{this.isHarmony=e?.platform?.toLowerCase().includes("harmony")}))},initVMInfo(t){if(!this.wvInfo)if(this.isHarmony)this.wvInfo=uni.createWebviewContext("webview",t);else try{this.wvInfo=t,t?.$scope?.$getAppWebview()&&(this.wvInfo=t.$scope.$getAppWebview().children()[0])}catch(t){e("initMessage","初始化消息模块,是否包含wvInfo:"+typeof this.wvInfo?.evalJS)}},getMsgFromH5(t={}){let i=this.getMsgDataFromH5(t);const{origin:n}=t||{},{href:o}=location||{};if(m()&&o?.includes(n))return!1;const{isH5Send:a,methodName:r,methodData:s}=i||{};return!!a&&(r?null==s?(e("getMsgFromH5","请传入需要执行的事件数据","warn"),!1):(e("getMsgFromH5",`需要执行的事件名称【${r}】,需要执行的事件数据【${JSON.stringify(s)}】,是否为H5发送的消息【${a}】`,"log"),void(this[r]?this.executeH5MethodName(r,i):e("getMsgFromH5",`【${r}】事件不存在`,"warn"))):(e("getMsgFromH5","请传入需要执行的事件名称","warn"),!1))},executeH5MethodName(t,i){const{msgId:n,methodData:o}=i;try{const i=this[t].toString();if(e("executeH5MethodName",`【${t}】方法定义:${i}`,"log"),i.includes("Promise"))return void this[t](o).then(i=>{e("executeH5MethodName",`${t}方法执行结果:${JSON.stringify(i)}`,"log");let o=i;try{o=JSON.parse(i)}catch(t){e("executeH5MethodName","强制给数据进行序列化失败","error",t)}this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:o,isWebviewSend:!0,resultMessage:`执行${t}方法完成`})}).catch(i=>{e("executeH5MethodName",`${t}方法执行失败`,"error",i),this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:null,isWebviewSend:!0,resultMessage:`执行${t}方法失败,具体错误信息,请查看控制台`})});this[t](o),this.postMsgToH5({msgId:n,sourceMethod:t,resultInfo:null,isWebviewSend:!0,resultMessage:`执行${t}方法完成`})}catch(i){e("getMsgFromH5",`${t}方法执行失败`,"error",i)}},postMsgToH5(t){const i=JSON.stringify(t);if(e("postMsgToH5",`消息内容:${i}`,"log"),m()){e("postMsgToH5","父页面运行在浏览器","log");document.querySelector("iframe").contentWindow.postMessage(JSON.stringify(i),"*")}else try{e("postMsgToH5","父页面运行在非浏览器","log"),this.wvInfo.evalJS(`getMessageFromWebview('${i}')`)}catch(t){e("postMsgToH5","执行浏览器的webview回传异常","error",t)}},getMsgDataFromH5(t){let i=null;const{data:n}=t;try{i=m()?n?.data?.arg?n?.data?.arg:n?.data?n.data:n:t.detail?.data[0]}catch(t){return e("getMsgDataFromH5","处理消息内容时发生异常","error",t),!1}return e("getMsgDataFromH5",`获取到的消息内容:${JSON.stringify(i)}`,"log"),i}},C=(t,i,n)=>{if(e("_parseFunction",`${JSON.stringify(t)}`),"function"==typeof t)return n[i]=t,void(t="[Function]::"+i);if("object"!=typeof t)return;let o=null;for(let e in t)switch(typeof t[e]){case"object":o=i?i+"_"+e:e,C(t[e],o,n);break;case"function":o=i?i+"_"+e:e,n[o]=t[e],t[e]="[Function]::"+o}},$=e=>{let t=0;return"string"==typeof e?t=1:"number"==typeof e?t=2:"boolean"==typeof e?t=3:"function"==typeof e?t=4:e instanceof Array?t=6:"object"==typeof e&&(t=5),t},D={appH5SendMsgToApp(i,n={},o={}){const{isWindowEv:a,description:r,moduleName:s,nativeEvName:c,isCustomEv:d}=n;if(a)return void this.h5SendMsgToAppByWindow(i,n,o);const m=d?"custom":s,u=d?"call":c,g=this;try{let a={};if(("object"==typeof o?Object.keys(o):[]).length>0&&(a=t(o)),d){const i=t(a);e("webviewSendMsgToApp",`${r}功能在是通过custom.call的方式调用,需要重新处理入参`),a.params=i,a.action=c}e("webviewSendMsgToApp",`${r}的完整参数:${JSON.stringify(a)}`),this.initEventCallbackEv(i,a,n);const s=function(){return g.formatBridgeData(window.c2[m][`${u}Callback`],arguments)}(a);e("webviewSendMsgToApp",`${r}功能在${l()}的Webview环境下执行,调用参数:${JSON.stringify(s)}`),this.h5SendMsgToAppByBrowser(i,n,s)}catch(t){console.log(`🚀发送消息给APP出现错误,错误信息:${t},${JSON.stringify(t)}`),e("webviewSendMsgToApp",`${r}执行数据处理失败`,"error",t)}},initEventCallbackEv(i,n,o={}){const{description:a,resDataFormat:r,resErrorFormat:s}=o;n.onSuccess=function(t){e("webviewSendMsgToApp",`${a}功能在App的Webview环境下执行完成`),i(r?r(t):t)},n.onFail=function(n){const o=t(n);e("webviewSendMsgToApp",`${a}功能在App的Webview环境下执行失败,收到的回调数据:::${JSON.stringify(o)}`),i(s?s(o):r?r(o):o)}},formatBridgeData(t,i){try{const n=Math.random().toString(32).slice(2),o=[];for(let e in i){const a=n+"_a"+e,r=i[e],s={};!1===/OpenHarmony ([5-9])|OpenHarmony (\d{2})/i.test(navigator.userAgent)&&C(r,a,s);for(let e in s)t[e]=s[e],this.C2ReceiveQueue.push(t);o.push({type:$(r),name:a,value:r})}return e("formatBridgeData",`格式化后的参数:${JSON.stringify(o)}`),{params:o,id:n}}catch(t){e("formatBridgeData","消息通讯数据格式化异常","error",t)}},h5SendMsgToAppByWindow(t,i={},n={}){const{nativeEvName:a,description:r,resDataFormat:s}=i,c=l(),d=`${a}Back`;let m=n;e("h5SendMsgToAppByWindow",`给【${c}】APP发送【${r}】-【${a}】事件调用,回调函数名称:【${d}】`,"log"),window[d]=i=>{let n=i;e("h5SendMsgToAppByWindow",`收到【${c}】APP发送的${r}事件调用的回调值:${JSON.stringify(n)},回调数据类型::${typeof n}`,"log"),n=o(n),t(s?s(n):n)},setTimeout(()=>{"ios"!==c.toLowerCase()?"android"!==c.toLowerCase()?window.harmony[a](m):window.android[a](m):window.webkit.messageHandlers[a].postMessage(m)},100)},h5SendMsgToAppByBrowser(t,i={},n={}){const o=l();e("h5SendMsgToAppByBrowser",`给【${o}】APP发送【${i.nativeEvName}】事件调用,入参:${JSON.stringify(n)}`,"log");const{nativeEvName:a,moduleName:r,isCustomEv:s}=i,{id:c,params:d}=n;if("android"!==o)return"ios"===o?(this.iosCallBackList.push({id:c,resolveInfo:t,configInfo:i}),void this.h5SendMsgToIOS(c,r,a,d,s)):void("harmony"===o&&this.h5SendMsgToHarmony(c,r,a,d,s));this.h5SendMsgToAndroid(c,r,a,d,s)},h5SendMsgToAndroid(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToAndroid",`发送给安卓APP的消息:${JSON.stringify(r)}`),JSON.parse(window.AndroidFunction.callAndroidFun(JSON.stringify(r)))},h5SendMsgToIOS(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToIOS",`发送给IOS APP的消息:${JSON.stringify(r)}`),JSON.parse(prompt(JSON.stringify(r)))},h5SendMsgToHarmony(t,i,n,o,a){const r={id:t,module:a?"custom":i,method:a?"call":n,parameters:o};return e("h5SendMsgToHarmony",`发送给鸿蒙APP的消息:${JSON.stringify(r)}`),JSON.parse(window.harmonyFunction.callHarmonyFun(r))}},k={msgList:[],msgStack:[],async miniAppH5SendMsgToApp(t,i,n){try{e("miniAppH5SendMsgToApp",`发送消息给webview:${i}`,"log");const o=await this.sendMsgToMiniApp({methodName:i,methodData:n});t(o?.resultInfo)}catch(n){e("miniAppH5SendMsgToApp",`执行${i}失败`,"error",n),t({isSuccess:!1,message:"执行事件失败,详情查看控制台"})}},sendMsgToMiniApp(t){return new Promise((n,o)=>{e("postMsgToWebview",`消息内容:${JSON.stringify(t)}`,"log");const{methodName:a,methodData:r}=t||{};if(!a)return void e("postMsgToWebview","请传入要调用的事件名称","warn");if(!r)return void e("postMsgToWebview","请传入要调用事件的数据信息","warn");const s=i(),c={data:{msgId:s,isH5Send:!0,...t}};if(this.msgList.push({id:s,resolveInfo:n,rejectInfo:o}),e("postMsgToWebview",`发送消息给父容器页面:${JSON.stringify(c)}`,"log"),!this.uniSDKInit)return e("postMsgToWebview","SDK尚未初始化完成,先行执行堆栈","log"),void this.msgStack.push({id:i(),msgContent:c,resolve:n,reject:o});uni?.webView?.postMessage?uni.webView.postMessage(c):uni?.postMessage(c)}).catch(t=>{e("postMsgToWebview","发生异常","error",t)})}},F={getMessageFromWebview(t,i=!1){let n={};try{n=i?t:t?.data||"{}",n=o(n)}catch(t){e("getMessageFromWebview","解析数据异常","error",t)}if(e("getMessageFromWebview",`是否为webview发送的消息内容:${n?.isWebviewSend},消息内容:${JSON.stringify(n)}`,"log"),!n?.isWebviewSend)return;const{msgId:a}=n,r=this.msgList.findIndex(e=>e.id===a);if(-1===r)return;const s=this.msgList[r],{resolveInfo:c}=s;c(n),this.msgList.splice(r,1)}},P=["getLoginUserInfo","getAuthToken"];let T=new class{version="";isInit=!1;isWebviewPage=!1;anaSDKInit=!1;uniSDKInit=!1;iosCallBackList=[];C2ReceiveQueue=[];constructor(e,t){this.version=e,this.isInit=!1,this.isWebviewPage=t,this.iosCallBackList=[],this.initModuleMethod(),this.initSDKAPI()}initModuleMethod(){n(A,this),n(E,this),n(M,this),n(b,this),n(I,this),n(D,this),n(k,this),n(F,this)}init(t){m()?(v()&&this.initWebviewMsgFormat(),this.initUNISDK(),this.trackSDKInit(t)):e("init","当前环境非浏览器环境,无需执行初始化动作","warn")}initWebviewMsgFormat(){e("initWebviewMsgFormat","初始化被嵌套的页面消息通讯","log"),m()?(window.addEventListener("message",t=>{e("initWebviewMsgFormat","浏览器消息处理","log"),this.getMessageFromWebview(t)}),window.getMessageFromWebview=t=>{e("initWebviewMsgFormat","事件注入消息处理","log"),this.getMessageFromWebview(t,!0)}):e("initWebviewMsgFormat","该API仅支持在被webview嵌套的H5页面中使用","error","")}initUNISDK(){m()&&this.loadUniWebviewSDK().then(()=>{window?.uni&&"function"==typeof window?.uni?.webView?.postMessage&&(this.uniSDKInit=!0,e("initUNISDK","UNI Webview SDK 挂载完成"))})}loadUniWebviewSDK(){return e("loadUniWebviewSDK","开始挂载UNI-WEBVIEW SDK文件","log"),new Promise(e=>{const t=document.createElement("script");t.src="https://mobile.zwfw.hunan.gov.cn:8088/uni.webview.1.5.6.js",t.onload=e,document.head.appendChild(t)}).catch(t=>(e("loadUniWebviewSDK","加载uni-webview SDK异常","error",t),!1))}initSDKAPI(){p()&&(e("initSDKAPI","App的Webview环境,初始化C2调用链的回调函数"),this.initMobileBridgeGlobalConfig()),e("initSDKAPI","开始初始化SDK API"),w.forEach(t=>{const{eventName:i,moduleName:n,nativeEvName:o,isCustomEv:a}=t;if((n&&o||a)&&p()&&(e("initSDKAPI",`初始化C2调用链的回调函数:${i}`),this.checkMobileModuleBack(n,o,a)),!P?.includes(i))try{this[i]=e=>new Promise(i=>{this.normalEvDataTransition(i,e,t)})}catch(t){e("initSDKAPI","执行API初始化挂载异常","error",t)}})}normalEvDataTransition(t,i={},n={}){const{eventName:o,description:a,reqDataFormat:r}=n||{},s=l();if(m()&&!u())return t({code:-1,isSuccess:!1,data:{},msg:"当前环境不支持该功能"}),void e(o,`${a}功能在浏览器环境执行失败,请检查是否为湘易办相关环境`,"warn");let c=i;if(r&&(c=r(i)),c){if(p())return e("normalEvDataTransition",`开始调用APP的嵌套H5能力,事件名称:${o},入参:${JSON.stringify(c)}`),void this.appH5SendMsgToApp(t,n,c);if(g())return e("normalEvDataTransition",`开始调用小程序/H5嵌套的H5能力,事件名称:${o},入参:${JSON.stringify(c)}`),void this.miniAppH5SendMsgToApp(t,o,c,a);e("normalEvDataTransition",`开始小程序调用原生能力,事件名称:${o},入参:${JSON.stringify(c)}`),this.executeEvByNative(t,c,n)}else e(o,`给【${s}】APP发送【${a}】-【${o}】事件失败,请检查数据格式是否正确`,"error")}executeEvByNative(t,i,n){const{description:a,uniEvName:r}=n;try{e("executeEvByNative",`开始调用原生${a}的能力,API名称:${r},格式化前的参数信息:${JSON.stringify(i)}`),uni.sendNativeEvent(r,i,i=>{e("executeEvByNative",`调用原生${a}的能力完成,结果:${JSON.stringify(i)}`,"log"),((t={},i={})=>{let n=i;try{n=o(i)}catch(t){e("formatResponseData","格式化失败","error",t),n=i}t(n)})(t,i)})}catch(t){e("executeEvByNative",`${a}API执行异常`,"error",t)}}}(N,v());return m()&&(window.xybAgent=T),T});
package/package.json CHANGED
@@ -1,13 +1,7 @@
1
1
  {
2
2
  "name": "@xybplugins/xyb-agent",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "湘易办功能集成JSSDK",
5
- "scripts": {
6
- "build": "rm -rf dist && NODE_ENV=production rollup -c",
7
- "build:test": "rm -rf dist && NODE_ENV=test rollup -c",
8
- "build:dev": "rm -rf dist && NODE_ENV=developer rollup -c",
9
- "dev": "rollup -c -w"
10
- },
11
5
  "main": "dist/index.esm.js",
12
6
  "devDependencies": {
13
7
  "@rollup/plugin-commonjs": "^28.0.3",
@@ -26,5 +20,11 @@
26
20
  "> 0.5%",
27
21
  "not dead",
28
22
  "not IE 11"
29
- ]
30
- }
23
+ ],
24
+ "scripts": {
25
+ "build": "rm -rf dist && NODE_ENV=production rollup -c",
26
+ "build:test": "rm -rf dist && NODE_ENV=test rollup -c",
27
+ "build:dev": "rm -rf dist && NODE_ENV=developer rollup -c",
28
+ "dev": "rollup -c -w"
29
+ }
30
+ }