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" modal-class="micro-app-modal"
drawer-class="micro-app-drawer" drawer-class="micro-app-drawer"
placement="right" placement="right"
:beforeClose="onBeforeClose"
:size="1200"> :size="1200">
<micro-app <template>
v-if="appConfig.isOpen" <micro-app
:name="appConfig.appName" v-if="appConfig.isOpen"
:url="appConfig.appUrl" :name="appConfig.appName"
:keep-alive="appConfig.keepAlive" :url="appConfig.appUrl"
:data="appData" :keep-alive="appConfig.keepAlive"
@created="created" :data="appData"
@beforemount="beforemount" @created="created"
@mounted="mounted" @beforemount="beforemount"
@unmount="unmount" @mounted="mounted"
@error="error"/> @unmount="unmount"
@error="error"/>
<div v-if="loadIng > 0" class="micro-app-loading">
<Loading/>
</div>
</template>
</DrawerOverlay> </DrawerOverlay>
</template> </template>
@ -48,6 +54,17 @@
overflow: hidden; overflow: hidden;
} }
} }
.micro-app-loading {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
align-items: center;
display: flex;
justify-content: center;
}
</style> </style>
<script> <script>
@ -72,6 +89,7 @@ export default {
data() { data() {
return { return {
loadIng: 0,
appConfig: {}, appConfig: {},
} }
}, },
@ -90,10 +108,8 @@ export default {
}, },
watch: { watch: {
userToken(val) { userToken(token) {
if (!val) { !token && microApp.unmountAllApps({destroy: true})
microApp.unmountAllApps({destroy: true})
}
}, },
}, },
@ -104,8 +120,6 @@ export default {
]), ]),
appData() { appData() {
const {initialData, appName} = this.appConfig;
return { return {
instance: { instance: {
Vue, Vue,
@ -121,7 +135,7 @@ export default {
}, },
initialData: { initialData: {
...initialData, ...this.appConfig.initialData,
systemInfo: window.systemInfo, systemInfo: window.systemInfo,
baseUrl: $A.mainUrl(), baseUrl: $A.mainUrl(),
@ -142,10 +156,7 @@ export default {
}, },
handleClose: (destroy = false) => { handleClose: (destroy = false) => {
this.appConfig.appName === appName && (this.appConfig.isOpen = false); this.closeMicroApp(destroy)
if (destroy) {
microApp.unmountApp(appName, {destroy: true})
}
}, },
nextModalIndex: () => { nextModalIndex: () => {
@ -172,22 +183,16 @@ export default {
methods: { methods: {
// //
created(e) { created(e) {
const item = appMaps.get(e.detail.name) this.stateChange(e)
if (item?.isLoading) {
this.$store.dispatch('showSpinner');
}
}, },
// //
beforemount(e) { beforemount() {
const item = appMaps.get(e.detail.name)
if (item?.isLoading) {
this.$store.dispatch('hiddenSpinner');
}
}, },
// //
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', // appName: 'micro-app', //
appUrl: null, // URL appUrl: null, // URL
initialData: {}, // initialData: {}, //
@ -214,26 +248,47 @@ export default {
isLoading: true, // (true/false) isLoading: true, // (true/false)
isOpen: false, // (true/false) isOpen: false, // (true/false)
}, config); }, appConfig);
// //
const lastApp = appMaps.get(config.appName) const lastConfig = appMaps.get(appConfig.appName)
if (lastApp) { if (lastConfig) {
if (lastApp.displayMode != config.displayMode || lastApp.appUrl != config.appUrl) { if (lastConfig.displayMode != appConfig.displayMode || lastConfig.appUrl != appConfig.appUrl) {
microApp.unmountApp(config.appName, {destroy: true}) microApp.unmountApp(appConfig.appName, {destroy: true})
} else { } else {
config.isLoading = false; appConfig.isLoading = false;
} }
} }
// //
appMaps.set(config.appName, this.appConfig = config); appMaps.set(appConfig.appName, this.appConfig = appConfig);
// //
this.$nextTick(_ => { this.$nextTick(_ => {
this.appConfig.isOpen = true 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> </script>