mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 03:01:12 +00:00
2 lines
18 KiB
JavaScript
Vendored
2 lines
18 KiB
JavaScript
Vendored
import{V as _}from"./vue.fd9b772e.js";import{m as v}from"./vuex.cc7cb26e.js";import{i as A}from"./view-design-hi.18b9f7fe.js";import{m as a}from"./@micro-zoe.f728a9f4.js";import{D as w}from"./DialogWrapper.b76cf53b.js";import{n as d,d as f,U as c,e as l,b as u,c as y,l as g}from"./app.aaf80a2e.js";import{R as $}from"./index.4dfd3ed4.js";var b=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:function(i){return e.onClose(!1)}}}):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-tools",class:{expanded:e.$A.isMainElectron}},[t("div",{staticClass:"tool-close",on:{click:function(i){return e.onClose(!0)}}},[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("div",{staticClass:"tool-fullscreen",on:{click:function(i){return e.$emit("on-popout-window")}}},[t("svg",{attrs:{viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg"}},[t("path",{attrs:{d:"M682.666667 298.666667H170.666667c-47.061333 0-85.333333 38.272-85.333334 85.333333v426.666667c0 47.061333 38.272 85.333333 85.333334 85.333333h512c47.061333 0 85.333333-38.272 85.333333-85.333333V384c0-47.061333-38.272-85.333333-85.333333-85.333333zM170.666667 810.666667v-341.333334h512V384l0.085333 426.666667H170.666667z",fill:"currentColor"}}),t("path",{attrs:{d:"M938.666667 213.333333c0-47.061333-38.272-85.333333-85.333334-85.333333H298.666667c-47.061333 0-85.333333 38.272-85.333334 85.333333h554.709334c46.976 0 85.162667 38.186667 85.290666 85.077334L853.418667 640H853.333333v85.333333c47.061333 0 85.333333-38.272 85.333334-85.333333V341.632L938.709333 341.333333V256L938.666667 255.573333V213.333333z",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)])},M=[];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(e=!1){if(!this.beforeClose)return this.handleClose();const s=this.beforeClose(e);s&&s.then?s.then(()=>{this.handleClose()}):this.handleClose()},handleClose(){this.$emit("input",!1)}}},p={};var O=d(C,b,M,!1,k,null,null,null);function k(e){for(let s in p)this[s]=p[s]}var E=function(){return O.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 L={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,isReady:!1,isLoading:!0,hasMounted:!1,hearTbeatLastTime:0}},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 s=e.data.type,t=this.handleMessageEnsureJson(e.data.message);switch(s){case"MICRO_APP_READY":this.handleMessageOfReady(t);break;case"MICRO_APP_HEARTBEAT":this.handleMessageOfHeartbeat(t);break;case"MICRO_APP_METHOD":this.handleMessageOfMethod(t);break;case"MICRO_APP_FUNCTION_RESULT":this.handleMessageOfFunctionResult(t);break;case"MICRO_APP_BEFORE_CLOSE":this.handleMessageOfBeforeClose(t);break;case"MICRO_APP_BEFORE_UNLOAD":this.handleMessageOfBeforeUnload(t);break}},handleMessageEnsureJson(e){return $A.isJson(e)?e:{}},handleMessageOfReady({supportBeforeClose:e}){this.handleLoad(),this.isReady=!0,this.isLoading=!1,e&&this.$store.commit("microApps/update",{name:this.name,data:{onBeforeClose:()=>this.hearTbeatLastTime&&Date.now()-this.hearTbeatLastTime>5e3?!0: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)})}})},handleMessageOfHeartbeat(){this.hearTbeatLastTime=Date.now()},handleMessageOfMethod({id:e,method:s,args:t}){if(!this.data||!this.data.methods||!this.data.methods[s])return;const i=n=>{this.$refs.iframe.contentWindow.postMessage({type:"MICRO_APP_METHOD_RESULT",message:{id:e,result:$A.cloneJSON(n)}},"*")},r=n=>{this.$refs.iframe.contentWindow.postMessage({type:"MICRO_APP_METHOD_RESULT",message:{id:e,result:null,error:(n==null?void 0:n.message)||n}},"*")};try{const n=this.deserializeFunctions(t),o=this.data.methods[s](...n);o&&o.then?o.then(i).catch(r):i(o)}catch(n){r(n)}},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))},handleMessageOfBeforeUnload(){this.isReady=!1,this.$store.commit("microApps/update",{name:this.name,data:{onBeforeClose:()=>!0}})},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 r=`call_${Date.now()}_${Math.random().toString(36).substring(2,9)}`,n=setTimeout(()=>{this.pendingFunctionCalls.delete(r),i(new Error("Function call timeout"))},5e3);if(this.pendingFunctionCalls.set(r,{resolve:t,reject:i,timeout:n}),!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:r,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 T=d(L,S,I,!1,x,"101ca27a",null,null);function x(e){for(let s in h)this[s]=h[s]}var R=function(){return T.exports}(),B=function(){var e=this,s=e.$createElement,t=e._self._c||s;return t("div",[e._l(e.microApps,function(i,r){return t("MicroModal",{key:r,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(n){await e.onBeforeClose(i.name,n)}},on:{"on-popout-window":function(n){return e.onPopoutWindow(i.name)}},model:{value:i.isOpen,callback:function(n){e.$set(i,"isOpen",n)},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)},P=[];const F={name:"MicroApps",directives:{TransferDom:f},components:{MicroModal:E,UserSelect:c,MicroIFrame:R},props:{windowType:{type:String,default:"embed"}},data(){return{assistShow:!1,userSelectOptions:{value:[],config:{}}}},created(){a.unmountAllApps({destroy:!0}),a.start({iframe:!0,"router-mode":"state",iframeSrc:window.location.origin+"/assets/empty.html"})},mounted(){l.on("observeMicroApp:open",this.onOpen),l.on("observeMicroApp:updatedOrUninstalled",this.onUpdatedOrUninstalled)},beforeDestroy(){l.off("observeMicroApp:open",this.onOpen),l.off("observeMicroApp:updatedOrUninstalled",this.onUpdatedOrUninstalled)},watch:{userToken(e){e||this.unmountAllMicroApp()},themeName(){this.unmountAllMicroApp()},microApps:{handler(e){this.assistShow=!!e.find(s=>s.isOpen)},deep:!0}},computed:{...v(["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:A.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:y,languageName:g,themeName:this.themeName,safeArea:this.safeAreaSize},methods:{close:(t=!1)=>{this.closeMicroApp(e,t)},back:()=>{this.closeByName(e)},popoutWindow:async(t=null)=>{await this.onPopoutWindow(e,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,r)=>{this.$refs.userSelect.onSelection(n=>{i(n)},r)})),nextZIndex:()=>typeof window.modalTransferIndex=="number"?window.modalTransferIndex++:1e3,isFullScreen:()=>window.innerWidth<768||this.windowType==="popout",extraCallA:(...t)=>{if(t.length>0&&typeof t[0]=="string"){const i=t[0],r=t.slice(1);if(typeof $A[i]=="function")return $A[i](...r)}return null},extraCallStore:async(...t)=>{if(t.length>0&&typeof t[0]=="string"){const i=t[0],r=t.slice(1);await this.$store.dispatch(i,...r)}return null}}}:{}},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}`,r=(await $A.IDBArray("cacheMicroApps")).filter(n=>n.name!=t.name);r.length>50&&r.splice(0,10),r.push(t),await $A.IDBSet("cacheMicroApps",$A.cloneJSON(r)),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))},unmountAllMicroApp(){this.microApps.forEach(e=>{e.isOpen=!1,this.unmountMicroApp(e)})},unmountMicroApp(e){e.keep_alive&&(e.keepAliveBackup=!0,e.keep_alive=!1),a.unmountApp(e.name,{destroy:!0})},onBeforeClose(e,s=!1){return new Promise(t=>{const i=()=>{$A.isSubElectron?$A.Electron.sendMessage("windowDestroy"):t()},r=this.microApps.find(n=>n.name==e);if(!r){i();return}if(s&&r.keep_alive){i();return}if(/^iframe/i.test(r.url_type)){const n=r.onBeforeClose();n&&n.then?n.then(()=>{i()}):i();return}a.forceSetData(e,{type:"beforeClose"},n=>{n!=null&&n.find(o=>o===!0)||($A.leftExists(e,"appstore")&&this.$store.dispatch("updateMicroAppsStatus"),i())})})},onAssistClose(){return new Promise(e=>{const s=this.microApps.findLast(t=>t.isOpen);s?this.closeByName(s.name):e()})},async onPopoutWindow(e,s=null){const t=this.microApps.find(i=>i.name==e);if(!t){$A.modalError("\u5E94\u7528\u4E0D\u5B58\u5728");return}await this.inlineBlank(t,s)},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(F,B,P,!1,D,null,null,null);function D(e){for(let s in m)this[s]=m[s]}var q=function(){return z.exports}();export{q as M};
|