From 4fc92de4b0dd0e6607970644cf95be7a60f82f3f Mon Sep 17 00:00:00 2001 From: Rewrite0 <49576640+Rewrite0@users.noreply.github.com> Date: Sun, 28 May 2023 00:35:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=92=8C=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 4 +- src/api/auth.ts | 2 +- src/api/bangumi.ts | 23 +++--- src/components/ab-bangumi-card.vue | 14 +++- src/components/ab-edit-rule.vue | 119 +++++++++++++++++++++++++++++ src/components/ab-setting.vue | 6 +- src/hooks/useAuth.ts | 4 +- src/pages/index/bangumi.vue | 76 ++++++++++++++++-- src/store/bangumi.ts | 35 ++++++++- src/store/config.ts | 4 +- src/store/program.ts | 2 +- types/bangumi.ts | 27 ++++--- types/components.ts | 10 ++- types/error.ts | 4 +- 14 files changed, 284 insertions(+), 46 deletions(-) create mode 100644 src/components/ab-edit-rule.vue diff --git a/src/App.vue b/src/App.vue index 39891f75..55d85331 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,9 +4,9 @@ import { NMessageProvider } from 'naive-ui'; diff --git a/src/api/auth.ts b/src/api/auth.ts index da43227d..0f8aca06 100644 --- a/src/api/auth.ts +++ b/src/api/auth.ts @@ -34,7 +34,7 @@ export const apiAuth = { const message = useMessage(); if (password.length < 8) { message.error('密码至少8个字符!'); - return; + } else { const { data } = await axios.post('api/v1/auth/update', { username, diff --git a/src/api/bangumi.ts b/src/api/bangumi.ts index c372a3c3..702c295c 100644 --- a/src/api/bangumi.ts +++ b/src/api/bangumi.ts @@ -30,12 +30,15 @@ export const apiBangumi = { * @returns axios 请求返回的数据 */ async updateRule(bangumiRule: BangumiRule) { - const { data } = await axios.post('api/v1/bangumi/updateData', bangumiRule); + const { data } = await axios.post<{ + msg: string; + status: 'success'; + }>('api/v1/bangumi/updateRule', bangumiRule); return data; }, /** - * 删除指定 bangumiId 的数据 + * 删除指定 bangumiId 的数据库规则,会在重新匹配到后重建 * @param bangumiId - 需要删除的 bangumi 的 id * @returns axios 请求返回的数据 */ @@ -53,14 +56,14 @@ export const apiBangumi = { * @returns axios 请求返回的数据 */ async deleteRule(bangumiId: number, file: boolean) { - const { data } = await axios.delete( - `api/v1/bangumi/deleteRule/${bangumiId}`, - { - params: { - file, - }, - } - ); + const { data } = await axios.delete<{ + msg: string; + status: 'success'; + }>(`api/v1/bangumi/deleteRule/${bangumiId}`, { + params: { + file, + }, + }); return data; }, diff --git a/src/components/ab-bangumi-card.vue b/src/components/ab-bangumi-card.vue index 14861d3d..1f678d5b 100644 --- a/src/components/ab-bangumi-card.vue +++ b/src/components/ab-bangumi-card.vue @@ -1,5 +1,5 @@ + + diff --git a/src/components/ab-setting.vue b/src/components/ab-setting.vue index bf2d0e5b..3ac87ab2 100644 --- a/src/components/ab-setting.vue +++ b/src/components/ab-setting.vue @@ -1,8 +1,8 @@ diff --git a/src/store/bangumi.ts b/src/store/bangumi.ts index edd960bc..ce512411 100644 --- a/src/store/bangumi.ts +++ b/src/store/bangumi.ts @@ -1,12 +1,41 @@ -import type { BangumiItem } from '#/bangumi'; +import type { BangumiRule } from '#/bangumi'; export const useBangumiStore = defineStore('bangumi', () => { - const data = ref(); + const message = useMessage(); + const data = ref(); const getAll = async () => { const res = await apiBangumi.getAll(); data.value = res; }; - return { data, getAll }; + const updateRule = async (newRule: BangumiRule) => { + try { + const res = await apiBangumi.updateRule(newRule); + if (res.status === 'success') { + message.success('Update Success!'); + return true; + } else { + message.error('Update Failed!'); + } + } catch (error) { + message.error('Operation Failed!'); + } + }; + + const removeRule = async (bangumiId: number, deleteFile = false) => { + try { + const res = await apiBangumi.deleteRule(bangumiId, deleteFile); + if (res.status === 'success') { + message.success(`${res.msg} Success!`); + return true; + } else { + message.error('Delete Failed!'); + } + } catch (error) { + message.error('Operation Failed!'); + } + }; + + return { data, getAll, updateRule, removeRule }; }); diff --git a/src/store/config.ts b/src/store/config.ts index b3c417f3..e60ffbe3 100644 --- a/src/store/config.ts +++ b/src/store/config.ts @@ -59,9 +59,9 @@ export const useConfigStore = defineStore('config', () => { const setConfig = async () => { const status = await apiConfig.updateConfig(config.value); if (status) { - message.success('apply success!'); + message.success('Apply Success!'); } else { - message.error('apply fail!'); + message.error('Apply Failed!'); } }; diff --git a/src/store/program.ts b/src/store/program.ts index ccd907de..0a03b6c9 100644 --- a/src/store/program.ts +++ b/src/store/program.ts @@ -24,7 +24,7 @@ export const useProgramStore = defineStore('program', () => { if (success) { message.success(`${handle} Success!`); } else { - message.error(`${handle} Fail!`); + message.error(`${handle} Failed!`); } } diff --git a/types/bangumi.ts b/types/bangumi.ts index a0f2a79c..eeed433d 100644 --- a/types/bangumi.ts +++ b/types/bangumi.ts @@ -1,18 +1,21 @@ -export interface BangumiItem { +export interface BangumiRule { + added: boolean; + deleted: boolean; + dpi: string; + eps_collect: boolean; + filter: string[]; + group_name: string; id: number; official_title: string; - year: string | null; - title_raw: string; + offset: number; + poster_link: string | null; + rss_link: string[]; + rule_name: string; + save_path: string; season: number; season_raw: string; - group_name: string; - dpi: string; - source: string; + source: string | null; subtitle: string; - eps_collect: boolean; - offset: number; - filter: string[]; - rss_link: string[]; - poster_link: string; - added: boolean; + title_raw: string; + year: string | null; } diff --git a/types/components.ts b/types/components.ts index d0e89ea1..3965f370 100644 --- a/types/components.ts +++ b/types/components.ts @@ -15,5 +15,13 @@ export interface AbSettingProps { export type SettingItem = AbSettingProps & { configKey: keyof T; - data?: any; }; + +export interface AbEditRule { + id: number; + official_title: string; + year: string; + season: number; + offset: number; + filter: string[]; +} diff --git a/types/error.ts b/types/error.ts index 324609ad..405071df 100644 --- a/types/error.ts +++ b/types/error.ts @@ -4,7 +4,7 @@ export type LoginError = 'Password error' | 'User not found'; export type ApiErrorMessage = AuthError | LoginError; -export type ApiError = { +export interface ApiError { status: 401 | 404 | 422; detail: ApiErrorMessage; -}; +}