mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-04-13 16:49:48 +08:00
程序启动等操作及操作结果通知
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user