程序启动等操作及操作结果通知

This commit is contained in:
Rewrite0
2023-05-27 22:32:37 +08:00
parent 75271f41e4
commit d71caa2fac
3 changed files with 46 additions and 2 deletions

View File

@@ -1,6 +1,7 @@
import type { Config } from '#/config';
export const useConfigStore = defineStore('config', () => {
const message = useMessage();
const config = ref<Config>({
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 = <Tkey extends keyof Config>(key: Tkey) => {

View File

@@ -1,4 +1,5 @@
export const useProgramStore = defineStore('program', () => {
const message = useMessage();
const running = ref(false);
const timer = ref<NodeJS.Timer | null>(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,
};
});

View File

@@ -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,