This commit is contained in:
Rewrite0
2023-05-21 23:08:01 +08:00
parent 92e686eec0
commit 63afc64f74
4 changed files with 9 additions and 81 deletions

View File

@@ -1,13 +1,12 @@
import { getABData } from '../api/bangumi';
import type { BangumiItem } from '#/bangumi';
export const bangumiStore = defineStore('bangumi', () => {
export const useBangumiStore = defineStore('bangumi', () => {
const data = ref<BangumiItem[]>();
const get = async () => {
const res = await getABData();
data.value = res.data;
const getAll = async () => {
const res = await apiBangumi.getAll();
data.value = res;
};
return { data, get };
return { data, getAll };
});

View File

@@ -1,70 +0,0 @@
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>();
const get = async () => {
config.value = await getConfig();
};
const set = async (newConfig: Omit<Config, 'data_version'>) => {
let finalConfig: Config;
if (config.value !== undefined) {
finalConfig = Object.assign(config.value, newConfig);
const res = await setConfig(finalConfig);
if (res) {
ElMessage({
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: '保存失败, 请重试!',
type: 'error',
});
}
}
return false;
};
return {
get,
set,
config,
};
});

View File

@@ -1,14 +1,13 @@
import { getABLog } from '../api/debug';
export const logStore = defineStore('log', () => {
export const useLogStore = defineStore('log', () => {
const log = ref('');
const timer = ref<NodeJS.Timer | null>(null);
const get = async () => {
log.value = await getABLog();
log.value = await apiLog.getLog();
};
const onUpdate = () => {
get();
timer.value = setInterval(() => get(), 3000);
};

View File

@@ -1,4 +1,4 @@
export const programStore = defineStore('program', () => {
export const useProgramStore = defineStore('program', () => {
const running = ref(false);
const timer = ref<NodeJS.Timer | null>(null);