Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b041bd3b01 | ||
|
|
385869604a |
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lanhu-admin",
|
"name": "lanhu-admin",
|
||||||
"version": "1.6.0",
|
"version": "1.7.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",
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ if ($confrim -ne "y") {
|
|||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
docker build -t repo.lanhuip.com:8554/lanhu/admin:latest .
|
docker build -t repo.lanhuip.com/lanhu/admin:latest .
|
||||||
docker build -t repo.lanhuip.com:8554/lanhu/admin:$($args[0]) .
|
docker build -t repo.lanhuip.com/lanhu/admin:$($args[0]) .
|
||||||
|
|
||||||
docker push repo.lanhuip.com:8554/lanhu/admin:latest
|
docker push repo.lanhuip.com/lanhu/admin:latest
|
||||||
docker push repo.lanhuip.com:8554/lanhu/admin:$($args[0])
|
docker push repo.lanhuip.com/lanhu/admin:$($args[0])
|
||||||
|
|||||||
@@ -8,22 +8,17 @@ export async function getGatewayPage(params: { page: number; size: number }) {
|
|||||||
return callByUser<PageRecord<Gateway>>("/api/admin/proxy/page", params)
|
return callByUser<PageRecord<Gateway>>("/api/admin/proxy/page", params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function createGateway(data: {
|
export async function createGateway(data: {
|
||||||
mac: string
|
mac: string
|
||||||
ip: string
|
ip: string
|
||||||
host?: string
|
host?: string
|
||||||
type: number
|
type: number
|
||||||
status: number
|
status: number
|
||||||
|
secret: string
|
||||||
}) {
|
}) {
|
||||||
return callByUser<Gateway>("/api/admin/proxy/create", data)
|
return callByUser<Gateway>("/api/admin/proxy/create", data)
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateGateway(data:{
|
export async function updateGateway(data: { id: number; status: number }) {
|
||||||
id: number,
|
return callByUser<Gateway>("/api/admin/proxy/update/status", data)
|
||||||
status: number}
|
|
||||||
) {
|
|
||||||
return callByUser<Gateway>("/api/admin/proxy/update/status",
|
|
||||||
data
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,8 +113,8 @@ export default function BatchPage() {
|
|||||||
data-invalid={fieldState.invalid}
|
data-invalid={fieldState.invalid}
|
||||||
className="w-40 flex-none"
|
className="w-40 flex-none"
|
||||||
>
|
>
|
||||||
<FieldLabel>批次号</FieldLabel>
|
<FieldLabel>提取编号</FieldLabel>
|
||||||
<Input {...field} placeholder="请输入批次号" />
|
<Input {...field} placeholder="请输入提取编号" />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
@@ -256,7 +256,7 @@ export default function BatchPage() {
|
|||||||
accessorFn: row => row.user?.phone || "",
|
accessorFn: row => row.user?.phone || "",
|
||||||
},
|
},
|
||||||
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
{ header: "批次号", accessorKey: "batch_no" },
|
{ header: "提取编号", accessorKey: "batch_no" },
|
||||||
{ header: "省份", accessorKey: "prov" },
|
{ header: "省份", accessorKey: "prov" },
|
||||||
{ header: "城市", accessorKey: "city" },
|
{ header: "城市", accessorKey: "city" },
|
||||||
{ header: "用户IP", accessorKey: "ip" },
|
{ header: "用户IP", accessorKey: "ip" },
|
||||||
|
|||||||
@@ -113,8 +113,8 @@ export default function ChannelPage() {
|
|||||||
data-invalid={fieldState.invalid}
|
data-invalid={fieldState.invalid}
|
||||||
className="w-40 flex-none"
|
className="w-40 flex-none"
|
||||||
>
|
>
|
||||||
<FieldLabel>批次号</FieldLabel>
|
<FieldLabel>提取编号</FieldLabel>
|
||||||
<Input {...field} placeholder="请输入批次号" />
|
<Input {...field} placeholder="请输入提取编号" />
|
||||||
<FieldError>{fieldState.error?.message}</FieldError>
|
<FieldError>{fieldState.error?.message}</FieldError>
|
||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
@@ -244,7 +244,7 @@ export default function ChannelPage() {
|
|||||||
accessorFn: row => row.user?.phone || "-",
|
accessorFn: row => row.user?.phone || "-",
|
||||||
},
|
},
|
||||||
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
{ header: "套餐号", accessorKey: "resource.resource_no" },
|
||||||
{ header: "批次号", accessorKey: "batch_no" },
|
{ header: "提取编号", accessorKey: "batch_no" },
|
||||||
{
|
{
|
||||||
header: "节点",
|
header: "节点",
|
||||||
accessorFn: row => row.ip || row.edge_ref || row.edge_id,
|
accessorFn: row => row.ip || row.edge_ref || row.edge_id,
|
||||||
|
|||||||
@@ -3,7 +3,9 @@
|
|||||||
import { zodResolver } from "@hookform/resolvers/zod"
|
import { zodResolver } from "@hookform/resolvers/zod"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { Controller, useForm } from "react-hook-form"
|
import { Controller, useForm } from "react-hook-form"
|
||||||
|
import { toast } from "sonner"
|
||||||
import z from "zod"
|
import z from "zod"
|
||||||
|
import { createGateway } from "@/actions/gateway"
|
||||||
import { Button } from "@/components/ui/button"
|
import { Button } from "@/components/ui/button"
|
||||||
import {
|
import {
|
||||||
Dialog,
|
Dialog,
|
||||||
@@ -27,19 +29,26 @@ import {
|
|||||||
SelectTrigger,
|
SelectTrigger,
|
||||||
SelectValue,
|
SelectValue,
|
||||||
} from "@/components/ui/select"
|
} from "@/components/ui/select"
|
||||||
import { toast } from "sonner"
|
|
||||||
import { createGateway } from "@/actions/gateway"
|
|
||||||
|
|
||||||
const schema = z.object({
|
const schema = z.object({
|
||||||
mac: z.string(),
|
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]?)$/, {
|
ip: z
|
||||||
message: "IP地址格式不正确,请使用如 192.168.1.1 的格式"
|
.string()
|
||||||
}),
|
.regex(
|
||||||
host: z.string().regex(/^([a-zA-Z0-9]([a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$/, {
|
/^(?:(?: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: "域名格式不正确,请使用如 example.com 的格式"
|
{
|
||||||
}).or(z.literal("")),
|
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(),
|
type: z.string().optional(),
|
||||||
status: z.string().optional(),
|
status: z.string().optional(),
|
||||||
|
secret: z.string().min(1, "请填写密钥"),
|
||||||
})
|
})
|
||||||
|
|
||||||
export default function CreatePage(props: { onSuccess?: () => void }) {
|
export default function CreatePage(props: { onSuccess?: () => void }) {
|
||||||
@@ -53,6 +62,7 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
|
|||||||
host: "",
|
host: "",
|
||||||
type: "1",
|
type: "1",
|
||||||
status: "0",
|
status: "0",
|
||||||
|
secret: "",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -65,6 +75,7 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
|
|||||||
host: data?.host.trim(),
|
host: data?.host.trim(),
|
||||||
type: data.type ? Number(data.type) : 0,
|
type: data.type ? Number(data.type) : 0,
|
||||||
status: data.status ? Number(data.status) : 0,
|
status: data.status ? Number(data.status) : 0,
|
||||||
|
secret: data.secret.trim(),
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await createGateway(payload)
|
const res = await createGateway(payload)
|
||||||
@@ -74,7 +85,7 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
|
|||||||
setOpen(false)
|
setOpen(false)
|
||||||
props.onSuccess?.()
|
props.onSuccess?.()
|
||||||
form.reset()
|
form.reset()
|
||||||
}else {
|
} else {
|
||||||
toast.error(res.message || "添加失败")
|
toast.error(res.message || "添加失败")
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -119,10 +130,7 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
|
|||||||
<DialogTitle>添加网关</DialogTitle>
|
<DialogTitle>添加网关</DialogTitle>
|
||||||
</DialogHeader>
|
</DialogHeader>
|
||||||
|
|
||||||
<form
|
<form id="gateway-create" onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
id="gateway-create"
|
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
|
||||||
>
|
|
||||||
<FieldGroup>
|
<FieldGroup>
|
||||||
<Controller
|
<Controller
|
||||||
control={form.control}
|
control={form.control}
|
||||||
@@ -178,6 +186,24 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
|
|||||||
</Field>
|
</Field>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<Controller
|
||||||
|
control={form.control}
|
||||||
|
name="secret"
|
||||||
|
render={({ field, fieldState }) => (
|
||||||
|
<Field>
|
||||||
|
<FieldLabel htmlFor="gateway-create-secret">密匙:</FieldLabel>
|
||||||
|
<Input
|
||||||
|
id="gateway-create-secret"
|
||||||
|
placeholder="请输入密匙"
|
||||||
|
{...field}
|
||||||
|
aria-invalid={fieldState.invalid}
|
||||||
|
/>
|
||||||
|
{fieldState.invalid && fieldState.error && (
|
||||||
|
<FieldError errors={[fieldState.error]} />
|
||||||
|
)}
|
||||||
|
</Field>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
<Controller
|
<Controller
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="type"
|
name="type"
|
||||||
|
|||||||
@@ -15,18 +15,18 @@ import CreatePage from "./create"
|
|||||||
export default function GatewayPage() {
|
export default function GatewayPage() {
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
|
||||||
const getGatewayPageWrapper = useCallback((page: number, size: number) => {
|
const getGatewayPageWrapper = useCallback((page: number, size: number) => {
|
||||||
return getGatewayPage({ page, size })
|
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)
|
setLoading(true)
|
||||||
try {
|
try {
|
||||||
const result = await updateGateway({
|
const result = await updateGateway({
|
||||||
id:id,
|
id: id,
|
||||||
status: status === 0 ? 1 : 0
|
status: status === 0 ? 1 : 0,
|
||||||
})
|
})
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
toast.success(status === 0 ? "启用成功" : "停用成功")
|
toast.success(status === 0 ? "启用成功" : "停用成功")
|
||||||
@@ -35,7 +35,8 @@ const table = useDataTable(getGatewayPageWrapper)
|
|||||||
toast.error(result.message || "操作失败")
|
toast.error(result.message || "操作失败")
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
toast.error("操作失败")
|
const message = error instanceof Error ? error.message : error
|
||||||
|
toast.error(`操作失败: ${message}`)
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
@@ -63,6 +64,10 @@ const table = useDataTable(getGatewayPageWrapper)
|
|||||||
header: "MAC地址",
|
header: "MAC地址",
|
||||||
accessorKey: "mac",
|
accessorKey: "mac",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
header: "密钥",
|
||||||
|
accessorKey: "secret",
|
||||||
|
},
|
||||||
{
|
{
|
||||||
header: "类型",
|
header: "类型",
|
||||||
accessorKey: "type",
|
accessorKey: "type",
|
||||||
@@ -86,9 +91,13 @@ const table = useDataTable(getGatewayPageWrapper)
|
|||||||
cell: ({ row }) => (
|
cell: ({ row }) => (
|
||||||
<div className="flex gap-2">
|
<div className="flex gap-2">
|
||||||
<Button
|
<Button
|
||||||
onClick={() => handleToggle(row.original.id, row.original.status)}
|
onClick={() =>
|
||||||
|
handleToggle(row.original.id, row.original.status)
|
||||||
|
}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
variant={row.original.status === 0 ? "default" : "destructive"}
|
variant={
|
||||||
|
row.original.status === 0 ? "default" : "destructive"
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{row.original.status === 0 ? "启用" : "停用"}
|
{row.original.status === 0 ? "启用" : "停用"}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user