import{V as _}from"./vue.fd9b772e.js";import{m as A}from"./vuex.cc7cb26e.js";import{i as v}from"./view-design-hi.18b9f7fe.js";import{m as l}from"./@micro-zoe.f728a9f4.js";import{D as w}from"./DialogWrapper.284bd8a0.js";import{n as d,d as f,U as c,e as a,b as u,c as g,l as y}from"./app.91cb3f05.js";import{R as $}from"./index.fa8c4bd1.js";var M=function(){var e=this,s=e.$createElement,t=e._self._c||s;return t("div",{directives:[{name:"transfer-dom",rawName:"v-transfer-dom"}],attrs:{"data-transfer":!0}},[t("div",{class:e.className},[t("transition",{attrs:{name:e.transitions[0]}},[e.shouldRenderInDom?t("div",{directives:[{name:"show",rawName:"v-show",value:e.value,expression:"value"}],staticClass:"micro-modal-mask",style:e.maskStyle,on:{click:e.onClose}}):e._e()]),t("transition",{attrs:{name:e.transitions[1]}},[e.shouldRenderInDom?t("div",{directives:[{name:"show",rawName:"v-show",value:e.value,expression:"value"}],staticClass:"micro-modal-content",style:e.contentStyle},[t("div",{staticClass:"micro-modal-close",on:{click:e.onClose}},[t("svg",{attrs:{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 26 26"}},[t("path",{attrs:{d:"M8.28596 6.51819C7.7978 6.03003 7.00634 6.03003 6.51819 6.51819C6.03003 7.00634 6.03003 7.7978 6.51819 8.28596L11.2322 13L6.51819 17.714C6.03003 18.2022 6.03003 18.9937 6.51819 19.4818C7.00634 19.97 7.7978 19.97 8.28596 19.4818L13 14.7678L17.714 19.4818C18.2022 19.97 18.9937 19.97 19.4818 19.4818C19.97 18.9937 19.97 18.2022 19.4818 17.714L14.7678 13L19.4818 8.28596C19.97 7.7978 19.97 7.00634 19.4818 6.51819C18.9937 6.03003 18.2022 6.03003 17.714 6.51819L13 11.2322L8.28596 6.51819Z",fill:"currentColor"}})])]),t("ResizeLine",{staticClass:"micro-modal-resize",attrs:{placement:"right",min:e.minSize,max:0,reverse:!0,beforeResize:e.beforeResize},on:{"on-change":e.onChangeResize},model:{value:e.dynamicSize,callback:function(i){e.dynamicSize=i},expression:"dynamicSize"}}),t("div",{ref:"body",staticClass:"micro-modal-body",style:e.bodyStyle},[e._t("default")],2)],1):e._e()])],1)])},b=[];const C={name:"MicroModal",components:{ResizeLine:$},directives:{TransferDom:f},props:{value:{type:Boolean,default:!1},size:{type:Number,default:300},minSize:{type:Number,default:300},background:{default:null},transparent:{type:Boolean,default:!1},autoDarkTheme:{type:Boolean,default:!0},keepAlive:{type:Boolean,default:!0},beforeClose:Function},data(){return{dynamicSize:0,zIndex:1e3}},computed:{shouldRenderInDom(){return this.value||this.keepAlive},className({value:e,transparent:s,autoDarkTheme:t}){return{"micro-modal":!0,"micro-modal-hidden":!e,"no-dark-content":!t,"transparent-mode":s}},transitions({transparent:e}){return e?["",""]:["micro-modal-fade","micro-modal-slide"]},bodyStyle(){const e={};return $A.isJson(this.background)?e.background=this.background:this.background&&(e.backgroundColor=this.background),e},maskStyle({zIndex:e}){return{zIndex:e}},contentStyle({dynamicSize:e,zIndex:s}){return{width:e<=100?`${e}%`:`${e}px`,zIndex:s}}},watch:{value:{handler(e){e&&(this.zIndex=typeof window.modalTransferIndex=="number"?window.modalTransferIndex++:1e3)},immediate:!0},size:{handler(e){this.dynamicSize=parseInt(e)},immediate:!0}},methods:{beforeResize(){return new Promise(e=>{this.dynamicSize<=100&&this.updateSize(),e()})},onChangeResize({event:e}){e==="up"&&this.updateSize()},updateSize(){this.$refs.body&&(this.dynamicSize=this.$refs.body.clientWidth)},onClose(){if(!this.beforeClose)return this.handleClose();const e=this.beforeClose();e&&e.then?e.then(()=>{this.handleClose()}):this.handleClose()},handleClose(){this.$emit("input",!1)}}},p={};var E=d(C,M,b,!1,O,null,null,null);function O(e){for(let s in p)this[s]=p[s]}var k=function(){return E.exports}(),S=function(){var e=this,s=e.$createElement,t=e._self._c||s;return t("div",{staticClass:"micro-app-iframe"},[t("iframe",{ref:"iframe",staticClass:"micro-app-iframe-container",class:{"iframe-immersive":e.immersive},attrs:{src:e.src,sandbox:"allow-scripts allow-forms allow-same-origin allow-popups allow-popups-to-escape-sandbox"}}),e.isLoading?t("div",{staticClass:"micro-app-iframe-cover"}):e._e()])},I=[];const x={name:"MicroIFrame",props:{name:{type:String,default:""},url:{type:String,default:""},data:{type:Object,default:null},immersive:{type:Boolean,default:!1}},data(){return{src:this.url,isLoading:!0,hasMounted:!1}},mounted(){this.pendingBeforeCloses=new Map,this.pendingFunctionCalls=new Map,this.boundHandleMessage=this.handleMessage.bind(this),this.boundHandleLoad=this.handleLoad.bind(this),this.boundHandleError=this.handleError.bind(this),this.injectMicroApp(),window.addEventListener("message",this.boundHandleMessage),this.$refs.iframe.addEventListener("load",this.boundHandleLoad),this.$refs.iframe.addEventListener("error",this.boundHandleError)},beforeDestroy(){this.cleanupMicroApp(),this.boundHandleMessage&&window.removeEventListener("message",this.boundHandleMessage),this.boundHandleLoad&&this.$refs.iframe.removeEventListener("load",this.boundHandleLoad),this.boundHandleError&&this.$refs.iframe.removeEventListener("error",this.boundHandleError),this.pendingFunctionCalls&&(this.pendingFunctionCalls.forEach(e=>{clearTimeout(e.timeout),e.reject(new Error("Component destroyed"))}),this.pendingFunctionCalls.clear()),this.pendingBeforeCloses&&(this.pendingBeforeCloses.forEach(e=>{e(!1)}),this.pendingBeforeCloses.clear())},methods:{handleLoad(){this.injectMicroApp(),this.hasMounted||(this.hasMounted=!0,this.$emit("mounted",{detail:{name:this.name}}))},handleError(e){this.$emit("error",{detail:{name:this.name,error:e}})},handleMessage(e){if(!this.isFromCurrentIframe(e))return;const{type:s,message:t}=e.data;switch(s){case"MICRO_APP_READY":this.handleMessageOfReady(this.handleMessageEnsureJson(t));break;case"MICRO_APP_METHOD":this.handleMessageOfMethod(this.handleMessageEnsureJson(t));break;case"MICRO_APP_FUNCTION_RESULT":this.handleMessageOfFunctionResult(this.handleMessageEnsureJson(t));break;case"MICRO_APP_BEFORE_CLOSE":this.handleMessageOfBeforeClose(this.handleMessageEnsureJson(t));break}},handleMessageEnsureJson(e){return $A.isJson(e)?e:{}},handleMessageOfReady({supportBeforeClose:e}){this.handleLoad(),this.isLoading=!1,e&&this.$store.commit("microApps/update",{name:this.name,data:{onBeforeClose:()=>new Promise(s=>{const t={id:$A.randomString(16),name:this.name};this.$refs.iframe.contentWindow.postMessage({type:"MICRO_APP_BEFORE_CLOSE",message:t},"*"),this.pendingBeforeCloses.set(t.id,s)})}})},handleMessageOfMethod({id:e,method:s,args:t}){if(!this.data||!this.data.methods||!this.data.methods[s])return;const i=r=>{this.$refs.iframe.contentWindow.postMessage({type:"MICRO_APP_METHOD_RESULT",message:{id:e,result:$A.cloneJSON(r)}},"*")},n=r=>{this.$refs.iframe.contentWindow.postMessage({type:"MICRO_APP_METHOD_RESULT",message:{id:e,result:null,error:(r==null?void 0:r.message)||r}},"*")};try{const r=this.deserializeFunctions(t),o=this.data.methods[s](...r);o&&o.then?o.then(i).catch(n):i(o)}catch(r){n(r)}},handleMessageOfFunctionResult({callId:e,result:s,error:t}){const i=this.pendingFunctionCalls.get(e);!i||(this.pendingFunctionCalls.delete(e),clearTimeout(i.timeout),t?i.reject(new Error(t)):i.resolve(s))},handleMessageOfBeforeClose({id:e}){!this.pendingBeforeCloses.has(e)||(this.pendingBeforeCloses.get(e)(),this.pendingBeforeCloses.delete(e))},isFromCurrentIframe(e){try{const{source:s}=e;return this.$refs.iframe&&s===this.$refs.iframe.contentWindow}catch{return!1}},deserializeFunctions(e){if(e&&typeof e=="object"&&e.__func)return(...s)=>new Promise((t,i)=>{const n=`call_${Date.now()}_${Math.random().toString(36).substring(2,9)}`,r=setTimeout(()=>{this.pendingFunctionCalls.delete(n),i(new Error("Function call timeout"))},5e3);if(this.pendingFunctionCalls.set(n,{resolve:t,reject:i,timeout:r}),!this.$refs.iframe||!this.$refs.iframe.contentWindow){i(new Error("Iframe not ready"));return}this.$refs.iframe.contentWindow.postMessage({type:"MICRO_APP_FUNCTION_CALL",message:{funcId:e.__func,callId:n,args:s}},"*")});if(Array.isArray(e))return e.map(s=>this.deserializeFunctions(s));if(e&&typeof e=="object"&&e.constructor===Object){const s={};for(const t in e)s[t]=this.deserializeFunctions(e[t]);return s}return e},injectMicroApp(){try{const e=this.$refs.iframe.contentWindow;if(e&&this.data)try{e.microApp={getData:()=>this.data}}catch{e.postMessage({type:"MICRO_APP_INJECT",message:{type:this.data.type,props:this.data.props}},"*")}}catch{}},cleanupMicroApp(){try{const e=this.$refs.iframe.contentWindow;e&&e.microApp&&delete e.microApp}catch{}}}},h={};var L=d(x,S,I,!1,F,"21ff54ee",null,null);function F(e){for(let s in h)this[s]=h[s]}var R=function(){return L.exports}(),T=function(){var e=this,s=e.$createElement,t=e._self._c||s;return t("div",[e._l(e.microApps,function(i,n){return t("MicroModal",{key:n,ref:`ref-${i.name}`,refInFor:!0,attrs:{size:1200,background:i.background,transparent:i.transparent,autoDarkTheme:i.auto_dark_theme,keepAlive:i.keep_alive,beforeClose:async function(){await e.onBeforeClose(i.name)}},model:{value:i.isOpen,callback:function(r){e.$set(i,"isOpen",r)},expression:"app.isOpen"}},[e.shouldRenderIFrame(i)?t("MicroIFrame",{attrs:{name:i.name,url:i.url,data:e.appData(i.name),immersive:i.iframe_immersive},on:{mounted:e.mounted,error:e.error}}):i.isOpen&&i.url?t("micro-app",{attrs:{name:i.name,url:i.url,"keep-alive":i.keep_alive,"disable-scopecss":i.disable_scope_css,data:e.appData(i.name)},on:{mounted:e.mounted,error:e.error}}):e._e(),i.isLoading?t("div",{staticClass:"micro-app-loader"},[t("Loading")],1):e._e()],1)}),t("UserSelect",e._b({ref:"userSelect",attrs:{module:""},model:{value:e.userSelectOptions.value,callback:function(i){e.$set(e.userSelectOptions,"value",i)},expression:"userSelectOptions.value"}},"UserSelect",e.userSelectOptions.config,!1)),t("Modal",{attrs:{closable:!0,mask:!1,"mask-closable":!1,"footer-hide":!0,"transition-names":["",""],beforeClose:e.onAssistClose,"class-name":"micro-app-assist"},model:{value:e.assistShow,callback:function(i){e.assistShow=i},expression:"assistShow"}})],2)},B=[];const P={name:"MicroApps",directives:{TransferDom:f},components:{MicroModal:k,UserSelect:c,MicroIFrame:R},props:{windowType:{type:String,default:"embed"}},data(){return{assistShow:!1,userSelectOptions:{value:[],config:{}}}},created(){l.start({iframe:!0,"router-mode":"state",iframeSrc:window.location.origin+"/assets/empty.html"})},mounted(){a.on("observeMicroApp:open",this.onOpen),a.on("observeMicroApp:updatedOrUninstalled",this.onUpdatedOrUninstalled)},beforeDestroy(){a.off("observeMicroApp:open",this.onOpen),a.off("observeMicroApp:updatedOrUninstalled",this.onUpdatedOrUninstalled)},watch:{userToken(e){e||this.closeAllMicroApp()},themeName(){this.closeAllMicroApp()},microApps:{handler(e){this.assistShow=!!e.find(s=>s.isOpen)},deep:!0}},computed:{...A(["userInfo","themeName","microApps","safeAreaSize"])},methods:{mounted(e){this.finish(e.detail.name)},error(e){this.finish(e.detail.name),$A.modalError({language:!1,title:this.$L("\u5E94\u7528\u52A0\u8F7D\u5931\u8D25"),content:e.detail.error,onOk:()=>{this.closeMicroApp(e.detail.name,!0)}})},finish(e){this.$store.commit("microApps/update",{name:e,data:{isLoading:!1}})},appData(e){const s=this.microApps.find(t=>t.name==e);return s?{type:"init",instance:{Vue:_,store:u,components:{DialogWrapper:w,UserSelect:c,DatePicker:v.exports.DatePicker}},props:{...s.props,name:s.name,url:s.url,urlType:s.url_type,userId:this.userId,userToken:this.userToken,userInfo:this.userInfo,baseUrl:$A.mainUrl(),systemInfo:window.systemInfo,windowType:this.windowType,isEEUIApp:$A.isEEUIApp,isElectron:$A.isElectron,isMainElectron:$A.isMainElectron,isSubElectron:$A.isSubElectron,languageList:g,languageName:y,themeName:this.themeName,safeArea:this.safeAreaSize},methods:{close:(t=!1)=>{this.closeMicroApp(e,t)},back:()=>{this.closeByName(e)},popoutWindow:async(t=null)=>{const i=this.microApps.find(n=>n.name==e);if(!i){$A.modalError("\u5E94\u7528\u4E0D\u5B58\u5728");return}await this.inlineBlank(i,t)},openWindow:t=>{$A.isJson(t)||(t={path:t}),t.url&&(t.path=t.url,delete t.url),this.$store.dispatch("openChildWindow",t)},openTabWindow:t=>{this.$store.dispatch("openWebTabWindow",t)},openAppPage:t=>{$A.isJson(t)||(t={url:t}),this.$store.dispatch("openAppChildPage",{pageType:"app",pageTitle:t.title||" ",url:"web.js",params:{url:t.url,titleFixed:typeof t.titleFixed=="boolean"?t.titleFixed:!1}})},requestAPI:async t=>await u.dispatch("call",t),selectUsers:async t=>($A.isJson(t)||(t={value:t}),$A.isArray(t.value)||(t.value=t.value?[t.value]:[]),this.userSelectOptions.value=t.value,delete t.value,this.userSelectOptions.config=t,await new Promise(i=>{this.$refs.userSelect.onSelection(n=>i(n))})),nextZIndex:()=>typeof window.modalTransferIndex=="number"?window.modalTransferIndex++:1e3,extraCallA:(...t)=>{if(t.length>0&&typeof t[0]=="string"){const i=t[0],n=t.slice(1);if(typeof $A[i]=="function")return $A[i](...n)}return null},isFullScreen:()=>window.innerWidth<768||this.windowType==="popout"}}:{}},async onOpen(e){if(/_blank$/i.test(e.url_type)){await this.inlineBlank(e);return}if(e.url_type==="external"){await this.externalWindow(e);return}const s=this.microApps.find(({name:t})=>t==e.name);s?(s.keepAliveBackup!==void 0&&(s.keep_alive=s.keepAliveBackup,delete s.keepAliveBackup),s.url!=e.url&&(this.unmountMicroApp(s),s.isLoading=!0),Object.assign(s,e),requestAnimationFrame(t=>{s.isOpen=!0,s.lastOpenAt=Date.now(),this.$store.commit("microApps/keepAlive",3)})):(e.isLoading=!0,e.isOpen=!1,e.onBeforeClose=()=>!0,this.$store.commit("microApps/push",e),requestAnimationFrame(t=>{e.isOpen=!0,e.lastOpenAt=Date.now(),this.$store.commit("microApps/keepAlive",3)}))},async inlineBlank(e,s=null){const t={...e,url_type:e.url_type.replace(/_blank$/,""),transparent:!0,keep_alive:!1};s!=null&&s.url&&(t.url=s.url,delete s.url);const i=`/single/apps/${t.name}`,n=(await $A.IDBArray("cacheMicroApps")).filter(r=>r.name!=t.name);n.length>50&&n.splice(0,10),n.push(t),await $A.IDBSet("cacheMicroApps",$A.cloneJSON(n)),this.$Electron?await this.$store.dispatch("openChildWindow",{name:`single-apps-${$A.randomString(6)}`,path:i,force:!1,config:Object.assign({title:" ",parent:null,width:Math.min(window.screen.availWidth,1440),height:Math.min(window.screen.availHeight,900)},$A.isJson(s)?s:{})}):this.$isEEUIApp?await this.$store.dispatch("openAppChildPage",{pageType:"app",pageTitle:" ",url:"web.js",params:{url:$A.urlReplaceHash(i)}}):window.open($A.mainUrl(i.substring(1)))},async externalWindow(e){this.$Electron?await this.$store.dispatch("openChildWindow",{name:`external-apps-${$A.randomString(6)}`,path:e.url,force:!1,config:{title:" ",parent:null,width:Math.min(window.screen.availWidth,1440),height:Math.min(window.screen.availHeight,900)}}):this.$isEEUIApp?await this.$store.dispatch("openAppChildPage",{pageType:"app",pageTitle:" ",url:"web.js",params:{url:e.url}}):window.open(e.url)},closeByName(e){try{this.$refs[`ref-${e}`][0].onClose()}catch{this.closeMicroApp(e)}},closeMicroApp(e,s){const t=this.microApps.find(i=>i.name==e);!t||(t.isOpen=!1,s&&this.unmountMicroApp(t))},closeAllMicroApp(e=!0){this.microApps.forEach(s=>{s.isOpen=!1,e&&this.unmountMicroApp(s)})},unmountMicroApp(e){e.keep_alive&&(e.keepAliveBackup=!0,e.keep_alive=!1),l.unmountApp(e.name,{destroy:!0})},onBeforeClose(e){return new Promise(s=>{const t=()=>{$A.isSubElectron?$A.Electron.sendMessage("windowDestroy"):s()},i=this.microApps.find(n=>n.name==e);if(!i){t();return}if(/^iframe/i.test(i.url_type)){const n=i.onBeforeClose();n&&n.then?n.then(()=>{t()}):t();return}l.forceSetData(e,{type:"beforeClose"},n=>{n!=null&&n.find(r=>r===!0)||($A.leftExists(e,"appstore")&&this.$store.dispatch("updateMicroAppsStatus"),t())})})},onAssistClose(){return new Promise(e=>{const s=this.microApps.findLast(t=>t.isOpen);s?this.closeByName(s.name):e()})},shouldRenderIFrame(e){return e.url_type==="iframe"&&(e.isOpen||e.keep_alive)&&e.url},onUpdatedOrUninstalled(e){const s=e.map(t=>t.id);s.length!==0&&this.microApps.forEach(t=>{s.includes(t.id)&&this.closeMicroApp(t.name,!0)})}}},m={};var z=d(P,T,B,!1,D,null,null,null);function D(e){for(let s in m)this[s]=m[s]}var V=function(){return z.exports}();export{V as M};