From c116efd6f4a6eece1ca8796fdd4b075bfaccf077 Mon Sep 17 00:00:00 2001 From: AoXuan Date: Mon, 4 Aug 2025 21:19:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(settings):=20=E6=96=B0=E5=A2=9E=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E9=A1=B5=E9=9D=A2=E5=92=8C=E7=9B=B8=E5=85=B3=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加设置页面组件和路由 - 实现设置数据的获取和更新逻辑 - 新增多个设置选项,包括功能设置、通知设置、更新设置等 - 优化设置页面样式和交互 --- frontend/src/composables/useSettingsApi.ts | 100 ++++ frontend/src/types/script.ts | 2 +- frontend/src/types/settings.ts | 69 +++ frontend/src/views/Settings.vue | 656 +++++++++++++++------ 4 files changed, 643 insertions(+), 184 deletions(-) create mode 100644 frontend/src/composables/useSettingsApi.ts create mode 100644 frontend/src/types/settings.ts diff --git a/frontend/src/composables/useSettingsApi.ts b/frontend/src/composables/useSettingsApi.ts new file mode 100644 index 0000000..b102ccf --- /dev/null +++ b/frontend/src/composables/useSettingsApi.ts @@ -0,0 +1,100 @@ +import { ref } from 'vue' +import { message } from 'ant-design-vue' +import type { SettingsData, GetSettingsResponse, UpdateSettingsResponse } from '../types/settings.ts' + +const API_BASE_URL = 'http://localhost:8000/api' + +export function useSettingsApi() { + const loading = ref(false) + const error = ref(null) + + // 获取设置 + const getSettings = async (): Promise => { + loading.value = true + error.value = null + + try { + const response = await fetch(`${API_BASE_URL}/setting/get`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({}), // 空请求体 + }) + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + const apiResponse: GetSettingsResponse = await response.json() + + // 根据code判断是否成功(非200就是不成功) + if (apiResponse.code !== 200) { + const errorMsg = apiResponse.message || '获取设置失败' + message.error(errorMsg) + throw new Error(errorMsg) + } + + return apiResponse.data + } catch (err) { + const errorMsg = err instanceof Error ? err.message : '获取设置失败' + error.value = errorMsg + if (!err.message?.includes('HTTP error')) { + message.error(errorMsg) + } + return null + } finally { + loading.value = false + } + } + + // 更新设置 + const updateSettings = async (settings: Partial): Promise => { + loading.value = true + error.value = null + + try { + const response = await fetch(`${API_BASE_URL}/setting/update`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + data: settings, + }), + }) + + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`) + } + + const apiResponse: UpdateSettingsResponse = await response.json() + + // 根据code判断是否成功(非200就是不成功) + if (apiResponse.code !== 200) { + const errorMsg = apiResponse.message || '设置修改失败' + message.error(errorMsg) + throw new Error(errorMsg) + } + + // message.success(apiResponse.message || '设置修改成功') + return true + } catch (err) { + const errorMsg = err instanceof Error ? err.message : '设置修改失败' + error.value = errorMsg + if (!err.message?.includes('HTTP error')) { + message.error(errorMsg) + } + return false + } finally { + loading.value = false + } + } + + return { + loading, + error, + getSettings, + updateSettings, + } +} diff --git a/frontend/src/types/script.ts b/frontend/src/types/script.ts index 838f085..100f296 100644 --- a/frontend/src/types/script.ts +++ b/frontend/src/types/script.ts @@ -182,4 +182,4 @@ export interface UpdateScriptResponse { code: number status: string message: string -} \ No newline at end of file +} diff --git a/frontend/src/types/settings.ts b/frontend/src/types/settings.ts new file mode 100644 index 0000000..9db8149 --- /dev/null +++ b/frontend/src/types/settings.ts @@ -0,0 +1,69 @@ + +// 设置相关类型定义 +export interface SettingsData { + Function: { + BossKey: string + HistoryRetentionTime: number + HomeImageMode: string + IfAgreeBilibili: boolean + IfAllowSleep: boolean + IfSilence: boolean + IfSkipMumuSplashAds: boolean + UnattendedMode: boolean + } + Notify: { + AuthorizationCode: string + CompanyWebHookBotUrl: string + FromAddress: string + IfCompanyWebHookBot: boolean + IfPushPlyer: boolean + IfSendMail: boolean + IfSendSixStar: boolean + IfSendStatistic: boolean + IfServerChan: boolean + SMTPServerAddress: string + SendTaskResultTime: string + ServerChanChannel: string + ServerChanKey: string + ServerChanTag: string + ToAddress: string + } + Update: { + IfAutoUpdate: boolean + MirrorChyanCDK: string + ProxyAddress: string + ProxyUrlList: string[] + ThreadNumb: number + UpdateType: string + } + Start: { + IfMinimizeDirectly: boolean + IfSelfStart: boolean + } + UI: { + IfShowTray: boolean + IfToTray: boolean + location: string + maximized: boolean + size: string + } + Voice: { + Enabled: boolean + Type: string + } +} + +// 获取设置API响应 +export interface GetSettingsResponse { + code: number + status: string + message: string + data: SettingsData +} + +// 更新设置API响应 +export interface UpdateSettingsResponse { + code: number + status: string + message: string +} \ No newline at end of file diff --git a/frontend/src/views/Settings.vue b/frontend/src/views/Settings.vue index 9606272..f9a1a3e 100644 --- a/frontend/src/views/Settings.vue +++ b/frontend/src/views/Settings.vue @@ -1,33 +1,129 @@