From eace1109ac9d7168d747cd942c2f91ccd2db0467 Mon Sep 17 00:00:00 2001 From: xiaozhu <2395895331@qq.com> Date: Tue, 4 Aug 2026 14:49:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E7=BB=9F=E7=AE=A1=E7=90=86=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E9=83=A8=E5=88=86=E6=9B=B4=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/app/features/admin/AdminPages.tsx | 209 ++++++++++++++---- .../features/platform/ModelPlatformApp.tsx | 11 +- frontend/app/styles/admin.css | 4 +- frontend/app/styles/platform.css | 36 ++- 4 files changed, 212 insertions(+), 48 deletions(-) diff --git a/frontend/app/features/admin/AdminPages.tsx b/frontend/app/features/admin/AdminPages.tsx index cc75cd6..5fe192a 100644 --- a/frontend/app/features/admin/AdminPages.tsx +++ b/frontend/app/features/admin/AdminPages.tsx @@ -8,6 +8,7 @@ import { useApi, useAuth } from "../../context/AuthContext"; import Icon from "../../components/Icon"; import "../../styles/admin.css"; import "../../styles/dashboard.css"; +import "../../styles/platform.css"; type Notice = { @@ -41,13 +42,13 @@ export function DashboardPage({
{scriptCount}工作副本
2Workspace
-
4平台员工
+
4平台用户
{online ? "正常" : "检查中"}平台状态
- +
@@ -105,6 +106,11 @@ const EMPTY_FORM = { status: "active" as "active" | "disabled" | "locked", }; +const EMPTY_PROJECT_FORM = { + project_name: "", + description: "", +}; + export function SystemAdminPage({ onNotify, onConnectionChange, @@ -112,6 +118,7 @@ export function SystemAdminPage({ onNotify: (notice: Notice) => void; onConnectionChange: (online: boolean) => void; }) { + const [activeTab, setActiveTab] = useState<"users" | "projects">("users"); const api = useApi(); const { user, currentWorkspace } = useAuth(); const [employees, setEmployees] = useState([]); @@ -120,6 +127,8 @@ export function SystemAdminPage({ const [editing, setEditing] = useState(null); const [dialogOpen, setDialogOpen] = useState(false); const [form, setForm] = useState(EMPTY_FORM); + const [projectDialogOpen, setProjectDialogOpen] = useState(false); + const [projectForm, setProjectForm] = useState(EMPTY_PROJECT_FORM); const canManage = user?.role_code === "admin"; const load = async (): Promise => { @@ -131,7 +140,7 @@ export function SystemAdminPage({ onConnectionChange(false); onNotify({ tone: "error", - message: error instanceof Error ? error.message : "员工列表加载失败", + message: error instanceof Error ? error.message : "用户列表加载失败", }); } finally { setLoading(false); @@ -160,7 +169,7 @@ export function SystemAdminPage({ setDialogOpen(true); }; - const submit = async (event: FormEvent): Promise => { + const submit = async (event: React.FormEvent): Promise => { event.preventDefault(); if (!form.display_name.trim() || (!editing && !form.username.trim())) return; setSaving(true); @@ -185,11 +194,11 @@ export function SystemAdminPage({ setEmployees((current) => [...current, created]); } setDialogOpen(false); - onNotify({ tone: "success", message: editing ? "员工信息已更新" : "员工已添加" }); + onNotify({ tone: "success", message: editing ? "用户信息已更新" : "用户已添加" }); } catch (error) { onNotify({ tone: "error", - message: error instanceof ApiRequestError ? error.message : "保存员工失败", + message: error instanceof ApiRequestError ? error.message : "保存用户失败", }); } finally { setSaving(false); @@ -197,62 +206,178 @@ export function SystemAdminPage({ }; const remove = async (employee: Employee): Promise => { - if (!window.confirm(`确定从当前 Workspace 删除员工“${employee.display_name}”吗?`)) return; + if (!window.confirm(`确定从当前 Workspace 删除用户"${employee.display_name}"吗?`)) return; try { await api.deleteEmployee(employee.user_id); setEmployees((current) => current.filter((item) => item.user_id !== employee.user_id)); - onNotify({ tone: "success", message: "员工已删除" }); + onNotify({ tone: "success", message: "用户已删除" }); } catch (error) { onNotify({ tone: "error", - message: error instanceof Error ? error.message : "删除员工失败", + message: error instanceof Error ? error.message : "删除用户失败", }); } }; + const openCreateProject = (): void => { + setProjectForm(EMPTY_PROJECT_FORM); + setProjectDialogOpen(true); + }; + + const submitProject = async (event: React.FormEvent): Promise => { + event.preventDefault(); + if (!projectForm.project_name.trim()) return; + setSaving(true); + try { + // TODO: 调用实际的项目创建 API + // await api.createProject({ ... }) + setProjectDialogOpen(false); + onNotify({ tone: "success", message: "项目已创建" }); + } catch (error) { + onNotify({ + tone: "error", + message: error instanceof ApiRequestError ? error.message : "创建项目失败", + }); + } finally { + setSaving(false); + } + }; + return (
-
+ {/*
系统管理 -

员工管理

-

{currentWorkspace?.workspace_name ?? "(未选择 Workspace)"} · {employees.length} 名员工

+

{activeTab === "users" ? "用户管理" : "项目管理"}

+

+ {currentWorkspace?.workspace_name ?? "(未选择 Workspace)"} + {activeTab === "users" ? ` · ${employees.length} 名用户` : ""} +

- + )} +
*/} + +
+ + -
- {!canManage &&
当前为开发人员,只能查看员工列表。
} -
-
员工账号角色状态操作
- {loading ?

正在加载员工…

: employees.map((employee) => { - const isProtectedAdmin = employee.role_code === "admin"; - return ( -
- {employee.display_name.slice(0, 1)}{employee.display_name}{employee.email ?? "未设置邮箱"} - {employee.username} - {employee.role_name} - {employee.status === "active" ? "正常" : employee.status === "disabled" ? "已停用" : "已锁定"} - - - - -
- ); - })}
- {dialogOpen && ( + {activeTab === "users" && ( +
+
+ + +
+ +
+ )} + + {activeTab === "projects" && ( +
+
+ + +
+ +
+ )} + + {activeTab === "users" ? ( + <> + {!canManage &&
当前为开发人员,只能查看用户列表。
} +
+
用户账号角色状态操作
+ {loading ?

正在加载用户…

: employees.map((employee) => { + const isProtectedAdmin = employee.role_code === "admin"; + return ( +
+ {employee.display_name.slice(0, 1)}{employee.display_name}{employee.email ?? "未设置邮箱"} + {employee.username} + {employee.role_name} + {employee.status === "active" ? "正常" : employee.status === "disabled" ? "已停用" : "已锁定"} + + + + +
+ ); + })} +
+ + {dialogOpen && ( +
+
+
EMPLOYEE

{editing ? "编辑用户" : "添加用户"}

+
void submit(event)}> + + + + + {editing && } +
+
+
+
+ )} + + ) : ( +
+ +

项目管理

+

项目管理功能开发中…

+
+ )} + + {projectDialogOpen && (
-
EMPLOYEE

{editing ? "编辑员工" : "添加员工"}

-
void submit(event)}> - - - - - {editing && } -
+
PROJECT

新建项目

+ void submitProject(event)}> + +