From d71caa2fac37a39b8ac49afb73fa88c48e010999 Mon Sep 17 00:00:00 2001 From: Rewrite0 <49576640+Rewrite0@users.noreply.github.com> Date: Sat, 27 May 2023 22:32:37 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=90=AF=E5=8A=A8=E7=AD=89?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E5=8F=8A=E6=93=8D=E4=BD=9C=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/config.ts | 8 +++++++- src/store/program.ts | 34 ++++++++++++++++++++++++++++++++++ src/views/ab-topbar.vue | 6 +++++- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/store/config.ts b/src/store/config.ts index 903a1297..b3c417f3 100644 --- a/src/store/config.ts +++ b/src/store/config.ts @@ -1,6 +1,7 @@ import type { Config } from '#/config'; export const useConfigStore = defineStore('config', () => { + const message = useMessage(); const config = ref({ program: { rss_time: 0, @@ -56,7 +57,12 @@ export const useConfigStore = defineStore('config', () => { }; const setConfig = async () => { - await apiConfig.updateConfig(config.value); + const status = await apiConfig.updateConfig(config.value); + if (status) { + message.success('apply success!'); + } else { + message.error('apply fail!'); + } }; const getSettingGroup = (key: Tkey) => { diff --git a/src/store/program.ts b/src/store/program.ts index 26761745..328188d5 100644 --- a/src/store/program.ts +++ b/src/store/program.ts @@ -1,4 +1,5 @@ export const useProgramStore = defineStore('program', () => { + const message = useMessage(); const running = ref(false); const timer = ref(null); @@ -11,9 +12,42 @@ export const useProgramStore = defineStore('program', () => { timer.value = setInterval(() => getStatus(), 3000); }; + function handleMessage(handle: string, success: boolean) { + if (success) { + message.success(`${handle} Success!`); + } else { + message.error(`${handle} Fail!`); + } + } + + const start = async () => { + const res = await apiProgram.start(); + handleMessage('Start', res); + }; + + const pause = async () => { + const res = await apiProgram.stop(); + handleMessage('Pause', res); + }; + + const shutdown = async () => { + const res = await apiProgram.shutdown(); + handleMessage('Shutdown', res); + }; + + const restart = async () => { + const res = await apiProgram.restart(); + handleMessage('Restart', res); + }; + return { running, getStatus, onUpdate, + + start, + pause, + shutdown, + restart, }; }); diff --git a/src/views/ab-topbar.vue b/src/views/ab-topbar.vue index ec2d1658..9507b693 100644 --- a/src/views/ab-topbar.vue +++ b/src/views/ab-topbar.vue @@ -3,7 +3,7 @@ import { Me, Pause, PlayOne, Power, Refresh } from '@icon-park/vue-next'; const search = ref(''); -const { onUpdate } = useProgramStore(); +const { onUpdate, start, pause, shutdown, restart } = useProgramStore(); const { running } = storeToRefs(useProgramStore()); const items = [ @@ -11,21 +11,25 @@ const items = [ id: 1, label: 'Start', icon: PlayOne, + handle: start, }, { id: 2, label: 'Pause', icon: Pause, + handle: pause, }, { id: 3, label: 'Restart', icon: Refresh, + handle: restart, }, { id: 4, label: 'Shutdown', icon: Power, + handle: shutdown, }, { id: 5,