diff --git a/resources/assets/js/components/MicroApps/index.vue b/resources/assets/js/components/MicroApps/index.vue index 1d774cee3..55c0f2686 100644 --- a/resources/assets/js/components/MicroApps/index.vue +++ b/resources/assets/js/components/MicroApps/index.vue @@ -327,46 +327,23 @@ export default { /** * 观察打开微应用 * @param config - * - name 应用名称 - * - url 应用地址 - * - props 传递参数 - * - transparent 是否透明模式 (true/false),默认 false - * - autoDarkTheme 是否自动适配深色主题 (true/false),默认 true - * - keepAlive 是否开启微应用保活 (true/false),默认 true - * - disableScopecss 是否禁用样式隔离 (true/false),默认 false */ - observeMicroApp(config) { - // 处理数据 - config.name = config.name || 'micro-app' - config.url = config.url || null - config.props = $A.isJson(config.props) ? config.props : {} - config.transparent = typeof config.transparent == 'boolean' ? config.transparent : false - config.autoDarkTheme = typeof config.autoDarkTheme == 'boolean' ? config.autoDarkTheme : true - config.keepAlive = typeof config.keepAlive == 'boolean' ? config.keepAlive : true - config.disableScopecss = typeof config.disableScopecss == 'boolean' ? config.disableScopecss : false - - // 判断处理 + async observeMicroApp(config) { const app = this.apps.find(({name}) => name == config.name); if (app) { // 更新微应用 if (app.url != config.url) { - microApp.unmountApp(app.name, {destroy: true}) + await microApp.unmountApp(app.name, {destroy: true}) app.isLoading = true } - for (let key in config) { - app[key] = config[key] - } - this.$nextTick(_ => { - app.isOpen = true - }) + Object.assign(app, config) + this.$nextTick(_ => app.isOpen = true) } else { // 新建微应用 config.isLoading = true config.isOpen = false this.apps.push(config) - this.$nextTick(_ => { - config.isOpen = true - }) + this.$nextTick(_ => config.isOpen = true) } }, diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index b6d27bfee..3b3a699c1 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -4641,46 +4641,45 @@ export default { /** ************************************ App Store ******************************************/ /** *****************************************************************************************/ - /** - * 更新微应用状态(已安装应用、菜单项) - * @param commit - * @param dispatch - */ - updateMicroAppsStatus({commit, dispatch}) { - dispatch("call", { - url: 'apps/status', - }).then(({data}) => { - commit("microApps/installed", data.installed) - commit("microApps/menu", data.menus) - }) - }, - /** * 打开微应用 * @param state - * @param menuItem + * @param data + * - name 应用名称 + * - url 应用地址 + * - props 传递参数 + * - transparent 是否透明模式 (true/false),默认 false + * - autoDarkTheme 是否自动适配深色主题 (true/false),默认 true + * - keepAlive 是否开启微应用保活 (true/false),默认 true + * - disableScopecss 是否禁用样式隔离 (true/false),默认 false */ - openMicroApp({state}, menuItem) { - if (!menuItem || !$A.isJson(menuItem)) { + openMicroApp({state}, data) { + if (!data || !$A.isJson(data)) { return } - const event = { - name: menuItem.app_name || menuItem.name, - url: $A.mainUrl(menuItem.url), + if (!data.url) { + return } - if (!state.microAppsInstalled.includes(event.name)) { - $A.modalWarning("应用未安装"); + const config = { + name: data.app_name || data.name, + url: $A.mainUrl(data.url), + props: $A.isJson(data.props) ? data.props : {}, + transparent: typeof data.transparent == 'boolean' ? data.transparent : false, + autoDarkTheme: typeof data.autoDarkTheme == 'boolean' ? data.autoDarkTheme : true, + keepAlive: typeof data.keepAlive == 'boolean' ? data.keepAlive : true, + disableScopecss: typeof data.disableScopecss == 'boolean' ? data.disableScopecss : false + } + if (!config.name) { + return + } + if (!state.microAppsInstalled.includes(config.name)) { + $A.modalWarning(`应用「${config.name}」未安装`); return; } - if (menuItem.key) { - event.name += `_${menuItem.key}` + if (data.key) { + config.name += `_${data.key}` } - for (let key in menuItem) { - if (['transparent', 'autoDarkTheme', 'keepAlive', 'disableScopecss'].includes(key)) { - event[key] = menuItem[key] - } - } - emitter.emit('observeMicroApp:open', event); + emitter.emit('observeMicroApp:open', config); }, /** @@ -4697,5 +4696,19 @@ export default { } resolve(!!state.microAppsInstalled.includes(appName)) }) - } + }, + + /** + * 更新微应用状态(已安装应用、菜单项) + * @param commit + * @param dispatch + */ + updateMicroAppsStatus({commit, dispatch}) { + dispatch("call", { + url: 'apps/status', + }).then(({data}) => { + commit("microApps/installed", data.installed) + commit("microApps/menu", data.menus) + }) + }, }