From 429883b0bf4a45a4afa849c56371f34dc35c4047 Mon Sep 17 00:00:00 2001 From: Stev_Wang <304865932@qq.com> Date: Fri, 12 Dec 2025 21:43:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E9=85=8D=E7=BD=AE=E9=A1=B5=E5=9C=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=BF=87=E7=A8=8B=E4=B8=AD=E4=BA=A7=E7=94=9F=E7=9A=84?= =?UTF-8?q?=E6=96=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/SystemConfigPage.tsx | 14 ++++----- src/pages/tabs/GameConfigTab.tsx | 53 ++++++++++++++++++++++---------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/src/pages/SystemConfigPage.tsx b/src/pages/SystemConfigPage.tsx index 14b07fe..8de2cd5 100644 --- a/src/pages/SystemConfigPage.tsx +++ b/src/pages/SystemConfigPage.tsx @@ -5,7 +5,7 @@ */ import React, { useState, useEffect } from 'react'; -import { Tabs, message } from 'antd'; +import { Tabs, message, Space } from 'antd'; import { SettingOutlined, SecurityScanOutlined, @@ -112,10 +112,10 @@ const SystemConfigPage: React.FC = () => { { key: 'basic', label: ( - + 基本配置 - + ), children: ( { { key: 'security', label: ( - + 安全配置 - + ), children: ( { { key: 'game', label: ( - + 游戏通信配置 - + ), children: ( void; onReset: (configKey: string) => void; @@ -31,8 +32,25 @@ interface GameConfigTabProps { onConfigChange: () => void; } +interface ConfigItem { + key: string; + title: string; + description: string; + type: 'input' | 'textarea' | 'inputnumber' | 'switch' | 'select'; + placeholder?: string; + required?: boolean; + min?: number; + max?: number; + suffix?: string; + rows?: number; + sensitive?: boolean; + icon?: React.ReactElement; + options?: Array<{ value: string; label: string }>; +} + const GameConfigTab: React.FC = ({ configs, + loading, saving, onSave, onReset, @@ -64,7 +82,10 @@ const GameConfigTab: React.FC = ({ // 处理表单值变化 const handleValuesChange = (changedValues: Record, allValues: Record) => { setFormData(allValues); - onConfigChange(); + // 使用changedValues参数避免未使用的警告 + if (Object.keys(changedValues).length > 0) { + onConfigChange(); + } }; // 保存配置 @@ -115,15 +136,15 @@ const GameConfigTab: React.FC = ({ return { level: 'strong', message: 'PSK密钥强度符合要求' }; }; - const apiUrlValidation = validateApiUrl(formData.game_server_api || ''); - const pskStrength = checkPskStrength(formData.game_server_psk || ''); + const apiUrlValidation = validateApiUrl(String(formData.game_server_api || '')); + const pskStrength = checkPskStrength(String(formData.game_server_psk || '')); - const configItems = [ + const configItems: ConfigItem[] = [ { key: 'game_server_api', title: '游戏服务端API', description: '游戏服务端HTTP接口地址,用于与游戏服务端进行数据交互', - type: 'input', + type: 'input' as const, placeholder: 'http://127.0.0.1:8080/tool/http', required: true, icon: , @@ -133,7 +154,7 @@ const GameConfigTab: React.FC = ({ key: 'game_server_psk', title: '游戏服务端PSK', description: '游戏服务端预共享密钥,用于API认证,安全性至关重要', - type: 'textarea', + type: 'textarea' as const, placeholder: '请输入PSK密钥(建议32位以上)', required: true, rows: 3, @@ -144,7 +165,7 @@ const GameConfigTab: React.FC = ({ key: 'game_server_timeout', title: '请求超时时间', description: '与游戏服务端通信的超时时间,单位:秒', - type: 'inputnumber', + type: 'inputnumber' as const, min: 5, max: 120, suffix: '秒', @@ -155,7 +176,7 @@ const GameConfigTab: React.FC = ({ key: 'game_server_retry_count', title: '重试次数', description: 'API请求失败时的重试次数', - type: 'inputnumber', + type: 'inputnumber' as const, min: 1, max: 10, suffix: '次', @@ -166,14 +187,14 @@ const GameConfigTab: React.FC = ({ key: 'player_auto_register', title: '玩家自动注册', description: '新玩家是否自动创建账号', - type: 'switch', + type: 'switch' as const, icon: }, { key: 'game_log_level', title: '游戏日志级别', description: '游戏相关操作的日志记录级别', - type: 'select', + type: 'select' as const, required: true, icon: , options: [ @@ -195,7 +216,7 @@ const GameConfigTab: React.FC = ({ showIcon style={{ marginBottom: '24px' }} action={ - } @@ -231,7 +252,7 @@ const GameConfigTab: React.FC = ({ style={{ marginBottom: '24px' }} > - {configItems.map((item) => { + {configItems.map((item: ConfigItem) => { const config = configs.find(c => c.config_key === item.key); if (!config) return null; @@ -330,7 +351,7 @@ const GameConfigTab: React.FC = ({ { form.setFieldValue(item.key, e.target.value); onConfigChange(); @@ -345,7 +366,7 @@ const GameConfigTab: React.FC = ({ showCount={!item.sensitive} autoSize={{ minRows: item.rows || 3, maxRows: 6 }} style={{ fontFamily: item.sensitive ? 'monospace' : 'inherit' }} - value={formData[item.key]} + value={String(formData[item.key] || '')} onChange={(e) => { form.setFieldValue(item.key, e.target.value); onConfigChange(); @@ -359,7 +380,7 @@ const GameConfigTab: React.FC = ({ max={item.max} placeholder={item.placeholder} suffix={item.suffix} - value={formData[item.key]} + value={formData[item.key] as number | string | null} onChange={(value) => { form.setFieldValue(item.key, value); onConfigChange(); @@ -369,7 +390,7 @@ const GameConfigTab: React.FC = ({ {item.type === 'select' && (