网关列表添加清理过期连接按钮功能

This commit is contained in:
Eamon
2026-05-08 17:47:42 +08:00
parent 85f9e68e32
commit bc29a025b0
4 changed files with 41 additions and 8 deletions

View File

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

View File

@@ -22,3 +22,7 @@ export async function createGateway(data: {
export async function updateGateway(data: { id: number; status: number }) {
return callByUser<Gateway>("/api/admin/proxy/update/status", data)
}
export async function clear(data: { proxy_id: number }) {
return callByUser<PageRecord>("/api/admin/channel/sync/clear-expired", data)
}

View File

@@ -3,12 +3,12 @@
import { format } from "date-fns"
import { Suspense, useCallback, useState } from "react"
import { toast } from "sonner"
import { getGatewayPage, updateGateway } from "@/actions/gateway"
import { clear, getGatewayPage, updateGateway } from "@/actions/gateway"
import { Auth } from "@/components/auth"
import { DataTable, useDataTable } from "@/components/data-table"
import { Page } from "@/components/page"
import { Button } from "@/components/ui/button"
import { ScopeProxyWrite } from "@/lib/scopes"
import { ScopeChannelWriteClearExpired, ScopeProxyWrite } from "@/lib/scopes"
import type { Gateway } from "@/models/gateway"
import CreatePage from "./create"
@@ -41,15 +41,38 @@ export default function GatewayPage() {
setLoading(false)
}
}
const clearExpired = async (val: Gateway) => {
setLoading(true)
try {
const result = await clear({
proxy_id: val.id,
})
if (result.success) {
const count =
result.data && "count" in result.data ? result.data.count : 0
toast.success(`清理过期连接成功,共 ${count}`)
} else {
toast.error(result.message || "清理过期连接失败,请稍后重试一下~")
}
} catch (error) {
const message = error instanceof Error ? error.message : error
toast.error(`清理过期连接失败: ${message}`)
} finally {
setLoading(false)
}
}
return (
<Page>
<Auth scope={ScopeProxyWrite}>
<div className="flex justify-between items-stretch">
<div className="flex gap-3">
<div className="flex justify-between items-stretch">
<div className="flex gap-3">
<Auth scope={ScopeProxyWrite}>
<CreatePage onSuccess={table.refresh} />
</div>
</Auth>
</div>
</Auth>
</div>
<Suspense>
<DataTable<Gateway>
{...table}
@@ -101,6 +124,11 @@ export default function GatewayPage() {
>
{row.original.status === 0 ? "启用" : "停用"}
</Button>
<Auth scope={ScopeChannelWriteClearExpired}>
<Button onClick={() => clearExpired(row.original)}>
</Button>
</Auth>
</div>
),
},

View File

@@ -91,3 +91,4 @@ export const ScopeProxy = "proxy"
export const ScopeProxyRead = "proxy:read" // 读取代理列表
export const ScopeProxyWrite = "proxy:write" // 写入代理
export const ScopeProxyWriteStatus = "proxy:write:status" // 更改代理状态
export const ScopeChannelWriteClearExpired = "channel:write:clear_expired" //清理过期连接