diff --git a/src/api/domain.ts b/src/api/domain.ts index 7d83cea..b3a0cbb 100644 --- a/src/api/domain.ts +++ b/src/api/domain.ts @@ -36,4 +36,9 @@ export const deleteDomain = (id: number) => { // 更新一个域名(包括公开状态和配置信息) export const updateDomain = (id: number, data: { is_public: boolean, billing_data: BillingDataMod }) => { return fetcher(FetcherMethod.PUT, `/api/v1/domains/${id}`, data) +} + +// 同步 Whois 信息 +export const syncDomainWHOIS = (id: number) => { + return fetcher(FetcherMethod.POST, `/api/v1/domains/${id}/sync`) } \ No newline at end of file diff --git a/src/routes/domain.tsx b/src/routes/domain.tsx index 43cfbf2..48bf184 100644 --- a/src/routes/domain.tsx +++ b/src/routes/domain.tsx @@ -1,7 +1,7 @@ // src/routes/domain.tsx (最终 Bug 修复版) import { useState, useEffect } from 'react' -import { PlusCircle, RefreshCw, MoreVertical, Trash2, Edit, CheckCircle } from 'lucide-react' +import { PlusCircle, RefreshCw, MoreVertical, Trash2, Edit, CheckCircle, RefreshCcw } from 'lucide-react' // 导入 shadcn/ui 组件 import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' @@ -19,7 +19,7 @@ import { toast } from 'sonner' // 导入 API 类型和函数 import type { Domain, BillingDataMod } from '@/types/api' -import { useDomainList, addDomain, verifyDomain, deleteDomain, updateDomain } from '@/api/domain' +import { useDomainList, addDomain, verifyDomain, deleteDomain, updateDomain, syncDomainWHOIS } from '@/api/domain' import useSWR from 'swr' @@ -83,6 +83,17 @@ export default function DomainPage() { } } + 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 handleDelete = async (domainId: number, domainName: string) => { if (window.confirm(`确定要删除域名 ${domainName} 吗?`)) { try { @@ -213,6 +224,7 @@ export default function DomainPage() { {domain.Status === 'pending' && ( handleVerify(domain.ID)}> 验证)} + {domain.Status === 'verified' && ( handleSyncWhois(domain.ID)}> 同步 Whois)} handleEditClick(domain)}> 编辑 handleDelete(domain.ID, domain.Domain)}> 删除