网关添加secret密钥字段 & 更新脚本的远程仓库地址

This commit is contained in:
Eamon
2026-04-23 11:04:57 +08:00
parent dca32c435a
commit 385869604a
6 changed files with 83 additions and 53 deletions

View File

@@ -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 }) {
<DialogTitle></DialogTitle>
</DialogHeader>
<form
id="gateway-create"
onSubmit={form.handleSubmit(onSubmit)}
>
<form id="gateway-create" onSubmit={form.handleSubmit(onSubmit)}>
<FieldGroup>
<Controller
control={form.control}
@@ -178,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"
@@ -240,4 +266,4 @@ export default function CreatePage(props: { onSuccess?: () => void }) {
</DialogContent>
</Dialog>
)
}
}