Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b041bd3b01 | ||
|
|
385869604a | ||
|
|
dca32c435a | ||
|
|
4b1d87bb14 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lanhu-admin",
|
||||
"version": "1.5.0",
|
||||
"version": "1.7.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev -H 0.0.0.0 -p 3001 --turbopack",
|
||||
|
||||
@@ -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])
|
||||
|
||||
@@ -8,19 +8,17 @@ export async function getGatewayPage(params: { page: number; size: number }) {
|
||||
return callByUser<PageRecord<Gateway>>("/api/admin/proxy/page", params)
|
||||
}
|
||||
|
||||
|
||||
export async function createGateway(data: {
|
||||
mac: string
|
||||
ip: string
|
||||
host?: string
|
||||
type: number
|
||||
status: number
|
||||
secret: string
|
||||
}) {
|
||||
return callByUser<Gateway>("/api/admin/proxy/create", data)
|
||||
}
|
||||
|
||||
export async function deletegateway(id: number) {
|
||||
return callByUser<Gateway>("/api/admin/proxy/remove", {
|
||||
id,
|
||||
})
|
||||
export async function updateGateway(data: { id: number; status: number }) {
|
||||
return callByUser<Gateway>("/api/admin/proxy/update/status", data)
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export async function listResourceShort(params: ResourceListParams) {
|
||||
)
|
||||
}
|
||||
|
||||
export async function updateResource(data: { id: number; active?: boolean }) {
|
||||
export async function updateResource(data: { id: number; active?: boolean; checkip?: boolean}) {
|
||||
return callByUser<Resources>("/api/admin/resource/update", data)
|
||||
}
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ export default function Appbar(props: { admin: Admin }) {
|
||||
}
|
||||
|
||||
return (
|
||||
<header className="bg-white flex-none basis-16 border-b border-gray-200 flex items-center justify-between px-6">
|
||||
<header className="bg-white flex-none basis-16 border-b border-gray-200 flex items-center justify-between px-6 z-40">
|
||||
{/* 面包屑导航 */}
|
||||
<div className="flex items-center text-sm">
|
||||
{breadcrumbs.map((crumb, index) => (
|
||||
@@ -194,7 +194,7 @@ export default function Appbar(props: { admin: Admin }) {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="py-1">
|
||||
<div className="py-1 ">
|
||||
<Link
|
||||
href="/profile"
|
||||
className="flex items-center px-4 py-2 text-sm text-gray-700 hover:bg-gray-100"
|
||||
|
||||
@@ -113,8 +113,8 @@ export default function BatchPage() {
|
||||
data-invalid={fieldState.invalid}
|
||||
className="w-40 flex-none"
|
||||
>
|
||||
<FieldLabel>批次号</FieldLabel>
|
||||
<Input {...field} placeholder="请输入批次号" />
|
||||
<FieldLabel>提取编号</FieldLabel>
|
||||
<Input {...field} placeholder="请输入提取编号" />
|
||||
<FieldError>{fieldState.error?.message}</FieldError>
|
||||
</Field>
|
||||
)}
|
||||
@@ -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" },
|
||||
|
||||
@@ -113,8 +113,8 @@ export default function ChannelPage() {
|
||||
data-invalid={fieldState.invalid}
|
||||
className="w-40 flex-none"
|
||||
>
|
||||
<FieldLabel>批次号</FieldLabel>
|
||||
<Input {...field} placeholder="请输入批次号" />
|
||||
<FieldLabel>提取编号</FieldLabel>
|
||||
<Input {...field} placeholder="请输入提取编号" />
|
||||
<FieldError>{fieldState.error?.message}</FieldError>
|
||||
</Field>
|
||||
)}
|
||||
@@ -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,
|
||||
|
||||
@@ -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,21 +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().regex(/^([0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$/, {
|
||||
message: "MAC地址格式不正确,请使用如 00:11:22:AA:BB:CC 或 00-11-22-AA-BB-CC 的格式"
|
||||
}),
|
||||
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 }) {
|
||||
@@ -55,6 +62,7 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
|
||||
host: "",
|
||||
type: "1",
|
||||
status: "0",
|
||||
secret: "",
|
||||
},
|
||||
})
|
||||
|
||||
@@ -63,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
|
||||
@@ -121,17 +130,14 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
|
||||
<DialogTitle>添加网关</DialogTitle>
|
||||
</DialogHeader>
|
||||
|
||||
<form
|
||||
id="gateway-create"
|
||||
onSubmit={form.handleSubmit(onSubmit)}
|
||||
>
|
||||
<form id="gateway-create" onSubmit={form.handleSubmit(onSubmit)}>
|
||||
<FieldGroup>
|
||||
<Controller
|
||||
control={form.control}
|
||||
name="mac"
|
||||
render={({ field, fieldState }) => (
|
||||
<Field>
|
||||
<FieldLabel htmlFor="gateway-create-mac">MAC地址:</FieldLabel>
|
||||
<FieldLabel htmlFor="gateway-create-mac">标识:</FieldLabel>
|
||||
<Input
|
||||
id="gateway-create-mac"
|
||||
placeholder="请输入MAC地址,如:00:11:22:33:44:55"
|
||||
@@ -180,6 +186,24 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
|
||||
</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
|
||||
control={form.control}
|
||||
name="type"
|
||||
@@ -242,4 +266,4 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
"use client"
|
||||
|
||||
import { format } from "date-fns"
|
||||
import { Suspense, useState } from "react"
|
||||
import { Suspense, useCallback, useState } from "react"
|
||||
import { toast } from "sonner"
|
||||
import { getGatewayPage } from "@/actions/gateway"
|
||||
import { getGatewayPage, updateGateway } from "@/actions/gateway"
|
||||
import { Auth } from "@/components/auth"
|
||||
import { DataTable, useDataTable } from "@/components/data-table"
|
||||
import { Page } from "@/components/page"
|
||||
@@ -15,8 +15,32 @@ import CreatePage from "./create"
|
||||
export default function GatewayPage() {
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const table = useDataTable((page, size) => getGatewayPage({ page, size }))
|
||||
const getGatewayPageWrapper = useCallback((page: number, size: number) => {
|
||||
return getGatewayPage({ page, size })
|
||||
}, [])
|
||||
|
||||
const table = useDataTable(getGatewayPageWrapper)
|
||||
|
||||
const handleToggle = async (id: number, status: number) => {
|
||||
setLoading(true)
|
||||
try {
|
||||
const result = await updateGateway({
|
||||
id: id,
|
||||
status: status === 0 ? 1 : 0,
|
||||
})
|
||||
if (result.success) {
|
||||
toast.success(status === 0 ? "启用成功" : "停用成功")
|
||||
table.refresh()
|
||||
} 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}>
|
||||
@@ -40,6 +64,10 @@ export default function GatewayPage() {
|
||||
header: "MAC地址",
|
||||
accessorKey: "mac",
|
||||
},
|
||||
{
|
||||
header: "密钥",
|
||||
accessorKey: "secret",
|
||||
},
|
||||
{
|
||||
header: "类型",
|
||||
accessorKey: "type",
|
||||
@@ -62,10 +90,17 @@ export default function GatewayPage() {
|
||||
header: "操作",
|
||||
cell: ({ row }) => (
|
||||
<div className="flex gap-2">
|
||||
<Button className="bg-green-600/60 hover:bg-green-600/60 active:bg-green-600/60">
|
||||
启用
|
||||
<Button
|
||||
onClick={() =>
|
||||
handleToggle(row.original.id, row.original.status)
|
||||
}
|
||||
disabled={loading}
|
||||
variant={
|
||||
row.original.status === 0 ? "default" : "destructive"
|
||||
}
|
||||
>
|
||||
{row.original.status === 0 ? "启用" : "停用"}
|
||||
</Button>
|
||||
<Button>停用</Button>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -10,6 +10,7 @@ type ResourceBase = {
|
||||
updated_at: Date
|
||||
deleted_at: Date | null
|
||||
user: User
|
||||
checkip:boolean
|
||||
}
|
||||
|
||||
type ResourceShort = {
|
||||
|
||||
Reference in New Issue
Block a user