mirror of
https://github.com/EstrellaXD/Auto_Bangumi.git
synced 2026-06-27 23:46:20 +08:00
更新配置和重启相关逻辑和部分布局修改
This commit is contained in:
@@ -2,8 +2,11 @@ import axios from 'axios';
|
||||
import type { Config } from '#/config';
|
||||
|
||||
export async function setConfig(newConfig: Config) {
|
||||
const { data } = await axios.post('api/v1/updateConfig', newConfig);
|
||||
return data;
|
||||
const { data } = await axios.post<{
|
||||
message: 'Success' | 'Failed to update config';
|
||||
}>('api/v1/updateConfig', newConfig);
|
||||
|
||||
return data.message === 'Success';
|
||||
}
|
||||
|
||||
export async function getConfig() {
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import axios from 'axios';
|
||||
|
||||
/** 重启 */
|
||||
export const appRestart = () => axios.get('api/v1/restart');
|
||||
export async function appRestart() {
|
||||
const { data } = await axios.get<{ status: 'ok' }>('api/v1/restart');
|
||||
return data.status === 'ok';
|
||||
}
|
||||
|
||||
/** 启动 */
|
||||
export const appStart = () => axios.get('api/v1/start');
|
||||
|
||||
@@ -15,13 +15,13 @@ import BangumiData from './components/BangumiData.vue';
|
||||
|
||||
<el-row :gutter="20">
|
||||
<!-- S 添加新番 -->
|
||||
<el-col :xs="24" :sm="24" :md="12" :lg="8">
|
||||
<el-col :xs="24" :sm="24" :md="12" :lg="8" mb-20px>
|
||||
<AddBangumi type="new" />
|
||||
</el-col>
|
||||
<!-- E 添加新番 -->
|
||||
|
||||
<!-- S 添加旧番 -->
|
||||
<el-col :xs="24" :sm="24" :md="12" :lg="8">
|
||||
<el-col :xs="24" :sm="24" :md="12" :lg="8" mb-20px>
|
||||
<AddBangumi type="old" />
|
||||
</el-col>
|
||||
<!-- E 添加旧番 -->
|
||||
|
||||
@@ -25,10 +25,10 @@ function restart() {
|
||||
ElMessageBox.confirm('该操作将重启程序!', {
|
||||
type: 'warning',
|
||||
})
|
||||
.then(async () => {
|
||||
.then(() => {
|
||||
appRestart()
|
||||
.then(({ data }) => {
|
||||
if (data.status === 'success') {
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
ElMessage({
|
||||
message: '正在重启, 请稍后刷新页面...',
|
||||
type: 'success',
|
||||
@@ -38,7 +38,7 @@ function restart() {
|
||||
.catch((error) => {
|
||||
console.error('🚀 ~ file: index.vue:41 ~ .then ~ error:', error);
|
||||
ElMessage({
|
||||
message: '操作失败, 请重试!',
|
||||
message: '操作失败, 请手动重启容器!',
|
||||
type: 'error',
|
||||
});
|
||||
});
|
||||
@@ -51,7 +51,7 @@ function restart() {
|
||||
<section class="debug">
|
||||
<el-row :gutter="20">
|
||||
<!-- S 重置数据 -->
|
||||
<el-col :xs="24" :sm="12" :lg="8">
|
||||
<el-col :xs="24" :sm="12" :lg="8" mb-20px>
|
||||
<el-card shadow="hover">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
@@ -69,7 +69,7 @@ function restart() {
|
||||
<!-- E 重置数据 -->
|
||||
|
||||
<!-- S 重启程序 -->
|
||||
<el-col :xs="24" :sm="12" :lg="8" style="display: none">
|
||||
<el-col :xs="24" :sm="12" :lg="8" mb-20px>
|
||||
<el-card shadow="hover">
|
||||
<template #header>
|
||||
<div class="card-header">
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
import { getConfig, setConfig } from '@/api/config';
|
||||
import { appRestart } from '@/api/program';
|
||||
import type { Config } from '#/config';
|
||||
|
||||
const { status } = storeToRefs(programStore());
|
||||
|
||||
export const configStore = defineStore('config', () => {
|
||||
const config = ref<Config>();
|
||||
|
||||
@@ -13,13 +16,41 @@ export const configStore = defineStore('config', () => {
|
||||
let finalConfig: Config;
|
||||
if (config.value !== undefined) {
|
||||
finalConfig = Object.assign(config.value, newConfig);
|
||||
const { message } = await setConfig(finalConfig);
|
||||
const res = await setConfig(finalConfig);
|
||||
|
||||
if (message === 'Success') {
|
||||
if (res) {
|
||||
ElMessage({
|
||||
message: '保存成功, 请重启容器以应用新的配置!',
|
||||
message: '保存成功!',
|
||||
type: 'success',
|
||||
});
|
||||
|
||||
if (!status.value) {
|
||||
ElMessageBox.confirm('当前程序没有运行,是否重启?', {
|
||||
type: 'warning',
|
||||
})
|
||||
.then(() => {
|
||||
appRestart()
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
ElMessage({
|
||||
message: '正在重启, 请稍后刷新页面...',
|
||||
type: 'success',
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error(
|
||||
'🚀 ~ file: index.vue:41 ~ .then ~ error:',
|
||||
error
|
||||
);
|
||||
ElMessage({
|
||||
message: '操作失败, 请手动重启容器!',
|
||||
type: 'error',
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
} else {
|
||||
ElMessage({
|
||||
message: '保存失败, 请重试!',
|
||||
|
||||
Reference in New Issue
Block a user