套餐管理添加IP检查状态字段
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lanhu-admin",
|
||||
"version": "1.5.0",
|
||||
"version": "1.6.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -H 0.0.0.0 -p 3001 --turbopack",
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function listResourceShort(params: ResourceListParams) {
|
||||
)
|
||||
}
|
||||
|
||||
export async function updateResource(data: { id: number; active?: boolean }) {
|
||||
export async function updateResource(data: { id: number; active?: boolean; checkip?: boolean}) {
|
||||
return callByUser<Resources>("/api/admin/resource/update", data)
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +255,30 @@ function ResourceList({ resourceType }: ResourceListProps) {
|
||||
},
|
||||
[refreshTable],
|
||||
)
|
||||
|
||||
const handleCheckipChange = useCallback(
|
||||
async (resource: Resources) => {
|
||||
const newCheckip = !resource.checkip
|
||||
setUpdatingId(resource.id)
|
||||
try {
|
||||
await updateResource({
|
||||
id: resource.id,
|
||||
checkip: newCheckip,
|
||||
})
|
||||
toast.success("更新成功", {
|
||||
description: `IP检查已${newCheckip ? "启用IP检查" : "停用IP检查"}`,
|
||||
})
|
||||
refreshTable()
|
||||
} catch (error) {
|
||||
console.error("更新IP检查状态失败:", error)
|
||||
toast.error("更新失败", {
|
||||
description: error instanceof Error ? error.message : "请稍后重试",
|
||||
})
|
||||
} finally {
|
||||
setUpdatingId(null)
|
||||
}
|
||||
},
|
||||
[refreshTable],
|
||||
)
|
||||
const onFilter = handleSubmit(data => {
|
||||
const result: FilterParams = {}
|
||||
if (data.user_phone?.trim()) result.user_phone = data.user_phone.trim()
|
||||
@@ -388,7 +411,7 @@ function ResourceList({ resourceType }: ResourceListProps) {
|
||||
{
|
||||
id: "action",
|
||||
meta: { pin: "right" },
|
||||
header: "状态",
|
||||
header: "操作",
|
||||
cell: ({ row }: { row: { original: Resources } }) => {
|
||||
const resource = row.original
|
||||
const isLoading = updatingId === resource.id
|
||||
@@ -411,12 +434,19 @@ function ResourceList({ resourceType }: ResourceListProps) {
|
||||
{isLoading && (
|
||||
<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" />
|
||||
)}
|
||||
<Button
|
||||
onClick={() => handleCheckipChange(resource)}
|
||||
variant={resource.checkip ? "destructive" : "default"}
|
||||
disabled={isLoading}
|
||||
>
|
||||
{resource.checkip ? "停用IP检查" : "启用IP检查"}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
},
|
||||
},
|
||||
],
|
||||
[isLong, updatingId, handleStatusChange],
|
||||
[isLong, updatingId, handleStatusChange, handleCheckipChange],
|
||||
)
|
||||
|
||||
return (
|
||||
|
||||
@@ -10,6 +10,7 @@ type ResourceBase = {
|
||||
updated_at: Date
|
||||
deleted_at: Date | null
|
||||
user: User
|
||||
checkip:boolean
|
||||
}
|
||||
|
||||
type ResourceShort = {
|
||||
|
||||
Reference in New Issue
Block a user