no message

This commit is contained in:
kuaifan 2025-05-23 11:26:22 +08:00
parent 2905059947
commit 6e03a05e6d
6 changed files with 37 additions and 40 deletions

View File

@ -4,18 +4,18 @@
v-for="(app, key) in apps"
:key="key"
v-model="app.isOpen"
:ref="`ref-${app.id}`"
:ref="`ref-${app.name}`"
:size="1200"
:transparent="app.transparent"
:autoDarkTheme="app.autoDarkTheme"
:beforeClose="async () => { await onBeforeClose(app.id) }">
:beforeClose="async () => { await onBeforeClose(app.name) }">
<micro-app
v-if="app.isOpen && app.url"
:name="app.id"
:name="app.name"
:url="app.url"
:keep-alive="app.keepAlive"
:disable-scopecss="app.disableScopecss"
:data="appData(app.id)"
:data="appData(app.name)"
@created="created"
@beforemount="beforemount"
@mounted="mounted"
@ -173,7 +173,7 @@ export default {
//
finish(e) {
const app = this.apps.find(({id}) => id == e.detail.name);
const app = this.apps.find(({name}) => name == e.detail.name);
if (app) {
app.isLoading = false
}
@ -181,11 +181,11 @@ export default {
/**
* 应用数据
* @param id
* @param name
* @returns {*}
*/
appData(id) {
const app = this.apps.find(item => item.id == id);
appData(name) {
const app = this.apps.find(item => item.name == name);
if (!app) {
return {};
}
@ -225,10 +225,10 @@ export default {
methods: {
close: (destroy = false) => {
this.closeMicroApp(id, destroy)
this.closeMicroApp(name, destroy)
},
back: () => {
this.closeById(id)
this.closeByName(name)
},
nextZIndex: () => {
if (typeof window.modalTransferIndex === 'number') {
@ -256,12 +256,12 @@ export default {
let appConfig = {}
if (config.url) {
appConfig = {
id: `url-${await $A.getSHA256Hash(config.url)}`,
name: `url-${await $A.getSHA256Hash(config.url)}`,
url: config.url,
}
delete config.url
} else {
const app = this.apps.find(item => item.id == id);
const app = this.apps.find(item => item.name == name);
if (!app) {
$A.modalError("应用不存在");
return
@ -271,14 +271,14 @@ export default {
appConfig.transparent = true
appConfig.keepAlive = false
const apps = (await $A.IDBArray("cacheMicroApps")).filter(item => item.id != appConfig.id);
const apps = (await $A.IDBArray("cacheMicroApps")).filter(item => item.name != appConfig.name);
apps.length > 50 && apps.splice(0, 10)
apps.push(appConfig)
await $A.IDBSet("cacheMicroApps", apps);
await this.$store.dispatch('openChildWindow', {
name: `single-apps-${$A.randomString(6)}`,
path: `/single/apps/${appConfig.id}`,
path: `/single/apps/${appConfig.name}`,
force: false,
config
});
@ -329,11 +329,11 @@ export default {
* @param config
*/
async observeMicroApp(config) {
const app = this.apps.find(({id}) => id == config.id);
const app = this.apps.find(({name}) => name == config.name);
if (app) {
//
if (app.url != config.url) {
await microApp.unmountApp(app.id, {destroy: true})
await microApp.unmountApp(app.name, {destroy: true})
app.isLoading = true
}
Object.assign(app, config)
@ -348,31 +348,31 @@ export default {
},
/**
* 通过ID关闭微应用
* @param id
* 通过名称关闭微应用
* @param name
*/
closeById(id) {
closeByName(name) {
try {
this.$refs[`ref-${id}`][0].onClose()
this.$refs[`ref-${name}`][0].onClose()
} catch (e) {
this.closeMicroApp(id)
this.closeMicroApp(name)
}
},
/**
* 关闭微应用
* @param id
* @param name
* @param destroy
*/
closeMicroApp(id, destroy) {
const app = this.apps.find(item => item.id == id);
closeMicroApp(name, destroy) {
const app = this.apps.find(item => item.name == name);
if (!app) {
return;
}
app.isOpen = false
if (destroy) {
microApp.unmountApp(app.id, {destroy: true})
microApp.unmountApp(app.name, {destroy: true})
}
},
@ -386,14 +386,14 @@ export default {
/**
* 关闭之前判断
* @param id
* @param name
* @returns {Promise<unknown>}
*/
onBeforeClose(id) {
onBeforeClose(name) {
return new Promise(resolve => {
microApp.forceSetData(id, {type: 'beforeClose'}, array => {
microApp.forceSetData(name, {type: 'beforeClose'}, array => {
if (!array?.find(item => item === true)) {
if (id === 'appstore') {
if (name === 'appstore') {
this.$store.dispatch("updateMicroAppsStatus");
}
if ($A.isSubElectron) {
@ -414,7 +414,7 @@ export default {
return new Promise(resolve => {
const app = this.apps.findLast(item => item.isOpen)
if (app) {
this.closeById(app.id)
this.closeByName(app.name)
} else {
resolve()
}

View File

@ -2626,7 +2626,7 @@ export default {
this.$store.dispatch("openMicroApp", {
id: 'okr',
key: 'details',
url: 'apps/okr/',
url: 'apps/okr/#details',
props: {type: 'details', id},
transparent: true,
});

View File

@ -9,13 +9,13 @@ export default {
components: { MicroApps },
async mounted() {
const id = this.$route.params.appId;
if (!id) {
const {name} = this.$route.params;
if (!name) {
$A.modalError("应用不存在");
return
}
const app = (await $A.IDBArray("cacheMicroApps")).reverse().find(item => item.id === id);
const app = (await $A.IDBArray("cacheMicroApps")).reverse().find(item => item.name === name);
if (!app) {
$A.modalError("应用不存在");
return

View File

@ -155,7 +155,7 @@ export default [
},
{
name: 'single-apps',
path: '/single/apps/:appId',
path: '/single/apps/:name',
component: () => import('./pages/single/apps.vue')
},
{

View File

@ -4654,7 +4654,7 @@ export default {
* - keepAlive 是否开启微应用保活 (true/false)默认 true
* - disableScopecss 是否禁用样式隔离 (true/false)默认 false
*/
openMicroApp({state}, data) {
async openMicroApp({state}, data) {
if (!data || !$A.isJson(data)) {
return
}
@ -4677,9 +4677,7 @@ export default {
$A.modalWarning(`应用「${config.id}」未安装`);
return;
}
if (data.key) {
config.id += `_${data.key}`
}
config.name = `${config.id}_${await $A.getSHA256Hash(config.url)}`
emitter.emit('observeMicroApp:open', config);
},

View File

@ -304,7 +304,6 @@ export default {
data.unshift({
id: 'appstore',
menu_items: [{
id: 'appstore',
location: "application/admin",
label: $A.L("应用商店"),
icon: $A.mainUrl("images/application/appstore.svg"),