From 385869604a373c47f93bf23dfbeb19775976f969 Mon Sep 17 00:00:00 2001 From: Eamon <17516219072@163.com> Date: Thu, 23 Apr 2026 11:04:57 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E5=85=B3=E6=B7=BB=E5=8A=A0secret?= =?UTF-8?q?=E5=AF=86=E9=92=A5=E5=AD=97=E6=AE=B5=20&=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E8=84=9A=E6=9C=AC=E7=9A=84=E8=BF=9C=E7=A8=8B=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E5=9C=B0=E5=9D=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish.ps1 | 8 ++-- src/actions/gateway.ts | 11 ++--- src/app/(root)/batch/page.tsx | 6 +-- src/app/(root)/channel/page.tsx | 6 +-- src/app/(root)/gateway/create.tsx | 68 +++++++++++++++++++++---------- src/app/(root)/gateway/page.tsx | 37 ++++++++++------- 6 files changed, 83 insertions(+), 53 deletions(-) diff --git a/publish.ps1 b/publish.ps1 index abb5a12..8fffdbc 100644 --- a/publish.ps1 +++ b/publish.ps1 @@ -9,8 +9,8 @@ if ($confrim -ne "y") { exit 0 } -docker build -t repo.lanhuip.com:8554/lanhu/admin:latest . -docker build -t repo.lanhuip.com:8554/lanhu/admin:$($args[0]) . +docker build -t repo.lanhuip.com/lanhu/admin:latest . +docker build -t repo.lanhuip.com/lanhu/admin:$($args[0]) . -docker push repo.lanhuip.com:8554/lanhu/admin:latest -docker push repo.lanhuip.com:8554/lanhu/admin:$($args[0]) +docker push repo.lanhuip.com/lanhu/admin:latest +docker push repo.lanhuip.com/lanhu/admin:$($args[0]) diff --git a/src/actions/gateway.ts b/src/actions/gateway.ts index 3fe01a5..7e28f27 100644 --- a/src/actions/gateway.ts +++ b/src/actions/gateway.ts @@ -8,22 +8,17 @@ export async function getGatewayPage(params: { page: number; size: number }) { return callByUser>("/api/admin/proxy/page", params) } - export async function createGateway(data: { mac: string ip: string host?: string type: number status: number + secret: string }) { return callByUser("/api/admin/proxy/create", data) } -export async function updateGateway(data:{ - id: number, - status: number} - ) { - return callByUser("/api/admin/proxy/update/status", - data - ) +export async function updateGateway(data: { id: number; status: number }) { + return callByUser("/api/admin/proxy/update/status", data) } diff --git a/src/app/(root)/batch/page.tsx b/src/app/(root)/batch/page.tsx index d4d5f0f..4632cb5 100644 --- a/src/app/(root)/batch/page.tsx +++ b/src/app/(root)/batch/page.tsx @@ -113,8 +113,8 @@ export default function BatchPage() { data-invalid={fieldState.invalid} className="w-40 flex-none" > - 批次号 - + 提取编号 + {fieldState.error?.message} )} @@ -256,7 +256,7 @@ export default function BatchPage() { accessorFn: row => row.user?.phone || "", }, { header: "套餐号", accessorKey: "resource.resource_no" }, - { header: "批次号", accessorKey: "batch_no" }, + { header: "提取编号", accessorKey: "batch_no" }, { header: "省份", accessorKey: "prov" }, { header: "城市", accessorKey: "city" }, { header: "用户IP", accessorKey: "ip" }, diff --git a/src/app/(root)/channel/page.tsx b/src/app/(root)/channel/page.tsx index 491ff5e..1dd84f3 100644 --- a/src/app/(root)/channel/page.tsx +++ b/src/app/(root)/channel/page.tsx @@ -113,8 +113,8 @@ export default function ChannelPage() { data-invalid={fieldState.invalid} className="w-40 flex-none" > - 批次号 - + 提取编号 + {fieldState.error?.message} )} @@ -244,7 +244,7 @@ export default function ChannelPage() { accessorFn: row => row.user?.phone || "-", }, { header: "套餐号", accessorKey: "resource.resource_no" }, - { header: "批次号", accessorKey: "batch_no" }, + { header: "提取编号", accessorKey: "batch_no" }, { header: "节点", accessorFn: row => row.ip || row.edge_ref || row.edge_id, diff --git a/src/app/(root)/gateway/create.tsx b/src/app/(root)/gateway/create.tsx index 5d83211..db51c9d 100644 --- a/src/app/(root)/gateway/create.tsx +++ b/src/app/(root)/gateway/create.tsx @@ -3,7 +3,9 @@ import { zodResolver } from "@hookform/resolvers/zod" import { useState } from "react" import { Controller, useForm } from "react-hook-form" +import { toast } from "sonner" import z from "zod" +import { createGateway } from "@/actions/gateway" import { Button } from "@/components/ui/button" import { Dialog, @@ -27,19 +29,26 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select" -import { toast } from "sonner" -import { createGateway } from "@/actions/gateway" const schema = z.object({ - mac: z.string(), - ip: z.string().regex(/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/, { - message: "IP地址格式不正确,请使用如 192.168.1.1 的格式" - }), - host: z.string().regex(/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/, { - message: "域名格式不正确,请使用如 example.com 的格式" -}).or(z.literal("")), + mac: z.string().min(1, "请填写mac地址"), + ip: z + .string() + .regex( + /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/, + { + message: "IP地址格式不正确,请使用如 192.168.1.1 的格式", + }, + ), + host: z + .string() + .regex(/^([a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/, { + message: "域名格式不正确,请使用如 example.com 的格式", + }) + .or(z.literal("")), type: z.string().optional(), status: z.string().optional(), + secret: z.string().min(1, "请填写密钥"), }) export default function CreatePage(props: { onSuccess?: () => void }) { @@ -53,6 +62,7 @@ export default function CreatePage(props: { onSuccess?: () => void }) { host: "", type: "1", status: "0", + secret: "", }, }) @@ -61,22 +71,23 @@ export default function CreatePage(props: { onSuccess?: () => void }) { try { const payload = { mac: data.mac.trim(), - ip: data.ip.trim(), - host: data?.host.trim(), + ip: data.ip.trim(), + host: data?.host.trim(), type: data.type ? Number(data.type) : 0, status: data.status ? Number(data.status) : 0, + secret: data.secret.trim(), } - + const res = await createGateway(payload) - + if (res.success) { toast.success("添加网关成功") setOpen(false) props.onSuccess?.() form.reset() - }else { - toast.error(res.message || "添加失败") - } + } else { + toast.error(res.message || "添加失败") + } } catch (error) { console.error("添加网关失败:", error) const message = error instanceof Error ? error.message : error @@ -119,10 +130,7 @@ export default function CreatePage(props: { onSuccess?: () => void }) { 添加网关 -
+ void }) { )} /> + ( + + 密匙: + + {fieldState.invalid && fieldState.error && ( + + )} + + )} + /> void }) { ) -} \ No newline at end of file +} diff --git a/src/app/(root)/gateway/page.tsx b/src/app/(root)/gateway/page.tsx index 011e2c8..63d789c 100644 --- a/src/app/(root)/gateway/page.tsx +++ b/src/app/(root)/gateway/page.tsx @@ -15,18 +15,18 @@ import CreatePage from "./create" export default function GatewayPage() { const [loading, setLoading] = useState(false) -const getGatewayPageWrapper = useCallback((page: number, size: number) => { - return getGatewayPage({ page, size }) -}, []) + const getGatewayPageWrapper = useCallback((page: number, size: number) => { + return getGatewayPage({ page, size }) + }, []) -const table = useDataTable(getGatewayPageWrapper) + const table = useDataTable(getGatewayPageWrapper) - const handleToggle = async (id: number, status: number) => { + const handleToggle = async (id: number, status: number) => { setLoading(true) try { const result = await updateGateway({ - id:id, - status: status === 0 ? 1 : 0 + id: id, + status: status === 0 ? 1 : 0, }) if (result.success) { toast.success(status === 0 ? "启用成功" : "停用成功") @@ -35,7 +35,8 @@ const table = useDataTable(getGatewayPageWrapper) toast.error(result.message || "操作失败") } } catch (error) { - toast.error("操作失败") + const message = error instanceof Error ? error.message : error + toast.error(`操作失败: ${message}`) } finally { setLoading(false) } @@ -63,6 +64,10 @@ const table = useDataTable(getGatewayPageWrapper) header: "MAC地址", accessorKey: "mac", }, + { + header: "密钥", + accessorKey: "secret", + }, { header: "类型", accessorKey: "type", @@ -86,12 +91,16 @@ const table = useDataTable(getGatewayPageWrapper) cell: ({ row }) => (
+ onClick={() => + handleToggle(row.original.id, row.original.status) + } + disabled={loading} + variant={ + row.original.status === 0 ? "default" : "destructive" + } + > + {row.original.status === 0 ? "启用" : "停用"} +
), },