diff --git a/components/accounts-manager.tsx b/components/accounts-manager.tsx index 4cafab4..11cafb1 100644 --- a/components/accounts-manager.tsx +++ b/components/accounts-manager.tsx @@ -2,8 +2,11 @@ import { useState } from 'react'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; +import { Button } from '@/components/ui/button'; +import { RefreshCw } from 'lucide-react'; import { Account } from '@/lib/types'; import { useAccounts } from '@/lib/hooks/use-accounts'; +import { useConfirmDialog } from '@/components/ui/confirm-dialog'; // 组件导入 import { StatsCards } from './accounts/stats-cards'; @@ -14,6 +17,8 @@ import { AccountTable } from './accounts/account-table'; import { AccountDetails } from './accounts/account-details'; export function AccountsManager() { + const { showConfirm, ConfirmDialogComponent } = useConfirmDialog(); + const { accounts, stats, @@ -34,6 +39,11 @@ export function AccountsManager() { setSelectedIds } = useAccounts(); + // 全局刷新函数 + const handleGlobalRefresh = async () => { + await Promise.all([fetchAccounts(), fetchStats()]); + }; + // 账户详情状态 const [detailsDialog, setDetailsDialog] = useState(false); const [detailsMode, setDetailsMode] = useState<'view' | 'edit'>('view'); @@ -55,16 +65,23 @@ export function AccountsManager() { // 处理删除单个账户 const handleDeleteAccount = async (account: Account) => { - if (!confirm('确认删除此账户?')) return; - - try { - // 设置选中的账户ID - setSelectedIds([account.id]); - // 执行删除 - await handleBatchDelete(); - } catch (error) { - console.error('Failed to delete account:', error); - } + showConfirm({ + title: '确认删除', + description: `确认删除账户 "${account.customId}"?此操作不可撤销。`, + confirmText: '确认删除', + cancelText: '取消', + variant: 'destructive', + onConfirm: async () => { + try { + // 设置选中的账户ID + setSelectedIds([account.id]); + // 执行删除 + await handleBatchDelete(); + } catch (error) { + console.error('Failed to delete account:', error); + } + } + }); }; // 处理保存编辑 @@ -114,7 +131,18 @@ export function AccountsManager() {
轻量化账户管理平台
-+ 可用: {stats.statusSummary.available || 0} | + 已导出: {stats.statusSummary.exported || 0} +
已锁定: {stats.statusSummary.locked || 0} |
已封禁: {stats.statusSummary.banned || 0}
diff --git a/components/ui/confirm-dialog.tsx b/components/ui/confirm-dialog.tsx
new file mode 100644
index 0000000..5909da7
--- /dev/null
+++ b/components/ui/confirm-dialog.tsx
@@ -0,0 +1,127 @@
+"use client";
+
+import { useState, useEffect } from 'react';
+import { Button } from '@/components/ui/button';
+import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog';
+import { AlertTriangle } from 'lucide-react';
+
+interface ConfirmDialogProps {
+ open: boolean;
+ onOpenChange: (open: boolean) => void;
+ title: string;
+ description: string;
+ confirmText?: string;
+ cancelText?: string;
+ variant?: 'default' | 'destructive';
+ onConfirm: () => void;
+ onCancel?: () => void;
+}
+
+export function ConfirmDialog({
+ open,
+ onOpenChange,
+ title,
+ description,
+ confirmText = '确认',
+ cancelText = '取消',
+ variant = 'default',
+ onConfirm,
+ onCancel
+}: ConfirmDialogProps) {
+ const handleConfirm = () => {
+ onConfirm();
+ onOpenChange(false);
+ };
+
+ const handleCancel = () => {
+ onCancel?.();
+ onOpenChange(false);
+ };
+
+ return (
+
+ );
+}
+
+// Hook for easier usage
+export function useConfirmDialog() {
+ const [confirmDialog, setConfirmDialog] = useState<{
+ open: boolean;
+ title: string;
+ description: string;
+ confirmText?: string;
+ cancelText?: string;
+ variant?: 'default' | 'destructive';
+ onConfirm: () => void;
+ onCancel?: () => void;
+ }>({
+ open: false,
+ title: '',
+ description: '',
+ onConfirm: () => {}
+ });
+
+ const showConfirm = (options: {
+ title: string;
+ description: string;
+ confirmText?: string;
+ cancelText?: string;
+ variant?: 'default' | 'destructive';
+ onConfirm: () => void;
+ onCancel?: () => void;
+ }) => {
+ setConfirmDialog({
+ ...options,
+ open: true
+ });
+ };
+
+ const hideConfirm = () => {
+ setConfirmDialog(prev => ({ ...prev, open: false }));
+ };
+
+ const ConfirmDialogComponent = () => (
+