mirror of
https://github.com/Buriburizaem0n/admin-frontend-domain.git
synced 2026-05-06 05:38:51 +00:00
feat: add Sync WHOIS button and API integration
This commit is contained in:
@@ -36,4 +36,9 @@ export const deleteDomain = (id: number) => {
|
|||||||
// 更新一个域名(包括公开状态和配置信息)
|
// 更新一个域名(包括公开状态和配置信息)
|
||||||
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)
|
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`)
|
||||||
}
|
}
|
||||||
+14
-2
@@ -1,7 +1,7 @@
|
|||||||
// src/routes/domain.tsx (最终 Bug 修复版)
|
// src/routes/domain.tsx (最终 Bug 修复版)
|
||||||
|
|
||||||
import { useState, useEffect } from 'react'
|
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 组件
|
// 导入 shadcn/ui 组件
|
||||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||||||
@@ -19,7 +19,7 @@ import { toast } from 'sonner'
|
|||||||
|
|
||||||
// 导入 API 类型和函数
|
// 导入 API 类型和函数
|
||||||
import type { Domain, BillingDataMod } from '@/types/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'
|
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) => {
|
const handleDelete = async (domainId: number, domainName: string) => {
|
||||||
if (window.confirm(`确定要删除域名 ${domainName} 吗?`)) {
|
if (window.confirm(`确定要删除域名 ${domainName} 吗?`)) {
|
||||||
try {
|
try {
|
||||||
@@ -213,6 +224,7 @@ export default function DomainPage() {
|
|||||||
<DropdownMenuTrigger asChild><Button variant="ghost" size="icon"><MoreVertical className="h-4 w-4" /></Button></DropdownMenuTrigger>
|
<DropdownMenuTrigger asChild><Button variant="ghost" size="icon"><MoreVertical className="h-4 w-4" /></Button></DropdownMenuTrigger>
|
||||||
<DropdownMenuContent>
|
<DropdownMenuContent>
|
||||||
{domain.Status === 'pending' && (<DropdownMenuItem onClick={() => handleVerify(domain.ID)}><CheckCircle className="mr-2 h-4 w-4" /> 验证</DropdownMenuItem>)}
|
{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 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>
|
<DropdownMenuItem className="text-red-600" onClick={() => handleDelete(domain.ID, domain.Domain)}><Trash2 className="mr-2 h-4 w-4" /> 删除</DropdownMenuItem>
|
||||||
</DropdownMenuContent>
|
</DropdownMenuContent>
|
||||||
|
|||||||
Reference in New Issue
Block a user