no message

This commit is contained in:
kuaifan 2025-05-07 09:41:12 +08:00
parent f53a5ea6c1
commit 1c5b856800
2 changed files with 102 additions and 45 deletions

View File

@ -2065,3 +2065,5 @@ AI开启新会话失败
按工作流
按状态
应用加载失败

View File

@ -21,18 +21,24 @@
modal-class="micro-app-modal"
drawer-class="micro-app-drawer"
placement="right"
:beforeClose="onBeforeClose"
:size="1200">
<micro-app
v-if="appConfig.isOpen"
:name="appConfig.appName"
:url="appConfig.appUrl"
:keep-alive="appConfig.keepAlive"
:data="appData"
@created="created"
@beforemount="beforemount"
@mounted="mounted"
@unmount="unmount"
@error="error"/>
<template>
<micro-app
v-if="appConfig.isOpen"
:name="appConfig.appName"
:url="appConfig.appUrl"
:keep-alive="appConfig.keepAlive"
:data="appData"
@created="created"
@beforemount="beforemount"
@mounted="mounted"
@unmount="unmount"
@error="error"/>
<div v-if="loadIng > 0" class="micro-app-loading">
<Loading/>
</div>
</template>
</DrawerOverlay>
</template>
@ -48,6 +54,17 @@
overflow: hidden;
}
}
.micro-app-loading {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
align-items: center;
display: flex;
justify-content: center;
}
</style>
<script>
@ -72,6 +89,7 @@ export default {
data() {
return {
loadIng: 0,
appConfig: {},
}
},
@ -90,10 +108,8 @@ export default {
},
watch: {
userToken(val) {
if (!val) {
microApp.unmountAllApps({destroy: true})
}
userToken(token) {
!token && microApp.unmountAllApps({destroy: true})
},
},
@ -104,8 +120,6 @@ export default {
]),
appData() {
const {initialData, appName} = this.appConfig;
return {
instance: {
Vue,
@ -121,7 +135,7 @@ export default {
},
initialData: {
...initialData,
...this.appConfig.initialData,
systemInfo: window.systemInfo,
baseUrl: $A.mainUrl(),
@ -142,10 +156,7 @@ export default {
},
handleClose: (destroy = false) => {
this.appConfig.appName === appName && (this.appConfig.isOpen = false);
if (destroy) {
microApp.unmountApp(appName, {destroy: true})
}
this.closeMicroApp(destroy)
},
nextModalIndex: () => {
@ -172,22 +183,16 @@ export default {
methods: {
//
created(e) {
const item = appMaps.get(e.detail.name)
if (item?.isLoading) {
this.$store.dispatch('showSpinner');
}
this.stateChange(e)
},
//
beforemount(e) {
const item = appMaps.get(e.detail.name)
if (item?.isLoading) {
this.$store.dispatch('hiddenSpinner');
}
beforemount() {
},
//
mounted() {
mounted(e) {
this.stateChange(e, true)
},
//
@ -195,16 +200,45 @@ export default {
},
//
error() {
error(e) {
this.stateChange(e, true)
$A.modalError({
language: false,
title: this.$L('应用加载失败'),
content: e.detail.error,
onOk: () => {
this.closeMicroApp(true)
},
});
},
//
stateChange(e, end = false) {
const appConfig = appMaps.get(e.detail.name)
if (appConfig?.isLoading) {
if (end) {
if (appConfig.transparent) {
this.$store.dispatch('hiddenSpinner');
} else {
this.loadIng--;
}
} else {
if (appConfig.transparent) {
this.$store.dispatch('showSpinner');
} else {
this.loadIng++;
}
}
}
},
/**
* 打开微应用
* @param config
* @param appConfig
*/
openMicroApp(config) {
openMicroApp(appConfig) {
//
config = Object.assign({
appConfig = Object.assign({
appName: 'micro-app', //
appUrl: null, // URL
initialData: {}, //
@ -214,26 +248,47 @@ export default {
isLoading: true, // (true/false)
isOpen: false, // (true/false)
}, config);
}, appConfig);
//
const lastApp = appMaps.get(config.appName)
if (lastApp) {
if (lastApp.displayMode != config.displayMode || lastApp.appUrl != config.appUrl) {
microApp.unmountApp(config.appName, {destroy: true})
//
const lastConfig = appMaps.get(appConfig.appName)
if (lastConfig) {
if (lastConfig.displayMode != appConfig.displayMode || lastConfig.appUrl != appConfig.appUrl) {
microApp.unmountApp(appConfig.appName, {destroy: true})
} else {
config.isLoading = false;
appConfig.isLoading = false;
}
}
//
appMaps.set(config.appName, this.appConfig = config);
appMaps.set(appConfig.appName, this.appConfig = appConfig);
//
this.$nextTick(_ => {
this.appConfig.isOpen = true
})
}
},
/**
* 关闭微应用
* @param destroy
*/
closeMicroApp(destroy) {
this.appConfig.isOpen = false
if (destroy) {
microApp.unmountApp(this.appConfig.appName, {destroy: true})
}
},
/**
* 关闭之前判断
* @returns {Promise<unknown>}
*/
onBeforeClose() {
return new Promise(resolve => {
resolve()
})
},
}
}
</script>