套餐管理添加IP检查状态字段

This commit is contained in:
Eamon
2026-04-22 13:26:44 +08:00
parent 4b1d87bb14
commit dca32c435a
4 changed files with 36 additions and 5 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "lanhu-admin", "name": "lanhu-admin",
"version": "1.5.0", "version": "1.6.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -H 0.0.0.0 -p 3001 --turbopack", "dev": "next dev -H 0.0.0.0 -p 3001 --turbopack",

View File

@@ -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) return callByUser<Resources>("/api/admin/resource/update", data)
} }

View File

@@ -255,7 +255,30 @@ function ResourceList({ resourceType }: ResourceListProps) {
}, },
[refreshTable], [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 onFilter = handleSubmit(data => {
const result: FilterParams = {} const result: FilterParams = {}
if (data.user_phone?.trim()) result.user_phone = data.user_phone.trim() if (data.user_phone?.trim()) result.user_phone = data.user_phone.trim()
@@ -388,7 +411,7 @@ function ResourceList({ resourceType }: ResourceListProps) {
{ {
id: "action", id: "action",
meta: { pin: "right" }, meta: { pin: "right" },
header: "状态", header: "操作",
cell: ({ row }: { row: { original: Resources } }) => { cell: ({ row }: { row: { original: Resources } }) => {
const resource = row.original const resource = row.original
const isLoading = updatingId === resource.id const isLoading = updatingId === resource.id
@@ -411,12 +434,19 @@ function ResourceList({ resourceType }: ResourceListProps) {
{isLoading && ( {isLoading && (
<Loader2 className="h-4 w-4 animate-spin text-muted-foreground" /> <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> </div>
) )
}, },
}, },
], ],
[isLong, updatingId, handleStatusChange], [isLong, updatingId, handleStatusChange, handleCheckipChange],
) )
return ( return (

View File

@@ -10,6 +10,7 @@ type ResourceBase = {
updated_at: Date updated_at: Date
deleted_at: Date | null deleted_at: Date | null
user: User user: User
checkip:boolean
} }
type ResourceShort = { type ResourceShort = {