mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-05-06 05:38:51 +00:00
fix: resolve domain.ts type errors and SWR fetching bugs; fix vps config unmarshal issue
This commit is contained in:
+1313
-1174
File diff suppressed because it is too large
Load Diff
+21
-12
@@ -1,44 +1,53 @@
|
||||
import { fetcher, FetcherMethod, swrFetcher } from './api' // 导入正确的 fetcher 函数和方法枚举
|
||||
import type { Domain, BillingDataMod} from '@/types/api'
|
||||
// 导入正确的 fetcher 函数和方法枚举
|
||||
import type { BillingDataMod, Domain } from "@/types/domain"
|
||||
|
||||
import { FetcherMethod, fetcher } from "./api"
|
||||
|
||||
// --- GET 请求 (用于 SWR) ---
|
||||
|
||||
// 获取域名列表的函数,专门为 useSWR 设计
|
||||
// swrFetcher 内部会调用 fetcher,这一部分是正确的
|
||||
export const useDomainList = () => {
|
||||
return swrFetcher<Domain[]>('/api/v1/domains')
|
||||
export const useDomainList = (url: string) => {
|
||||
return fetcher<Domain[]>(FetcherMethod.GET, url)
|
||||
}
|
||||
|
||||
|
||||
// --- POST, PUT, DELETE 请求 (使用 fetcher) ---
|
||||
|
||||
// 添加一个新的域名
|
||||
export const addDomain = (domain: string) => {
|
||||
return fetcher<Domain>(FetcherMethod.POST, '/api/v1/domains', { domain })
|
||||
return fetcher<Domain>(FetcherMethod.POST, "/api/v1/domains", { domain })
|
||||
}
|
||||
|
||||
// 触发域名验证
|
||||
export const verifyDomain = (id: number) => {
|
||||
return fetcher<{ success: boolean; message: string }>(FetcherMethod.POST, `/api/v1/domains/${id}/verify`)
|
||||
return fetcher<{ success: boolean; message: string }>(
|
||||
FetcherMethod.POST,
|
||||
`/api/v1/domains/${id}/verify`,
|
||||
)
|
||||
}
|
||||
|
||||
// 更新域名的配置信息
|
||||
export const updateDomainConfig = (id: number, billingData: BillingDataMod) => {
|
||||
return fetcher<Domain>(FetcherMethod.PUT, `/api/v1/domains/${id}`, { billing_data: billingData })
|
||||
return fetcher<Domain>(FetcherMethod.PUT, `/api/v1/domains/${id}`, {
|
||||
billing_data: billingData,
|
||||
})
|
||||
}
|
||||
|
||||
// 删除一个域名
|
||||
export const deleteDomain = (id: number) => {
|
||||
// DELETE 请求通常没有响应体,所以 T 可以是 any 或 unknown
|
||||
return fetcher<any>(FetcherMethod.DELETE, `/api/v1/domains/${id}`)
|
||||
// DELETE 请求通常没有响应体,所以 T 可以是 any 或 unknown
|
||||
return fetcher<any>(FetcherMethod.DELETE, `/api/v1/domains/${id}`)
|
||||
}
|
||||
|
||||
// 更新一个域名(包括公开状态和配置信息)
|
||||
export const updateDomain = (id: number, data: { is_public: boolean, billing_data: BillingDataMod }) => {
|
||||
export const updateDomain = (
|
||||
id: number,
|
||||
data: { is_public: boolean; billing_data: BillingDataMod },
|
||||
) => {
|
||||
return fetcher<Domain>(FetcherMethod.PUT, `/api/v1/domains/${id}`, data)
|
||||
}
|
||||
|
||||
// 同步 Whois 信息
|
||||
export const syncDomainWHOIS = (id: number) => {
|
||||
return fetcher<Domain>(FetcherMethod.POST, `/api/v1/domains/${id}/sync`)
|
||||
return fetcher<Domain>(FetcherMethod.POST, `/api/v1/domains/${id}/sync`)
|
||||
}
|
||||
+14
-16
@@ -1,4 +1,6 @@
|
||||
import { ModeToggle } from "@/components/mode-toggle"
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
Drawer,
|
||||
DrawerClose,
|
||||
@@ -9,12 +11,24 @@ import {
|
||||
DrawerTitle,
|
||||
DrawerTrigger,
|
||||
} from "@/components/ui/drawer"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import {
|
||||
NavigationMenu,
|
||||
NavigationMenuItem,
|
||||
NavigationMenuLink,
|
||||
navigationMenuTriggerStyle,
|
||||
} from "@/components/ui/navigation-menu"
|
||||
import { IconButton } from "@/components/xui/icon-button"
|
||||
import { NzNavigationMenuLink } from "@/components/xui/navigation-menu"
|
||||
import { useAuth } from "@/hooks/useAuth"
|
||||
import { useMainStore } from "@/hooks/useMainStore"
|
||||
import { useMediaQuery } from "@/hooks/useMediaQuery"
|
||||
@@ -26,21 +40,6 @@ import { useEffect, useRef, useState } from "react"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { Link, useLocation, useNavigate } from "react-router-dom"
|
||||
|
||||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuGroup,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuLabel,
|
||||
DropdownMenuSeparator,
|
||||
DropdownMenuShortcut,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { IconButton } from "@/components/xui/icon-button"
|
||||
import { NzNavigationMenuLink } from "@/components/xui/navigation-menu"
|
||||
|
||||
// =======================================================
|
||||
// vvvvvvvvvvv 1. 在这里为移动端菜单添加新页面 vvvvvvvvvvv
|
||||
const pages = [
|
||||
@@ -428,4 +427,3 @@ function Overview() {
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+45
-15
@@ -177,11 +177,21 @@ export const NotifierCard: React.FC<NotifierCardProps> = ({ data, mutate }) => {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
{form.watch("type") == 2 ? "SMTP Server (host:port)" :
|
||||
form.watch("type") == 3 ? "Bot Token" : "URL"}
|
||||
{form.watch("type") == 2
|
||||
? "SMTP Server (host:port)"
|
||||
: form.watch("type") == 3
|
||||
? "Bot Token"
|
||||
: "URL"}
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Input {...field} placeholder={form.watch("type") == 3 ? "123456:ABC-DEF" : ""} />
|
||||
<Input
|
||||
{...field}
|
||||
placeholder={
|
||||
form.watch("type") == 3
|
||||
? "123456:ABC-DEF"
|
||||
: ""
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -234,11 +244,13 @@ export const NotifierCard: React.FC<NotifierCardProps> = ({ data, mutate }) => {
|
||||
</SelectTrigger>
|
||||
</FormControl>
|
||||
<SelectContent>
|
||||
{Object.entries(nrequestTypes).map(([k, v]) => (
|
||||
<SelectItem key={k} value={k}>
|
||||
{v}
|
||||
</SelectItem>
|
||||
))}
|
||||
{Object.entries(nrequestTypes).map(
|
||||
([k, v]) => (
|
||||
<SelectItem key={k} value={k}>
|
||||
{v}
|
||||
</SelectItem>
|
||||
),
|
||||
)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<FormMessage />
|
||||
@@ -253,15 +265,21 @@ export const NotifierCard: React.FC<NotifierCardProps> = ({ data, mutate }) => {
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>
|
||||
{form.watch("type") == 2 ? "SMTP User:Pass" :
|
||||
form.watch("type") == 3 ? "Chat ID" : t("RequestHeader")}
|
||||
{form.watch("type") == 2
|
||||
? "SMTP User:Pass"
|
||||
: form.watch("type") == 3
|
||||
? "Chat ID"
|
||||
: t("RequestHeader")}
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
className="resize-y"
|
||||
placeholder={
|
||||
form.watch("type") == 2 ? "user:pass" :
|
||||
form.watch("type") == 3 ? "123456789" : '{"User-Agent":"Nezha-Agent"}'
|
||||
form.watch("type") == 2
|
||||
? "user:pass"
|
||||
: form.watch("type") == 3
|
||||
? "123456789"
|
||||
: '{"User-Agent":"Nezha-Agent"}'
|
||||
}
|
||||
{...field}
|
||||
/>
|
||||
@@ -276,11 +294,23 @@ export const NotifierCard: React.FC<NotifierCardProps> = ({ data, mutate }) => {
|
||||
name="request_body"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
<FormLabel>{form.watch("type") == 2 ? "Recipient Email" : t("RequestBody")}</FormLabel>
|
||||
<FormLabel>
|
||||
{form.watch("type") == 2
|
||||
? "Recipient Email"
|
||||
: t("RequestBody")}
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
<Textarea
|
||||
className={form.watch("type") == 2 ? "resize-y" : "resize-y h-[240px]"}
|
||||
placeholder={form.watch("type") == 2 ? "target@example.com" : '...'}
|
||||
className={
|
||||
form.watch("type") == 2
|
||||
? "resize-y"
|
||||
: "resize-y h-[240px]"
|
||||
}
|
||||
placeholder={
|
||||
form.watch("type") == 2
|
||||
? "target@example.com"
|
||||
: "..."
|
||||
}
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
|
||||
@@ -160,13 +160,17 @@ export const ServerConfigCard = ({ sid, menuItem = false, ...props }: ServerConf
|
||||
const onSubmit = async (values: any) => {
|
||||
let resp: ModelServerTaskResponse = {}
|
||||
try {
|
||||
values.nic_allowlist = values.nic_allowlist_raw
|
||||
? JSON.parse(values.nic_allowlist_raw)
|
||||
const submitValues = { ...values }
|
||||
submitValues.nic_allowlist = submitValues.nic_allowlist_raw
|
||||
? JSON.parse(submitValues.nic_allowlist_raw)
|
||||
: undefined
|
||||
values.hard_drive_partition_allowlist = values.hard_drive_partition_allowlist_raw
|
||||
? JSON.parse(values.hard_drive_partition_allowlist_raw)
|
||||
: undefined
|
||||
resp = await setServerConfig({ config: JSON.stringify(values), servers: [sid] })
|
||||
submitValues.hard_drive_partition_allowlist =
|
||||
submitValues.hard_drive_partition_allowlist_raw
|
||||
? JSON.parse(submitValues.hard_drive_partition_allowlist_raw)
|
||||
: undefined
|
||||
delete submitValues.nic_allowlist_raw
|
||||
delete submitValues.hard_drive_partition_allowlist_raw
|
||||
resp = await setServerConfig({ config: JSON.stringify(submitValues), servers: [sid] })
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
toast(t("Error"), {
|
||||
|
||||
+59
-29
@@ -28,7 +28,7 @@ import { conv } from "@/lib/utils"
|
||||
import { asOptionalField } from "@/lib/utils"
|
||||
import { ModelServer } from "@/types"
|
||||
import { zodResolver } from "@hookform/resolvers/zod"
|
||||
import { useState, useEffect } from "react"
|
||||
import { useEffect, useState } from "react"
|
||||
import { useForm } from "react-hook-form"
|
||||
import { useTranslation } from "react-i18next"
|
||||
import { toast } from "sonner"
|
||||
@@ -65,11 +65,13 @@ const serverFormSchema = z.object({
|
||||
},
|
||||
),
|
||||
),
|
||||
billing_data: z.object({
|
||||
registrar: asOptionalField(z.string()),
|
||||
endDate: asOptionalField(z.string()),
|
||||
notes: asOptionalField(z.string()),
|
||||
}).optional(),
|
||||
billing_data: z
|
||||
.object({
|
||||
registrar: asOptionalField(z.string()),
|
||||
endDate: asOptionalField(z.string()),
|
||||
notes: asOptionalField(z.string()),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
|
||||
export const ServerCard: React.FC<ServerCardProps> = ({ data, mutate }) => {
|
||||
@@ -92,16 +94,16 @@ export const ServerCard: React.FC<ServerCardProps> = ({ data, mutate }) => {
|
||||
|
||||
useEffect(() => {
|
||||
const handleMessage = (e: MessageEvent) => {
|
||||
if (e.data?.type === 'NZCFG_JSON') {
|
||||
if (e.data.target === 'public_note') {
|
||||
form.setValue('public_note', e.data.payload);
|
||||
toast(t("Success"), { description: "配置已通过可视化构建器自动填入" });
|
||||
if (e.data?.type === "NZCFG_JSON") {
|
||||
if (e.data.target === "public_note") {
|
||||
form.setValue("public_note", e.data.payload)
|
||||
toast(t("Success"), { description: "配置已通过可视化构建器自动填入" })
|
||||
}
|
||||
}
|
||||
};
|
||||
window.addEventListener('message', handleMessage);
|
||||
return () => window.removeEventListener('message', handleMessage);
|
||||
}, [form, t]);
|
||||
}
|
||||
window.addEventListener("message", handleMessage)
|
||||
return () => window.removeEventListener("message", handleMessage)
|
||||
}, [form, t])
|
||||
|
||||
const onSubmit = async (values: any) => {
|
||||
try {
|
||||
@@ -255,7 +257,9 @@ export const ServerCard: React.FC<ServerCardProps> = ({ data, mutate }) => {
|
||||
)}
|
||||
/>
|
||||
<div className="p-3 border rounded-md border-dashed space-y-2">
|
||||
<Label className="text-xs text-muted-foreground uppercase font-bold">Billing & Expiry</Label>
|
||||
<Label className="text-xs text-muted-foreground uppercase font-bold">
|
||||
Billing & Expiry
|
||||
</Label>
|
||||
<FormField
|
||||
control={form.control as any}
|
||||
name="billing_data.registrar"
|
||||
@@ -263,7 +267,10 @@ export const ServerCard: React.FC<ServerCardProps> = ({ data, mutate }) => {
|
||||
<FormItem>
|
||||
<FormLabel>Registrar</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="AWS / Azure /阿里云" {...field} />
|
||||
<Input
|
||||
placeholder="AWS / Azure /阿里云"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -276,7 +283,20 @@ export const ServerCard: React.FC<ServerCardProps> = ({ data, mutate }) => {
|
||||
<FormItem>
|
||||
<FormLabel>Expiry Date</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="date" {...field} value={field.value?.split('T')[0] || ''} onChange={(e) => field.onChange(e.target.value ? new Date(e.target.value).toISOString() : '')} />
|
||||
<Input
|
||||
type="date"
|
||||
{...field}
|
||||
value={field.value?.split("T")[0] || ""}
|
||||
onChange={(e) =>
|
||||
field.onChange(
|
||||
e.target.value
|
||||
? new Date(
|
||||
e.target.value,
|
||||
).toISOString()
|
||||
: "",
|
||||
)
|
||||
}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -290,18 +310,28 @@ export const ServerCard: React.FC<ServerCardProps> = ({ data, mutate }) => {
|
||||
<FormItem>
|
||||
<FormLabel className="flex justify-between items-center w-full">
|
||||
<span>{t("Public") + t("Note")}</span>
|
||||
<a href="/dashboard/nzcfg.html" target="_blank" className="text-blue-500 hover:text-blue-700 text-xs flex items-center gap-1" onClick={(e) => {
|
||||
e.preventDefault();
|
||||
const popup = window.open('/dashboard/nzcfg.html', 'nzcfg', 'width=1000,height=800');
|
||||
if(popup) {
|
||||
const timer = setInterval(() => {
|
||||
if(popup.closed) {
|
||||
clearInterval(timer);
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
}}>
|
||||
可视化管理配置 <i className="fa-solid fa-up-right-from-square"></i>
|
||||
<a
|
||||
href="/dashboard/nzcfg.html"
|
||||
target="_blank"
|
||||
className="text-blue-500 hover:text-blue-700 text-xs flex items-center gap-1"
|
||||
onClick={(e) => {
|
||||
e.preventDefault()
|
||||
const popup = window.open(
|
||||
"/dashboard/nzcfg.html",
|
||||
"nzcfg",
|
||||
"width=1000,height=800",
|
||||
)
|
||||
if (popup) {
|
||||
const timer = setInterval(() => {
|
||||
if (popup.closed) {
|
||||
clearInterval(timer)
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
}}
|
||||
>
|
||||
可视化管理配置{" "}
|
||||
<i className="fa-solid fa-up-right-from-square"></i>
|
||||
</a>
|
||||
</FormLabel>
|
||||
<FormControl>
|
||||
|
||||
@@ -23,8 +23,7 @@ const badgeVariants = cva(
|
||||
)
|
||||
|
||||
export interface BadgeProps
|
||||
extends HTMLAttributes<HTMLDivElement>,
|
||||
VariantProps<typeof badgeVariants> {}
|
||||
extends HTMLAttributes<HTMLDivElement>, VariantProps<typeof badgeVariants> {}
|
||||
|
||||
function Badge({ className, variant, ...props }: BadgeProps) {
|
||||
return <div className={cn(badgeVariants({ variant }), className)} {...props} />
|
||||
|
||||
@@ -31,8 +31,7 @@ const buttonVariants = cva(
|
||||
)
|
||||
|
||||
export interface ButtonProps
|
||||
extends ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof buttonVariants> {
|
||||
extends ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
||||
asChild?: boolean
|
||||
}
|
||||
|
||||
|
||||
@@ -67,7 +67,8 @@ const multiSelectVariants = cva(
|
||||
* Props for MultiSelect component
|
||||
*/
|
||||
interface MultiSelectProps
|
||||
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
extends
|
||||
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
||||
VariantProps<typeof multiSelectVariants> {
|
||||
/**
|
||||
* An array of option objects to be displayed in the multi-select component.
|
||||
|
||||
@@ -37,7 +37,8 @@ const sheetVariants = cva(
|
||||
)
|
||||
|
||||
interface SheetContentProps
|
||||
extends ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
|
||||
extends
|
||||
ComponentPropsWithoutRef<typeof SheetPrimitive.Content>,
|
||||
VariantProps<typeof sheetVariants> {
|
||||
setOpen: Dispatch<SetStateAction<boolean>>
|
||||
}
|
||||
|
||||
+436
-253
@@ -1,284 +1,467 @@
|
||||
// src/routes/domain.tsx (最终 Bug 修复版)
|
||||
|
||||
import { useState, useEffect } from 'react'
|
||||
import { PlusCircle, RefreshCw, MoreVertical, Trash2, Edit, CheckCircle, RefreshCcw } from 'lucide-react'
|
||||
|
||||
import {
|
||||
addDomain,
|
||||
deleteDomain,
|
||||
syncDomainWHOIS,
|
||||
updateDomain,
|
||||
useDomainList,
|
||||
verifyDomain,
|
||||
} from "@/api/domain"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { Button } from "@/components/ui/button"
|
||||
// 导入 shadcn/ui 组件
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog'
|
||||
import { Badge } from '@/components/ui/badge'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
DialogTrigger,
|
||||
} from "@/components/ui/dialog"
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
DropdownMenuItem,
|
||||
DropdownMenuTrigger,
|
||||
} from "@/components/ui/dropdown-menu"
|
||||
import { Input } from "@/components/ui/input"
|
||||
import { Label } from "@/components/ui/label"
|
||||
import { Switch } from "@/components/ui/switch"
|
||||
|
||||
import { toast } from 'sonner'
|
||||
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
// 导入 API 类型和函数
|
||||
import type { Domain, BillingDataMod } from '@/types/api'
|
||||
import { useDomainList, addDomain, verifyDomain, deleteDomain, updateDomain, syncDomainWHOIS } from '@/api/domain'
|
||||
import useSWR from 'swr'
|
||||
|
||||
import type { BillingDataMod, Domain } from "@/types/domain"
|
||||
import {
|
||||
CheckCircle,
|
||||
Edit,
|
||||
MoreVertical,
|
||||
PlusCircle,
|
||||
RefreshCcw,
|
||||
RefreshCw,
|
||||
Trash2,
|
||||
} from "lucide-react"
|
||||
import { useEffect, useState } from "react"
|
||||
import { toast } from "sonner"
|
||||
import useSWR from "swr"
|
||||
|
||||
export default function DomainPage() {
|
||||
// --- React State Hooks ---
|
||||
const [domains, setDomains] = useState<Domain[]>([])
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
// --- React State Hooks ---
|
||||
const [domains, setDomains] = useState<Domain[]>([])
|
||||
const [isLoading, setIsLoading] = useState(true)
|
||||
|
||||
const [isAddModalOpen, setIsAddModalOpen] = useState(false)
|
||||
const [newDomainName, setNewDomainName] = useState('')
|
||||
const [isAddModalOpen, setIsAddModalOpen] = useState(false)
|
||||
const [newDomainName, setNewDomainName] = useState("")
|
||||
|
||||
const [verificationToken, setVerificationToken] = useState('')
|
||||
const [isVerificationInfoModalOpen, setIsVerificationInfoModalOpen] = useState(false)
|
||||
const [verificationToken, setVerificationToken] = useState("")
|
||||
const [isVerificationInfoModalOpen, setIsVerificationInfoModalOpen] = useState(false)
|
||||
|
||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false)
|
||||
const [currentDomain, setCurrentDomain] = useState<Domain | null>(null)
|
||||
const [editFormData, setEditFormData] = useState<Partial<BillingDataMod>>({})
|
||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false)
|
||||
const [currentDomain, setCurrentDomain] = useState<Domain | null>(null)
|
||||
const [editFormData, setEditFormData] = useState<Partial<BillingDataMod>>({})
|
||||
|
||||
// --- 数据获取 (使用 SWR) ---
|
||||
const { data: domainData, error, mutate } = useSWR('/api/v1/domains', useDomainList, { revalidateOnFocus: false })
|
||||
// --- 数据获取 (使用 SWR) ---
|
||||
const {
|
||||
data: domainData,
|
||||
error,
|
||||
mutate,
|
||||
} = useSWR("/api/v1/domains", useDomainList, { revalidateOnFocus: false })
|
||||
|
||||
useEffect(() => {
|
||||
if (domainData) {
|
||||
setDomains(domainData)
|
||||
setIsLoading(false)
|
||||
useEffect(() => {
|
||||
if (domainData) {
|
||||
setDomains(domainData)
|
||||
setIsLoading(false)
|
||||
}
|
||||
if (error) {
|
||||
toast.error("无法加载域名列表,请检查后端服务是否正常。")
|
||||
setIsLoading(false)
|
||||
}
|
||||
}, [domainData, error])
|
||||
|
||||
const handleAddDomain = async () => {
|
||||
if (!newDomainName) {
|
||||
toast.error("请输入域名")
|
||||
return
|
||||
}
|
||||
try {
|
||||
const response = await addDomain(newDomainName)
|
||||
setVerificationToken(response.VerifyToken)
|
||||
setIsAddModalOpen(false)
|
||||
setIsVerificationInfoModalOpen(true)
|
||||
setNewDomainName("")
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error("添加失败", { description: (err as Error).message })
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
toast.error('无法加载域名列表,请检查后端服务是否正常。')
|
||||
setIsLoading(false)
|
||||
|
||||
const handleVerify = async (domainId: number) => {
|
||||
try {
|
||||
const response = await verifyDomain(domainId)
|
||||
if (response.success) {
|
||||
toast.success("验证成功", { description: response.message })
|
||||
} else {
|
||||
toast.warning("验证失败", { description: response.message })
|
||||
}
|
||||
setTimeout(() => mutate(), 2000)
|
||||
} catch (err) {
|
||||
toast.error("操作失败", { description: (err as Error).message })
|
||||
}
|
||||
}
|
||||
}, [domainData, error])
|
||||
|
||||
const handleAddDomain = async () => {
|
||||
if (!newDomainName) {
|
||||
toast.error('请输入域名')
|
||||
return
|
||||
const handleSyncWhois = async (domainId: number) => {
|
||||
const loadingToast = toast.loading("正在同步 Whois 信息...")
|
||||
try {
|
||||
await syncDomainWHOIS(domainId)
|
||||
toast.success("同步成功", { id: loadingToast, description: "域名 Whois 信息已更新。" })
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error("同步失败", { id: loadingToast, description: (err as Error).message })
|
||||
}
|
||||
}
|
||||
try {
|
||||
const response = await addDomain(newDomainName)
|
||||
setVerificationToken(response.VerifyToken)
|
||||
setIsAddModalOpen(false)
|
||||
setIsVerificationInfoModalOpen(true)
|
||||
setNewDomainName('')
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error('添加失败', { description: (err as Error).message })
|
||||
|
||||
const handleDelete = async (domainId: number, domainName: string) => {
|
||||
if (window.confirm(`确定要删除域名 ${domainName} 吗?`)) {
|
||||
try {
|
||||
await deleteDomain(domainId)
|
||||
toast.success("删除成功", { description: `域名 ${domainName} 已被删除。` })
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error("删除失败", { description: (err as Error).message })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleVerify = async (domainId: number) => {
|
||||
try {
|
||||
const response = await verifyDomain(domainId)
|
||||
if (response.success) {
|
||||
toast.success('验证成功', { description: response.message })
|
||||
} else {
|
||||
toast.warning('验证失败', { description: response.message })
|
||||
}
|
||||
setTimeout(() => mutate(), 2000)
|
||||
} catch (err) {
|
||||
toast.error('操作失败', { description: (err as Error).message })
|
||||
const handlePublicToggle = async (domain: Domain) => {
|
||||
try {
|
||||
await updateDomain(domain.ID, {
|
||||
is_public: !domain.IsPublic,
|
||||
billing_data: domain.BillingData as BillingDataMod,
|
||||
})
|
||||
toast.success(`域名 ${domain.Domain} 的可见状态已更新`)
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error("更新失败", { description: (err as Error).message })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleSyncWhois = async (domainId: number) => {
|
||||
const loadingToast = toast.loading('正在同步 Whois 信息...')
|
||||
try {
|
||||
await syncDomainWHOIS(domainId)
|
||||
toast.success('同步成功', { id: loadingToast, description: '域名 Whois 信息已更新。' })
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error('同步失败', { id: loadingToast, description: (err as Error).message })
|
||||
const handleEditClick = (domain: Domain) => {
|
||||
setCurrentDomain(domain)
|
||||
setEditFormData(domain.BillingData || {})
|
||||
setIsEditModalOpen(true)
|
||||
}
|
||||
}
|
||||
|
||||
const handleDelete = async (domainId: number, domainName: string) => {
|
||||
if (window.confirm(`确定要删除域名 ${domainName} 吗?`)) {
|
||||
try {
|
||||
await deleteDomain(domainId)
|
||||
toast.success('删除成功', { description: `域名 ${domainName} 已被删除。` })
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error('删除失败', { description: (err as Error).message })
|
||||
}
|
||||
const handleEditFormChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||
setEditFormData({
|
||||
...editFormData,
|
||||
[e.target.name]: e.target.value,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const handlePublicToggle = async (domain: Domain) => {
|
||||
try {
|
||||
await updateDomain(domain.ID, {
|
||||
is_public: !domain.IsPublic,
|
||||
billing_data: domain.BillingData as BillingDataMod,
|
||||
})
|
||||
toast.success(`域名 ${domain.Domain} 的可见状态已更新`)
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error('更新失败', { description: (err as Error).message })
|
||||
const handleUpdateDomain = async () => {
|
||||
if (!currentDomain) return
|
||||
try {
|
||||
const dataToSend = { ...editFormData }
|
||||
if (dataToSend.registeredDate) {
|
||||
dataToSend.registeredDate = new Date(dataToSend.registeredDate).toISOString()
|
||||
}
|
||||
if (dataToSend.endDate) {
|
||||
dataToSend.endDate = new Date(dataToSend.endDate).toISOString()
|
||||
}
|
||||
|
||||
await updateDomain(currentDomain.ID, {
|
||||
is_public: currentDomain.IsPublic,
|
||||
billing_data: dataToSend as BillingDataMod,
|
||||
})
|
||||
toast.success("更新成功", {
|
||||
description: `域名 ${currentDomain.Domain} 的配置已保存。`,
|
||||
})
|
||||
setIsEditModalOpen(false)
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error("更新失败", { description: (err as Error).message })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleEditClick = (domain: Domain) => {
|
||||
setCurrentDomain(domain)
|
||||
setEditFormData(domain.BillingData || {})
|
||||
setIsEditModalOpen(true)
|
||||
}
|
||||
|
||||
const handleEditFormChange = (e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
||||
setEditFormData({
|
||||
...editFormData,
|
||||
[e.target.name]: e.target.value,
|
||||
})
|
||||
}
|
||||
|
||||
const handleUpdateDomain = async () => {
|
||||
if (!currentDomain) return
|
||||
try {
|
||||
const dataToSend = { ...editFormData };
|
||||
if (dataToSend.registeredDate) {
|
||||
dataToSend.registeredDate = new Date(dataToSend.registeredDate).toISOString();
|
||||
}
|
||||
if (dataToSend.endDate) {
|
||||
dataToSend.endDate = new Date(dataToSend.endDate).toISOString();
|
||||
}
|
||||
|
||||
await updateDomain(currentDomain.ID, {
|
||||
is_public: currentDomain.IsPublic,
|
||||
billing_data: dataToSend as BillingDataMod
|
||||
})
|
||||
toast.success('更新成功', { description: `域名 ${currentDomain.Domain} 的配置已保存。` })
|
||||
setIsEditModalOpen(false)
|
||||
mutate()
|
||||
} catch (err) {
|
||||
toast.error('更新失败', { description: (err as Error).message })
|
||||
const getStatusVariant = (
|
||||
status: string,
|
||||
): "default" | "secondary" | "destructive" | "outline" => {
|
||||
switch (status) {
|
||||
case "verified":
|
||||
return "default"
|
||||
case "pending":
|
||||
return "secondary"
|
||||
case "expired":
|
||||
return "destructive"
|
||||
default:
|
||||
return "outline"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const getStatusVariant = (status: string): 'default' | 'secondary' | 'destructive' | 'outline' => {
|
||||
switch (status) {
|
||||
case 'verified': return 'default'
|
||||
case 'pending': return 'secondary'
|
||||
case 'expired': return 'destructive'
|
||||
default: return 'outline'
|
||||
}
|
||||
}
|
||||
// --- JSX 渲染 (保持不变) ---
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between">
|
||||
<div>
|
||||
<CardTitle>域名监控</CardTitle>
|
||||
<CardDescription>管理并监控您的域名到期状态。</CardDescription>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={() => mutate()}
|
||||
disabled={isLoading}
|
||||
>
|
||||
<RefreshCw className={`h-4 w-4 ${isLoading ? "animate-spin" : ""}`} />
|
||||
</Button>
|
||||
<Dialog open={isAddModalOpen} onOpenChange={setIsAddModalOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button>
|
||||
<PlusCircle className="mr-2 h-4 w-4" />
|
||||
添加域名
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>添加新域名</DialogTitle>
|
||||
<DialogDescription>
|
||||
输入您需要监控的域名,例如 "example.com"。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="py-4">
|
||||
<Input
|
||||
value={newDomainName}
|
||||
onChange={(e) => setNewDomainName(e.target.value)}
|
||||
placeholder="your-domain.com"
|
||||
onKeyUp={(e) => e.key === "Enter" && handleAddDomain()}
|
||||
/>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button
|
||||
variant="secondary"
|
||||
onClick={() => setIsAddModalOpen(false)}
|
||||
>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={handleAddDomain}>提交</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoading ? (
|
||||
<div className="text-center py-10 text-muted-foreground">加载中...</div>
|
||||
) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>域名</TableHead>
|
||||
<TableHead>状态</TableHead>
|
||||
<TableHead>剩余天数</TableHead>
|
||||
<TableHead>公开</TableHead>
|
||||
<TableHead className="text-right">操作</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{domains.map((domain) => (
|
||||
<TableRow key={domain.ID}>
|
||||
<TableCell className="font-medium">
|
||||
{domain.Domain}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Badge variant={getStatusVariant(domain.Status)}>
|
||||
{domain.Status}
|
||||
</Badge>
|
||||
</TableCell>
|
||||
<TableCell>{domain.expires_in_days ?? "N/A"}</TableCell>
|
||||
<TableCell>
|
||||
<Switch
|
||||
checked={domain.IsPublic}
|
||||
onCheckedChange={() => handlePublicToggle(domain)}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button variant="ghost" size="icon">
|
||||
<MoreVertical className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
{domain.Status === "pending" && (
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleVerify(domain.ID)}
|
||||
>
|
||||
<CheckCircle className="mr-2 h-4 w-4" />{" "}
|
||||
验证
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
{domain.Status === "verified" && (
|
||||
<DropdownMenuItem
|
||||
onClick={() =>
|
||||
handleSyncWhois(domain.ID)
|
||||
}
|
||||
>
|
||||
<RefreshCcw className="mr-2 h-4 w-4" />{" "}
|
||||
同步 Whois
|
||||
</DropdownMenuItem>
|
||||
)}
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleEditClick(domain)}
|
||||
>
|
||||
<Edit className="mr-2 h-4 w-4" /> 编辑
|
||||
</DropdownMenuItem>
|
||||
<DropdownMenuItem
|
||||
className="text-red-600"
|
||||
onClick={() =>
|
||||
handleDelete(domain.ID, domain.Domain)
|
||||
}
|
||||
>
|
||||
<Trash2 className="mr-2 h-4 w-4" /> 删除
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
// --- JSX 渲染 (保持不变) ---
|
||||
return (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader className="flex flex-row items-center justify-between">
|
||||
<div>
|
||||
<CardTitle>域名监控</CardTitle>
|
||||
<CardDescription>管理并监控您的域名到期状态。</CardDescription>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<Button variant="outline" size="icon" onClick={() => mutate()} disabled={isLoading}>
|
||||
<RefreshCw className={`h-4 w-4 ${isLoading ? 'animate-spin' : ''}`} />
|
||||
</Button>
|
||||
<Dialog open={isAddModalOpen} onOpenChange={setIsAddModalOpen}>
|
||||
<DialogTrigger asChild><Button><PlusCircle className="mr-2 h-4 w-4" />添加域名</Button></DialogTrigger>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>添加新域名</DialogTitle>
|
||||
<DialogDescription>输入您需要监控的域名,例如 "example.com"。</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="py-4">
|
||||
<Input value={newDomainName} onChange={(e) => setNewDomainName(e.target.value)} placeholder="your-domain.com" onKeyUp={(e) => e.key === 'Enter' && handleAddDomain()} />
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="secondary" onClick={() => setIsAddModalOpen(false)}>取消</Button>
|
||||
<Button onClick={handleAddDomain}>提交</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
{/* 验证信息弹窗 */}
|
||||
<Dialog
|
||||
open={isVerificationInfoModalOpen}
|
||||
onOpenChange={setIsVerificationInfoModalOpen}
|
||||
>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>请验证域名所有权</DialogTitle>
|
||||
<DialogDescription>
|
||||
为了开始监控,请为您的域名添加一条 DNS TXT 记录。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="py-4 space-y-2">
|
||||
<p>请将以下内容添加到您的 DNS 解析记录中:</p>
|
||||
<div className="p-2 bg-muted rounded-md text-sm">
|
||||
<p>
|
||||
<span className="font-semibold">类型:</span> TXT
|
||||
</p>
|
||||
<p>
|
||||
<span className="font-semibold">主机/名称:</span> @
|
||||
</p>
|
||||
<p className="font-semibold">记录值:</p>
|
||||
<p className="font-mono bg-background p-2 rounded">
|
||||
{verificationToken}
|
||||
</p>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
DNS
|
||||
记录生效可能需要几分钟到几小时不等。生效后,请回到域名列表点击“验证”。
|
||||
</p>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button onClick={() => setIsVerificationInfoModalOpen(false)}>
|
||||
我明白了
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoading ? ( <div className="text-center py-10 text-muted-foreground">加载中...</div> ) : (
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>域名</TableHead>
|
||||
<TableHead>状态</TableHead>
|
||||
<TableHead>剩余天数</TableHead>
|
||||
<TableHead>公开</TableHead>
|
||||
<TableHead className="text-right">操作</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{domains.map((domain) => (
|
||||
<TableRow key={domain.ID}>
|
||||
<TableCell className="font-medium">{domain.Domain}</TableCell>
|
||||
<TableCell><Badge variant={getStatusVariant(domain.Status)}>{domain.Status}</Badge></TableCell>
|
||||
<TableCell>{domain.expires_in_days ?? 'N/A'}</TableCell>
|
||||
<TableCell>
|
||||
<Switch
|
||||
checked={domain.IsPublic}
|
||||
onCheckedChange={() => handlePublicToggle(domain)}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell className="text-right">
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild><Button variant="ghost" size="icon"><MoreVertical className="h-4 w-4" /></Button></DropdownMenuTrigger>
|
||||
<DropdownMenuContent>
|
||||
{domain.Status === 'pending' && (<DropdownMenuItem onClick={() => handleVerify(domain.ID)}><CheckCircle className="mr-2 h-4 w-4" /> 验证</DropdownMenuItem>)}
|
||||
{domain.Status === 'verified' && (<DropdownMenuItem onClick={() => handleSyncWhois(domain.ID)}><RefreshCcw className="mr-2 h-4 w-4" /> 同步 Whois</DropdownMenuItem>)}
|
||||
<DropdownMenuItem onClick={() => handleEditClick(domain)}><Edit className="mr-2 h-4 w-4" /> 编辑</DropdownMenuItem>
|
||||
<DropdownMenuItem className="text-red-600" onClick={() => handleDelete(domain.ID, domain.Domain)}><Trash2 className="mr-2 h-4 w-4" /> 删除</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* 验证信息弹窗 */}
|
||||
<Dialog open={isVerificationInfoModalOpen} onOpenChange={setIsVerificationInfoModalOpen}>
|
||||
<DialogContent>
|
||||
<DialogHeader>
|
||||
<DialogTitle>请验证域名所有权</DialogTitle>
|
||||
<DialogDescription>为了开始监控,请为您的域名添加一条 DNS TXT 记录。</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="py-4 space-y-2">
|
||||
<p>请将以下内容添加到您的 DNS 解析记录中:</p>
|
||||
<div className="p-2 bg-muted rounded-md text-sm">
|
||||
<p><span className="font-semibold">类型:</span> TXT</p>
|
||||
<p><span className="font-semibold">主机/名称:</span> @</p>
|
||||
<p className="font-semibold">记录值:</p>
|
||||
<p className="font-mono bg-background p-2 rounded">{verificationToken}</p>
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">DNS 记录生效可能需要几分钟到几小时不等。生效后,请回到域名列表点击“验证”。</p>
|
||||
</div>
|
||||
<DialogFooter><Button onClick={() => setIsVerificationInfoModalOpen(false)}>我明白了</Button></DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
|
||||
{/* 编辑弹窗 */}
|
||||
<Dialog open={isEditModalOpen} onOpenChange={setIsEditModalOpen}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>编辑域名信息</DialogTitle>
|
||||
<DialogDescription>为 <span className="font-mono">{currentDomain?.Domain}</span> 添加或修改详细信息。</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-4 py-4">
|
||||
<div className="grid grid-cols-4 items-center gap-4"><Label htmlFor="registrar" className="text-right">注册商</Label><Input id="registrar" name="registrar" value={editFormData.registrar || ''} onChange={handleEditFormChange} className="col-span-3" /></div>
|
||||
<div className="grid grid-cols-4 items-center gap-4"><Label htmlFor="registeredDate" className="text-right">注册日期</Label><Input id="registeredDate" name="registeredDate" type="date" value={editFormData.registeredDate?.split('T')[0] || ''} onChange={handleEditFormChange} className="col-span-3" /></div>
|
||||
<div className="grid grid-cols-4 items-center gap-4"><Label htmlFor="endDate" className="text-right">到期日期</Label><Input id="endDate" name="endDate" type="date" value={editFormData.endDate?.split('T')[0] || ''} onChange={handleEditFormChange} className="col-span-3" /></div>
|
||||
<div className="grid grid-cols-4 items-center gap-4"><Label htmlFor="renewalPrice" className="text-right">续费价格</Label><Input id="renewalPrice" name="renewalPrice" value={editFormData.renewalPrice || ''} onChange={handleEditFormChange} className="col-span-3" /></div>
|
||||
<div className="grid grid-cols-4 items-center gap-4"><Label htmlFor="notes" className="text-right">备注</Label><Textarea id="notes" name="notes" value={editFormData.notes || ''} onChange={handleEditFormChange} className="col-span-3" /></div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="secondary" onClick={() => setIsEditModalOpen(false)}>取消</Button>
|
||||
<Button onClick={handleUpdateDomain}>保存</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
)
|
||||
{/* 编辑弹窗 */}
|
||||
<Dialog open={isEditModalOpen} onOpenChange={setIsEditModalOpen}>
|
||||
<DialogContent className="sm:max-w-[425px]">
|
||||
<DialogHeader>
|
||||
<DialogTitle>编辑域名信息</DialogTitle>
|
||||
<DialogDescription>
|
||||
为 <span className="font-mono">{currentDomain?.Domain}</span>{" "}
|
||||
添加或修改详细信息。
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<div className="grid gap-4 py-4">
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<Label htmlFor="registrar" className="text-right">
|
||||
注册商
|
||||
</Label>
|
||||
<Input
|
||||
id="registrar"
|
||||
name="registrar"
|
||||
value={editFormData.registrar || ""}
|
||||
onChange={handleEditFormChange}
|
||||
className="col-span-3"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<Label htmlFor="registeredDate" className="text-right">
|
||||
注册日期
|
||||
</Label>
|
||||
<Input
|
||||
id="registeredDate"
|
||||
name="registeredDate"
|
||||
type="date"
|
||||
value={editFormData.registeredDate?.split("T")[0] || ""}
|
||||
onChange={handleEditFormChange}
|
||||
className="col-span-3"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<Label htmlFor="endDate" className="text-right">
|
||||
到期日期
|
||||
</Label>
|
||||
<Input
|
||||
id="endDate"
|
||||
name="endDate"
|
||||
type="date"
|
||||
value={editFormData.endDate?.split("T")[0] || ""}
|
||||
onChange={handleEditFormChange}
|
||||
className="col-span-3"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<Label htmlFor="renewalPrice" className="text-right">
|
||||
续费价格
|
||||
</Label>
|
||||
<Input
|
||||
id="renewalPrice"
|
||||
name="renewalPrice"
|
||||
value={editFormData.renewalPrice || ""}
|
||||
onChange={handleEditFormChange}
|
||||
className="col-span-3"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid grid-cols-4 items-center gap-4">
|
||||
<Label htmlFor="notes" className="text-right">
|
||||
备注
|
||||
</Label>
|
||||
<Textarea
|
||||
id="notes"
|
||||
name="notes"
|
||||
value={editFormData.notes || ""}
|
||||
onChange={handleEditFormChange}
|
||||
className="col-span-3"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<DialogFooter>
|
||||
<Button variant="secondary" onClick={() => setIsEditModalOpen(false)}>
|
||||
取消
|
||||
</Button>
|
||||
<Button onClick={handleUpdateDomain}>保存</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</>
|
||||
)
|
||||
}
|
||||
@@ -212,7 +212,9 @@ export default function ServerPage() {
|
||||
})
|
||||
}}
|
||||
/>
|
||||
<BatchMoveServerIcon serverIds={selectedRows.map((r) => r.original.id) as number[]} />
|
||||
<BatchMoveServerIcon
|
||||
serverIds={selectedRows.map((r) => r.original.id) as number[]}
|
||||
/>
|
||||
<ServerConfigCardBatch
|
||||
sid={selectedRows.map((r) => r.original.id) as number[]}
|
||||
className="shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] bg-yellow-600 text-white hover:bg-yellow-500 dark:hover:bg-yellow-700 rounded-lg"
|
||||
|
||||
+23
-7
@@ -3,6 +3,7 @@ import { SettingsTab } from "@/components/settings-tab"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Card, CardContent } from "@/components/ui/card"
|
||||
import { Checkbox } from "@/components/ui/checkbox"
|
||||
import { Combobox } from "@/components/ui/combobox"
|
||||
import {
|
||||
Form,
|
||||
FormControl,
|
||||
@@ -21,9 +22,8 @@ import {
|
||||
SelectValue,
|
||||
} from "@/components/ui/select"
|
||||
import { Textarea } from "@/components/ui/textarea"
|
||||
import { Combobox } from "@/components/ui/combobox"
|
||||
import { useNotification } from "@/hooks/useNotfication"
|
||||
import { useAuth } from "@/hooks/useAuth"
|
||||
import { useNotification } from "@/hooks/useNotfication"
|
||||
import useSetting from "@/hooks/useSetting"
|
||||
import { asOptionalField } from "@/lib/utils"
|
||||
import { nezhaLang, settingCoverageTypes } from "@/types"
|
||||
@@ -151,7 +151,11 @@ export default function SettingsPage() {
|
||||
<FormItem>
|
||||
<FormLabel>Expiry Notification Group ID</FormLabel>
|
||||
<FormControl>
|
||||
<Input type="number" placeholder="Enter Group ID" {...field} />
|
||||
<Input
|
||||
type="number"
|
||||
placeholder="Enter Group ID"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -177,7 +181,10 @@ export default function SettingsPage() {
|
||||
<FormItem>
|
||||
<FormLabel>Custom Logo URL</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="https://example.com/logo.png" {...field} />
|
||||
<Input
|
||||
placeholder="https://example.com/logo.png"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -203,7 +210,10 @@ export default function SettingsPage() {
|
||||
<FormItem>
|
||||
<FormLabel>Custom Links (JSON Array)</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder='[{"link":"https://loohui.com/","name":"Blog","blank":false}]' {...field} />
|
||||
<Input
|
||||
placeholder='[{"link":"https://loohui.com/","name":"Blog","blank":false}]'
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -216,7 +226,10 @@ export default function SettingsPage() {
|
||||
<FormItem>
|
||||
<FormLabel>Background Image (Day)</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="https://example.com/day.jpg" {...field} />
|
||||
<Input
|
||||
placeholder="https://example.com/day.jpg"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
@@ -229,7 +242,10 @@ export default function SettingsPage() {
|
||||
<FormItem>
|
||||
<FormLabel>Background Image (Night)</FormLabel>
|
||||
<FormControl>
|
||||
<Input placeholder="https://example.com/night.jpg" {...field} />
|
||||
<Input
|
||||
placeholder="https://example.com/night.jpg"
|
||||
{...field}
|
||||
/>
|
||||
</FormControl>
|
||||
<FormMessage />
|
||||
</FormItem>
|
||||
|
||||
+531
-531
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
||||
export interface BillingDataMod {
|
||||
registrar?: string;
|
||||
registeredDate?: string;
|
||||
endDate?: string;
|
||||
renewalPrice?: string;
|
||||
autoRenewal?: string;
|
||||
notes?: string;
|
||||
cycle?: string;
|
||||
amount?: string;
|
||||
}
|
||||
|
||||
export interface Domain {
|
||||
ID: number;
|
||||
Domain: string;
|
||||
Status: string;
|
||||
VerifyToken: string;
|
||||
IsPublic: boolean;
|
||||
BillingData: BillingDataMod | null;
|
||||
expires_in_days?: number;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
IPReportPeriod int `json:"ip_report_period"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
jsonData := `{"ip_report_period":30, "unknown_field": 123}`
|
||||
var c Config
|
||||
|
||||
dec := json.NewDecoder(strings.NewReader(jsonData))
|
||||
dec.DisallowUnknownFields()
|
||||
err := dec.Decode(&c)
|
||||
if err != nil {
|
||||
fmt.Println("Error:", err)
|
||||
} else {
|
||||
fmt.Println("Success")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user