套餐管理添加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

@@ -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 (