超管后台 - 编辑管理员查看详情
This commit is contained in:
@@ -2,29 +2,34 @@
|
||||
|
||||
import type React from "react"
|
||||
|
||||
import { useState } from "react"
|
||||
import { useState, useEffect } from "react"
|
||||
import { useRouter } from "next/navigation"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { ArrowLeft } from "lucide-react"
|
||||
import { ArrowLeft, Loader2 } from "lucide-react"
|
||||
import Link from "next/link"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import { getAdministratorDetail, AdministratorDetail } from "@/lib/admin-api"
|
||||
import { useToast } from "@/components/ui/use-toast"
|
||||
|
||||
// Sample admin data for editing
|
||||
const adminData = {
|
||||
id: "2",
|
||||
username: "admin_li",
|
||||
name: "李管理",
|
||||
permissions: ["project_management", "customer_pool"],
|
||||
}
|
||||
// 权限 ID 到前端权限键的映射
|
||||
const permissionMapping: Record<number, string[]> = {
|
||||
1: ["project_management", "customer_pool", "admin_management"], // 超级管理员
|
||||
2: ["project_management", "customer_pool"], // 项目管理员
|
||||
3: ["customer_pool"], // 客户管理员
|
||||
4: [], // 普通管理员
|
||||
};
|
||||
|
||||
export default function EditAdminPage({ params }: { params: { id: string } }) {
|
||||
const router = useRouter()
|
||||
const { toast } = useToast()
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
const [isSubmitting, setIsSubmitting] = useState(false)
|
||||
const [username, setUsername] = useState(adminData.username)
|
||||
const [name, setName] = useState(adminData.name)
|
||||
const [adminInfo, setAdminInfo] = useState<AdministratorDetail | null>(null)
|
||||
const [username, setUsername] = useState("")
|
||||
const [name, setName] = useState("")
|
||||
|
||||
const permissions = [
|
||||
{ id: "project_management", label: "项目管理" },
|
||||
@@ -32,7 +37,42 @@ export default function EditAdminPage({ params }: { params: { id: string } }) {
|
||||
{ id: "admin_management", label: "管理员权限" },
|
||||
]
|
||||
|
||||
const [selectedPermissions, setSelectedPermissions] = useState<string[]>(adminData.permissions)
|
||||
const [selectedPermissions, setSelectedPermissions] = useState<string[]>([])
|
||||
|
||||
// 加载管理员详情
|
||||
useEffect(() => {
|
||||
const fetchAdminDetail = async () => {
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const response = await getAdministratorDetail(params.id)
|
||||
if (response.code === 200 && response.data) {
|
||||
setAdminInfo(response.data)
|
||||
// 设置表单数据
|
||||
setUsername(response.data.username)
|
||||
setName(response.data.name)
|
||||
// 根据 authId 设置权限
|
||||
setSelectedPermissions(permissionMapping[response.data.authId] || [])
|
||||
} else {
|
||||
toast({
|
||||
title: "获取管理员详情失败",
|
||||
description: response.msg || "请稍后重试",
|
||||
variant: "destructive",
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("获取管理员详情出错:", error)
|
||||
toast({
|
||||
title: "获取管理员详情失败",
|
||||
description: "请检查网络连接后重试",
|
||||
variant: "destructive",
|
||||
})
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
fetchAdminDetail()
|
||||
}, [params.id])
|
||||
|
||||
const togglePermission = (permissionId: string) => {
|
||||
setSelectedPermissions((prev) =>
|
||||
@@ -51,6 +91,17 @@ export default function EditAdminPage({ params }: { params: { id: string } }) {
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="flex h-[calc(100vh-200px)] items-center justify-center">
|
||||
<div className="flex flex-col items-center gap-2">
|
||||
<Loader2 className="h-8 w-8 animate-spin text-primary" />
|
||||
<p className="text-sm text-muted-foreground">加载管理员详情中...</p>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<div className="flex items-center gap-2">
|
||||
|
||||
Reference in New Issue
Block a user