网关列表添加清理过期连接按钮功能
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lanhu-admin",
|
"name": "lanhu-admin",
|
||||||
"version": "1.7.0",
|
"version": "1.8.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",
|
||||||
|
|||||||
@@ -22,3 +22,7 @@ export async function createGateway(data: {
|
|||||||
export async function updateGateway(data: { id: number; status: number }) {
|
export async function updateGateway(data: { id: number; status: number }) {
|
||||||
return callByUser<Gateway>("/api/admin/proxy/update/status", data)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,12 +3,12 @@
|
|||||||
import { format } from "date-fns"
|
import { format } from "date-fns"
|
||||||
import { Suspense, useCallback, useState } from "react"
|
import { Suspense, useCallback, useState } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
import { getGatewayPage, updateGateway } from "@/actions/gateway"
|
import { clear, getGatewayPage, updateGateway } from "@/actions/gateway"
|
||||||
import { Auth } from "@/components/auth"
|
import { Auth } from "@/components/auth"
|
||||||
import { DataTable, useDataTable } from "@/components/data-table"
|
import { DataTable, useDataTable } from "@/components/data-table"
|
||||||
import { Page } from "@/components/page"
|
import { Page } from "@/components/page"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import { ScopeProxyWrite } from "@/lib/scopes"
|
import { ScopeChannelWriteClearExpired, ScopeProxyWrite } from "@/lib/scopes"
|
||||||
import type { Gateway } from "@/models/gateway"
|
import type { Gateway } from "@/models/gateway"
|
||||||
import CreatePage from "./create"
|
import CreatePage from "./create"
|
||||||
|
|
||||||
@@ -41,15 +41,38 @@ export default function GatewayPage() {
|
|||||||
setLoading(false)
|
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 (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<Auth scope={ScopeProxyWrite}>
|
<div className="flex justify-between items-stretch">
|
||||||
<div className="flex justify-between items-stretch">
|
<div className="flex gap-3">
|
||||||
<div className="flex gap-3">
|
<Auth scope={ScopeProxyWrite}>
|
||||||
<CreatePage onSuccess={table.refresh} />
|
<CreatePage onSuccess={table.refresh} />
|
||||||
</div>
|
</Auth>
|
||||||
</div>
|
</div>
|
||||||
</Auth>
|
</div>
|
||||||
<Suspense>
|
<Suspense>
|
||||||
<DataTable<Gateway>
|
<DataTable<Gateway>
|
||||||
{...table}
|
{...table}
|
||||||
@@ -101,6 +124,11 @@ export default function GatewayPage() {
|
|||||||
>
|
>
|
||||||
{row.original.status === 0 ? "启用" : "停用"}
|
{row.original.status === 0 ? "启用" : "停用"}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Auth scope={ScopeChannelWriteClearExpired}>
|
||||||
|
<Button onClick={() => clearExpired(row.original)}>
|
||||||
|
清理过期连接
|
||||||
|
</Button>
|
||||||
|
</Auth>
|
||||||
</div>
|
</div>
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -91,3 +91,4 @@ export const ScopeProxy = "proxy"
|
|||||||
export const ScopeProxyRead = "proxy:read" // 读取代理列表
|
export const ScopeProxyRead = "proxy:read" // 读取代理列表
|
||||||
export const ScopeProxyWrite = "proxy:write" // 写入代理
|
export const ScopeProxyWrite = "proxy:write" // 写入代理
|
||||||
export const ScopeProxyWriteStatus = "proxy:write:status" // 更改代理状态
|
export const ScopeProxyWriteStatus = "proxy:write:status" // 更改代理状态
|
||||||
|
export const ScopeChannelWriteClearExpired = "channel:write:clear_expired" //清理过期连接
|
||||||
|
|||||||
Reference in New Issue
Block a user