From b127ca0fb9ae4ba8fbd17ba937811deb7b9f8abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E6=9C=B1?= <10714957+xiao-zhu245@user.noreply.gitee.com> Date: Mon, 8 Sep 2025 22:04:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B8=B8=E6=88=8F=E9=83=A8?= =?UTF-8?q?=E7=BD=B2=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=BC=96=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../developer/components/DeveloperSidebar.tsx | 26 +- .../components/sections/GameConfigSection.tsx | 546 ++++++++++++++++++ .../modules/developer/pages/DeveloperPage.tsx | 6 + .../developer/services/developerApi.ts | 78 ++- .../src/modules/developer/types/developer.ts | 51 ++ .../controllers/DeveloperController.ts | 146 ++++- .../developer/routes/developerRoutes.ts | 25 +- .../developer/services/DeveloperService.ts | 140 ++++- .../src/modules/developer/types/developer.ts | 43 ++ 9 files changed, 1043 insertions(+), 18 deletions(-) create mode 100644 client/src/modules/developer/components/sections/GameConfigSection.tsx diff --git a/client/src/modules/developer/components/DeveloperSidebar.tsx b/client/src/modules/developer/components/DeveloperSidebar.tsx index f4d03c5..9b11098 100644 --- a/client/src/modules/developer/components/DeveloperSidebar.tsx +++ b/client/src/modules/developer/components/DeveloperSidebar.tsx @@ -1,16 +1,17 @@ import React from 'react' -import { - Code, - Shield, - Package, - Settings, - Database, - Terminal, - FileText, +import { + Code, + Shield, + Package, + Settings, + Database, + Terminal, + FileText, Activity, Wrench, Info, - ChevronRight + ChevronRight, + GamepadIcon } from 'lucide-react' interface SidebarItem { @@ -40,6 +41,13 @@ const DeveloperSidebar: React.FC = ({ icon: Info, description: '开发者工具概览和状态' }, + { + id: 'game-config', + label: '游戏部署配置文件编辑', + icon: GamepadIcon, + description: '编辑游戏部署配置文件', + disabled: !isAuthenticated + }, { id: 'panel', label: '面板设置', diff --git a/client/src/modules/developer/components/sections/GameConfigSection.tsx b/client/src/modules/developer/components/sections/GameConfigSection.tsx new file mode 100644 index 0000000..d51dd82 --- /dev/null +++ b/client/src/modules/developer/components/sections/GameConfigSection.tsx @@ -0,0 +1,546 @@ +import React, { useState, useEffect } from 'react' +import { + Plus, + Edit, + Trash2, + Save, + X, + Search, + GamepadIcon, + ExternalLink, + Monitor, + HardDrive, + AlertCircle, + CheckCircle, + Loader2 +} from 'lucide-react' +import { developerApi } from '../../services/developerApi' +import type { GameConfig, GameConfigData } from '../../types/developer' + +interface GameConfigSectionProps { + isAuthenticated: boolean +} + +const GameConfigSection: React.FC = ({ isAuthenticated }) => { + const [configs, setConfigs] = useState({}) + const [loading, setLoading] = useState(true) + const [error, setError] = useState(null) + const [searchTerm, setSearchTerm] = useState('') + const [editingConfig, setEditingConfig] = useState(null) + const [isCreating, setIsCreating] = useState(false) + const [actionLoading, setActionLoading] = useState(null) + + // 加载游戏配置 + const loadConfigs = async () => { + try { + setLoading(true) + setError(null) + const data = await developerApi.getGameConfigs() + setConfigs(data) + } catch (err) { + setError(err instanceof Error ? err.message : '加载游戏配置失败') + } finally { + setLoading(false) + } + } + + useEffect(() => { + if (isAuthenticated) { + loadConfigs() + } + }, [isAuthenticated]) + + // 过滤配置 + const filteredConfigs = Object.entries(configs).filter(([key, config]) => { + const searchLower = searchTerm.toLowerCase() + return ( + key.toLowerCase().includes(searchLower) || + config.game_nameCN.toLowerCase().includes(searchLower) || + config.appid.includes(searchTerm) + ) + }) + + // 开始创建新配置 + const handleCreate = () => { + setEditingConfig({ + key: '', + game_nameCN: '', + appid: '', + tip: '', + image: '', + url: '', + system: ['Windows'], + system_info: [], + memory: 4 + }) + setIsCreating(true) + } + + // 开始编辑配置 + const handleEdit = (key: string, config: Omit) => { + setEditingConfig({ key, ...config }) + setIsCreating(false) + } + + // 保存配置 + const handleSave = async () => { + if (!editingConfig) return + + try { + setActionLoading('save') + + if (isCreating) { + await developerApi.createGameConfig(editingConfig) + } else { + const { key, ...configData } = editingConfig + await developerApi.updateGameConfig(key, configData) + } + + await loadConfigs() + setEditingConfig(null) + setIsCreating(false) + } catch (err) { + setError(err instanceof Error ? err.message : '保存配置失败') + } finally { + setActionLoading(null) + } + } + + // 删除配置 + const handleDelete = async (key: string) => { + if (!confirm(`确定要删除游戏配置 "${key}" 吗?`)) return + + try { + setActionLoading(`delete-${key}`) + await developerApi.deleteGameConfig(key) + await loadConfigs() + } catch (err) { + setError(err instanceof Error ? err.message : '删除配置失败') + } finally { + setActionLoading(null) + } + } + + // 取消编辑 + const handleCancel = () => { + setEditingConfig(null) + setIsCreating(false) + } + + if (!isAuthenticated) { + return ( +
+
+ +
+

+ 需要开发者认证 +

+

+ 请先完成开发者认证才能访问游戏配置编辑功能 +

+
+
+
+ ) + } + + if (loading) { + return ( +
+
+ +

加载游戏配置中...

+
+
+ ) + } + + return ( +
+ {/* 错误提示 */} + {error && ( +
+
+ +
+

操作失败

+

{error}

+
+
+
+ )} + + {/* 头部操作栏 */} +
+
+
+

+ 游戏部署配置管理 +

+

+ 管理 installgame.json 文件中的游戏配置 +

+
+ +
+ {/* 搜索框 */} +
+ + setSearchTerm(e.target.value)} + className="pl-10 pr-4 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white placeholder-gray-500 dark:placeholder-gray-400 focus:ring-2 focus:ring-blue-500 focus:border-transparent" + /> +
+ + {/* 添加按钮 */} + +
+
+
+ + {/* 游戏配置列表 */} +
+ {filteredConfigs.map(([key, config]) => ( +
+ {/* 游戏图片 */} +
+ {config.image ? ( + {config.game_nameCN} { + const target = e.target as HTMLImageElement + target.style.display = 'none' + }} + /> + ) : ( +
+ +
+ )} + + {/* 操作按钮 */} +
+ + +
+
+ + {/* 游戏信息 */} +
+
+
+

+ {config.game_nameCN} +

+

+ {key} +

+
+ {config.url && ( + + + + )} +
+ +
+
+ App ID: + {config.appid} +
+ + {config.system && config.system.length > 0 && ( +
+ +
+ {config.system.map((sys) => ( + + {sys} + + ))} +
+
+ )} + + {config.memory && ( +
+ + + {config.memory}GB 内存 + +
+ )} +
+ + {config.tip && ( +
+ {config.tip.length > 100 ? `${config.tip.substring(0, 100)}...` : config.tip} +
+ )} +
+
+ ))} +
+ + {filteredConfigs.length === 0 && !loading && ( +
+ +

+ {searchTerm ? '未找到匹配的游戏' : '暂无游戏配置'} +

+

+ {searchTerm ? '尝试使用其他关键词搜索' : '点击"添加游戏"按钮创建第一个游戏配置'} +

+
+ )} + + {/* 编辑模态框 */} + {editingConfig && ( +
+
+
+ +
+
+

+ {isCreating ? '添加游戏配置' : '编辑游戏配置'} +

+ +
+ +
+ {/* 游戏标识 */} +
+ + setEditingConfig({ ...editingConfig, key: e.target.value })} + disabled={!isCreating} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white disabled:bg-gray-100 dark:disabled:bg-gray-600 disabled:cursor-not-allowed" + placeholder="例如: Palworld" + /> + {!isCreating && ( +

+ 游戏标识不可修改 +

+ )} +
+ + {/* 游戏中文名 */} +
+ + setEditingConfig({ ...editingConfig, game_nameCN: e.target.value })} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + placeholder="例如: 幻兽帕鲁" + /> +
+ + {/* Steam App ID */} +
+ + setEditingConfig({ ...editingConfig, appid: e.target.value })} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + placeholder="例如: 2394010" + /> +
+ + {/* 游戏图片URL */} +
+ + setEditingConfig({ ...editingConfig, image: e.target.value })} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + placeholder="https://..." + /> +
+ + {/* Steam商店URL */} +
+ + setEditingConfig({ ...editingConfig, url: e.target.value })} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + placeholder="https://store.steampowered.com/app/..." + /> +
+ + {/* 支持系统 */} +
+ +
+ {['Windows', 'Linux', 'macOS'].map((system) => ( + + ))} +
+
+ + {/* 内存要求 */} +
+ + setEditingConfig({ + ...editingConfig, + memory: e.target.value ? parseInt(e.target.value) : undefined + })} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + placeholder="4" + /> +
+ + {/* 文档链接 */} +
+ + setEditingConfig({ ...editingConfig, docs: e.target.value })} + className="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-lg bg-white dark:bg-gray-700 text-gray-900 dark:text-white" + placeholder="https://docs.gsm.xiaozhuhouses.asia/..." + /> +
+ + {/* 游戏提示 */} +
+ +