管理员页面操作列添加权限控制
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
"use client"
|
"use client"
|
||||||
|
import { Lock } from "lucide-react"
|
||||||
import { Suspense, useState } from "react"
|
import { Suspense, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { deleteAdmin, getPageAdmin, updateAdmin } from "@/actions/admin"
|
import { deleteAdmin, getPageAdmin, updateAdmin } from "@/actions/admin"
|
||||||
@@ -21,6 +22,11 @@ import {
|
|||||||
HoverCardContent,
|
HoverCardContent,
|
||||||
HoverCardTrigger,
|
HoverCardTrigger,
|
||||||
} from "@/components/ui/hover-card"
|
} from "@/components/ui/hover-card"
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from "@/components/ui/tooltip"
|
||||||
import { type Admin, AdminStatus } from "@/models/admin"
|
import { type Admin, AdminStatus } from "@/models/admin"
|
||||||
import type { Role } from "@/models/role"
|
import type { Role } from "@/models/role"
|
||||||
import { AssignRoles } from "./assign-roles"
|
import { AssignRoles } from "./assign-roles"
|
||||||
@@ -29,6 +35,7 @@ import { UpdateAdmin } from "./update"
|
|||||||
|
|
||||||
export default function AdminPage() {
|
export default function AdminPage() {
|
||||||
const table = useDataTable((page, size) => getPageAdmin({ page, size }))
|
const table = useDataTable((page, size) => getPageAdmin({ page, size }))
|
||||||
|
console.log(table, "table")
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-3">
|
<div className="flex flex-col gap-3">
|
||||||
@@ -81,20 +88,43 @@ export default function AdminPage() {
|
|||||||
id: "action",
|
id: "action",
|
||||||
meta: { pin: "right" },
|
meta: { pin: "right" },
|
||||||
header: "操作",
|
header: "操作",
|
||||||
cell: ({ row }) => (
|
cell: ({ row }) => {
|
||||||
<div className="flex gap-2">
|
const admin = row.original
|
||||||
<UpdateAdmin admin={row.original} onSuccess={table.refresh} />
|
if (admin.lock === true) {
|
||||||
<AssignRoles admin={row.original} onSuccess={table.refresh} />
|
return (
|
||||||
<ToggleStatusButton
|
<Tooltip>
|
||||||
admin={row.original}
|
<TooltipTrigger asChild>
|
||||||
onSuccess={table.refresh}
|
<div className="flex justify-center items-center">
|
||||||
/>
|
<Lock className="h-4 w-4 text-muted-foreground" />
|
||||||
<DeleteButton
|
</div>
|
||||||
admin={row.original}
|
</TooltipTrigger>
|
||||||
onSuccess={table.refresh}
|
<TooltipContent>
|
||||||
/>
|
<p>该账号为系统账号,不可修改</p>
|
||||||
</div>
|
</TooltipContent>
|
||||||
),
|
</Tooltip>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div className="flex gap-2">
|
||||||
|
<UpdateAdmin
|
||||||
|
admin={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
<AssignRoles
|
||||||
|
admin={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
<ToggleStatusButton
|
||||||
|
admin={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
<DeleteButton
|
||||||
|
admin={row.original}
|
||||||
|
onSuccess={table.refresh}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export type Admin = {
|
|||||||
phone?: string
|
phone?: string
|
||||||
email?: string
|
email?: string
|
||||||
status: AdminStatus
|
status: AdminStatus
|
||||||
|
lock: boolean
|
||||||
lastLogin?: Date
|
lastLogin?: Date
|
||||||
lastLoginIp?: string
|
lastLoginIp?: string
|
||||||
lastLoginUa?: string
|
lastLoginUa?: string
|
||||||
|
|||||||
Reference in New Issue
Block a user