diff --git a/frontend/src/components/router-button/index.vue b/frontend/src/components/router-button/index.vue index 361837889..9d3ba5200 100644 --- a/frontend/src/components/router-button/index.vue +++ b/frontend/src/components/router-button/index.vue @@ -8,7 +8,7 @@ size="large" :key="index" > - + {{ button.label }} diff --git a/frontend/src/utils/bus.ts b/frontend/src/utils/bus.ts new file mode 100644 index 000000000..84a19e8f5 --- /dev/null +++ b/frontend/src/utils/bus.ts @@ -0,0 +1,26 @@ +class Bus { + list: { [key: string]: Array }; + constructor() { + this.list = {}; + } + + on(name: string, fn: Function) { + this.list[name] = this.list[name] || []; + this.list[name].push(fn); + } + + emit(name: string, data?: any) { + if (this.list[name]) { + this.list[name].forEach((fn: Function) => { + fn(data); + }); + } + } + + off(name: string) { + if (this.list[name]) { + delete this.list[name]; + } + } +} +export default Bus; diff --git a/frontend/src/views/app-store/bus.ts b/frontend/src/views/app-store/bus.ts new file mode 100644 index 000000000..a8feefa2a --- /dev/null +++ b/frontend/src/views/app-store/bus.ts @@ -0,0 +1,3 @@ +import Bus from '@/utils/bus'; + +export default new Bus(); diff --git a/frontend/src/views/app-store/index.vue b/frontend/src/views/app-store/index.vue index 50ec55fa7..3a228ba6d 100644 --- a/frontend/src/views/app-store/index.vue +++ b/frontend/src/views/app-store/index.vue @@ -15,6 +15,7 @@ import RouterButton from '@/components/router-button/index.vue'; import i18n from '@/lang'; import { onMounted, ref } from 'vue'; import { SearchAppInstalled } from '@/api/modules/app'; +import bus from './bus'; let showButton = ref(false); const buttons = [ { @@ -31,12 +32,26 @@ const buttons = [ count: 0, }, ]; + +const search = () => { + SearchAppInstalled({ update: true, page: 1, pageSize: 100 }) + .then((res) => { + if (res.data.items) { + buttons[2].count = res.data.items.length; + } else { + buttons[2].count = 0; + } + }) + .finally(() => { + showButton.value = true; + }); +}; + onMounted(() => { - SearchAppInstalled({ update: true, page: 1, pageSize: 100 }).then((res) => { - if (res.data.items) { - buttons[2].count = res.data.items.length; - } - showButton.value = true; + search(); + bus.on('update', () => { + showButton.value = false; + search(); }); }); diff --git a/frontend/src/views/app-store/installed/update/index.vue b/frontend/src/views/app-store/installed/update/index.vue index 21a3b00ce..ae83414d0 100644 --- a/frontend/src/views/app-store/installed/update/index.vue +++ b/frontend/src/views/app-store/installed/update/index.vue @@ -34,10 +34,11 @@ import { App } from '@/api/interface/app'; import { GetAppUpdateVersions, InstalledOp } from '@/api/modules/app'; import i18n from '@/lang'; import { ElMessageBox, FormInstance } from 'element-plus'; -import { reactive, ref } from 'vue'; +import { reactive, ref, onBeforeUnmount } from 'vue'; import Header from '@/components/drawer-header/index.vue'; import { MsgSuccess } from '@/utils/message'; import { Rules } from '@/global/form-rules'; +import bus from '../../bus'; const updateRef = ref(); let open = ref(false); @@ -75,8 +76,9 @@ const operate = async () => { loading.value = true; await InstalledOp(operateReq) .then(() => { - open.value = false; MsgSuccess(i18n.global.t('commons.msg.operationSuccess')); + bus.emit('update', true); + handleClose(); }) .finally(() => { loading.value = false; @@ -97,6 +99,10 @@ const onOperate = async () => { }); }; +onBeforeUnmount(() => { + bus.off('update'); +}); + defineExpose({ acceptParams, });