'use client'; import Link from 'next/link'; import { useMemo, useState } from 'react'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { MapPin, Plus, RefreshCw, Trash2 } from 'lucide-react'; import { toast } from 'sonner'; import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, } from '@/components/ui/alert-dialog'; import { EmptyStateWithBorder } from '@/components/layout/empty'; import { ErrorInline } from '@/components/layout/error'; import { LoadingStateWithBorder } from '@/components/layout/loading'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { type OriginItem, OriginService } from '@/lib/services/openflare'; import { formatDateTime } from '@/lib/utils'; import { OriginEditorDialog } from './components/origin-editor-dialog'; const originsQueryKey = ['openflare', 'origins'] as const; export default function OriginsPage() { const queryClient = useQueryClient(); const [editorOpen, setEditorOpen] = useState(false); const [editingOrigin, setEditingOrigin] = useState(null); const [deleteTarget, setDeleteTarget] = useState(null); const originsQuery = useQuery({ queryKey: originsQueryKey, queryFn: () => OriginService.list(), }); const origins = useMemo(() => originsQuery.data ?? [], [originsQuery.data]); const deleteMutation = useMutation({ mutationFn: (id: number) => OriginService.deleteById(id), onSuccess: async () => { toast.success('源站已删除'); setDeleteTarget(null); await queryClient.invalidateQueries({ queryKey: originsQueryKey }); }, onError: (error) => { toast.error(error instanceof Error ? error.message : '删除失败'); }, }); return (

源站

集中维护规则复用的源站地址,减少批量改地址时的重复操作。

{originsQuery.isError ? ( void originsQuery.refetch()} /> ) : null}
{originsQuery.isLoading ? ( ) : origins.length === 0 ? ( ) : (
{origins.map((origin) => (

{origin.name}

0 ? 'text-emerald-600 border-emerald-500/20' : 'text-amber-600 border-amber-500/20' }`} > {origin.route_count} 条规则

{origin.address}

{origin.remark || '暂无备注'}

最后更新:{formatDateTime(origin.updated_at)}

))}
)}
{ if (!open) setDeleteTarget(null); }} > 删除源站 确认删除源站 {deleteTarget?.name} 吗? 取消 { if (deleteTarget) deleteMutation.mutate(deleteTarget.id); }} > 确认删除
); }