fix: 🐛 修复系统配置页保存配置的bug
This commit is contained in:
@@ -69,11 +69,25 @@ export class ConfigService {
|
|||||||
*/
|
*/
|
||||||
async update(key: string, value: string, description?: string) {
|
async update(key: string, value: string, description?: string) {
|
||||||
try {
|
try {
|
||||||
// 更新数据库
|
// 先查找记录是否存在
|
||||||
await this.configRepository.upsert(
|
const existingConfig = await this.configRepository.findOne({ where: { key } })
|
||||||
{ key, value, description },
|
|
||||||
['key']
|
if (existingConfig) {
|
||||||
)
|
// 记录存在,更新它
|
||||||
|
existingConfig.value = value
|
||||||
|
if (description !== undefined) {
|
||||||
|
existingConfig.description = description
|
||||||
|
}
|
||||||
|
await this.configRepository.save(existingConfig)
|
||||||
|
} else {
|
||||||
|
// 记录不存在,创建新记录
|
||||||
|
const newConfig = this.configRepository.create({
|
||||||
|
key,
|
||||||
|
value,
|
||||||
|
description
|
||||||
|
})
|
||||||
|
await this.configRepository.save(newConfig)
|
||||||
|
}
|
||||||
|
|
||||||
// 更新缓存
|
// 更新缓存
|
||||||
this.configCache[key] = value
|
this.configCache[key] = value
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export const useConfigStore = defineStore('config', {
|
|||||||
this.error = null
|
this.error = null
|
||||||
try {
|
try {
|
||||||
const response = await configApi.getAllConfigs()
|
const response = await configApi.getAllConfigs()
|
||||||
this.configs = response.data
|
this.configs = response.data || {}
|
||||||
return response
|
return response
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.error = error
|
this.error = error
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
label-width="80px"
|
label-width="80px"
|
||||||
class="login-form-inner"
|
class="login-form-inner"
|
||||||
>
|
>
|
||||||
<el-form-item label="管理员账号" prop="username">
|
<el-form-item label="账号" prop="username">
|
||||||
<el-input
|
<el-input
|
||||||
v-model="loginForm.username"
|
v-model="loginForm.username"
|
||||||
placeholder="请输入管理员账号"
|
placeholder="请输入管理员账号"
|
||||||
|
|||||||
@@ -254,6 +254,12 @@ const loadSystemConfig = async () => {
|
|||||||
// 将获取到的配置映射到表单中
|
// 将获取到的配置映射到表单中
|
||||||
if (response && response.success && response.data) {
|
if (response && response.success && response.data) {
|
||||||
const configData = 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)
|
Object.assign(configForm, configData)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -267,7 +273,9 @@ const handleSaveConfig = async () => {
|
|||||||
try {
|
try {
|
||||||
// 遍历配置表单,逐个保存配置项
|
// 遍历配置表单,逐个保存配置项
|
||||||
for (const [key, value] of Object.entries(configForm)) {
|
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('配置保存成功')
|
ElMessage.success('配置保存成功')
|
||||||
|
|||||||
@@ -47,17 +47,17 @@ ON DUPLICATE KEY UPDATE id = id;
|
|||||||
|
|
||||||
-- 插入系统配置
|
-- 插入系统配置
|
||||||
INSERT INTO config (`key`, `value`, description) VALUES
|
INSERT INTO config (`key`, `value`, description) VALUES
|
||||||
('website_name', '', '网站名称'),
|
('website_name', '梦幻西游WEB版', '网站名称'),
|
||||||
('admin_domain', '', '运营后台域名'),
|
('admin_domain', 'http://localhost:5173', '运营后台域名'),
|
||||||
('player_domain', '', '玩家中心域名'),
|
('player_domain', 'http://localhost:5173', '玩家中心域名'),
|
||||||
('server_host', '', '后端服务器主机地址'),
|
('server_host', 'localhost', '后端服务器主机地址'),
|
||||||
('server_port', '', '后端服务器端口'),
|
('server_port', '3000', '后端服务器端口'),
|
||||||
('game_api_url', '', '游戏服务API地址'),
|
('game_api_url', 'http://127.0.0.1:8080/tool/http', '游戏服务API地址'),
|
||||||
('game_psk', '', '游戏服务端的PSK'),
|
('game_psk', 'THIS_IS_A_32_BYTE_FIXED_PSK!!!!!', '游戏服务端的PSK'),
|
||||||
('jwt_secret', '', 'JWT密钥'),
|
('jwt_secret', 'your_jwt_secret_key_here_change_in_production', 'JWT密钥'),
|
||||||
('jwt_expires_in', '', 'JWT过期时间'),
|
('jwt_expires_in', '24h', 'JWT过期时间'),
|
||||||
('jwt_refresh_secret', '', 'JWT刷新令牌密钥'),
|
('jwt_refresh_secret', 'your_jwt_refresh_secret_key_here_change_in_production', 'JWT刷新令牌密钥'),
|
||||||
('jwt_refresh_expires_in', '', 'JWT刷新令牌过期时间'),
|
('jwt_refresh_expires_in', '7d', 'JWT刷新令牌过期时间'),
|
||||||
('service_status', 'running', '服务运行状态'),
|
('service_status', 'running', '服务运行状态'),
|
||||||
('maintenance_mode', 'false', '维护模式开关')
|
('maintenance_mode', 'false', '维护模式开关')
|
||||||
ON DUPLICATE KEY UPDATE id = id;
|
ON DUPLICATE KEY UPDATE id = id;
|
||||||
|
|||||||
Reference in New Issue
Block a user