fix: 🐛 修复系统配置页保存配置的bug

This commit is contained in:
Stev_Wang
2025-12-23 10:44:39 +08:00
parent 18b65d4635
commit a670270d87
5 changed files with 41 additions and 19 deletions

View File

@@ -19,7 +19,7 @@ export const useConfigStore = defineStore('config', {
this.error = null
try {
const response = await configApi.getAllConfigs()
this.configs = response.data
this.configs = response.data || {}
return response
} catch (error) {
this.error = error

View File

@@ -14,7 +14,7 @@
label-width="80px"
class="login-form-inner"
>
<el-form-item label="管理员账号" prop="username">
<el-form-item label="账号" prop="username">
<el-input
v-model="loginForm.username"
placeholder="请输入管理员账号"

View File

@@ -254,6 +254,12 @@ const loadSystemConfig = async () => {
// 将获取到的配置映射到表单中
if (response && response.success && response.data) {
const configData = response.data
// 处理布尔值转换
if (configData.maintenance_mode !== undefined) {
configData.maintenance_mode = configData.maintenance_mode === 'true' || configData.maintenance_mode === true
}
Object.assign(configForm, configData)
}
} catch (error) {
@@ -267,7 +273,9 @@ const handleSaveConfig = async () => {
try {
// 遍历配置表单,逐个保存配置项
for (const [key, value] of Object.entries(configForm)) {
await configStore.updateConfig({ key, value })
// 处理布尔值转换为字符串
const saveValue = typeof value === 'boolean' ? value.toString() : value
await configStore.updateConfig({ key, value: saveValue })
}
ElMessage.success('配置保存成功')