import { Template } from "interface/template"; import { Container, Heading, Text, Box, Flex, Table, Button, TextField, ScrollArea, Dialog, Avatar, DropdownMenu, Badge } from "@radix-ui/themes"; import { PlusIcon, MagnifyingGlassIcon, Pencil1Icon, TrashIcon, PersonIcon, DotsHorizontalIcon, LockClosedIcon, ExclamationTriangleIcon } from "@radix-ui/react-icons"; import { useState } from "react"; import type { User } from "interface/fields"; // 模拟用户数据 const mockUsers: (User & { id: number })[] = [ { id: 1, username: "admin", email: "admin@example.com", avatarUrl: "https://api.dicebear.com/7.x/avataaars/svg?seed=1", role: "admin", createdAt: new Date("2024-01-01"), updatedAt: new Date("2024-03-15"), lastLoginAt: new Date("2024-03-15"), passwordHash: "", }, { id: 2, username: "editor", email: "editor@example.com", avatarUrl: "https://api.dicebear.com/7.x/avataaars/svg?seed=2", role: "editor", createdAt: new Date("2024-02-01"), updatedAt: new Date("2024-03-14"), lastLoginAt: new Date("2024-03-14"), passwordHash: "", }, { id: 3, username: "user", email: "user@example.com", avatarUrl: "https://api.dicebear.com/7.x/avataaars/svg?seed=3", role: "user", createdAt: new Date("2024-03-01"), updatedAt: new Date("2024-03-13"), lastLoginAt: new Date("2024-03-13"), passwordHash: "", } ]; export default new Template({}, ({ http, args }) => { const [searchTerm, setSearchTerm] = useState(""); const [isAddDialogOpen, setIsAddDialogOpen] = useState(false); const [isEditDialogOpen, setIsEditDialogOpen] = useState(false); const [selectedUser, setSelectedUser] = useState(null); const [newUserData, setNewUserData] = useState({ username: "", email: "", password: "", role: "user" }); // 获取角色标签样式 const getRoleBadgeColor = (role: string) => { switch(role) { case 'admin': return 'red'; case 'editor': return 'blue'; default: return 'gray'; } }; return ( {/* 页面标题和操作栏 */} 用户管理 共 {mockUsers.length} 个用户 {/* 搜索栏 */} ) => setSearchTerm(e.target.value)} > {/* 用户列表 */} 用户 邮箱 角色 注册时间 最后登录 操作 {mockUsers.map((user) => ( {user.username} {user.email} {user.role} {user.createdAt.toLocaleDateString()} {user.lastLoginAt?.toLocaleDateString()} ))} {/* 新建用户对话框 */} 新建用户 创建一个新的用户账号 用户名 ) => setNewUserData({...newUserData, username: e.target.value}) } /> 邮箱 ) => setNewUserData({...newUserData, email: e.target.value}) } /> 密码 ) => setNewUserData({...newUserData, password: e.target.value}) } /> 角色 {/* 编辑用户对话框 */} {selectedUser && ( <> 编辑用户 修改用户信息 用户名 邮箱 角色 重置密码 )} ); });