From 3456ab7509467dcc1872a1d4afda9f864702e273 Mon Sep 17 00:00:00 2001 From: zhengkunwang223 Date: Tue, 21 Feb 2023 11:27:32 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=8D=87=E7=BA=A7?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E4=B9=8B=E5=90=8E=20=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=88=B7=E6=96=B0=E7=9A=84BUG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/router-button/index.vue | 2 +- frontend/src/utils/bus.ts | 26 +++++++++++++++++++ frontend/src/views/app-store/bus.ts | 3 +++ frontend/src/views/app-store/index.vue | 25 ++++++++++++++---- .../app-store/installed/update/index.vue | 10 +++++-- 5 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 frontend/src/utils/bus.ts create mode 100644 frontend/src/views/app-store/bus.ts 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, });