From 46a97c35bd55e21df085bec3f5c864ad9ec6a397 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Clegeling=E2=80=9D?= Date: Sun, 7 Dec 2025 14:33:41 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E4=BF=9D=E5=AD=98=E5=92=8CAI=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 系统设置:过滤空值避免无效更新 - 系统设置:添加错误捕获和失败提示 - 系统设置:改进值类型转换,使用 String() 统一处理 - AI测试:提取并显示后端返回的详细错误信息 - AI测试:优化错误类型定义,正确解析 Axios 错误响应 --- frontend/src/api/settings.ts | 43 ++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/frontend/src/api/settings.ts b/frontend/src/api/settings.ts index 7f90c6b..82f249a 100644 --- a/frontend/src/api/settings.ts +++ b/frontend/src/api/settings.ts @@ -20,20 +20,28 @@ export const getSystemSettings = async (): Promise<{ success: boolean; data?: Sy // 更新系统设置 export const updateSystemSettings = async (data: Partial): Promise => { // 逐个更新设置项,确保 value 是字符串 - const promises = Object.entries(data).map(([key, value]) => { - // 将布尔值和数字转换为字符串 - let stringValue: string - if (typeof value === 'boolean') { - stringValue = value ? 'true' : 'false' - } else if (typeof value === 'number') { - stringValue = String(value) - } else { - stringValue = value as string - } - return put(`/system-settings/${key}`, { value: stringValue }) - }) - await Promise.all(promises) - return { success: true, message: '设置已保存' } + const promises = Object.entries(data) + .filter(([, value]) => value !== undefined && value !== null) // 过滤掉空值 + .map(([key, value]) => { + // 将布尔值和数字转换为字符串 + let stringValue: string + if (typeof value === 'boolean') { + stringValue = value ? 'true' : 'false' + } else if (typeof value === 'number') { + stringValue = String(value) + } else { + stringValue = String(value ?? '') + } + return put(`/system-settings/${key}`, { value: stringValue }) + }) + + try { + await Promise.all(promises) + return { success: true, message: '设置已保存' } + } catch (error) { + console.error('保存设置失败:', error) + return { success: false, message: '保存设置失败' } + } } // 获取 AI 设置 @@ -59,8 +67,11 @@ export const testAIConnection = async (cookieId?: string): Promise return { success: true, message: `AI 回复: ${result.reply}` } } return { success: result.success ?? true, message: result.message || 'AI 连接测试成功' } - } catch (error) { - return { success: false, message: 'AI 连接测试失败' } + } catch (error: unknown) { + // 提取后端返回的错误信息 + const axiosError = error as { response?: { data?: { detail?: string; message?: string } } } + const detail = axiosError.response?.data?.detail || axiosError.response?.data?.message + return { success: false, message: detail || 'AI 连接测试失败' } } }