Explorar el Código

refactor: componentize admin, slots, and payment pages into dedicated components

jerry hace 2 meses
padre
commit
7bf7f4ed25

+ 2 - 1
.gitignore

@@ -1,2 +1,3 @@
 node_modules
-.next
+.next
+*.tsbuildinfo

+ 42 - 305
src/app/admin/accounts/page.tsx

@@ -1,44 +1,17 @@
 'use client';
 
 import { useState, useEffect } from 'react';
-import { Plus, Search, RefreshCw, X, Lock, User, Pencil } from 'lucide-react';
+import { Plus, Search, RefreshCw } from 'lucide-react';
 import api from '@/lib/api';
 import { toast } from 'react-hot-toast';
 
-// 引入拆分后的组件
 import AccountTable from '@/components/admin/accounts/AccountTable';
+import AccountAddModal from '@/components/admin/accounts/AccountAddModal';
+import AccountEditModal from '@/components/admin/accounts/AccountEditModal';
+import AccountLockModal from '@/components/admin/accounts/AccountLockModal';
+import AccountRegistrationModal from '@/components/admin/accounts/AccountRegistrationModal';
 import Pagination from '@/components/common/Pagination';
-import LocalTime from '@/components/common/LocalTime';
-import { Account, AccountStatus } from '@/types';
-
-const DEFAULT_EXTRA_DATA = '{}';
-
-function parseUtcDateTime(value?: string | null) {
-  if (!value) return null;
-  const normalized = value.trim().replace(' ', 'T');
-  const hasTimezone = /[zZ]|[+-]\d{2}:\d{2}$/.test(normalized);
-  const utcValue = hasTimezone ? normalized : `${normalized}Z`;
-  const timestamp = new Date(utcValue).getTime();
-
-  return Number.isNaN(timestamp) ? null : timestamp;
-}
-
-function toDatetimeLocalValue(value?: string | null) {
-  if (!value) return '';
-  const timestamp = parseUtcDateTime(value);
-  if (timestamp === null) return '';
-  const date = new Date(timestamp);
-  const offset = date.getTimezoneOffset();
-  const localDate = new Date(date.getTime() - offset * 60 * 1000);
-  return localDate.toISOString().slice(0, 16);
-}
-
-function toApiDateTime(value: string) {
-  if (!value) return null;
-  const date = new Date(value);
-  if (Number.isNaN(date.getTime())) return null;
-  return date.toISOString();
-}
+import { Account } from '@/types';
 
 export default function AdminAccountsPage() {
   // === 1. 状态定义 ===
@@ -46,7 +19,7 @@ export default function AdminAccountsPage() {
   const [data, setData] = useState<Account[]>([]);
   
   // 分页与搜索
-  const [page, setPage] = useState(1); // 1-based UI
+  const [page, setPage] = useState(1);
   const [pageSize] = useState(10);
   const [total, setTotal] = useState(0);
   const [keyword, setKeyword] = useState('');
@@ -58,24 +31,6 @@ export default function AdminAccountsPage() {
   const [showEditModal, setShowEditModal] = useState(false);
   const [selectedAccount, setSelectedAccount] = useState<Account | null>(null);
 
-  // 表单状态
-  const [addForm, setAddForm] = useState({
-    pool_name: '',
-    username: '',
-    password: '',
-    extra_data_str: DEFAULT_EXTRA_DATA,
-    status: 'active' as AccountStatus
-  });
-  const [lockDuration, setLockDuration] = useState<number>(3600);
-  const [editForm, setEditForm] = useState({
-    pool_name: '',
-    username: '',
-    password: '',
-    extra_data_str: DEFAULT_EXTRA_DATA,
-    status: 'active' as AccountStatus,
-    next_use_time: ''
-  });
-
   // === 2. 数据获取 ===
   const fetchAccounts = async (targetPage: number = page) => {
     setLoading(true);
@@ -84,8 +39,8 @@ export default function AdminAccountsPage() {
         params: {
           page: targetPage,
           size: pageSize,
-          keyword: keyword
-        }
+          keyword: keyword,
+        },
       });
 
       const resData = res.data?.data || {};
@@ -99,13 +54,11 @@ export default function AdminAccountsPage() {
       
       setPage(targetPage);
 
-      // 翻页滚动优化
       if (targetPage > 1) {
         window.scrollTo({ top: 0, behavior: 'smooth' });
       }
-
     } catch (error) {
-      console.error("Fetch accounts failed", error);
+      console.error('Fetch accounts failed', error);
       toast.error('获取列表失败');
       setData([]);
     } finally {
@@ -124,91 +77,25 @@ export default function AdminAccountsPage() {
     if (e.key === 'Enter') handleSearch();
   };
 
-  // === 3. 业务逻辑 ===
-  const handleAddAccount = async () => {
-    try {
-      let extraDataJson: Record<string, any> | null = null;
-      try {
-        extraDataJson = addForm.extra_data_str.trim() ? JSON.parse(addForm.extra_data_str) : null;
-      } catch {
-        toast.error('Extra Data 必须是 JSON 格式');
-        return;
-      }
-      await api.post('/api/account/add', {
-        pool_name: addForm.pool_name,
-        username: addForm.username,
-        password: addForm.password || null,
-        extra_data: extraDataJson,
-        status: addForm.status || null
-      });
-      toast.success('添加成功');
-      setShowAddModal(false);
-      setAddForm({
-        pool_name: '',
-        username: '',
-        password: '',
-        extra_data_str: DEFAULT_EXTRA_DATA,
-        status: 'active'
-      });
-      fetchAccounts(1);
-    } catch (error) {
-      toast.error('添加失败');
-    }
-  };
-
+  // === 3. 业务操作 ===
   const handleEditClick = (account: Account) => {
     setSelectedAccount(account);
-    setEditForm({
-      pool_name: account.pool_name || '',
-      username: account.username || '',
-      password: account.password || '',
-      extra_data_str: JSON.stringify(account.extra_data || {}, null, 2),
-      status: (account.status?.toLowerCase() === 'disable' ? 'disable' : 'active') as AccountStatus,
-      next_use_time: toDatetimeLocalValue(account.next_use_time)
-    });
     setShowEditModal(true);
   };
 
-  const handleEditAccount = async () => {
-    if (!selectedAccount) return;
+  const handleLockClick = async (account: Account, unlock: boolean, duration: number) => {
     try {
-      let extraDataJson: Record<string, any> | null = null;
-      try {
-        extraDataJson = editForm.extra_data_str.trim() ? JSON.parse(editForm.extra_data_str) : null;
-      } catch {
-        toast.error('Extra Data 必须是 JSON 格式');
-        return;
-      }
+      const nextUseTime = unlock ? null : new Date(Date.now() + Number(duration) * 1000).toISOString();
       await api.put('/api/account/update', {
-        pool_name: editForm.pool_name || null,
-        username: editForm.username || null,
-        password: editForm.password || null,
-        extra_data: extraDataJson,
-        status: editForm.status || null,
-        next_use_time: toApiDateTime(editForm.next_use_time)
+        next_use_time: nextUseTime,
       }, {
-        params: { account_id: selectedAccount.id }
-      });
-      toast.success('修改成功');
-      setShowEditModal(false);
-      fetchAccounts(page);
-    } catch (error) {
-      toast.error('修改失败');
-    }
-  };
-
-  const handleLockClick = async (account: Account, unlock: boolean) => {
-    try {
-      const nextUseTime = unlock ? null : new Date(Date.now() + Number(lockDuration) * 1000).toISOString();
-      await api.put('/api/account/update', {
-        next_use_time: nextUseTime
-      }, {
-        params: { account_id: account.id }
+        params: { account_id: account.id },
       });
       toast.success(unlock ? '解锁成功' : '锁定成功');
       fetchAccounts(page);
     } catch (error) {
       toast.error(unlock ? '解锁失败' : '锁定失败');
+      throw error;
     }
   };
 
@@ -216,7 +103,7 @@ export default function AdminAccountsPage() {
     if (!confirm(`确定要删除账号 ${account.username} 吗?此操作不可恢复。`)) return;
     try {
       await api.delete('/api/account/delete', {
-        params: { account_id: account.id }
+        params: { account_id: account.id },
       });
       toast.success('删除成功');
       const nextPage = data.length === 1 && page > 1 ? page - 1 : page;
@@ -228,7 +115,6 @@ export default function AdminAccountsPage() {
 
   return (
     <div className="p-4 md:p-6 space-y-6">
-      
       {/* === 头部区域 === */}
       <div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
         <div>
@@ -244,7 +130,7 @@ export default function AdminAccountsPage() {
               placeholder="搜索账号 / Pool..." 
               className="w-full pl-9 pr-4 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none transition shadow-sm"
               value={keyword}
-              onChange={e => setKeyword(e.target.value)}
+              onChange={(e) => setKeyword(e.target.value)}
               onKeyDown={handleKeyDown}
             />
             <Search size={16} className="absolute left-3 top-2.5 text-gray-400" />
@@ -286,185 +172,36 @@ export default function AdminAccountsPage() {
           currentPage={page}
           total={total}
           pageSize={pageSize}
-          onPageChange={fetchAccounts} // 传递函数,分页组件点击时回调
+          onPageChange={fetchAccounts}
         />
       </div>
 
-      {/* === Modals === */}
-      {/* 新增 Modal */}
-      {showAddModal && (
-        <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
-          <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
-            <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-slate-50/50">
-              <h3 className="font-bold text-lg text-slate-800">新增账号</h3>
-              <button onClick={() => setShowAddModal(false)} className="text-slate-400 hover:text-slate-600">
-                <X size={20} />
-              </button>
-            </div>
-            <div className="p-6 space-y-4 max-h-[80vh] overflow-y-auto">
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Pool Name</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={addForm.pool_name} onChange={e => setAddForm({...addForm, pool_name: e.target.value})} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Username</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={addForm.username} onChange={e => setAddForm({...addForm, username: e.target.value})} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Password</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={addForm.password} onChange={e => setAddForm({...addForm, password: e.target.value})} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Status</label>
-                <select className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white" value={addForm.status} onChange={e => setAddForm({...addForm, status: e.target.value as AccountStatus})}>
-                  <option value="active">active</option>
-                  <option value="disable">disable</option>
-                </select>
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Extra Data (JSON)</label>
-                <textarea className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none font-mono text-xs bg-slate-50" rows={4} value={addForm.extra_data_str} onChange={e => setAddForm({...addForm, extra_data_str: e.target.value})} placeholder='{"country": "fr"}' />
-              </div>
-            </div>
-            <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
-              <button onClick={() => setShowAddModal(false)} className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg">取消</button>
-              <button onClick={handleAddAccount} className="px-4 py-2 text-sm font-bold bg-slate-900 text-white rounded-lg hover:bg-slate-800">确认添加</button>
-            </div>
-          </div>
-        </div>
-      )}
+      {/* === 弹窗组件 === */}
+      <AccountAddModal
+        isOpen={showAddModal}
+        onClose={() => setShowAddModal(false)}
+        onSuccess={() => fetchAccounts(1)}
+      />
 
-{/* 锁定 Modal */}
-      {showLockModal && selectedAccount && (
-        <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
-          <div className="bg-white rounded-xl shadow-2xl w-full max-w-sm overflow-hidden">
-             <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-orange-50/50">
-              <h3 className="font-bold text-lg text-orange-900 flex items-center gap-2">
-                <Lock size={18} /> 锁定账号
-              </h3>
-              <button onClick={() => setShowLockModal(false)} className="text-slate-400 hover:text-slate-600">
-                <X size={20} />
-              </button>
-            </div>
-            <div className="p-6 space-y-4">
-              <p className="text-sm text-slate-600 bg-orange-50 p-3 rounded-lg border border-orange-100">
-                账号: <span className="font-bold text-slate-900">{selectedAccount.username}</span>
-              </p>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">持续时间 (秒)</label>
-                <input type="number" min="0" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-orange-500 outline-none font-mono" value={lockDuration} onChange={e => setLockDuration(Number(e.target.value))} />
-                <div className="flex gap-2 mt-2">
-                   <button onClick={() => setLockDuration(3600)} className="flex-1 text-xs bg-slate-100 border px-2 py-1 rounded hover:bg-slate-200">1小时</button>
-                   <button onClick={() => setLockDuration(86400)} className="flex-1 text-xs bg-slate-100 border px-2 py-1 rounded hover:bg-slate-200">1天</button>
-                </div>
-              </div>
-            </div>
-            <div className="px-6 py-4 bg-slate-50 flex justify-between gap-3 border-t">
-              <button onClick={async () => { await handleLockClick(selectedAccount, true); setShowLockModal(false); }} className="px-4 py-2 text-sm text-green-600 hover:bg-green-100 rounded-lg">
-                直接解锁
-              </button>
-              <div className="flex gap-3 ml-auto">
-                <button onClick={() => setShowLockModal(false)} className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg">取消</button>
-                <button onClick={async () => { await handleLockClick(selectedAccount, false); setShowLockModal(false); }} className="px-4 py-2 text-sm font-bold bg-orange-600 text-white rounded-lg hover:bg-orange-700">确认锁定</button>
-              </div>
-            </div>
-          </div>
-        </div>
-      )}
+      <AccountLockModal
+        isOpen={showLockModal}
+        onClose={() => setShowLockModal(false)}
+        account={selectedAccount}
+        onLock={handleLockClick}
+      />
 
-      {/* 注册信息 Modal */}
-      {showRegistrationModal && selectedAccount && (
-        <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
-          <div className="bg-white rounded-xl shadow-2xl w-full max-w-lg overflow-hidden">
-             <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-blue-50/50">
-              <h3 className="font-bold text-lg text-blue-900 flex items-center gap-2">
-                <User size={18} /> 注册信息
-              </h3>
-              <button onClick={() => setShowRegistrationModal(false)} className="text-slate-400 hover:text-slate-600">
-                <X size={20} />
-              </button>
-            </div>
-            <div className="p-6 space-y-4">
-              <p className="text-sm text-slate-600 bg-blue-50 p-3 rounded-lg border border-blue-100">
-                账号: <span className="font-bold text-slate-900">{selectedAccount.username}</span>
-              </p>
-              <div className="bg-slate-50 p-4 rounded-lg border border-slate-200">
-                <pre className="text-xs font-mono text-slate-700 whitespace-pre-wrap overflow-x-auto">
-                  {JSON.stringify(selectedAccount.extra_data || {}, null, 2)}
-                </pre>
-              </div>
-            </div>
-            <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
-              <button onClick={() => setShowRegistrationModal(false)} className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg">关闭</button>
-            </div>
-          </div>
-        </div>
-      )}
+      <AccountRegistrationModal
+        isOpen={showRegistrationModal}
+        onClose={() => setShowRegistrationModal(false)}
+        account={selectedAccount}
+      />
 
-      {/* 编辑账号 Modal */}
-      {showEditModal && selectedAccount && (
-        <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
-          <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
-             <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-blue-50/50">
-              <h3 className="font-bold text-lg text-blue-900 flex items-center gap-2">
-                <Pencil size={18} /> 编辑账号
-              </h3>
-              <button onClick={() => setShowEditModal(false)} className="text-slate-400 hover:text-slate-600">
-                <X size={20} />
-              </button>
-            </div>
-            <div className="p-6 space-y-4 max-h-[80vh] overflow-y-auto">
-              <div className="text-sm text-slate-600 bg-blue-50 p-3 rounded-lg border border-blue-100">
-                ID: <span className="font-bold text-slate-900">#{selectedAccount.id}</span>
-                <br />
-                Created:{' '}
-                <span className="font-bold text-slate-900">
-                  {selectedAccount.created_at ? <LocalTime date={selectedAccount.created_at} /> : '-'}
-                </span>
-                <br />
-                Updated:{' '}
-                <span className="font-bold text-slate-900">
-                  {selectedAccount.updated_at ? <LocalTime date={selectedAccount.updated_at} /> : '-'}
-                </span>
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Pool Name</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={editForm.pool_name} onChange={e => setEditForm({...editForm, pool_name: e.target.value})} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Username</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={editForm.username} onChange={e => setEditForm({...editForm, username: e.target.value})} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Password</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm font-mono" value={editForm.password} onChange={e => setEditForm({...editForm, password: e.target.value})} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Status</label>
-                <select className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white" value={editForm.status} onChange={e => setEditForm({...editForm, status: e.target.value as AccountStatus})}>
-                  <option value="active">active</option>
-                  <option value="disable">disable</option>
-                </select>
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Next Use Time</label>
-                <input type="datetime-local" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={editForm.next_use_time} onChange={e => setEditForm({...editForm, next_use_time: e.target.value})} />
-                <p className="mt-1 text-xs text-slate-500">
-                  {selectedAccount.next_use_time ? <LocalTime date={selectedAccount.next_use_time} /> : '未设置'}
-                </p>
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Extra Data (JSON)</label>
-                <textarea className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none font-mono text-xs bg-slate-50" rows={6} value={editForm.extra_data_str} onChange={e => setEditForm({...editForm, extra_data_str: e.target.value})} />
-              </div>
-            </div>
-            <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
-              <button onClick={() => setShowEditModal(false)} className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg">取消</button>
-              <button onClick={handleEditAccount} className="px-4 py-2 text-sm font-bold bg-blue-600 text-white rounded-lg hover:bg-blue-700">保存修改</button>
-            </div>
-          </div>
-        </div>
-      )}
+      <AccountEditModal
+        isOpen={showEditModal}
+        onClose={() => setShowEditModal(false)}
+        account={selectedAccount}
+        onSuccess={() => fetchAccounts(page)}
+      />
     </div>
   );
 }

+ 19 - 264
src/app/admin/configurations/page.tsx

@@ -1,31 +1,17 @@
 'use client';
 
-import { useCallback, useEffect, useMemo, useState } from 'react';
+import { useEffect, useMemo, useState } from 'react';
 import api from '@/lib/api';
-import JsonConfigEditor from '@/components/common/JsonConfigEditor';
 import {
-  Edit3,
   FileText,
-  Loader2,
   Plus,
   RefreshCw,
-  Save,
   Search,
-  SlidersHorizontal,
-  X,
-  AlertCircle,
 } from 'lucide-react';
+import ConfigurationTable from '@/components/admin/configurations/ConfigurationTable';
+import ConfigurationModal from '@/components/admin/configurations/ConfigurationModal';
 import { DynamicConfiguration } from '@/types';
 
-type ConfigurationForm = DynamicConfiguration;
-
-const emptyForm: ConfigurationForm = {
-  config_key: '',
-  config_value: '',
-  description: '',
-  type: '',
-};
-
 function normalizeConfig(item: Partial<DynamicConfiguration>): DynamicConfiguration {
   return {
     id: item.id,
@@ -42,13 +28,10 @@ function normalizeConfig(item: Partial<DynamicConfiguration>): DynamicConfigurat
 export default function AdminConfigurationsPage() {
   const [configs, setConfigs] = useState<DynamicConfiguration[]>([]);
   const [loading, setLoading] = useState(true);
-  const [submitting, setSubmitting] = useState(false);
   const [keyword, setKeyword] = useState('');
   const [keyLookup, setKeyLookup] = useState('');
   const [isModalOpen, setModalOpen] = useState(false);
   const [editingConfig, setEditingConfig] = useState<DynamicConfiguration | null>(null);
-  const [form, setForm] = useState<ConfigurationForm>(emptyForm);
-  const [valueJsonError, setValueJsonError] = useState<string | null>(null);
 
   const filteredConfigs = useMemo(() => {
     const query = keyword.trim().toLowerCase();
@@ -81,35 +64,14 @@ export default function AdminConfigurationsPage() {
 
   const openCreate = () => {
     setEditingConfig(null);
-    setForm(emptyForm);
-    setValueJsonError(null);
     setModalOpen(true);
   };
 
   const openEdit = (config: DynamicConfiguration) => {
     setEditingConfig(config);
-    
-    // 打开时,尝试格式化 JSON
-    let displayValue = config.config_value;
-    try {
-      displayValue = JSON.stringify(JSON.parse(config.config_value), null, 2);
-    } catch (e) {
-      // 解析失败说明不是标准的纯 JSON,保持原样
-    }
-    
-    setForm({ ...config, config_value: displayValue });
-    setValueJsonError(null);
     setModalOpen(true);
   };
 
-  const closeModal = () => {
-    if (submitting) return;
-    setModalOpen(false);
-    setEditingConfig(null);
-    setForm(emptyForm);
-    setValueJsonError(null);
-  };
-
   const handleLookupByKey = async () => {
     const targetKey = keyLookup.trim();
     if (!targetKey) {
@@ -131,58 +93,13 @@ export default function AdminConfigurationsPage() {
     }
   };
 
-  const handleSubmit = async (e: React.FormEvent) => {
-    e.preventDefault();
-
-    const payload: DynamicConfiguration = {
-      config_key: form.config_key.trim(),
-      config_value: form.config_value,
-      description: form.description.trim(),
-      type: form.type.trim(),
-    };
-
-    if (!payload.config_key) {
-      alert('配置 Key 不能为空');
-      return;
-    }
-
-    if (valueJsonError) {
-      alert('配置值 JSON 语法错误,请修复后再保存');
-      return;
-    }
-
-    setSubmitting(true);
-    try {
-      if (editingConfig?.config_key) {
-        await api.put(
-          `/api/dynamic-configurations/key/${encodeURIComponent(editingConfig.config_key)}`,
-          payload
-        );
-      } else {
-        await api.post('/api/dynamic-configurations', payload);
-      }
-
-      alert(editingConfig ? '配置已更新' : '配置已创建');
-      closeModal();
-      fetchConfigs();
-    } catch (e: any) {
-      console.error(e);
-      alert('保存失败: ' + (e.response?.data?.message || e.message || '未知错误'));
-    } finally {
-      setSubmitting(false);
-    }
-  };
-
   const handleKeyDown = (e: React.KeyboardEvent) => {
     if (e.key === 'Enter') handleLookupByKey();
   };
 
-  const handleValueValidityChange = useCallback((isValid: boolean, error: string | null) => {
-    setValueJsonError(isValid ? null : error || 'JSON 语法错误');
-  }, []);
-
   return (
     <div className="p-4 md:p-6">
+      {/* 头部区域 */}
       <div className="flex flex-col lg:flex-row lg:items-center justify-between gap-4 mb-6">
         <div>
           <h1 className="text-2xl font-bold text-slate-800">动态配置管理</h1>
@@ -217,6 +134,7 @@ export default function AdminConfigurationsPage() {
         </div>
       </div>
 
+      {/* 按 Key 查询 */}
       <div className="bg-white border border-slate-200 rounded-lg p-4 mb-4">
         <div className="flex flex-col md:flex-row md:items-center gap-3">
           <div className="flex items-center gap-2 text-sm font-semibold text-slate-700 md:w-36">
@@ -240,183 +158,20 @@ export default function AdminConfigurationsPage() {
         </div>
       </div>
 
-      <div className="bg-white border border-slate-200 rounded-lg overflow-hidden">
-        {/* 去掉了 Value 列,调整了各列的比例让 Key 和 Description 有更大空间 */}
-        <div className="hidden md:grid grid-cols-[80px_2fr_1fr_3fr_100px] gap-4 px-4 py-3 bg-slate-50 border-b border-slate-200 text-xs font-bold text-slate-500 uppercase">
-          <div>ID</div>
-          <div>Key</div>
-          <div>Type</div>
-          <div>Description</div>
-          <div className="text-right">Actions</div>
-        </div>
-
-        {loading ? (
-          <div className="flex items-center justify-center py-16 text-slate-400">
-            <Loader2 size={28} className="animate-spin mr-2" />
-            正在读取配置...
-          </div>
-        ) : filteredConfigs.length === 0 ? (
-          <div className="flex flex-col items-center justify-center py-16 text-slate-400">
-            <SlidersHorizontal size={32} className="mb-2" />
-            暂无配置数据
-          </div>
-        ) : (
-          <div className="divide-y divide-slate-100">
-            {filteredConfigs.map((item) => (
-              <div
-                key={`${item.id || 'new'}-${item.config_key}`}
-                className="grid grid-cols-1 md:grid-cols-[80px_2fr_1fr_3fr_100px] gap-3 md:gap-4 px-4 py-4 hover:bg-slate-50 transition items-center"
-              >
-                <div className="text-sm text-slate-500">
-                  <span className="md:hidden text-xs font-semibold text-slate-400 mr-2">ID</span>
-                  {item.id ?? '-'}
-                </div>
-                <div className="min-w-0">
-                  <div className="md:hidden text-xs font-semibold text-slate-400 mb-1">Key</div>
-                  <code className="text-sm font-semibold text-blue-700 break-all">{item.config_key}</code>
-                </div>
-                <div>
-                  <div className="md:hidden text-xs font-semibold text-slate-400 mb-1">Type</div>
-                  <span className="inline-flex max-w-full px-2 py-1 bg-slate-100 text-slate-700 rounded text-xs font-medium break-all">
-                    {item.type || '未分类'}
-                  </span>
-                </div>
-                <div className="min-w-0 text-sm text-slate-600 break-words">
-                  <div className="md:hidden text-xs font-semibold text-slate-400 mb-1">Description</div>
-                  {item.description || <span className="text-slate-400">无描述</span>}
-                </div>
-                
-                <div className="flex md:justify-end">
-                  <button
-                    onClick={() => openEdit(item)}
-                    className="inline-flex items-center gap-2 px-3 py-2 text-sm font-medium text-blue-700 bg-blue-50 hover:bg-blue-100 rounded-lg transition"
-                  >
-                    <Edit3 size={14} /> 编辑
-                  </button>
-                </div>
-              </div>
-            ))}
-          </div>
-        )}
-      </div>
-
-      {isModalOpen && (
-        <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4">
-          <div className="bg-white rounded-xl shadow-2xl w-full max-w-[1400px] h-[95vh] overflow-hidden flex flex-col">
-            
-            {/* Header: 压缩高度 */}
-            <div className="px-5 py-3 border-b flex items-center justify-between bg-white shrink-0">
-              <div className="flex items-center gap-3">
-                <h3 className="font-bold text-lg text-slate-800">
-                  {editingConfig ? '编辑动态配置' : '新增动态配置'}
-                </h3>
-                {editingConfig && (
-                  <span className="px-2 py-1 bg-blue-50 text-blue-700 text-xs rounded-md font-mono">
-                    {editingConfig.config_key}
-                  </span>
-                )}
-              </div>
-              <button onClick={closeModal} className="p-2 hover:bg-slate-100 rounded-full transition text-slate-500">
-                <X size={20} />
-              </button>
-            </div>
-
-            {/* Body: 左右分栏 */}
-            <form onSubmit={handleSubmit} className="flex-1 flex flex-col min-h-0">
-              <div className="flex-1 flex flex-col lg:flex-row min-h-0 bg-slate-50/50">
-                
-                {/* 左侧:JSON 编辑器,占据绝对主力空间 */}
-                <div className="flex-1 flex flex-col min-h-0 p-4">
-                  <div className="flex-1 min-h-0 border border-slate-200 shadow-sm rounded-lg overflow-hidden bg-white">
-                    <JsonConfigEditor
-                      type={form.type}
-                      value={form.config_value}
-                      onChange={(configValue) => setForm({ ...form, config_value: configValue })}
-                      onValidityChange={handleValueValidityChange}
-                    />
-                  </div>
-                </div>
-
-                {/* 右侧:将非核心配置移至侧边栏,宽度固定,方便查看描述和填写字段 */}
-                <div className="w-full lg:w-[320px] bg-white border-t lg:border-t-0 lg:border-l border-slate-200 p-5 shrink-0 overflow-y-auto">
-                  <h4 className="text-sm font-bold text-slate-800 mb-4 pb-2 border-b border-slate-100">基础属性</h4>
-                  
-                  <div className="space-y-5">
-                    <label className="block">
-                      <span className="block text-sm font-semibold text-slate-700 mb-1.5">配置 Key</span>
-                      <input
-                        type="text"
-                        value={form.config_key}
-                        onChange={(e) => setForm({ ...form, config_key: e.target.value })}
-                        className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none transition bg-slate-50 font-mono"
-                        placeholder="CONFIG_KEY"
-                        required
-                        disabled={!!editingConfig}
-                      />
-                      <p className="text-xs text-slate-400 mt-1">唯一键,供后端读取使用</p>
-                    </label>
-
-                    <label className="block">
-                      <span className="block text-sm font-semibold text-slate-700 mb-1.5">类型 (Type)</span>
-                      <input
-                        type="text"
-                        value={form.type}
-                        onChange={(e) => setForm({ ...form, type: e.target.value })}
-                        className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none transition font-mono"
-                        placeholder="json / string / ..."
-                      />
-                    </label>
-
-                    <label className="block">
-                      <span className="block text-sm font-semibold text-slate-700 mb-1.5">用途描述</span>
-                      {/* 右侧空间充足,改用 textarea 方便填写详细的说明 */}
-                      <textarea
-                        rows={5}
-                        value={form.description}
-                        onChange={(e) => setForm({ ...form, description: e.target.value })}
-                        className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none transition resize-none leading-relaxed"
-                        placeholder="该配置的用途、结构说明及注意事项..."
-                      />
-                    </label>
-                  </div>
-                </div>
-
-              </div>
-
-              {/* Footer: 压缩高度并贴边 */}
-              <div className="px-5 py-3 border-t bg-white flex items-center justify-between shrink-0">
-                <div className="text-sm font-medium text-red-600 flex items-center gap-2">
-                   {valueJsonError && (
-                     <>
-                        <AlertCircle size={16} /> 
-                        {valueJsonError}
-                     </>
-                   )}
-                </div>
-                
-                <div className="flex gap-3">
-                  <button
-                    type="button"
-                    onClick={closeModal}
-                    className="px-5 py-2 text-slate-600 hover:bg-slate-100 rounded-lg transition font-medium"
-                    disabled={submitting}
-                  >
-                    取消
-                  </button>
-                  <button
-                    type="submit"
-                    disabled={submitting || Boolean(valueJsonError)}
-                    className="flex items-center gap-2 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 shadow-sm transition disabled:opacity-70 disabled:cursor-not-allowed font-medium"
-                  >
-                    {submitting ? <Loader2 size={16} className="animate-spin" /> : <Save size={16} />}
-                    保存配置
-                  </button>
-                </div>
-              </div>
-            </form>
-          </div>
-        </div>
-      )}
+      {/* 表格组件 */}
+      <ConfigurationTable
+        configs={filteredConfigs}
+        loading={loading}
+        onEdit={openEdit}
+      />
+
+      {/* 编辑/新增弹窗组件 */}
+      <ConfigurationModal
+        isOpen={isModalOpen}
+        onClose={() => setModalOpen(false)}
+        config={editingConfig}
+        onSuccess={fetchConfigs}
+      />
     </div>
   );
 }

+ 70 - 317
src/app/admin/orders/new/page.tsx

@@ -1,144 +1,87 @@
 'use client';
 
 import { useState, useEffect } from 'react';
-import api from '@/lib/api';
 import { useRouter } from 'next/navigation';
-// 修复:添加 Info 导入
-import { 
-  Loader2, ArrowLeft, Search, CheckCircle, Package, 
-  Sparkles, Bot, Wand2, Check, Info 
-} from 'lucide-react';
-import { useDebounce } from 'use-debounce'; 
+import { ArrowLeft } from 'lucide-react';
+import api from '@/lib/api';
+import ProductSearchSelector from '@/components/admin/orders/ProductSearchSelector';
+import AiDataParserPanel from '@/components/admin/orders/AiDataParserPanel';
+import DynamicOrderSchemaForm from '@/components/admin/orders/DynamicOrderSchemaForm';
 import { SchemaProperty } from '@/types';
 
 export default function AdminCreateOrderPage() {
   const router = useRouter();
   const [loading, setLoading] = useState(false);
-  
-  // 1. 商品搜索状态
-  const [keyword, setKeyword] = useState('');
-  const [debouncedKeyword] = useDebounce(keyword, 500);
-  const [productList, setProductList] = useState<any[]>([]);
-  const [isSearchingProduct, setIsSearchingProduct] = useState(false);
+
+  // 1. 商品状态
   const [selectedProduct, setSelectedProduct] = useState<any>(null);
 
-  // 2. 表单状态
+  // 2. 表单与 Schema 状态
   const [formSchema, setFormSchema] = useState<any>(null);
   const [formValues, setFormValues] = useState<Record<string, any>>({});
   const [sortedFields, setSortedFields] = useState<string[]>([]);
 
-  // 3. AI 解析状态
-  const [rawInput, setRawInput] = useState('');
-  const [parsing, setParsing] = useState(false);
-  // 默认展开,确保可见
-  const [showAiPanel, setShowAiPanel] = useState(true); 
-
-  // --- 商品搜索逻辑 ---
-  useEffect(() => {
-    if (!debouncedKeyword) {
-      setProductList([]);
-      return;
-    }
-    async function searchProducts() {
-      setIsSearchingProduct(true);
-      try {
-        const res = await api.get('/api/vas/product/list', {
-          params: { keyword: debouncedKeyword, page: 1, size: 20 }
-        });
-        const data = res.data.data;
-        if (Array.isArray(data)) setProductList(data);
-        else if (data.items) setProductList(data.items);
-      } catch (e) {
-        console.error("Search failed", e);
-      } finally {
-        setIsSearchingProduct(false);
-      }
-    }
-    searchProducts();
-  }, [debouncedKeyword]);
-
-  // --- 加载 Schema ---
+  // 加载 Schema
   useEffect(() => {
     async function loadSchema() {
       if (!selectedProduct?.schema_id) {
         setFormSchema(null);
         setSortedFields([]);
+        setFormValues({});
         return;
       }
       try {
-        const res = await api.get('/api/vas/schema/detail', { 
-            params: { schema_id: selectedProduct.schema_id }
+        const res = await api.get('/api/vas/schema/detail', {
+          params: { schema_id: selectedProduct.schema_id },
         });
         const data = res.data.data || res.data;
-        const schemaJson = typeof data.schema_json === 'string' 
-          ? JSON.parse(data.schema_json) 
-          : data.schema_json;
-        
+        const schemaJson =
+          typeof data.schema_json === 'string'
+            ? JSON.parse(data.schema_json)
+            : data.schema_json;
+
         setFormSchema(schemaJson);
         setFormValues({});
-        setShowAiPanel(true); // 重新选择商品时展开
 
         if (schemaJson.properties) {
           const keys = Object.keys(schemaJson.properties);
           if (Array.isArray(schemaJson['ui:order'])) {
-             setSortedFields(schemaJson['ui:order']);
+            setSortedFields(schemaJson['ui:order']);
           } else {
-             const sorted = keys.sort((a, b) => {
-               const propA = schemaJson.properties[a] as SchemaProperty;
-               const propB = schemaJson.properties[b] as SchemaProperty;
-               const orderA = propA['x-order'] ?? propA.order ?? 999;
-               const orderB = propB['x-order'] ?? propB.order ?? 999;
-               return orderA - orderB;
-             });
-             setSortedFields(sorted);
+            const sorted = keys.sort((a, b) => {
+              const propA = schemaJson.properties[a] as SchemaProperty;
+              const propB = schemaJson.properties[b] as SchemaProperty;
+              const orderA = propA['x-order'] ?? propA.order ?? 999;
+              const orderB = propB['x-order'] ?? propB.order ?? 999;
+              return orderA - orderB;
+            });
+            setSortedFields(sorted);
           }
         }
       } catch (e) {
-        alert("表单定义加载失败");
+        alert('表单定义加载失败');
       }
     }
     loadSchema();
   }, [selectedProduct]);
 
-  // --- AI 解析逻辑 ---
-  const handleAiParse = async () => {
-    if (!rawInput.trim()) return alert("请先粘贴需要解析的文本内容");
-    if (!selectedProduct?.schema_id) return alert("AI 解析依赖于 Schema,请先选择商品");
+  // AI 解析结果回填
+  const handleAiFieldsParsed = (fields: Record<string, any>) => {
+    setFormValues((prev) => ({
+      ...prev,
+      ...fields,
+    }));
+  };
 
-    setParsing(true);
-    try {
-      const res = await api.post('/api/vas/llm/data_parsing', {
-        input_raw_str: rawInput,
-        schema_id: selectedProduct.schema_id
-      });
-      
-      const responseData = res.data.data || res.data;
-      // 读取 parsed_obj
-      const fieldsToFill = responseData?.parsed_obj || responseData;
-      
-      if (fieldsToFill && typeof fieldsToFill === 'object') {
-        setFormValues(prev => ({
-          ...prev,
-          ...fieldsToFill
-        }));
-        
-        const count = Object.keys(fieldsToFill).length;
-        alert(`✨ AI 成功识别并填充了 ${count} 个字段!`);
-      } else {
-        alert("解析失败:未能识别有效数据");
-      }
-    } catch (e: any) {
-      console.error(e);
-      alert("解析失败: " + (e.response?.data?.message || e.message));
-    } finally {
-      setParsing(false);
-    }
+  // 单个字段修改
+  const handleInputChange = (key: string, value: any) => {
+    setFormValues((prev) => ({ ...prev, [key]: value }));
   };
 
-  // --- 提交订单 ---
+  // 提交订单
   const handleSubmit = async (e: React.FormEvent) => {
     e.preventDefault();
-    if (!selectedProduct) return alert("请先搜索并选择商品");
+    if (!selectedProduct) return alert('请先搜索并选择商品');
 
     setLoading(true);
     try {
@@ -152,261 +95,71 @@ export default function AdminCreateOrderPage() {
 
       alert(`代下单成功!订单号: ${orderId}`);
       router.push('/admin/orders');
-
     } catch (error: any) {
       console.error(error);
-      alert("下单失败: " + (error.response?.data?.message || error.message));
+      alert('下单失败: ' + (error.response?.data?.message || error.message));
     } finally {
       setLoading(false);
     }
   };
 
-  const handleInputChange = (key: string, value: any) => {
-    setFormValues(prev => ({ ...prev, [key]: value }));
-  };
-
-  const renderField = (key: string, fieldSchema: SchemaProperty) => {
-    const commonClass = "w-full border border-slate-300 rounded-lg p-2.5 text-sm focus:ring-2 focus:ring-blue-500 outline-none transition bg-white";
-    const label = fieldSchema.title || key;
-    const placeholder = fieldSchema.description || `请输入 ${label}`;
-    const currentValue = formValues[key] || '';
-
-    if (fieldSchema.enum && fieldSchema.enum.length > 0) {
-      return (
-        <select 
-          className={commonClass} 
-          onChange={e => handleInputChange(key, e.target.value)}
-          value={currentValue}
-        >
-          <option value="">请选择 {label}</option>
-          {fieldSchema.enum.map((v: string) => <option key={v} value={v}>{v}</option>)}
-        </select>
-      );
-    }
-
-    if (fieldSchema.format === 'date') {
-      return (
-        <input 
-          type="date"
-          className={commonClass}
-          onChange={e => handleInputChange(key, e.target.value)}
-          value={currentValue}
-        />
-      );
-    }
-
-    return (
-      <input 
-        type={fieldSchema.type === 'integer' || fieldSchema.type === 'number' ? 'number' : 'text'} 
-        className={commonClass}
-        placeholder={placeholder}
-        onChange={e => handleInputChange(key, e.target.value)}
-        value={currentValue}
-      />
-    );
-  };
-
   return (
     <div className="max-w-5xl mx-auto p-4 md:p-8">
-      
       {/* 头部导航 */}
       <div className="flex items-center justify-between mb-8">
-        <button onClick={() => router.back()} className="flex items-center text-slate-500 hover:text-slate-900 transition text-sm font-medium">
+        <button
+          onClick={() => router.back()}
+          className="flex items-center text-slate-500 hover:text-slate-900 transition text-sm font-medium"
+        >
           <ArrowLeft size={18} className="mr-1" /> 返回列表
         </button>
         <h1 className="text-xl font-bold text-slate-800">管理员代客下单</h1>
       </div>
 
       <div className="space-y-6">
-        
         {/* Step 1: 搜索选择商品 */}
-        <div className="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
-          <label className="block text-base font-bold text-slate-800 mb-3 flex items-center gap-2">
-            <span className="w-6 h-6 rounded-full bg-slate-900 text-white flex items-center justify-center text-xs font-mono">1</span>
-            选择服务商品
-          </label>
-          
-          <div className="relative">
-            <input 
-              type="text" 
-              className={`w-full pl-11 pr-4 py-3 border rounded-xl shadow-sm outline-none transition text-base
-                ${selectedProduct ? 'border-green-500 ring-1 ring-green-500 bg-green-50/20' : 'border-slate-300 focus:ring-2 focus:ring-blue-500'}
-              `}
-              placeholder="输入关键词搜索 (例如: 日本, France...)"
-              value={keyword}
-              onChange={e => {
-                setKeyword(e.target.value);
-                if(!e.target.value) {
-                    setProductList([]);
-                    setSelectedProduct(null);
-                    setShowAiPanel(false);
-                }
-              }}
-            />
-            <Search className="absolute left-3.5 top-3.5 text-slate-400" size={20} />
-            {isSearchingProduct && (
-              <Loader2 className="absolute right-3 top-3.5 text-blue-500 animate-spin" size={20} />
-            )}
-            
-            {selectedProduct && (
-              <div className="absolute right-3 top-2.5 flex items-center gap-2">
-                <span className="text-xs font-bold text-green-600 bg-green-100 px-2 py-1 rounded-full flex items-center gap-1">
-                  <CheckCircle size={12} /> 已选: {selectedProduct.title}
-                </span>
-                <button 
-                  onClick={() => { setSelectedProduct(null); setKeyword(''); setFormSchema(null); setSortedFields([]); setRawInput(''); }}
-                  className="text-xs text-slate-400 hover:text-red-500 underline ml-2"
-                >
-                  清除
-                </button>
-              </div>
-            )}
-          </div>
-
-          {/* 搜索结果下拉 */}
-          {productList.length > 0 && !selectedProduct && (
-            <div className="mt-2 bg-white border border-slate-200 rounded-xl shadow-xl max-h-60 overflow-y-auto divide-y divide-slate-100 animate-in fade-in zoom-in-95 duration-200">
-              {productList.map(p => (
-                <div 
-                  key={p.id} 
-                  onClick={() => {
-                    setSelectedProduct(p);
-                    setKeyword(p.title);
-                    setProductList([]);
-                    setShowAiPanel(true); // 选中后展开 AI
-                  }}
-                  className="p-4 hover:bg-blue-50 cursor-pointer transition flex justify-between items-center group"
-                >
-                  <div className="flex items-center gap-3">
-                    <div className="p-2 bg-slate-100 rounded-lg group-hover:bg-blue-100 text-slate-500 group-hover:text-blue-600 transition">
-                      <Package size={20} />
-                    </div>
-                    <div>
-                      <div className="font-bold text-sm text-slate-800">{p.title}</div>
-                      <div className="text-xs text-slate-500 mt-0.5">{p.country} • {p.visa_type}</div>
-                    </div>
-                  </div>
-                  <div className="text-sm font-mono font-bold text-slate-600">
-                    {p.price_amount / 100} {p.price_currency}
-                  </div>
-                </div>
-              ))}
-            </div>
-          )}
-        </div>
+        <ProductSearchSelector
+          selectedProduct={selectedProduct}
+          onSelectProduct={setSelectedProduct}
+        />
 
         {/* Step 2: 填写表单 (含 AI) */}
         {selectedProduct && (
-          <form onSubmit={handleSubmit} className="animate-in fade-in slide-in-from-bottom-4 duration-500">
+          <form
+            onSubmit={handleSubmit}
+            className="animate-in fade-in slide-in-from-bottom-4 duration-500"
+          >
             <div className="bg-white rounded-xl shadow-sm border border-slate-200 overflow-hidden">
               <div className="p-6 border-b border-slate-100 bg-slate-50/50">
                 <label className="block text-base font-bold text-slate-800 flex items-center gap-2">
-                  <span className="w-6 h-6 rounded-full bg-slate-900 text-white flex items-center justify-center text-xs font-mono">2</span>
+                  <span className="w-6 h-6 rounded-full bg-slate-900 text-white flex items-center justify-center text-xs font-mono">
+                    2
+                  </span>
                   填写申请资料
                 </label>
               </div>
 
-              {/* === AI 智能填充区域 === */}
+              {/* AI 智能填充面板 */}
               {formSchema && (
-                <div className="bg-gradient-to-r from-violet-50 to-fuchsia-50 p-6 border-b border-violet-100">
-                  <div className="flex items-start gap-3">
-                    <div className="p-2 bg-white rounded-lg shadow-sm text-violet-600 mt-1">
-                      <Bot size={24} />
-                    </div>
-                    <div className="flex-1">
-                      <h3 className="font-bold text-violet-900 text-base mb-1 flex items-center gap-2">
-                        AI 智能填表助手 <Sparkles size={16} className="text-amber-500 animate-pulse" />
-                      </h3>
-                      <p className="text-xs text-violet-600 mb-3">
-                        直接粘贴客户发来的聊天记录、邮件或证件文本,AI 将自动识别并填充到下方表单。
-                      </p>
-                      
-                      <div className="relative">
-                        <textarea
-                          className="w-full border border-violet-200 rounded-xl p-4 text-sm focus:ring-2 focus:ring-violet-500 outline-none resize-none shadow-sm min-h-[100px] bg-white/80 focus:bg-white transition"
-                          placeholder="例如:
-姓名:张三
-护照号:E12345678
-出生日期:1990-01-01
-..."
-                          value={rawInput}
-                          onChange={e => setRawInput(e.target.value)}
-                        />
-                        <div className="absolute bottom-3 right-3">
-                          <button
-                            type="button"
-                            disabled={parsing || !rawInput.trim()}
-                            onClick={handleAiParse}
-                            className="bg-violet-600 text-white px-4 py-2 rounded-lg text-xs font-bold hover:bg-violet-700 transition flex items-center gap-2 shadow-md disabled:opacity-50 disabled:cursor-not-allowed transform active:scale-95"
-                          >
-                            {parsing ? <Loader2 size={14} className="animate-spin" /> : <Wand2 size={14} />}
-                            {parsing ? 'AI 正在分析...' : '一键识别填充'}
-                          </button>
-                        </div>
-                      </div>
-                    </div>
-                  </div>
-                </div>
+                <AiDataParserPanel
+                  schemaId={selectedProduct.schema_id}
+                  onFieldsParsed={handleAiFieldsParsed}
+                />
               )}
 
-              <div className="p-6">
-                {!formSchema ? (
-                  <div className="text-center py-8 text-slate-400 text-sm flex flex-col items-center">
-                     <Loader2 className="animate-spin mb-2" /> 正在加载表单定义...
-                  </div>
-                ) : (
-                  <div className="grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-6">
-                    {sortedFields.map(key => {
-                      const fieldSchema = formSchema.properties[key] as SchemaProperty;
-                      const hasValue = formValues[key] !== undefined && formValues[key] !== '';
-                      
-                      return (
-                        <div key={key}>
-                          <label className="block text-sm font-bold text-slate-700 mb-2 ml-1 flex items-center gap-2">
-                            {fieldSchema.title || key}
-                            {/* 如果有 AI 填充的提示图标 */}
-                            {hasValue && <Check size={14} className="text-green-500" />}
-                          </label>
-                          {renderField(key, fieldSchema)}
-                          {fieldSchema.description && (
-                            <p className="text-xs text-gray-400 mt-1.5 ml-1">{fieldSchema.description}</p>
-                          )}
-                        </div>
-                      );
-                    })}
-                    
-                    {sortedFields.length === 0 && (
-                       <div className="col-span-2 text-center text-slate-400 text-sm py-4 bg-slate-50 rounded-lg border border-dashed border-slate-200">
-                          此商品无需填写额外信息
-                       </div>
-                    )}
-                  </div>
-                )}
-              </div>
-
-              {/* Footer Action */}
-              <div className="p-6 bg-slate-50 border-t border-slate-100 flex items-center justify-between">
-                 <div className="hidden md:flex text-xs text-slate-500 max-w-md items-start gap-2">
-                    <Info size={16} className="shrink-0 mt-0.5 text-blue-500" />
-                    <div>
-                      <span className="font-bold text-slate-700">下单说明:</span>
-                      系统将自动创建订单并标记为 <span className="font-bold text-green-600">PAID</span>,机器人任务将立即启动。
-                    </div>
-                 </div>
-                 
-                 <button 
-                    type="submit" 
-                    disabled={loading || !selectedProduct}
-                    className="w-full md:w-auto px-8 py-3.5 bg-slate-900 text-white rounded-xl font-bold hover:bg-slate-800 transition flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed shadow-lg shadow-slate-300 transform active:scale-95"
-                  >
-                    {loading ? <Loader2 className="animate-spin" /> : <CheckCircle size={18} />}
-                    确认创建订单
-                  </button>
-              </div>
+              {/* 动态表单项及底部提交按钮 */}
+              <DynamicOrderSchemaForm
+                formSchema={formSchema}
+                sortedFields={sortedFields}
+                formValues={formValues}
+                onInputChange={handleInputChange}
+                onSubmit={handleSubmit}
+                loading={loading}
+                selectedProduct={selectedProduct}
+              />
             </div>
           </form>
         )}
-
       </div>
     </div>
   );

+ 16 - 74
src/app/admin/page.tsx

@@ -4,27 +4,20 @@ import { useState, useEffect } from 'react';
 import api from '@/lib/api';
 import DataStats from '@/components/admin/DataStats'; 
 import OverviewCharts from '@/components/admin/dashboard/OverviewCharts'; 
-import { ShoppingBag, Users, AlertCircle, CheckCircle, Wallet, ArrowRight } from 'lucide-react';
+import RecentActivities, { ActivityItem } from '@/components/admin/dashboard/RecentActivities';
+import { ShoppingBag, AlertCircle, CheckCircle, Wallet, ArrowRight } from 'lucide-react';
 import Link from 'next/link';
 
-// 定义接口以匹配后端 API 返回的数据结构
 interface DashboardStats {
   totalOrders: number;
-  totalOrdersTrend: number;   // 动态增长率
+  totalOrdersTrend: number;
   totalRevenue: number;
-  totalRevenueTrend: number;  // 动态增长率
+  totalRevenueTrend: number;
   activeUsers: number;
   pendingTickets: number;
   successRate: string;
 }
 
-interface ActivityItem {
-  id: string;
-  text: string;
-  time: string;
-  type: 'order' | 'money' | 'ticket' | 'system';
-}
-
 interface TaskDistItem {
   routing_key: string;
   count: number;
@@ -33,7 +26,6 @@ interface TaskDistItem {
 export default function AdminDashboard() {
   const [loading, setLoading] = useState(true);
   
-  // 状态数据
   const [stats, setStats] = useState<DashboardStats>({
     totalOrders: 0,
     totalOrdersTrend: 0,
@@ -41,14 +33,13 @@ export default function AdminDashboard() {
     totalRevenueTrend: 0,
     activeUsers: 0,
     pendingTickets: 0,
-    successRate: '0%'
+    successRate: '0%',
   });
 
-  // 图表数据
   const [chartData, setChartData] = useState<{
-    revenue: any[],
-    products: any[],
-    tasks: TaskDistItem[] // [新增] 活跃任务数据类型
+    revenue: any[];
+    products: any[];
+    tasks: TaskDistItem[];
   }>({ revenue: [], products: [], tasks: [] });
 
   const [recentActivities, setRecentActivities] = useState<ActivityItem[]>([]);
@@ -60,9 +51,7 @@ export default function AdminDashboard() {
   const fetchDashboardData = async () => {
     setLoading(true);
     try {
-      // 调用后端 API
       const res = await api.get('/api/vas/statistics/overview');
-      // 假设后端返回结构为: { code: 0, message: "success", data: { ... } }
       const data = res.data.data;
 
       if (data) {
@@ -71,28 +60,20 @@ export default function AdminDashboard() {
         setChartData({ 
           revenue: data.revenue_trend || [], 
           products: data.product_dist || [],
-          // [新增] 获取后端返回的活跃任务分布数据
-          tasks: data.active_tasks_dist || [] 
+          tasks: data.active_tasks_dist || [],
         });
 
         setRecentActivities(data.recent_activities || []);
       }
-
     } catch (error) {
-      console.error("Failed to load dashboard data", error);
+      console.error('Failed to load dashboard data', error);
     } finally {
       setLoading(false);
     }
   };
 
-  /**
-   * 格式化趋势百分比
-   * 例如: 12.5 -> "+12.5%", -5 -> "-5.0%"
-   */
   const formatTrend = (val: number) => {
-    // 处理 NaN 或 null 情况
-    if (val === undefined || val === null || isNaN(val)) return "0.0%";
-    
+    if (val === undefined || val === null || isNaN(val)) return '0.0%';
     const absVal = Math.abs(val);
     const sign = val >= 0 ? '+' : '-';
     return `${sign}${absVal.toFixed(1)}%`;
@@ -104,21 +85,15 @@ export default function AdminDashboard() {
       
       {/* 1. 核心指标卡片区域 */}
       <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6 mb-8">
-        
-        {/* 卡片1: 总营收 (本月) */}
         <DataStats 
           title="总营收 (本月)" 
-          // 后端返回的是分,除以100转为元
           value={`¥${(stats.totalRevenue / 100).toLocaleString()}`} 
           icon={Wallet} 
-          // 动态设置趋势文本
           trend={formatTrend(stats.totalRevenueTrend)} 
-          // 动态判断颜色方向 (大于等于0为上升绿色/蓝色,小于0为红色)
           trendUp={stats.totalRevenueTrend >= 0} 
           color="blue"
         />
         
-        {/* 卡片2: 活跃订单 (本月) */}
         <DataStats 
           title="本月订单数" 
           value={stats.totalOrders} 
@@ -128,17 +103,15 @@ export default function AdminDashboard() {
           color="purple"
         />
         
-        {/* 卡片3: 待处理工单 (无环比概念,仅根据数量预警) */}
         <DataStats 
           title="待处理工单" 
           value={stats.pendingTickets} 
           icon={AlertCircle} 
-          trend={stats.pendingTickets > 0 ? "需关注" : "良好"} 
+          trend={stats.pendingTickets > 0 ? '需关注' : '良好'} 
           trendUp={stats.pendingTickets === 0}
-          color={stats.pendingTickets > 0 ? "red" : "green"}
+          color={stats.pendingTickets > 0 ? 'red' : 'green'}
         />
         
-        {/* 卡片4: 机器人成功率 */}
         <DataStats 
           title="机器人成功率" 
           value={stats.successRate} 
@@ -153,44 +126,14 @@ export default function AdminDashboard() {
       <OverviewCharts 
         revenueData={chartData.revenue} 
         productData={chartData.products} 
-        taskData={chartData.tasks} // [新增] 传递任务数据给子组件
+        taskData={chartData.tasks} 
       />
 
       {/* 3. 底部:最新动态与快捷入口 */}
       <div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
-        
-        {/* 左侧:最新动态列表 */}
-        <div className="lg:col-span-2 bg-white p-6 rounded-xl shadow-sm border border-slate-100">
-          <div className="flex justify-between items-center mb-4">
-            <h3 className="font-bold text-slate-800">最新系统动态</h3>
-            <button className="text-xs text-blue-600 hover:underline">查看全部日志</button>
-          </div>
-          
-          {loading && recentActivities.length === 0 ? (
-            <div className="py-10 text-center text-slate-400">加载中...</div>
-          ) : recentActivities.length === 0 ? (
-            <div className="py-10 text-center text-slate-400">暂无最新动态</div>
-          ) : (
-            <div className="space-y-4">
-              {recentActivities.map((item) => (
-                <div key={item.id} className="flex items-start gap-3 pb-3 border-b border-slate-50 last:border-0 last:pb-0">
-                  {/* 根据类型显示不同颜色的圆点 */}
-                  <div className={`mt-1 w-2 h-2 rounded-full flex-shrink-0 
-                    ${item.type === 'order' ? 'bg-blue-500' : 
-                      item.type === 'money' ? 'bg-green-500' : 
-                      item.type === 'ticket' ? 'bg-orange-500' : 'bg-gray-400'}`} 
-                  />
-                  <div className="flex-1">
-                    <p className="text-sm text-slate-700">{item.text}</p>
-                    <p className="text-xs text-slate-400 mt-0.5">{item.time}</p>
-                  </div>
-                </div>
-              ))}
-            </div>
-          )}
-        </div>
+        <RecentActivities activities={recentActivities} loading={loading} />
 
-        {/* 右侧:快捷操作区 */}
+        {/* 快捷操作区 */}
         <div className="bg-slate-900 text-white p-6 rounded-xl shadow-lg flex flex-col justify-between">
           <div>
             <h3 className="font-bold text-lg mb-2">管理快捷入口</h3>
@@ -216,7 +159,6 @@ export default function AdminDashboard() {
             <p className="text-xs text-slate-500">System Status: <span className="text-green-400">Normal</span></p>
           </div>
         </div>
-
       </div>
     </div>
   );

+ 27 - 345
src/app/admin/proxies/page.tsx

@@ -1,40 +1,15 @@
 'use client';
 
 import { useEffect, useState } from 'react';
-import { Plus, Search, RefreshCw, X, Pencil, Download } from 'lucide-react';
+import { Plus, Search, RefreshCw, Download } from 'lucide-react';
 import api from '@/lib/api';
 import { toast } from 'react-hot-toast';
 import Pagination from '@/components/common/Pagination';
-import LocalTime from '@/components/common/LocalTime';
 import ProxyTable from '@/components/admin/proxies/ProxyTable';
-import { ProxyItem, ProxyStatus } from '@/types';
-
-function parseUtcDateTime(value?: string | null) {
-  if (!value) return null;
-  const normalized = value.trim().replace(' ', 'T');
-  const hasTimezone = /[zZ]|[+-]\d{2}:\d{2}$/.test(normalized);
-  const utcValue = hasTimezone ? normalized : `${normalized}Z`;
-  const timestamp = new Date(utcValue).getTime();
-
-  return Number.isNaN(timestamp) ? null : timestamp;
-}
-
-function toDatetimeLocalValue(value?: string | null) {
-  if (!value) return '';
-  const timestamp = parseUtcDateTime(value);
-  if (timestamp === null) return '';
-  const date = new Date(timestamp);
-  const offset = date.getTimezoneOffset();
-  const localDate = new Date(date.getTime() - offset * 60 * 1000);
-  return localDate.toISOString().slice(0, 16);
-}
-
-function toApiDateTime(value: string) {
-  if (!value) return null;
-  const date = new Date(value);
-  if (Number.isNaN(date.getTime())) return null;
-  return date.toISOString();
-}
+import ProxyAddModal from '@/components/admin/proxies/ProxyAddModal';
+import ProxyEditModal from '@/components/admin/proxies/ProxyEditModal';
+import ProxyExportModal from '@/components/admin/proxies/ProxyExportModal';
+import { ProxyItem } from '@/types';
 
 export default function AdminProxiesPage() {
   const [loading, setLoading] = useState(true);
@@ -50,27 +25,6 @@ export default function AdminProxiesPage() {
   const [selectedProxy, setSelectedProxy] = useState<ProxyItem | null>(null);
   const [selectedIds, setSelectedIds] = useState<number[]>([]);
 
-  const [addForm, setAddForm] = useState({
-    pool_name: '',
-    proto: 'http',
-    ip: '',
-    port: 8080,
-    username: '',
-    password: '',
-    status: 'active' as ProxyStatus
-  });
-
-  const [editForm, setEditForm] = useState({
-    pool_name: '',
-    proto: 'http',
-    ip: '',
-    port: 8080,
-    username: '',
-    password: '',
-    status: 'active' as ProxyStatus,
-    next_use_time: ''
-  });
-
   const fetchProxies = async (targetPage: number = page) => {
     setLoading(true);
     try {
@@ -78,19 +32,17 @@ export default function AdminProxiesPage() {
         params: {
           page: targetPage,
           size: pageSize,
-          keyword
-        }
+          keyword,
+        },
       });
 
       const resData = res.data?.data || {};
       if (resData && Array.isArray(resData.items)) {
         setData(resData.items);
         setTotal(resData.total || 0);
-        setSelectedIds((prev) => prev.filter((id) => resData.items.some((item: ProxyItem) => item.id === id)));
       } else {
         setData([]);
         setTotal(0);
-        setSelectedIds([]);
       }
 
       setPage(targetPage);
@@ -102,7 +54,6 @@ export default function AdminProxiesPage() {
       console.error('Fetch proxies failed', error);
       toast.error('获取代理列表失败');
       setData([]);
-      setTotal(0);
     } finally {
       setLoading(false);
     }
@@ -119,77 +70,16 @@ export default function AdminProxiesPage() {
     if (e.key === 'Enter') handleSearch();
   };
 
-  const handleAddProxy = async () => {
-    try {
-      await api.post('/api/proxy/create', {
-        pool_name: addForm.pool_name,
-        proto: addForm.proto,
-        ip: addForm.ip,
-        port: Number(addForm.port),
-        username: addForm.username || null,
-        password: addForm.password || null,
-        status: addForm.status || null
-      });
-      toast.success('代理创建成功');
-      setShowAddModal(false);
-      setAddForm({
-        pool_name: '',
-        proto: 'http',
-        ip: '',
-        port: 8080,
-        username: '',
-        password: '',
-        status: 'active'
-      });
-      fetchProxies(1);
-    } catch (error) {
-      toast.error('代理创建失败');
-    }
-  };
-
   const handleEditClick = (proxy: ProxyItem) => {
     setSelectedProxy(proxy);
-    setEditForm({
-      pool_name: proxy.pool_name || '',
-      proto: proxy.proto || 'http',
-      ip: proxy.ip || '',
-      port: proxy.port || 8080,
-      username: proxy.username || '',
-      password: proxy.password || '',
-      status: (proxy.status?.toLowerCase() === 'disable' ? 'disable' : 'active') as ProxyStatus,
-      next_use_time: toDatetimeLocalValue(proxy.next_use_time)
-    });
     setShowEditModal(true);
   };
 
-  const handleEditProxy = async () => {
-    if (!selectedProxy) return;
-    try {
-      await api.put('/api/proxy/update', {
-        pool_name: editForm.pool_name || null,
-        proto: editForm.proto || null,
-        ip: editForm.ip || null,
-        port: Number(editForm.port) || null,
-        username: editForm.username || null,
-        password: editForm.password || null,
-        status: editForm.status || null,
-        next_use_time: toApiDateTime(editForm.next_use_time)
-      }, {
-        params: { proxy_id: selectedProxy.id }
-      });
-      toast.success('代理更新成功');
-      setShowEditModal(false);
-      fetchProxies(page);
-    } catch (error) {
-      toast.error('代理更新失败');
-    }
-  };
-
   const handleDeleteProxy = async (proxy: ProxyItem) => {
     if (!confirm(`确定要删除代理 ${proxy.ip}:${proxy.port} 吗?此操作不可恢复。`)) return;
     try {
       await api.delete('/api/proxy/delete', {
-        params: { proxy_id: proxy.id }
+        params: { proxy_id: proxy.id },
       });
       toast.success('代理删除成功');
       const nextPage = data.length === 1 && page > 1 ? page - 1 : page;
@@ -218,49 +108,6 @@ export default function AdminProxiesPage() {
 
   const selectedProxies = data.filter((item) => selectedIds.includes(item.id));
 
-  const downloadTextFile = (filename: string, content: string, mimeType: string) => {
-    const blob = new Blob([content], { type: mimeType });
-    const url = URL.createObjectURL(blob);
-    const link = document.createElement('a');
-    link.href = url;
-    link.download = filename;
-    document.body.appendChild(link);
-    link.click();
-    document.body.removeChild(link);
-    URL.revokeObjectURL(url);
-  };
-
-  const handleExport = (format: 'colon' | 'url' | 'json') => {
-    if (selectedProxies.length === 0) {
-      toast.error('请先选择要导出的代理');
-      return;
-    }
-
-    const timestamp = new Date().toISOString().slice(0, 19).replace(/[:T]/g, '-');
-
-    if (format === 'colon') {
-      const content = selectedProxies.map((item) => (
-        `${item.ip}:${item.port}:${item.username || ''}:${item.password || ''}`
-      )).join('\n');
-      downloadTextFile(`proxies-colon-${timestamp}.txt`, content, 'text/plain;charset=utf-8');
-    }
-
-    if (format === 'url') {
-      const content = selectedProxies.map((item) => {
-        const auth = item.username ? `${encodeURIComponent(item.username)}:${encodeURIComponent(item.password || '')}@` : '';
-        return `${item.proto}://${auth}${item.ip}:${item.port}`;
-      }).join('\n');
-      downloadTextFile(`proxies-url-${timestamp}.txt`, content, 'text/plain;charset=utf-8');
-    }
-
-    if (format === 'json') {
-      downloadTextFile(`proxies-raw-${timestamp}.json`, JSON.stringify(selectedProxies, null, 2), 'application/json;charset=utf-8');
-    }
-
-    setShowExportModal(false);
-    toast.success(`已导出 ${selectedProxies.length} 条代理`);
-  };
-
   return (
     <div className="p-4 md:p-6 space-y-6">
       <div className="flex flex-col md:flex-row md:items-center justify-between gap-4">
@@ -309,6 +156,7 @@ export default function AdminProxiesPage() {
         </div>
       </div>
 
+      {/* 表格组件 */}
       <ProxyTable
         data={data}
         loading={loading}
@@ -319,17 +167,7 @@ export default function AdminProxiesPage() {
         onDelete={handleDeleteProxy}
       />
 
-      <div className="flex items-center justify-between rounded-xl border border-slate-200 bg-white px-4 py-3 text-sm text-slate-600 shadow-sm">
-        <span>已选择 {selectedProxies.length} 条代理</span>
-        <button
-          onClick={() => setSelectedIds([])}
-          className="text-slate-500 hover:text-slate-700"
-          disabled={selectedProxies.length === 0}
-        >
-          清空选择
-        </button>
-      </div>
-
+      {/* 分页组件 */}
       <div className="mt-4">
         <Pagination
           currentPage={page}
@@ -339,181 +177,25 @@ export default function AdminProxiesPage() {
         />
       </div>
 
-      {showAddModal && (
-        <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
-          <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
-            <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-slate-50/50">
-              <h3 className="font-bold text-lg text-slate-800">新增代理</h3>
-              <button onClick={() => setShowAddModal(false)} className="text-slate-400 hover:text-slate-600">
-                <X size={20} />
-              </button>
-            </div>
-            <div className="p-6 space-y-4 max-h-[80vh] overflow-y-auto">
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Pool Name</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={addForm.pool_name} onChange={(e) => setAddForm({ ...addForm, pool_name: e.target.value })} />
-              </div>
-              <div className="grid grid-cols-2 gap-4">
-                <div>
-                  <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Proto</label>
-                  <select className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white" value={addForm.proto} onChange={(e) => setAddForm({ ...addForm, proto: e.target.value })}>
-                    <option value="http">http</option>
-                    <option value="https">https</option>
-                    <option value="socks5">socks5</option>
-                  </select>
-                </div>
-                <div>
-                  <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Port</label>
-                  <input type="number" min="1" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={addForm.port} onChange={(e) => setAddForm({ ...addForm, port: Number(e.target.value) })} />
-                </div>
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">IP</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm font-mono" value={addForm.ip} onChange={(e) => setAddForm({ ...addForm, ip: e.target.value })} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Username</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={addForm.username} onChange={(e) => setAddForm({ ...addForm, username: e.target.value })} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Password</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={addForm.password} onChange={(e) => setAddForm({ ...addForm, password: e.target.value })} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Status</label>
-                <select className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white" value={addForm.status} onChange={(e) => setAddForm({ ...addForm, status: e.target.value as ProxyStatus })}>
-                  <option value="active">active</option>
-                  <option value="disable">disable</option>
-                </select>
-              </div>
-            </div>
-            <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
-              <button onClick={() => setShowAddModal(false)} className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg">取消</button>
-              <button onClick={handleAddProxy} className="px-4 py-2 text-sm font-bold bg-slate-900 text-white rounded-lg hover:bg-slate-800">确认添加</button>
-            </div>
-          </div>
-        </div>
-      )}
+      {/* 模态框组件 */}
+      <ProxyAddModal
+        isOpen={showAddModal}
+        onClose={() => setShowAddModal(false)}
+        onSuccess={() => fetchProxies(1)}
+      />
 
-      {showEditModal && selectedProxy && (
-        <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
-          <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
-            <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-blue-50/50">
-              <h3 className="font-bold text-lg text-blue-900 flex items-center gap-2">
-                <Pencil size={18} /> 编辑代理
-              </h3>
-              <button onClick={() => setShowEditModal(false)} className="text-slate-400 hover:text-slate-600">
-                <X size={20} />
-              </button>
-            </div>
-            <div className="p-6 space-y-4 max-h-[80vh] overflow-y-auto">
-              <div className="text-sm text-slate-600 bg-blue-50 p-3 rounded-lg border border-blue-100">
-                ID: <span className="font-bold text-slate-900">#{selectedProxy.id}</span>
-                <br />
-                Created:{' '}
-                <span className="font-bold text-slate-900">
-                  {selectedProxy.created_at ? <LocalTime date={selectedProxy.created_at} /> : '-'}
-                </span>
-                <br />
-                Updated:{' '}
-                <span className="font-bold text-slate-900">
-                  {selectedProxy.updated_at ? <LocalTime date={selectedProxy.updated_at} /> : '-'}
-                </span>
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Pool Name</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={editForm.pool_name} onChange={(e) => setEditForm({ ...editForm, pool_name: e.target.value })} />
-              </div>
-              <div className="grid grid-cols-2 gap-4">
-                <div>
-                  <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Proto</label>
-                  <select className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white" value={editForm.proto} onChange={(e) => setEditForm({ ...editForm, proto: e.target.value })}>
-                    <option value="http">http</option>
-                    <option value="https">https</option>
-                    <option value="socks5">socks5</option>
-                  </select>
-                </div>
-                <div>
-                  <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Port</label>
-                  <input type="number" min="1" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={editForm.port} onChange={(e) => setEditForm({ ...editForm, port: Number(e.target.value) })} />
-                </div>
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">IP</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm font-mono" value={editForm.ip} onChange={(e) => setEditForm({ ...editForm, ip: e.target.value })} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Username</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={editForm.username} onChange={(e) => setEditForm({ ...editForm, username: e.target.value })} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Password</label>
-                <input type="text" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={editForm.password} onChange={(e) => setEditForm({ ...editForm, password: e.target.value })} />
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Status</label>
-                <select className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white" value={editForm.status} onChange={(e) => setEditForm({ ...editForm, status: e.target.value as ProxyStatus })}>
-                  <option value="active">active</option>
-                  <option value="disable">disable</option>
-                </select>
-              </div>
-              <div>
-                <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Next Use Time</label>
-                <input type="datetime-local" className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm" value={editForm.next_use_time} onChange={(e) => setEditForm({ ...editForm, next_use_time: e.target.value })} />
-                <p className="mt-1 text-xs text-slate-500">
-                  {selectedProxy.next_use_time ? <LocalTime date={selectedProxy.next_use_time} /> : '未设置'}
-                </p>
-              </div>
-            </div>
-            <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
-              <button onClick={() => setShowEditModal(false)} className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg">取消</button>
-              <button onClick={handleEditProxy} className="px-4 py-2 text-sm font-bold bg-blue-600 text-white rounded-lg hover:bg-blue-700">保存修改</button>
-            </div>
-          </div>
-        </div>
-      )}
+      <ProxyEditModal
+        isOpen={showEditModal}
+        onClose={() => setShowEditModal(false)}
+        proxy={selectedProxy}
+        onSuccess={() => fetchProxies(page)}
+      />
 
-      {showExportModal && (
-        <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
-          <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
-            <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-slate-50/50">
-              <h3 className="font-bold text-lg text-slate-800">导出代理</h3>
-              <button onClick={() => setShowExportModal(false)} className="text-slate-400 hover:text-slate-600">
-                <X size={20} />
-              </button>
-            </div>
-            <div className="p-6 space-y-4">
-              <p className="text-sm text-slate-600">
-                当前已选择 <span className="font-bold text-slate-900">{selectedProxies.length}</span> 条代理
-              </p>
-              <button
-                onClick={() => handleExport('colon')}
-                className="w-full rounded-lg border border-slate-200 px-4 py-3 text-left hover:bg-slate-50 transition"
-              >
-                <div className="font-medium text-slate-900">导出为 `ip:port:username:password`</div>
-                <div className="text-xs text-slate-500 mt-1">适合纯文本代理池导入</div>
-              </button>
-              <button
-                onClick={() => handleExport('url')}
-                className="w-full rounded-lg border border-slate-200 px-4 py-3 text-left hover:bg-slate-50 transition"
-              >
-                <div className="font-medium text-slate-900">导出为 `proto://username:password@ip:port`</div>
-                <div className="text-xs text-slate-500 mt-1">适合 URL 形式代理配置</div>
-              </button>
-              <button
-                onClick={() => handleExport('json')}
-                className="w-full rounded-lg border border-slate-200 px-4 py-3 text-left hover:bg-slate-50 transition"
-              >
-                <div className="font-medium text-slate-900">导出原始 JSON</div>
-                <div className="text-xs text-slate-500 mt-1">保留后端返回字段,便于二次处理</div>
-              </button>
-            </div>
-            <div className="px-6 py-4 bg-slate-50 flex justify-end border-t">
-              <button onClick={() => setShowExportModal(false)} className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg">关闭</button>
-            </div>
-          </div>
-        </div>
-      )}
+      <ProxyExportModal
+        isOpen={showExportModal}
+        onClose={() => setShowExportModal(false)}
+        selectedProxies={selectedProxies}
+      />
     </div>
   );
 }

+ 4 - 135
src/app/payment/confirm/page.tsx

@@ -1,144 +1,13 @@
 'use client';
 
-import { useEffect, useState, useRef, Suspense } from 'react'; // 1. 引入 Suspense
-import { useSearchParams, useRouter } from 'next/navigation';
-import api from '@/lib/api';
-import { Loader2, CheckCircle, XCircle, ArrowLeft } from 'lucide-react';
+import { Suspense } from 'react';
+import PaymentConfirmCard, { PaymentConfirmFallback } from '@/components/payment/PaymentConfirmCard';
 
-// 2. 将原来的主要逻辑提取到一个单独的组件中 (非 default export)
-function PaymentConfirmContent() {
-  const searchParams = useSearchParams();
-  const router = useRouter();
-  
-  const hasFetched = useRef(false);
-
-  const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading');
-  const [message, setMessage] = useState('正在验证支付信息...');
-  const [paymentId, setPaymentId] = useState<string>('');
-
-  useEffect(() => {
-    const pid = searchParams.get('payment_id');
-    const token = searchParams.get('token');
-
-    if (!pid || !token) {
-      setStatus('error');
-      setMessage('参数缺失:URL 中必须包含 payment_id 和 token');
-      return;
-    }
-
-    setPaymentId(pid);
-
-    const confirmPayment = async () => {
-      if (hasFetched.current) return;
-      hasFetched.current = true;
-
-      try {
-        await api.get('/api/vas/payment/confirm', {
-          params: {
-            payment_id: pid,
-            token: token
-          }
-        });
-
-        setStatus('success');
-        setMessage('支付已成功确认!系统正在处理后续流程。');
-      } catch (error: any) {
-        console.error(error);
-        setStatus('error');
-        const errorMsg = error.response?.data?.message || error.message || '未知错误';
-        setMessage(`确认失败: ${errorMsg}`);
-      }
-    };
-
-    confirmPayment();
-  }, [searchParams]);
-
-  return (
-    <div className="bg-white rounded-2xl shadow-xl w-full max-w-md overflow-hidden border border-slate-100">
-      {/* 顶部装饰条 */}
-      <div className={`h-2 w-full ${
-        status === 'loading' ? 'bg-blue-500 animate-pulse' :
-        status === 'success' ? 'bg-green-500' : 'bg-red-500'
-      }`} />
-
-      <div className="p-8 text-center">
-        {/* 图标状态 */}
-        <div className="flex justify-center mb-6">
-          {status === 'loading' && (
-            <div className="w-20 h-20 bg-blue-50 rounded-full flex items-center justify-center">
-              <Loader2 className="w-10 h-10 text-blue-600 animate-spin" />
-            </div>
-          )}
-          {status === 'success' && (
-            <div className="w-20 h-20 bg-green-50 rounded-full flex items-center justify-center animate-in zoom-in duration-300">
-              <CheckCircle className="w-10 h-10 text-green-600" />
-            </div>
-          )}
-          {status === 'error' && (
-            <div className="w-20 h-20 bg-red-50 rounded-full flex items-center justify-center animate-in zoom-in duration-300">
-              <XCircle className="w-10 h-10 text-red-600" />
-            </div>
-          )}
-        </div>
-
-        {/* 标题与描述 */}
-        <h1 className="text-xl font-bold text-slate-900 mb-2">
-          {status === 'loading' ? '处理中...' : 
-           status === 'success' ? '操作成功' : '操作失败'}
-        </h1>
-        
-        <p className={`text-sm mb-6 leading-relaxed ${
-          status === 'error' ? 'text-red-500' : 'text-slate-500'
-        }`}>
-          {message}
-        </p>
-
-        {/* 详情信息 */}
-        {status !== 'loading' && paymentId && (
-          <div className="bg-slate-50 rounded-lg p-3 mb-6 text-xs text-slate-400 font-mono">
-            Payment ID: {paymentId}
-          </div>
-        )}
-
-        {/* 底部按钮 */}
-        <div className="space-y-3">
-          <button 
-            onClick={() => router.push('/admin/orders')}
-            className="w-full flex items-center justify-center gap-2 bg-slate-900 text-white py-2.5 rounded-lg text-sm font-medium hover:bg-slate-800 transition shadow-sm"
-          >
-            <ArrowLeft size={16} /> 返回订单管理
-          </button>
-          
-          {status === 'error' && (
-            <button 
-              onClick={() => window.location.reload()}
-              className="w-full py-2.5 text-slate-600 text-sm hover:bg-slate-50 rounded-lg transition"
-            >
-              重试
-            </button>
-          )}
-        </div>
-      </div>
-    </div>
-  );
-}
-
-// 3. 定义一个 Loading Fallback 组件 (在 Suspense 加载时显示)
-function PageFallback() {
-  return (
-    <div className="bg-white rounded-2xl shadow-xl w-full max-w-md p-12 flex flex-col items-center justify-center">
-      <Loader2 className="w-10 h-10 text-blue-600 animate-spin mb-4" />
-      <p className="text-slate-500 text-sm">正在加载支付信息...</p>
-    </div>
-  );
-}
-
-// 4. 默认导出主页面组件,包裹 Suspense
 export default function PaymentConfirmPage() {
   return (
     <div className="min-h-screen bg-slate-50 flex flex-col items-center justify-center p-4">
-      <Suspense fallback={<PageFallback />}>
-        <PaymentConfirmContent />
+      <Suspense fallback={<PaymentConfirmFallback />}>
+        <PaymentConfirmCard />
       </Suspense>
 
       <p className="mt-8 text-xs text-slate-400">

+ 36 - 163
src/app/slots/page.tsx

@@ -2,17 +2,12 @@
 
 import { useState, useEffect, useMemo } from 'react';
 import api from '@/lib/api';
-import { RefreshCw, MapPin, Info, Globe, Search } from 'lucide-react';
+import { Info } from 'lucide-react';
 import { useLanguage } from '@/lib/i18n/LanguageContext';
-import CitySlotCard from '@/components/slots/CitySlotCard';
+import SlotFilterBar, { LOCATIONS } from '@/components/slots/SlotFilterBar';
+import SlotGrid from '@/components/slots/SlotGrid';
 import { SlotSnapshot } from '@/types';
 
-const LOCATIONS = [
-  { code: 'IE', name: 'Ireland', flag: '🇮🇪', cities: ['Dublin'] },
-  { code: 'GB', name: 'United Kingdom', flag: '🇬🇧', cities: ['London', 'Manchester'] },
-  { code: 'SG', name: 'Singapore', flag: '🇸🇬', cities: ['Singapore'] }
-];
-
 const SUBSCRIPTION_BLACKLIST = [
   { city: 'Dublin', country: 'France' },
 ];
@@ -34,12 +29,12 @@ export default function SlotDashboardPage() {
   const [selectedCity, setSelectedCity] = useState('Dublin');
 
   const currentCities = useMemo(() => {
-    return LOCATIONS.find(l => l.code === selectedCountryCode)?.cities || [];
+    return LOCATIONS.find((l) => l.code === selectedCountryCode)?.cities || [];
   }, [selectedCountryCode]);
 
   const handleCountryChange = (code: string) => {
     setSelectedCountryCode(code);
-    const countryData = LOCATIONS.find(l => l.code === code);
+    const countryData = LOCATIONS.find((l) => l.code === code);
     if (countryData && countryData.cities.length > 0) {
       setSelectedCity(countryData.cities[0]);
     } else {
@@ -47,95 +42,39 @@ export default function SlotDashboardPage() {
     }
   };
 
-  useEffect(() => {
-    if (selectedCity) {
-      fetchDashboard();
-    }
-  }, [selectedCity]);
-
   const fetchDashboard = async () => {
     setLoading(true);
     try {
-      // 暂时注释掉真实 API,使用下方的 Mock 数据
       const res = await api.get('/api/slots/overview', { params: { city: selectedCity } }); 
-      let data = res.data.data || [];
-      
-      // === 模拟网络延迟 ===
-      await new Promise(resolve => setTimeout(resolve, 800));
+      const data = res.data.data || [];
 
-      // === 构造 Mock 数据 ===
-      const now = new Date();
-      const subMins = (m: number) => new Date(now.getTime() - m * 60000).toISOString();
-      const subHours = (h: number) => new Date(now.getTime() - h * 3600000).toISOString();
-
-      // const mockData: SlotSnapshot[] = [
-      //   { 
-      //     id: 1, 
-      //     country: 'France', 
-      //     city: 'Dublin', 
-      //     visa_type: 'Short Stay', 
-      //     availability_status: 'Available', 
-      //     earliest_date: '2026-02-14', 
-      //     website: 'https://google.com',
-      //     snapshot_at: subMins(10),       // 数据是10分钟前更新的
-      //     last_check_at: subMins(1)       // 爬虫刚刚(1分钟前)还在跑 -> 健康 (显示呼吸灯)
-      //   },
-      //   { 
-      //     id: 2, 
-      //     country: 'Spain', 
-      //     city: 'Dublin', 
-      //     visa_type: 'Tourist', 
-      //     availability_status: 'Waitlist', 
-      //     earliest_date: null, 
-      //     website: 'https://google.com',
-      //     snapshot_at: subHours(2), 
-      //     last_check_at: subMins(5)       // 5分钟前跑过 -> 健康 (显示呼吸灯)
-      //   },
-      //   { 
-      //     id: 3, 
-      //     country: 'Italy', 
-      //     city: 'Dublin', 
-      //     visa_type: 'Tourism', 
-      //     availability_status: 'None', 
-      //     earliest_date: null, 
-      //     snapshot_at: subHours(5), 
-      //     last_check_at: subMins(2)       // 重点:虽然无号,但2分钟前刚查过 -> 增加用户信任
-      //   },
-      //   { 
-      //     id: 4, 
-      //     country: 'Germany', 
-      //     city: 'Dublin', 
-      //     visa_type: 'Business', 
-      //     availability_status: 'None', 
-      //     earliest_date: null, 
-      //     snapshot_at: subHours(10), 
-      //     last_check_at: subHours(8)      // 8小时前查的 -> 离线/过期 (无呼吸灯,提示数据旧)
-      //   }
-      // ];
-
-      // 简单过滤一下城市,模拟真实效果
-      const filtered = data.filter(i => i.city === selectedCity);
+      // 过滤当前城市
+      const filtered = data.filter((i: SlotSnapshot) => i.city === selectedCity);
       
-      // 排序
-      filtered.sort((a, b) => {
-        const score = (s: string) => s === 'Available' ? 3 : s === 'Waitlist' ? 2 : 1;
+      // 排序: Available > Waitlist > None
+      filtered.sort((a: SlotSnapshot, b: SlotSnapshot) => {
+        const score = (s: string) => (s === 'Available' ? 3 : s === 'Waitlist' ? 2 : 1);
         return score(b.availability_status) - score(a.availability_status);
       });
 
       setSnapshots(filtered);
-
     } catch (e) {
-      console.warn("Error", e);
+      console.warn('Fetch slots failed', e);
       setSnapshots([]);
     } finally {
       setLoading(false);
     }
   };
 
+  useEffect(() => {
+    if (selectedCity) {
+      fetchDashboard();
+    }
+  }, [selectedCity]);
+
   return (
     <div className="min-h-screen bg-slate-50 py-6 px-4 md:py-12 md:px-8">
       <div className="max-w-7xl mx-auto">
-        
         {/* Header */}
         <div className="mb-8">
           <h1 className="text-2xl md:text-3xl font-bold text-slate-900">{t('slots.title')}</h1>
@@ -145,90 +84,24 @@ export default function SlotDashboardPage() {
           </p>
         </div>
 
-        {/* Filter Bar */}
-        <div className="bg-white p-4 rounded-2xl shadow-sm border border-slate-200 mb-8 flex flex-col md:flex-row gap-4 items-center">
-          
-          {/* Country */}
-          <div className="w-full md:w-auto flex-1 max-w-xs relative">
-            <label className="text-xs font-bold text-slate-400 uppercase ml-1 mb-1 block">
-              Application Location (Country)
-            </label>
-            <div className="relative">
-              <select 
-                className="w-full pl-10 pr-8 py-3 border border-slate-200 rounded-xl bg-slate-50 text-sm font-bold text-slate-800 outline-none focus:ring-2 focus:ring-blue-500 appearance-none cursor-pointer"
-                value={selectedCountryCode}
-                onChange={(e) => handleCountryChange(e.target.value)}
-              >
-                {LOCATIONS.map(loc => (
-                  <option key={loc.code} value={loc.code}>
-                    {loc.flag} {loc.name}
-                  </option>
-                ))}
-              </select>
-              <Globe size={18} className="absolute left-3 top-3.5 text-slate-400 pointer-events-none" />
-              <div className="absolute right-3 top-4 pointer-events-none text-slate-400">
-                <svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L5 5L9 1" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/></svg>
-              </div>
-            </div>
-          </div>
-
-          {/* City */}
-          <div className="w-full md:w-auto flex-1 max-w-xs relative">
-            <label className="text-xs font-bold text-slate-400 uppercase ml-1 mb-1 block">
-              Application City
-            </label>
-            <div className="relative">
-              <select 
-                className="w-full pl-10 pr-8 py-3 border border-slate-200 rounded-xl bg-slate-50 text-sm font-bold text-slate-800 outline-none focus:ring-2 focus:ring-blue-500 appearance-none cursor-pointer"
-                value={selectedCity}
-                onChange={(e) => setSelectedCity(e.target.value)}
-              >
-                {currentCities.map(city => (
-                  <option key={city} value={city}>{city}</option>
-                ))}
-              </select>
-              <MapPin size={18} className="absolute left-3 top-3.5 text-slate-400 pointer-events-none" />
-              <div className="absolute right-3 top-4 pointer-events-none text-slate-400">
-                <svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L5 5L9 1" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round"/></svg>
-              </div>
-            </div>
-          </div>
-
-          {/* Refresh */}
-          <div className="w-full md:w-auto pt-5">
-            <button 
-              onClick={fetchDashboard} 
-              disabled={loading}
-              className="w-full md:w-auto flex items-center justify-center gap-2 px-6 py-3 bg-slate-900 text-white rounded-xl hover:bg-slate-800 transition disabled:opacity-70 shadow-sm active:scale-95"
-            >
-              <RefreshCw size={18} className={loading ? 'animate-spin' : ''} />
-              <span className="font-bold text-sm">{t('common.refresh') || 'Refresh'}</span>
-            </button>
-          </div>
-        </div>
-
-        {/* Grid List */}
-        {loading && snapshots.length === 0 ? (
-          <div className="text-center py-24 text-slate-400 bg-white rounded-2xl border border-dashed">
-            <RefreshCw size={32} className="animate-spin mx-auto mb-3 opacity-50" />
-            <p>正在获取 {selectedCity} 的最新数据...</p>
-          </div>
-        ) : snapshots.length === 0 ? (
-          <div className="text-center py-24 bg-white rounded-2xl border border-dashed border-slate-200">
-            <div className="mx-auto w-16 h-16 bg-slate-50 rounded-full flex items-center justify-center mb-4">
-              <Search className="text-slate-300" size={32} />
-            </div>
-            <h3 className="text-slate-900 font-bold mb-1">暂无监控数据</h3>
-            <p className="text-slate-500 text-sm">当前城市没有被监控的签证服务</p>
-          </div>
-        ) : (
-          <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
-            {snapshots.map((slot) => (
-              <CitySlotCard key={slot.id} data={slot} isBlacklisted={isBlacklisted(slot)} />
-            ))}
-          </div>
-        )}
-
+        {/* Filter Bar 组件 */}
+        <SlotFilterBar
+          selectedCountryCode={selectedCountryCode}
+          selectedCity={selectedCity}
+          currentCities={currentCities}
+          onCountryChange={handleCountryChange}
+          onCityChange={setSelectedCity}
+          onRefresh={fetchDashboard}
+          loading={loading}
+        />
+
+        {/* Grid List 组件 */}
+        <SlotGrid
+          loading={loading}
+          snapshots={snapshots}
+          selectedCity={selectedCity}
+          isBlacklisted={isBlacklisted}
+        />
       </div>
     </div>
   );

+ 148 - 0
src/components/admin/accounts/AccountAddModal.tsx

@@ -0,0 +1,148 @@
+'use client';
+
+import { useState, useEffect } from 'react';
+import { X } from 'lucide-react';
+import { toast } from 'react-hot-toast';
+import api from '@/lib/api';
+import { AccountStatus } from '@/types';
+
+const DEFAULT_EXTRA_DATA = '{}';
+
+interface AccountAddModalProps {
+  isOpen: boolean;
+  onClose: () => void;
+  onSuccess: () => void;
+}
+
+export default function AccountAddModal({ isOpen, onClose, onSuccess }: AccountAddModalProps) {
+  const [form, setForm] = useState({
+    pool_name: '',
+    username: '',
+    password: '',
+    extra_data_str: DEFAULT_EXTRA_DATA,
+    status: 'active' as AccountStatus,
+  });
+  const [submitting, setSubmitting] = useState(false);
+
+  useEffect(() => {
+    if (isOpen) {
+      setForm({
+        pool_name: '',
+        username: '',
+        password: '',
+        extra_data_str: DEFAULT_EXTRA_DATA,
+        status: 'active',
+      });
+    }
+  }, [isOpen]);
+
+  if (!isOpen) return null;
+
+  const handleSubmit = async () => {
+    try {
+      let extraDataJson: Record<string, any> | null = null;
+      try {
+        extraDataJson = form.extra_data_str.trim() ? JSON.parse(form.extra_data_str) : null;
+      } catch {
+        toast.error('Extra Data 必须是 JSON 格式');
+        return;
+      }
+
+      setSubmitting(true);
+      await api.post('/api/account/add', {
+        pool_name: form.pool_name,
+        username: form.username,
+        password: form.password || null,
+        extra_data: extraDataJson,
+        status: form.status || null,
+      });
+
+      toast.success('添加成功');
+      onClose();
+      onSuccess();
+    } catch (error) {
+      toast.error('添加失败');
+    } finally {
+      setSubmitting(false);
+    }
+  };
+
+  return (
+    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
+      <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
+        <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-slate-50/50">
+          <h3 className="font-bold text-lg text-slate-800">新增账号</h3>
+          <button onClick={onClose} className="text-slate-400 hover:text-slate-600">
+            <X size={20} />
+          </button>
+        </div>
+        <div className="p-6 space-y-4 max-h-[80vh] overflow-y-auto">
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Pool Name</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.pool_name}
+              onChange={(e) => setForm({ ...form, pool_name: e.target.value })}
+            />
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Username</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.username}
+              onChange={(e) => setForm({ ...form, username: e.target.value })}
+            />
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Password</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.password}
+              onChange={(e) => setForm({ ...form, password: e.target.value })}
+            />
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Status</label>
+            <select
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white"
+              value={form.status}
+              onChange={(e) => setForm({ ...form, status: e.target.value as AccountStatus })}
+            >
+              <option value="active">active</option>
+              <option value="disable">disable</option>
+            </select>
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Extra Data (JSON)</label>
+            <textarea
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none font-mono text-xs bg-slate-50"
+              rows={4}
+              value={form.extra_data_str}
+              onChange={(e) => setForm({ ...form, extra_data_str: e.target.value })}
+              placeholder='{"country": "fr"}'
+            />
+          </div>
+        </div>
+        <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
+          <button
+            onClick={onClose}
+            className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg transition"
+            disabled={submitting}
+          >
+            取消
+          </button>
+          <button
+            onClick={handleSubmit}
+            className="px-4 py-2 text-sm font-bold bg-slate-900 text-white rounded-lg hover:bg-slate-800 transition disabled:opacity-50"
+            disabled={submitting}
+          >
+            {submitting ? '提交中...' : '确认添加'}
+          </button>
+        </div>
+      </div>
+    </div>
+  );
+}

+ 208 - 0
src/components/admin/accounts/AccountEditModal.tsx

@@ -0,0 +1,208 @@
+'use client';
+
+import { useState, useEffect } from 'react';
+import { X, Pencil } from 'lucide-react';
+import { toast } from 'react-hot-toast';
+import api from '@/lib/api';
+import LocalTime from '@/components/common/LocalTime';
+import { Account, AccountStatus } from '@/types';
+
+const DEFAULT_EXTRA_DATA = '{}';
+
+function parseUtcDateTime(value?: string | null) {
+  if (!value) return null;
+  const normalized = value.trim().replace(' ', 'T');
+  const hasTimezone = /[zZ]|[+-]\d{2}:\d{2}$/.test(normalized);
+  const utcValue = hasTimezone ? normalized : `${normalized}Z`;
+  const timestamp = new Date(utcValue).getTime();
+
+  return Number.isNaN(timestamp) ? null : timestamp;
+}
+
+function toDatetimeLocalValue(value?: string | null) {
+  if (!value) return '';
+  const timestamp = parseUtcDateTime(value);
+  if (timestamp === null) return '';
+  const date = new Date(timestamp);
+  const offset = date.getTimezoneOffset();
+  const localDate = new Date(date.getTime() - offset * 60 * 1000);
+  return localDate.toISOString().slice(0, 16);
+}
+
+function toApiDateTime(value: string) {
+  if (!value) return null;
+  const date = new Date(value);
+  if (Number.isNaN(date.getTime())) return null;
+  return date.toISOString();
+}
+
+interface AccountEditModalProps {
+  isOpen: boolean;
+  onClose: () => void;
+  account: Account | null;
+  onSuccess: () => void;
+}
+
+export default function AccountEditModal({ isOpen, onClose, account, onSuccess }: AccountEditModalProps) {
+  const [form, setForm] = useState({
+    pool_name: '',
+    username: '',
+    password: '',
+    extra_data_str: DEFAULT_EXTRA_DATA,
+    status: 'active' as AccountStatus,
+    next_use_time: '',
+  });
+  const [submitting, setSubmitting] = useState(false);
+
+  useEffect(() => {
+    if (isOpen && account) {
+      setForm({
+        pool_name: account.pool_name || '',
+        username: account.username || '',
+        password: account.password || '',
+        extra_data_str: JSON.stringify(account.extra_data || {}, null, 2),
+        status: (account.status?.toLowerCase() === 'disable' ? 'disable' : 'active') as AccountStatus,
+        next_use_time: toDatetimeLocalValue(account.next_use_time),
+      });
+    }
+  }, [isOpen, account]);
+
+  if (!isOpen || !account) return null;
+
+  const handleSubmit = async () => {
+    try {
+      let extraDataJson: Record<string, any> | null = null;
+      try {
+        extraDataJson = form.extra_data_str.trim() ? JSON.parse(form.extra_data_str) : null;
+      } catch {
+        toast.error('Extra Data 必须是 JSON 格式');
+        return;
+      }
+
+      setSubmitting(true);
+      await api.put('/api/account/update', {
+        pool_name: form.pool_name || null,
+        username: form.username || null,
+        password: form.password || null,
+        extra_data: extraDataJson,
+        status: form.status || null,
+        next_use_time: toApiDateTime(form.next_use_time),
+      }, {
+        params: { account_id: account.id },
+      });
+
+      toast.success('修改成功');
+      onClose();
+      onSuccess();
+    } catch (error) {
+      toast.error('修改失败');
+    } finally {
+      setSubmitting(false);
+    }
+  };
+
+  return (
+    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
+      <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
+        <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-blue-50/50">
+          <h3 className="font-bold text-lg text-blue-900 flex items-center gap-2">
+            <Pencil size={18} /> 编辑账号
+          </h3>
+          <button onClick={onClose} className="text-slate-400 hover:text-slate-600">
+            <X size={20} />
+          </button>
+        </div>
+        <div className="p-6 space-y-4 max-h-[80vh] overflow-y-auto">
+          <div className="text-sm text-slate-600 bg-blue-50 p-3 rounded-lg border border-blue-100">
+            ID: <span className="font-bold text-slate-900">#{account.id}</span>
+            <br />
+            Created:{' '}
+            <span className="font-bold text-slate-900">
+              {account.created_at ? <LocalTime date={account.created_at} /> : '-'}
+            </span>
+            <br />
+            Updated:{' '}
+            <span className="font-bold text-slate-900">
+              {account.updated_at ? <LocalTime date={account.updated_at} /> : '-'}
+            </span>
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Pool Name</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.pool_name}
+              onChange={(e) => setForm({ ...form, pool_name: e.target.value })}
+            />
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Username</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.username}
+              onChange={(e) => setForm({ ...form, username: e.target.value })}
+            />
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Password</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm font-mono"
+              value={form.password}
+              onChange={(e) => setForm({ ...form, password: e.target.value })}
+            />
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Status</label>
+            <select
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white"
+              value={form.status}
+              onChange={(e) => setForm({ ...form, status: e.target.value as AccountStatus })}
+            >
+              <option value="active">active</option>
+              <option value="disable">disable</option>
+            </select>
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Next Use Time</label>
+            <input
+              type="datetime-local"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.next_use_time}
+              onChange={(e) => setForm({ ...form, next_use_time: e.target.value })}
+            />
+            <p className="mt-1 text-xs text-slate-500">
+              {account.next_use_time ? <LocalTime date={account.next_use_time} /> : '未设置'}
+            </p>
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Extra Data (JSON)</label>
+            <textarea
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none font-mono text-xs bg-slate-50"
+              rows={6}
+              value={form.extra_data_str}
+              onChange={(e) => setForm({ ...form, extra_data_str: e.target.value })}
+            />
+          </div>
+        </div>
+        <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
+          <button
+            onClick={onClose}
+            className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg transition"
+            disabled={submitting}
+          >
+            取消
+          </button>
+          <button
+            onClick={handleSubmit}
+            className="px-4 py-2 text-sm font-bold bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition disabled:opacity-50"
+            disabled={submitting}
+          >
+            {submitting ? '保存中...' : '保存修改'}
+          </button>
+        </div>
+      </div>
+    </div>
+  );
+}

+ 109 - 0
src/components/admin/accounts/AccountLockModal.tsx

@@ -0,0 +1,109 @@
+'use client';
+
+import { useState, useEffect } from 'react';
+import { X, Lock } from 'lucide-react';
+import { Account } from '@/types';
+
+interface AccountLockModalProps {
+  isOpen: boolean;
+  onClose: () => void;
+  account: Account | null;
+  onLock: (account: Account, unlock: boolean, duration: number) => Promise<void>;
+}
+
+export default function AccountLockModal({ isOpen, onClose, account, onLock }: AccountLockModalProps) {
+  const [lockDuration, setLockDuration] = useState<number>(3600);
+  const [submitting, setSubmitting] = useState(false);
+
+  useEffect(() => {
+    if (isOpen) {
+      setLockDuration(3600);
+    }
+  }, [isOpen]);
+
+  if (!isOpen || !account) return null;
+
+  const handleAction = async (unlock: boolean) => {
+    setSubmitting(true);
+    try {
+      await onLock(account, unlock, lockDuration);
+      onClose();
+    } finally {
+      setSubmitting(false);
+    }
+  };
+
+  return (
+    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
+      <div className="bg-white rounded-xl shadow-2xl w-full max-w-sm overflow-hidden">
+        <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-orange-50/50">
+          <h3 className="font-bold text-lg text-orange-900 flex items-center gap-2">
+            <Lock size={18} /> 锁定账号
+          </h3>
+          <button onClick={onClose} className="text-slate-400 hover:text-slate-600">
+            <X size={20} />
+          </button>
+        </div>
+        <div className="p-6 space-y-4">
+          <p className="text-sm text-slate-600 bg-orange-50 p-3 rounded-lg border border-orange-100">
+            账号: <span className="font-bold text-slate-900">{account.username}</span>
+          </p>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">持续时间 (秒)</label>
+            <input
+              type="number"
+              min="0"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-orange-500 outline-none font-mono"
+              value={lockDuration}
+              onChange={(e) => setLockDuration(Number(e.target.value))}
+            />
+            <div className="flex gap-2 mt-2">
+              <button
+                type="button"
+                onClick={() => setLockDuration(3600)}
+                className="flex-1 text-xs bg-slate-100 border px-2 py-1 rounded hover:bg-slate-200 transition"
+              >
+                1小时
+              </button>
+              <button
+                type="button"
+                onClick={() => setLockDuration(86400)}
+                className="flex-1 text-xs bg-slate-100 border px-2 py-1 rounded hover:bg-slate-200 transition"
+              >
+                1天
+              </button>
+            </div>
+          </div>
+        </div>
+        <div className="px-6 py-4 bg-slate-50 flex justify-between gap-3 border-t">
+          <button
+            type="button"
+            onClick={() => handleAction(true)}
+            className="px-4 py-2 text-sm text-green-600 hover:bg-green-100 rounded-lg transition disabled:opacity-50"
+            disabled={submitting}
+          >
+            直接解锁
+          </button>
+          <div className="flex gap-3 ml-auto">
+            <button
+              type="button"
+              onClick={onClose}
+              className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg transition"
+              disabled={submitting}
+            >
+              取消
+            </button>
+            <button
+              type="button"
+              onClick={() => handleAction(false)}
+              className="px-4 py-2 text-sm font-bold bg-orange-600 text-white rounded-lg hover:bg-orange-700 transition disabled:opacity-50"
+              disabled={submitting}
+            >
+              {submitting ? '处理中...' : '确认锁定'}
+            </button>
+          </div>
+        </div>
+      </div>
+    </div>
+  );
+}

+ 51 - 0
src/components/admin/accounts/AccountRegistrationModal.tsx

@@ -0,0 +1,51 @@
+'use client';
+
+import { X, User } from 'lucide-react';
+import { Account } from '@/types';
+
+interface AccountRegistrationModalProps {
+  isOpen: boolean;
+  onClose: () => void;
+  account: Account | null;
+}
+
+export default function AccountRegistrationModal({
+  isOpen,
+  onClose,
+  account,
+}: AccountRegistrationModalProps) {
+  if (!isOpen || !account) return null;
+
+  return (
+    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
+      <div className="bg-white rounded-xl shadow-2xl w-full max-w-lg overflow-hidden">
+        <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-blue-50/50">
+          <h3 className="font-bold text-lg text-blue-900 flex items-center gap-2">
+            <User size={18} /> 注册信息
+          </h3>
+          <button onClick={onClose} className="text-slate-400 hover:text-slate-600">
+            <X size={20} />
+          </button>
+        </div>
+        <div className="p-6 space-y-4">
+          <p className="text-sm text-slate-600 bg-blue-50 p-3 rounded-lg border border-blue-100">
+            账号: <span className="font-bold text-slate-900">{account.username}</span>
+          </p>
+          <div className="bg-slate-50 p-4 rounded-lg border border-slate-200">
+            <pre className="text-xs font-mono text-slate-700 whitespace-pre-wrap overflow-x-auto">
+              {JSON.stringify(account.extra_data || {}, null, 2)}
+            </pre>
+          </div>
+        </div>
+        <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
+          <button
+            onClick={onClose}
+            className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg transition"
+          >
+            关闭
+          </button>
+        </div>
+      </div>
+    </div>
+  );
+}

+ 217 - 0
src/components/admin/configurations/ConfigurationModal.tsx

@@ -0,0 +1,217 @@
+'use client';
+
+import { useState, useEffect, useCallback } from 'react';
+import { X, Save, Loader2, AlertCircle } from 'lucide-react';
+import JsonConfigEditor from '@/components/common/JsonConfigEditor';
+import api from '@/lib/api';
+import { DynamicConfiguration } from '@/types';
+
+type ConfigurationForm = DynamicConfiguration;
+
+const emptyForm: ConfigurationForm = {
+  config_key: '',
+  config_value: '',
+  description: '',
+  type: '',
+};
+
+interface ConfigurationModalProps {
+  isOpen: boolean;
+  onClose: () => void;
+  config: DynamicConfiguration | null;
+  onSuccess: () => void;
+}
+
+export default function ConfigurationModal({
+  isOpen,
+  onClose,
+  config,
+  onSuccess,
+}: ConfigurationModalProps) {
+  const [form, setForm] = useState<ConfigurationForm>(emptyForm);
+  const [submitting, setSubmitting] = useState(false);
+  const [valueJsonError, setValueJsonError] = useState<string | null>(null);
+
+  useEffect(() => {
+    if (isOpen) {
+      if (config) {
+        let displayValue = config.config_value;
+        try {
+          displayValue = JSON.stringify(JSON.parse(config.config_value), null, 2);
+        } catch (e) {
+          // not standard JSON, keep as-is
+        }
+        setForm({ ...config, config_value: displayValue });
+      } else {
+        setForm(emptyForm);
+      }
+      setValueJsonError(null);
+    }
+  }, [isOpen, config]);
+
+  const handleValueValidityChange = useCallback((isValid: boolean, error: string | null) => {
+    setValueJsonError(isValid ? null : error || 'JSON 语法错误');
+  }, []);
+
+  if (!isOpen) return null;
+
+  const handleSubmit = async (e: React.FormEvent) => {
+    e.preventDefault();
+
+    const payload: DynamicConfiguration = {
+      config_key: form.config_key.trim(),
+      config_value: form.config_value,
+      description: form.description.trim(),
+      type: form.type.trim(),
+    };
+
+    if (!payload.config_key) {
+      alert('配置 Key 不能为空');
+      return;
+    }
+
+    if (valueJsonError) {
+      alert('配置值 JSON 语法错误,请修复后再保存');
+      return;
+    }
+
+    setSubmitting(true);
+    try {
+      if (config?.config_key) {
+        await api.put(
+          `/api/dynamic-configurations/key/${encodeURIComponent(config.config_key)}`,
+          payload
+        );
+      } else {
+        await api.post('/api/dynamic-configurations', payload);
+      }
+
+      alert(config ? '配置已更新' : '配置已创建');
+      onClose();
+      onSuccess();
+    } catch (e: any) {
+      console.error(e);
+      alert('保存失败: ' + (e.response?.data?.message || e.message || '未知错误'));
+    } finally {
+      setSubmitting(false);
+    }
+  };
+
+  return (
+    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm p-4">
+      <div className="bg-white rounded-xl shadow-2xl w-full max-w-[1400px] h-[95vh] overflow-hidden flex flex-col">
+        {/* Header */}
+        <div className="px-5 py-3 border-b flex items-center justify-between bg-white shrink-0">
+          <div className="flex items-center gap-3">
+            <h3 className="font-bold text-lg text-slate-800">
+              {config ? '编辑动态配置' : '新增动态配置'}
+            </h3>
+            {config && (
+              <span className="px-2 py-1 bg-blue-50 text-blue-700 text-xs rounded-md font-mono">
+                {config.config_key}
+              </span>
+            )}
+          </div>
+          <button
+            onClick={onClose}
+            disabled={submitting}
+            className="p-2 hover:bg-slate-100 rounded-full transition text-slate-500"
+          >
+            <X size={20} />
+          </button>
+        </div>
+
+        {/* Body */}
+        <form onSubmit={handleSubmit} className="flex-1 flex flex-col min-h-0">
+          <div className="flex-1 flex flex-col lg:flex-row min-h-0 bg-slate-50/50">
+            {/* 左侧:JSON 编辑器 */}
+            <div className="flex-1 flex flex-col min-h-0 p-4">
+              <div className="flex-1 min-h-0 border border-slate-200 shadow-sm rounded-lg overflow-hidden bg-white">
+                <JsonConfigEditor
+                  type={form.type}
+                  value={form.config_value}
+                  onChange={(configValue) => setForm({ ...form, config_value: configValue })}
+                  onValidityChange={handleValueValidityChange}
+                />
+              </div>
+            </div>
+
+            {/* 右侧:属性面板 */}
+            <div className="w-full lg:w-[320px] bg-white border-t lg:border-t-0 lg:border-l border-slate-200 p-5 shrink-0 overflow-y-auto">
+              <h4 className="text-sm font-bold text-slate-800 mb-4 pb-2 border-b border-slate-100">基础属性</h4>
+
+              <div className="space-y-5">
+                <label className="block">
+                  <span className="block text-sm font-semibold text-slate-700 mb-1.5">配置 Key</span>
+                  <input
+                    type="text"
+                    value={form.config_key}
+                    onChange={(e) => setForm({ ...form, config_key: e.target.value })}
+                    className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none transition bg-slate-50 font-mono"
+                    placeholder="CONFIG_KEY"
+                    required
+                    disabled={!!config}
+                  />
+                  <p className="text-xs text-slate-400 mt-1">唯一键,供后端读取使用</p>
+                </label>
+
+                <label className="block">
+                  <span className="block text-sm font-semibold text-slate-700 mb-1.5">类型 (Type)</span>
+                  <input
+                    type="text"
+                    value={form.type}
+                    onChange={(e) => setForm({ ...form, type: e.target.value })}
+                    className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none transition font-mono"
+                    placeholder="json / string / ..."
+                  />
+                </label>
+
+                <label className="block">
+                  <span className="block text-sm font-semibold text-slate-700 mb-1.5">用途描述</span>
+                  <textarea
+                    rows={5}
+                    value={form.description}
+                    onChange={(e) => setForm({ ...form, description: e.target.value })}
+                    className="w-full px-3 py-2 border border-slate-300 rounded-lg text-sm focus:ring-2 focus:ring-blue-500 outline-none transition resize-none leading-relaxed"
+                    placeholder="该配置的用途、结构说明及注意事项..."
+                  />
+                </label>
+              </div>
+            </div>
+          </div>
+
+          {/* Footer */}
+          <div className="px-5 py-3 border-t bg-white flex items-center justify-between shrink-0">
+            <div className="text-sm font-medium text-red-600 flex items-center gap-2">
+              {valueJsonError && (
+                <>
+                  <AlertCircle size={16} />
+                  {valueJsonError}
+                </>
+              )}
+            </div>
+
+            <div className="flex gap-3">
+              <button
+                type="button"
+                onClick={onClose}
+                className="px-5 py-2 text-slate-600 hover:bg-slate-100 rounded-lg transition font-medium"
+                disabled={submitting}
+              >
+                取消
+              </button>
+              <button
+                type="submit"
+                disabled={submitting || Boolean(valueJsonError)}
+                className="flex items-center gap-2 px-6 py-2 bg-blue-600 text-white rounded-lg hover:bg-blue-700 shadow-sm transition disabled:opacity-70 disabled:cursor-not-allowed font-medium"
+              >
+                {submitting ? <Loader2 size={16} className="animate-spin" /> : <Save size={16} />}
+                保存配置
+              </button>
+            </div>
+          </div>
+        </form>
+      </div>
+    </div>
+  );
+}

+ 73 - 0
src/components/admin/configurations/ConfigurationTable.tsx

@@ -0,0 +1,73 @@
+'use client';
+
+import { Edit3, Loader2, SlidersHorizontal } from 'lucide-react';
+import { DynamicConfiguration } from '@/types';
+
+interface ConfigurationTableProps {
+  configs: DynamicConfiguration[];
+  loading: boolean;
+  onEdit: (config: DynamicConfiguration) => void;
+}
+
+export default function ConfigurationTable({ configs, loading, onEdit }: ConfigurationTableProps) {
+  return (
+    <div className="bg-white border border-slate-200 rounded-lg overflow-hidden">
+      <div className="hidden md:grid grid-cols-[80px_2fr_1fr_3fr_100px] gap-4 px-4 py-3 bg-slate-50 border-b border-slate-200 text-xs font-bold text-slate-500 uppercase">
+        <div>ID</div>
+        <div>Key</div>
+        <div>Type</div>
+        <div>Description</div>
+        <div className="text-right">Actions</div>
+      </div>
+
+      {loading ? (
+        <div className="flex items-center justify-center py-16 text-slate-400">
+          <Loader2 size={28} className="animate-spin mr-2" />
+          正在读取配置...
+        </div>
+      ) : configs.length === 0 ? (
+        <div className="flex flex-col items-center justify-center py-16 text-slate-400">
+          <SlidersHorizontal size={32} className="mb-2" />
+          暂无配置数据
+        </div>
+      ) : (
+        <div className="divide-y divide-slate-100">
+          {configs.map((item) => (
+            <div
+              key={`${item.id || 'new'}-${item.config_key}`}
+              className="grid grid-cols-1 md:grid-cols-[80px_2fr_1fr_3fr_100px] gap-3 md:gap-4 px-4 py-4 hover:bg-slate-50 transition items-center"
+            >
+              <div className="text-sm text-slate-500">
+                <span className="md:hidden text-xs font-semibold text-slate-400 mr-2">ID</span>
+                {item.id ?? '-'}
+              </div>
+              <div className="min-w-0">
+                <div className="md:hidden text-xs font-semibold text-slate-400 mb-1">Key</div>
+                <code className="text-sm font-semibold text-blue-700 break-all">{item.config_key}</code>
+              </div>
+              <div>
+                <div className="md:hidden text-xs font-semibold text-slate-400 mb-1">Type</div>
+                <span className="inline-flex max-w-full px-2 py-1 bg-slate-100 text-slate-700 rounded text-xs font-medium break-all">
+                  {item.type || '未分类'}
+                </span>
+              </div>
+              <div className="min-w-0 text-sm text-slate-600 break-words">
+                <div className="md:hidden text-xs font-semibold text-slate-400 mb-1">Description</div>
+                {item.description || <span className="text-slate-400">无描述</span>}
+              </div>
+
+              <div className="flex md:justify-end">
+                <button
+                  onClick={() => onEdit(item)}
+                  className="inline-flex items-center gap-2 px-3 py-2 text-sm font-medium text-blue-700 bg-blue-50 hover:bg-blue-100 rounded-lg transition"
+                >
+                  <Edit3 size={14} /> 编辑
+                </button>
+              </div>
+            </div>
+          ))}
+        </div>
+      )}
+    </div>
+  );
+}

+ 56 - 0
src/components/admin/dashboard/RecentActivities.tsx

@@ -0,0 +1,56 @@
+'use client';
+
+export interface ActivityItem {
+  id: string;
+  text: string;
+  time: string;
+  type: 'order' | 'money' | 'ticket' | 'system';
+}
+
+interface RecentActivitiesProps {
+  activities: ActivityItem[];
+  loading: boolean;
+}
+
+export default function RecentActivities({ activities, loading }: RecentActivitiesProps) {
+  return (
+    <div className="lg:col-span-2 bg-white p-6 rounded-xl shadow-sm border border-slate-100">
+      <div className="flex justify-between items-center mb-4">
+        <h3 className="font-bold text-slate-800">最新系统动态</h3>
+        <button className="text-xs text-blue-600 hover:underline">查看全部日志</button>
+      </div>
+
+      {loading && activities.length === 0 ? (
+        <div className="py-10 text-center text-slate-400">加载中...</div>
+      ) : activities.length === 0 ? (
+        <div className="py-10 text-center text-slate-400">暂无最新动态</div>
+      ) : (
+        <div className="space-y-4">
+          {activities.map((item) => (
+            <div
+              key={item.id}
+              className="flex items-start gap-3 pb-3 border-b border-slate-50 last:border-0 last:pb-0"
+            >
+              {/* 根据类型显示不同颜色的圆点 */}
+              <div
+                className={`mt-1 w-2 h-2 rounded-full flex-shrink-0 ${
+                  item.type === 'order'
+                    ? 'bg-blue-500'
+                    : item.type === 'money'
+                    ? 'bg-green-500'
+                    : item.type === 'ticket'
+                    ? 'bg-orange-500'
+                    : 'bg-gray-400'
+                }`}
+              />
+              <div className="flex-1">
+                <p className="text-sm text-slate-700">{item.text}</p>
+                <p className="text-xs text-slate-400 mt-0.5">{item.time}</p>
+              </div>
+            </div>
+          ))}
+        </div>
+      )}
+    </div>
+  );
+}

+ 88 - 0
src/components/admin/orders/AiDataParserPanel.tsx

@@ -0,0 +1,88 @@
+'use client';
+
+import { useState } from 'react';
+import { Bot, Sparkles, Loader2, Wand2 } from 'lucide-react';
+import api from '@/lib/api';
+
+interface AiDataParserPanelProps {
+  schemaId: number | string | undefined;
+  onFieldsParsed: (fields: Record<string, any>) => void;
+}
+
+export default function AiDataParserPanel({ schemaId, onFieldsParsed }: AiDataParserPanelProps) {
+  const [rawInput, setRawInput] = useState('');
+  const [parsing, setParsing] = useState(false);
+
+  const handleAiParse = async () => {
+    if (!rawInput.trim()) {
+      alert('请先粘贴需要解析的文本内容');
+      return;
+    }
+    if (!schemaId) {
+      alert('AI 解析依赖于 Schema,请先选择商品');
+      return;
+    }
+
+    setParsing(true);
+    try {
+      const res = await api.post('/api/vas/llm/data_parsing', {
+        input_raw_str: rawInput,
+        schema_id: schemaId,
+      });
+
+      const responseData = res.data?.data || res.data;
+      const fieldsToFill = responseData?.parsed_obj || responseData;
+
+      if (fieldsToFill && typeof fieldsToFill === 'object') {
+        onFieldsParsed(fieldsToFill);
+        const count = Object.keys(fieldsToFill).length;
+        alert(`✨ AI 成功识别并填充了 ${count} 个字段!`);
+      } else {
+        alert('解析失败:未能识别有效数据');
+      }
+    } catch (e: any) {
+      console.error(e);
+      alert('解析失败: ' + (e.response?.data?.message || e.message));
+    } finally {
+      setParsing(false);
+    }
+  };
+
+  return (
+    <div className="bg-gradient-to-r from-violet-50 to-fuchsia-50 p-6 border-b border-violet-100">
+      <div className="flex items-start gap-3">
+        <div className="p-2 bg-white rounded-lg shadow-sm text-violet-600 mt-1">
+          <Bot size={24} />
+        </div>
+        <div className="flex-1">
+          <h3 className="font-bold text-violet-900 text-base mb-1 flex items-center gap-2">
+            AI 智能填表助手 <Sparkles size={16} className="text-amber-500 animate-pulse" />
+          </h3>
+          <p className="text-xs text-violet-600 mb-3">
+            直接粘贴客户发来的聊天记录、邮件或证件文本,AI 将自动识别并填充到下方表单。
+          </p>
+
+          <div className="relative">
+            <textarea
+              className="w-full border border-violet-200 rounded-xl p-4 text-sm focus:ring-2 focus:ring-violet-500 outline-none resize-none shadow-sm min-h-[100px] bg-white/80 focus:bg-white transition"
+              placeholder="例如:&#10;姓名:张三&#10;护照号:E12345678&#10;出生日期:1990-01-01&#10;..."
+              value={rawInput}
+              onChange={(e) => setRawInput(e.target.value)}
+            />
+            <div className="absolute bottom-3 right-3">
+              <button
+                type="button"
+                disabled={parsing || !rawInput.trim()}
+                onClick={handleAiParse}
+                className="bg-violet-600 text-white px-4 py-2 rounded-lg text-xs font-bold hover:bg-violet-700 transition flex items-center gap-2 shadow-md disabled:opacity-50 disabled:cursor-not-allowed transform active:scale-95"
+              >
+                {parsing ? <Loader2 size={14} className="animate-spin" /> : <Wand2 size={14} />}
+                {parsing ? 'AI 正在分析...' : '一键识别填充'}
+              </button>
+            </div>
+          </div>
+        </div>
+      </div>
+    </div>
+  );
+}

+ 127 - 0
src/components/admin/orders/DynamicOrderSchemaForm.tsx

@@ -0,0 +1,127 @@
+'use client';
+
+import { Loader2, Check, CheckCircle, Info } from 'lucide-react';
+import { SchemaProperty } from '@/types';
+
+interface DynamicOrderSchemaFormProps {
+  formSchema: any;
+  sortedFields: string[];
+  formValues: Record<string, any>;
+  onInputChange: (key: string, value: any) => void;
+  onSubmit: (e: React.FormEvent) => void;
+  loading: boolean;
+  selectedProduct: any;
+}
+
+export default function DynamicOrderSchemaForm({
+  formSchema,
+  sortedFields,
+  formValues,
+  onInputChange,
+  onSubmit,
+  loading,
+  selectedProduct,
+}: DynamicOrderSchemaFormProps) {
+  const renderField = (key: string, fieldSchema: SchemaProperty) => {
+    const commonClass =
+      'w-full border border-slate-300 rounded-lg p-2.5 text-sm focus:ring-2 focus:ring-blue-500 outline-none transition bg-white';
+    const label = fieldSchema.title || key;
+    const placeholder = fieldSchema.description || `请输入 ${label}`;
+    const currentValue = formValues[key] || '';
+
+    if (fieldSchema.enum && fieldSchema.enum.length > 0) {
+      return (
+        <select
+          className={commonClass}
+          onChange={(e) => onInputChange(key, e.target.value)}
+          value={currentValue}
+        >
+          <option value="">请选择 {label}</option>
+          {fieldSchema.enum.map((v: string) => (
+            <option key={v} value={v}>
+              {v}
+            </option>
+          ))}
+        </select>
+      );
+    }
+
+    if (fieldSchema.format === 'date') {
+      return (
+        <input
+          type="date"
+          className={commonClass}
+          onChange={(e) => onInputChange(key, e.target.value)}
+          value={currentValue}
+        />
+      );
+    }
+
+    return (
+      <input
+        type={fieldSchema.type === 'integer' || fieldSchema.type === 'number' ? 'number' : 'text'}
+        className={commonClass}
+        placeholder={placeholder}
+        onChange={(e) => onInputChange(key, e.target.value)}
+        value={currentValue}
+      />
+    );
+  };
+
+  return (
+    <div className="p-6">
+      {!formSchema ? (
+        <div className="text-center py-8 text-slate-400 text-sm flex flex-col items-center">
+          <Loader2 className="animate-spin mb-2" /> 正在加载表单定义...
+        </div>
+      ) : (
+        <div className="grid grid-cols-1 md:grid-cols-2 gap-x-8 gap-y-6">
+          {sortedFields.map((key) => {
+            const fieldSchema = formSchema.properties[key] as SchemaProperty;
+            const hasValue = formValues[key] !== undefined && formValues[key] !== '';
+
+            return (
+              <div key={key}>
+                <label className="block text-sm font-bold text-slate-700 mb-2 ml-1 flex items-center gap-2">
+                  {fieldSchema.title || key}
+                  {hasValue && <Check size={14} className="text-green-500" />}
+                </label>
+                {renderField(key, fieldSchema)}
+                {fieldSchema.description && (
+                  <p className="text-xs text-gray-400 mt-1.5 ml-1">{fieldSchema.description}</p>
+                )}
+              </div>
+            );
+          })}
+
+          {sortedFields.length === 0 && (
+            <div className="col-span-2 text-center text-slate-400 text-sm py-4 bg-slate-50 rounded-lg border border-dashed border-slate-200">
+              此商品无需填写额外信息
+            </div>
+          )}
+        </div>
+      )}
+
+      {/* Footer Action */}
+      <div className="mt-6 pt-6 bg-slate-50 -mx-6 -mb-6 p-6 border-t border-slate-100 flex items-center justify-between">
+        <div className="hidden md:flex text-xs text-slate-500 max-w-md items-start gap-2">
+          <Info size={16} className="shrink-0 mt-0.5 text-blue-500" />
+          <div>
+            <span className="font-bold text-slate-700">下单说明:</span>
+            系统将自动创建订单并标记为 <span className="font-bold text-green-600">PAID</span>
+            ,机器人任务将立即启动。
+          </div>
+        </div>
+
+        <button
+          type="submit"
+          disabled={loading || !selectedProduct}
+          className="w-full md:w-auto px-8 py-3.5 bg-slate-900 text-white rounded-xl font-bold hover:bg-slate-800 transition flex items-center justify-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed shadow-lg shadow-slate-300 transform active:scale-95"
+        >
+          {loading ? <Loader2 className="animate-spin" /> : <CheckCircle size={18} />}
+          确认创建订单
+        </button>
+      </div>
+    </div>
+  );
+}

+ 135 - 0
src/components/admin/orders/ProductSearchSelector.tsx

@@ -0,0 +1,135 @@
+'use client';
+
+import { useState, useEffect } from 'react';
+import { Search, Loader2, CheckCircle, Package } from 'lucide-react';
+import { useDebounce } from 'use-debounce';
+import api from '@/lib/api';
+
+interface ProductSearchSelectorProps {
+  selectedProduct: any | null;
+  onSelectProduct: (product: any | null) => void;
+}
+
+export default function ProductSearchSelector({
+  selectedProduct,
+  onSelectProduct,
+}: ProductSearchSelectorProps) {
+  const [keyword, setKeyword] = useState('');
+  const [debouncedKeyword] = useDebounce(keyword, 500);
+  const [productList, setProductList] = useState<any[]>([]);
+  const [isSearchingProduct, setIsSearchingProduct] = useState(false);
+
+  useEffect(() => {
+    if (!debouncedKeyword) {
+      setProductList([]);
+      return;
+    }
+
+    async function searchProducts() {
+      setIsSearchingProduct(true);
+      try {
+        const res = await api.get('/api/vas/product/list', {
+          params: { keyword: debouncedKeyword, page: 1, size: 20 },
+        });
+        const data = res.data.data;
+        if (Array.isArray(data)) setProductList(data);
+        else if (data?.items) setProductList(data.items);
+      } catch (e) {
+        console.error('Search failed', e);
+      } finally {
+        setIsSearchingProduct(false);
+      }
+    }
+
+    searchProducts();
+  }, [debouncedKeyword]);
+
+  const handleSelect = (product: any) => {
+    onSelectProduct(product);
+    setKeyword(product.title);
+    setProductList([]);
+  };
+
+  const handleClear = () => {
+    onSelectProduct(null);
+    setKeyword('');
+    setProductList([]);
+  };
+
+  return (
+    <div className="bg-white rounded-xl shadow-sm border border-slate-200 p-6">
+      <label className="block text-base font-bold text-slate-800 mb-3 flex items-center gap-2">
+        <span className="w-6 h-6 rounded-full bg-slate-900 text-white flex items-center justify-center text-xs font-mono">
+          1
+        </span>
+        选择服务商品
+      </label>
+
+      <div className="relative">
+        <input
+          type="text"
+          className={`w-full pl-11 pr-4 py-3 border rounded-xl shadow-sm outline-none transition text-base ${
+            selectedProduct
+              ? 'border-green-500 ring-1 ring-green-500 bg-green-50/20'
+              : 'border-slate-300 focus:ring-2 focus:ring-blue-500'
+          }`}
+          placeholder="输入关键词搜索 (例如: 日本, France...)"
+          value={keyword}
+          onChange={(e) => {
+            setKeyword(e.target.value);
+            if (!e.target.value) {
+              setProductList([]);
+              onSelectProduct(null);
+            }
+          }}
+        />
+        <Search className="absolute left-3.5 top-3.5 text-slate-400" size={20} />
+        {isSearchingProduct && (
+          <Loader2 className="absolute right-3 top-3.5 text-blue-500 animate-spin" size={20} />
+        )}
+
+        {selectedProduct && (
+          <div className="absolute right-3 top-2.5 flex items-center gap-2">
+            <span className="text-xs font-bold text-green-600 bg-green-100 px-2 py-1 rounded-full flex items-center gap-1">
+              <CheckCircle size={12} /> 已选: {selectedProduct.title}
+            </span>
+            <button
+              onClick={handleClear}
+              className="text-xs text-slate-400 hover:text-red-500 underline ml-2"
+            >
+              清除
+            </button>
+          </div>
+        )}
+      </div>
+
+      {/* 搜索结果下拉 */}
+      {productList.length > 0 && !selectedProduct && (
+        <div className="mt-2 bg-white border border-slate-200 rounded-xl shadow-xl max-h-60 overflow-y-auto divide-y divide-slate-100 animate-in fade-in zoom-in-95 duration-200">
+          {productList.map((p) => (
+            <div
+              key={p.id}
+              onClick={() => handleSelect(p)}
+              className="p-4 hover:bg-blue-50 cursor-pointer transition flex justify-between items-center group"
+            >
+              <div className="flex items-center gap-3">
+                <div className="p-2 bg-slate-100 rounded-lg group-hover:bg-blue-100 text-slate-500 group-hover:text-blue-600 transition">
+                  <Package size={20} />
+                </div>
+                <div>
+                  <div className="font-bold text-sm text-slate-800">{p.title}</div>
+                  <div className="text-xs text-slate-500 mt-0.5">
+                    {p.country} • {p.visa_type}
+                  </div>
+                </div>
+              </div>
+              <div className="text-sm font-mono font-bold text-slate-600">
+                {p.price_amount / 100} {p.price_currency}
+              </div>
+            </div>
+          ))}
+        </div>
+      )}
+    </div>
+  );
+}

+ 171 - 0
src/components/admin/proxies/ProxyAddModal.tsx

@@ -0,0 +1,171 @@
+'use client';
+
+import { useState, useEffect } from 'react';
+import { X } from 'lucide-react';
+import { toast } from 'react-hot-toast';
+import api from '@/lib/api';
+import { ProxyStatus } from '@/types';
+
+interface ProxyAddModalProps {
+  isOpen: boolean;
+  onClose: () => void;
+  onSuccess: () => void;
+}
+
+export default function ProxyAddModal({ isOpen, onClose, onSuccess }: ProxyAddModalProps) {
+  const [form, setForm] = useState({
+    pool_name: '',
+    proto: 'http',
+    ip: '',
+    port: 8080,
+    username: '',
+    password: '',
+    status: 'active' as ProxyStatus,
+  });
+  const [submitting, setSubmitting] = useState(false);
+
+  useEffect(() => {
+    if (isOpen) {
+      setForm({
+        pool_name: '',
+        proto: 'http',
+        ip: '',
+        port: 8080,
+        username: '',
+        password: '',
+        status: 'active',
+      });
+    }
+  }, [isOpen]);
+
+  if (!isOpen) return null;
+
+  const handleSubmit = async () => {
+    if (!form.ip) {
+      toast.error('请填写 IP');
+      return;
+    }
+    setSubmitting(true);
+    try {
+      await api.post('/api/proxy/add', {
+        pool_name: form.pool_name,
+        proto: form.proto,
+        ip: form.ip,
+        port: Number(form.port),
+        username: form.username || null,
+        password: form.password || null,
+        status: form.status || null,
+      });
+      toast.success('代理添加成功');
+      onClose();
+      onSuccess();
+    } catch (error) {
+      toast.error('代理添加失败');
+    } finally {
+      setSubmitting(false);
+    }
+  };
+
+  return (
+    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
+      <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
+        <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-slate-50/50">
+          <h3 className="font-bold text-lg text-slate-800">新增代理</h3>
+          <button onClick={onClose} className="text-slate-400 hover:text-slate-600">
+            <X size={20} />
+          </button>
+        </div>
+        <div className="p-6 space-y-4 max-h-[80vh] overflow-y-auto">
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Pool Name</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.pool_name}
+              onChange={(e) => setForm({ ...form, pool_name: e.target.value })}
+            />
+          </div>
+          <div className="grid grid-cols-2 gap-3">
+            <div>
+              <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">协议</label>
+              <select
+                className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white"
+                value={form.proto}
+                onChange={(e) => setForm({ ...form, proto: e.target.value })}
+              >
+                <option value="http">http</option>
+                <option value="https">https</option>
+                <option value="socks5">socks5</option>
+              </select>
+            </div>
+            <div>
+              <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">状态</label>
+              <select
+                className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white"
+                value={form.status}
+                onChange={(e) => setForm({ ...form, status: e.target.value as ProxyStatus })}
+              >
+                <option value="active">active</option>
+                <option value="disable">disable</option>
+              </select>
+            </div>
+          </div>
+          <div className="grid grid-cols-3 gap-3">
+            <div className="col-span-2">
+              <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">IP</label>
+              <input
+                type="text"
+                className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+                value={form.ip}
+                onChange={(e) => setForm({ ...form, ip: e.target.value })}
+              />
+            </div>
+            <div>
+              <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">端口</label>
+              <input
+                type="number"
+                className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+                value={form.port}
+                onChange={(e) => setForm({ ...form, port: Number(e.target.value) })}
+              />
+            </div>
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">用户名 (可选)</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.username}
+              onChange={(e) => setForm({ ...form, username: e.target.value })}
+            />
+          </div>
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">密码 (可选)</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.password}
+              onChange={(e) => setForm({ ...form, password: e.target.value })}
+            />
+          </div>
+        </div>
+        <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
+          <button
+            onClick={onClose}
+            className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg transition"
+            disabled={submitting}
+          >
+            取消
+          </button>
+          <button
+            onClick={handleSubmit}
+            className="px-4 py-2 text-sm font-bold bg-slate-900 text-white rounded-lg hover:bg-slate-800 transition disabled:opacity-50"
+            disabled={submitting}
+          >
+            {submitting ? '提交中...' : '确认添加'}
+          </button>
+        </div>
+      </div>
+    </div>
+  );
+}

+ 238 - 0
src/components/admin/proxies/ProxyEditModal.tsx

@@ -0,0 +1,238 @@
+'use client';
+
+import { useState, useEffect } from 'react';
+import { X, Pencil } from 'lucide-react';
+import { toast } from 'react-hot-toast';
+import api from '@/lib/api';
+import LocalTime from '@/components/common/LocalTime';
+import { ProxyItem, ProxyStatus } from '@/types';
+
+function parseUtcDateTime(value?: string | null) {
+  if (!value) return null;
+  const normalized = value.trim().replace(' ', 'T');
+  const hasTimezone = /[zZ]|[+-]\d{2}:\d{2}$/.test(normalized);
+  const utcValue = hasTimezone ? normalized : `${normalized}Z`;
+  const timestamp = new Date(utcValue).getTime();
+
+  return Number.isNaN(timestamp) ? null : timestamp;
+}
+
+function toDatetimeLocalValue(value?: string | null) {
+  if (!value) return '';
+  const timestamp = parseUtcDateTime(value);
+  if (timestamp === null) return '';
+  const date = new Date(timestamp);
+  const offset = date.getTimezoneOffset();
+  const localDate = new Date(date.getTime() - offset * 60 * 1000);
+  return localDate.toISOString().slice(0, 16);
+}
+
+function toApiDateTime(value: string) {
+  if (!value) return null;
+  const date = new Date(value);
+  if (Number.isNaN(date.getTime())) return null;
+  return date.toISOString();
+}
+
+interface ProxyEditModalProps {
+  isOpen: boolean;
+  onClose: () => void;
+  proxy: ProxyItem | null;
+  onSuccess: () => void;
+}
+
+export default function ProxyEditModal({ isOpen, onClose, proxy, onSuccess }: ProxyEditModalProps) {
+  const [form, setForm] = useState({
+    pool_name: '',
+    proto: 'http',
+    ip: '',
+    port: 8080,
+    username: '',
+    password: '',
+    status: 'active' as ProxyStatus,
+    next_use_time: '',
+  });
+  const [submitting, setSubmitting] = useState(false);
+
+  useEffect(() => {
+    if (isOpen && proxy) {
+      setForm({
+        pool_name: proxy.pool_name || '',
+        proto: proxy.proto || 'http',
+        ip: proxy.ip || '',
+        port: proxy.port || 8080,
+        username: proxy.username || '',
+        password: proxy.password || '',
+        status: (proxy.status?.toLowerCase() === 'disable' ? 'disable' : 'active') as ProxyStatus,
+        next_use_time: toDatetimeLocalValue(proxy.next_use_time),
+      });
+    }
+  }, [isOpen, proxy]);
+
+  if (!isOpen || !proxy) return null;
+
+  const handleSubmit = async () => {
+    if (!form.ip) {
+      toast.error('请填写 IP');
+      return;
+    }
+    setSubmitting(true);
+    try {
+      await api.put('/api/proxy/update', {
+        pool_name: form.pool_name || null,
+        proto: form.proto || null,
+        ip: form.ip || null,
+        port: Number(form.port) || null,
+        username: form.username || null,
+        password: form.password || null,
+        status: form.status || null,
+        next_use_time: toApiDateTime(form.next_use_time),
+      }, {
+        params: { proxy_id: proxy.id },
+      });
+      toast.success('代理更新成功');
+      onClose();
+      onSuccess();
+    } catch (error) {
+      toast.error('代理更新失败');
+    } finally {
+      setSubmitting(false);
+    }
+  };
+
+  return (
+    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
+      <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
+        <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-blue-50/50">
+          <h3 className="font-bold text-lg text-blue-900 flex items-center gap-2">
+            <Pencil size={18} /> 编辑代理
+          </h3>
+          <button onClick={onClose} className="text-slate-400 hover:text-slate-600">
+            <X size={20} />
+          </button>
+        </div>
+        <div className="p-6 space-y-4 max-h-[80vh] overflow-y-auto">
+          <div className="text-sm text-slate-600 bg-blue-50 p-3 rounded-lg border border-blue-100">
+            ID: <span className="font-bold text-slate-900">#{proxy.id}</span>
+            <br />
+            Created:{' '}
+            <span className="font-bold text-slate-900">
+              {proxy.created_at ? <LocalTime date={proxy.created_at} /> : '-'}
+            </span>
+            <br />
+            Updated:{' '}
+            <span className="font-bold text-slate-900">
+              {proxy.updated_at ? <LocalTime date={proxy.updated_at} /> : '-'}
+            </span>
+          </div>
+
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Pool Name</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.pool_name}
+              onChange={(e) => setForm({ ...form, pool_name: e.target.value })}
+            />
+          </div>
+
+          <div className="grid grid-cols-2 gap-3">
+            <div>
+              <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">协议</label>
+              <select
+                className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white"
+                value={form.proto}
+                onChange={(e) => setForm({ ...form, proto: e.target.value })}
+              >
+                <option value="http">http</option>
+                <option value="https">https</option>
+                <option value="socks5">socks5</option>
+              </select>
+            </div>
+            <div>
+              <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">状态</label>
+              <select
+                className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm bg-white"
+                value={form.status}
+                onChange={(e) => setForm({ ...form, status: e.target.value as ProxyStatus })}
+              >
+                <option value="active">active</option>
+                <option value="disable">disable</option>
+              </select>
+            </div>
+          </div>
+
+          <div className="grid grid-cols-3 gap-3">
+            <div className="col-span-2">
+              <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">IP</label>
+              <input
+                type="text"
+                className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+                value={form.ip}
+                onChange={(e) => setForm({ ...form, ip: e.target.value })}
+              />
+            </div>
+            <div>
+              <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">端口</label>
+              <input
+                type="number"
+                className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+                value={form.port}
+                onChange={(e) => setForm({ ...form, port: Number(e.target.value) })}
+              />
+            </div>
+          </div>
+
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">用户名 (可选)</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.username}
+              onChange={(e) => setForm({ ...form, username: e.target.value })}
+            />
+          </div>
+
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">密码 (可选)</label>
+            <input
+              type="text"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.password}
+              onChange={(e) => setForm({ ...form, password: e.target.value })}
+            />
+          </div>
+
+          <div>
+            <label className="block text-xs font-bold uppercase text-slate-500 mb-1.5">Next Use Time</label>
+            <input
+              type="datetime-local"
+              className="w-full px-3 py-2 border rounded-lg focus:ring-2 focus:ring-blue-500 outline-none text-sm"
+              value={form.next_use_time}
+              onChange={(e) => setForm({ ...form, next_use_time: e.target.value })}
+            />
+            <p className="mt-1 text-xs text-slate-500">
+              {proxy.next_use_time ? <LocalTime date={proxy.next_use_time} /> : '未设置'}
+            </p>
+          </div>
+        </div>
+        <div className="px-6 py-4 bg-slate-50 flex justify-end gap-3 border-t">
+          <button
+            onClick={onClose}
+            className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg transition"
+            disabled={submitting}
+          >
+            取消
+          </button>
+          <button
+            onClick={handleSubmit}
+            className="px-4 py-2 text-sm font-bold bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition disabled:opacity-50"
+            disabled={submitting}
+          >
+            {submitting ? '保存中...' : '保存修改'}
+          </button>
+        </div>
+      </div>
+    </div>
+  );
+}

+ 129 - 0
src/components/admin/proxies/ProxyExportModal.tsx

@@ -0,0 +1,129 @@
+'use client';
+
+import { X, Download } from 'lucide-react';
+import { toast } from 'react-hot-toast';
+import { ProxyItem } from '@/types';
+
+interface ProxyExportModalProps {
+  isOpen: boolean;
+  onClose: () => void;
+  selectedProxies: ProxyItem[];
+}
+
+export default function ProxyExportModal({
+  isOpen,
+  onClose,
+  selectedProxies,
+}: ProxyExportModalProps) {
+  if (!isOpen) return null;
+
+  const downloadTextFile = (filename: string, content: string, mimeType: string) => {
+    const blob = new Blob([content], { type: mimeType });
+    const url = URL.createObjectURL(blob);
+    const link = document.createElement('a');
+    link.href = url;
+    link.download = filename;
+    document.body.appendChild(link);
+    link.click();
+    document.body.removeChild(link);
+    URL.revokeObjectURL(url);
+  };
+
+  const handleExport = (format: 'colon' | 'url' | 'json') => {
+    if (selectedProxies.length === 0) {
+      toast.error('请先选择要导出的代理');
+      return;
+    }
+
+    const timestamp = new Date().toISOString().slice(0, 19).replace(/[:T]/g, '-');
+
+    if (format === 'colon') {
+      const content = selectedProxies
+        .map((item) => `${item.ip}:${item.port}:${item.username || ''}:${item.password || ''}`)
+        .join('\n');
+      downloadTextFile(`proxies-colon-${timestamp}.txt`, content, 'text/plain;charset=utf-8');
+    }
+
+    if (format === 'url') {
+      const content = selectedProxies
+        .map((item) => {
+          const auth = item.username
+            ? `${encodeURIComponent(item.username)}:${encodeURIComponent(item.password || '')}@`
+            : '';
+          return `${item.proto}://${auth}${item.ip}:${item.port}`;
+        })
+        .join('\n');
+      downloadTextFile(`proxies-url-${timestamp}.txt`, content, 'text/plain;charset=utf-8');
+    }
+
+    if (format === 'json') {
+      downloadTextFile(
+        `proxies-raw-${timestamp}.json`,
+        JSON.stringify(selectedProxies, null, 2),
+        'application/json;charset=utf-8'
+      );
+    }
+
+    onClose();
+    toast.success(`已导出 ${selectedProxies.length} 条代理`);
+  };
+
+  return (
+    <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4 animate-in fade-in zoom-in-95 duration-200">
+      <div className="bg-white rounded-xl shadow-2xl w-full max-w-md overflow-hidden">
+        <div className="px-6 py-4 border-b border-slate-100 flex justify-between items-center bg-slate-50/50">
+          <h3 className="font-bold text-lg text-slate-800 flex items-center gap-2">
+            <Download size={18} /> 导出代理
+          </h3>
+          <button onClick={onClose} className="text-slate-400 hover:text-slate-600">
+            <X size={20} />
+          </button>
+        </div>
+
+        <div className="p-6 space-y-4">
+          <p className="text-sm text-slate-600">
+            已勾选 <span className="font-bold text-slate-900">{selectedProxies.length}</span> 条代理。请选择导出格式:
+          </p>
+
+          <div className="space-y-2">
+            <button
+              onClick={() => handleExport('colon')}
+              disabled={selectedProxies.length === 0}
+              className="w-full text-left p-3 border rounded-lg hover:bg-slate-50 transition disabled:opacity-50 disabled:cursor-not-allowed"
+            >
+              <div className="text-sm font-semibold text-slate-800">冒号分隔格式 (.txt)</div>
+              <div className="text-xs text-slate-500 font-mono mt-0.5">ip:port:username:password</div>
+            </button>
+
+            <button
+              onClick={() => handleExport('url')}
+              disabled={selectedProxies.length === 0}
+              className="w-full text-left p-3 border rounded-lg hover:bg-slate-50 transition disabled:opacity-50 disabled:cursor-not-allowed"
+            >
+              <div className="text-sm font-semibold text-slate-800">标准 URL 格式 (.txt)</div>
+              <div className="text-xs text-slate-500 font-mono mt-0.5">http://user:pass@ip:port</div>
+            </button>
+
+            <button
+              onClick={() => handleExport('json')}
+              disabled={selectedProxies.length === 0}
+              className="w-full text-left p-3 border rounded-lg hover:bg-slate-50 transition disabled:opacity-50 disabled:cursor-not-allowed"
+            >
+              <div className="text-sm font-semibold text-slate-800">完整 JSON 格式 (.json)</div>
+              <div className="text-xs text-slate-500 mt-0.5">包含 ID、状态、Pool 等全部原始字段</div>
+            </button>
+          </div>
+        </div>
+
+        <div className="px-6 py-4 bg-slate-50 flex justify-end border-t">
+          <button
+            onClick={onClose}
+            className="px-4 py-2 text-sm text-slate-600 hover:bg-slate-200 rounded-lg transition"
+          >
+            关闭
+          </button>
+        </div>
+      </div>
+    </div>
+  );
+}

+ 138 - 0
src/components/payment/PaymentConfirmCard.tsx

@@ -0,0 +1,138 @@
+'use client';
+
+import { useEffect, useState, useRef } from 'react';
+import { useSearchParams, useRouter } from 'next/navigation';
+import api from '@/lib/api';
+import { Loader2, CheckCircle, XCircle, ArrowLeft } from 'lucide-react';
+
+export function PaymentConfirmFallback() {
+  return (
+    <div className="bg-white rounded-2xl shadow-xl w-full max-w-md p-12 flex flex-col items-center justify-center">
+      <Loader2 className="w-10 h-10 text-blue-600 animate-spin mb-4" />
+      <p className="text-slate-500 text-sm">正在加载支付信息...</p>
+    </div>
+  );
+}
+
+export default function PaymentConfirmCard() {
+  const searchParams = useSearchParams();
+  const router = useRouter();
+
+  const hasFetched = useRef(false);
+
+  const [status, setStatus] = useState<'loading' | 'success' | 'error'>('loading');
+  const [message, setMessage] = useState('正在验证支付信息...');
+  const [paymentId, setPaymentId] = useState<string>('');
+
+  useEffect(() => {
+    const pid = searchParams.get('payment_id');
+    const token = searchParams.get('token');
+
+    if (!pid || !token) {
+      setStatus('error');
+      setMessage('参数缺失:URL 中必须包含 payment_id 和 token');
+      return;
+    }
+
+    setPaymentId(pid);
+
+    const confirmPayment = async () => {
+      if (hasFetched.current) return;
+      hasFetched.current = true;
+
+      try {
+        await api.get('/api/vas/payment/confirm', {
+          params: {
+            payment_id: pid,
+            token: token,
+          },
+        });
+
+        setStatus('success');
+        setMessage('支付已成功确认!系统正在处理后续流程。');
+      } catch (error: any) {
+        console.error(error);
+        setStatus('error');
+        const errorMsg = error.response?.data?.message || error.message || '未知错误';
+        setMessage(`确认失败: ${errorMsg}`);
+      }
+    };
+
+    confirmPayment();
+  }, [searchParams]);
+
+  return (
+    <div className="bg-white rounded-2xl shadow-xl w-full max-w-md overflow-hidden border border-slate-100">
+      {/* 顶部装饰条 */}
+      <div
+        className={`h-2 w-full ${
+          status === 'loading'
+            ? 'bg-blue-500 animate-pulse'
+            : status === 'success'
+            ? 'bg-green-500'
+            : 'bg-red-500'
+        }`}
+      />
+
+      <div className="p-8 text-center">
+        {/* 图标状态 */}
+        <div className="flex justify-center mb-6">
+          {status === 'loading' && (
+            <div className="w-20 h-20 bg-blue-50 rounded-full flex items-center justify-center">
+              <Loader2 className="w-10 h-10 text-blue-600 animate-spin" />
+            </div>
+          )}
+          {status === 'success' && (
+            <div className="w-20 h-20 bg-green-50 rounded-full flex items-center justify-center animate-in zoom-in duration-300">
+              <CheckCircle className="w-10 h-10 text-green-600" />
+            </div>
+          )}
+          {status === 'error' && (
+            <div className="w-20 h-20 bg-red-50 rounded-full flex items-center justify-center animate-in zoom-in duration-300">
+              <XCircle className="w-10 h-10 text-red-600" />
+            </div>
+          )}
+        </div>
+
+        {/* 标题与描述 */}
+        <h1 className="text-xl font-bold text-slate-900 mb-2">
+          {status === 'loading' ? '处理中...' : status === 'success' ? '操作成功' : '操作失败'}
+        </h1>
+
+        <p
+          className={`text-sm mb-6 leading-relaxed ${
+            status === 'error' ? 'text-red-500' : 'text-slate-500'
+          }`}
+        >
+          {message}
+        </p>
+
+        {/* 详情信息 */}
+        {status !== 'loading' && paymentId && (
+          <div className="bg-slate-50 rounded-lg p-3 mb-6 text-xs text-slate-400 font-mono">
+            Payment ID: {paymentId}
+          </div>
+        )}
+
+        {/* 底部按钮 */}
+        <div className="space-y-3">
+          <button
+            onClick={() => router.push('/admin/orders')}
+            className="w-full flex items-center justify-center gap-2 bg-slate-900 text-white py-2.5 rounded-lg text-sm font-medium hover:bg-slate-800 transition shadow-sm"
+          >
+            <ArrowLeft size={16} /> 返回订单管理
+          </button>
+
+          {status === 'error' && (
+            <button
+              onClick={() => window.location.reload()}
+              className="w-full py-2.5 text-slate-600 text-sm hover:bg-slate-50 rounded-lg transition"
+            >
+              重试
+            </button>
+          )}
+        </div>
+      </div>
+    </div>
+  );
+}

+ 107 - 0
src/components/slots/SlotFilterBar.tsx

@@ -0,0 +1,107 @@
+'use client';
+
+import { Globe, MapPin, RefreshCw } from 'lucide-react';
+import { useLanguage } from '@/lib/i18n/LanguageContext';
+
+export interface LocationItem {
+  code: string;
+  name: string;
+  flag: string;
+  cities: string[];
+}
+
+export const LOCATIONS: LocationItem[] = [
+  { code: 'IE', name: 'Ireland', flag: '🇮🇪', cities: ['Dublin'] },
+  { code: 'GB', name: 'United Kingdom', flag: '🇬🇧', cities: ['London', 'Manchester'] },
+  { code: 'SG', name: 'Singapore', flag: '🇸🇬', cities: ['Singapore'] },
+];
+
+interface SlotFilterBarProps {
+  selectedCountryCode: string;
+  selectedCity: string;
+  currentCities: string[];
+  onCountryChange: (code: string) => void;
+  onCityChange: (city: string) => void;
+  onRefresh: () => void;
+  loading: boolean;
+}
+
+export default function SlotFilterBar({
+  selectedCountryCode,
+  selectedCity,
+  currentCities,
+  onCountryChange,
+  onCityChange,
+  onRefresh,
+  loading,
+}: SlotFilterBarProps) {
+  const { t } = useLanguage();
+
+  return (
+    <div className="bg-white p-4 rounded-2xl shadow-sm border border-slate-200 mb-8 flex flex-col md:flex-row gap-4 items-center">
+      {/* Country */}
+      <div className="w-full md:w-auto flex-1 max-w-xs relative">
+        <label className="text-xs font-bold text-slate-400 uppercase ml-1 mb-1 block">
+          Application Location (Country)
+        </label>
+        <div className="relative">
+          <select
+            className="w-full pl-10 pr-8 py-3 border border-slate-200 rounded-xl bg-slate-50 text-sm font-bold text-slate-800 outline-none focus:ring-2 focus:ring-blue-500 appearance-none cursor-pointer"
+            value={selectedCountryCode}
+            onChange={(e) => onCountryChange(e.target.value)}
+          >
+            {LOCATIONS.map((loc) => (
+              <option key={loc.code} value={loc.code}>
+                {loc.flag} {loc.name}
+              </option>
+            ))}
+          </select>
+          <Globe size={18} className="absolute left-3 top-3.5 text-slate-400 pointer-events-none" />
+          <div className="absolute right-3 top-4 pointer-events-none text-slate-400">
+            <svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg">
+              <path d="M1 1L5 5L9 1" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
+            </svg>
+          </div>
+        </div>
+      </div>
+
+      {/* City */}
+      <div className="w-full md:w-auto flex-1 max-w-xs relative">
+        <label className="text-xs font-bold text-slate-400 uppercase ml-1 mb-1 block">
+          Application City
+        </label>
+        <div className="relative">
+          <select
+            className="w-full pl-10 pr-8 py-3 border border-slate-200 rounded-xl bg-slate-50 text-sm font-bold text-slate-800 outline-none focus:ring-2 focus:ring-blue-500 appearance-none cursor-pointer"
+            value={selectedCity}
+            onChange={(e) => onCityChange(e.target.value)}
+          >
+            {currentCities.map((city) => (
+              <option key={city} value={city}>
+                {city}
+              </option>
+            ))}
+          </select>
+          <MapPin size={18} className="absolute left-3 top-3.5 text-slate-400 pointer-events-none" />
+          <div className="absolute right-3 top-4 pointer-events-none text-slate-400">
+            <svg width="10" height="6" viewBox="0 0 10 6" fill="none" xmlns="http://www.w3.org/2000/svg">
+              <path d="M1 1L5 5L9 1" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
+            </svg>
+          </div>
+        </div>
+      </div>
+
+      {/* Refresh */}
+      <div className="w-full md:w-auto pt-5">
+        <button
+          onClick={onRefresh}
+          disabled={loading}
+          className="w-full md:w-auto flex items-center justify-center gap-2 px-6 py-3 bg-slate-900 text-white rounded-xl hover:bg-slate-800 transition disabled:opacity-70 shadow-sm active:scale-95"
+        >
+          <RefreshCw size={18} className={loading ? 'animate-spin' : ''} />
+          <span className="font-bold text-sm">{t('common.refresh') || 'Refresh'}</span>
+        </button>
+      </div>
+    </div>
+  );
+}

+ 48 - 0
src/components/slots/SlotGrid.tsx

@@ -0,0 +1,48 @@
+'use client';
+
+import { RefreshCw, Search } from 'lucide-react';
+import CitySlotCard from '@/components/slots/CitySlotCard';
+import { SlotSnapshot } from '@/types';
+
+interface SlotGridProps {
+  loading: boolean;
+  snapshots: SlotSnapshot[];
+  selectedCity: string;
+  isBlacklisted: (slot: SlotSnapshot) => boolean;
+}
+
+export default function SlotGrid({
+  loading,
+  snapshots,
+  selectedCity,
+  isBlacklisted,
+}: SlotGridProps) {
+  if (loading && snapshots.length === 0) {
+    return (
+      <div className="text-center py-24 text-slate-400 bg-white rounded-2xl border border-dashed">
+        <RefreshCw size={32} className="animate-spin mx-auto mb-3 opacity-50" />
+        <p>正在获取 {selectedCity} 的最新数据...</p>
+      </div>
+    );
+  }
+
+  if (snapshots.length === 0) {
+    return (
+      <div className="text-center py-24 bg-white rounded-2xl border border-dashed border-slate-200">
+        <div className="mx-auto w-16 h-16 bg-slate-50 rounded-full flex items-center justify-center mb-4">
+          <Search className="text-slate-300" size={32} />
+        </div>
+        <h3 className="text-slate-900 font-bold mb-1">暂无监控数据</h3>
+        <p className="text-slate-500 text-sm">当前城市没有被监控的签证服务</p>
+      </div>
+    );
+  }
+
+  return (
+    <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
+      {snapshots.map((slot) => (
+        <CitySlotCard key={slot.id} data={slot} isBlacklisted={isBlacklisted(slot)} />
+      ))}
+    </div>
+  );
+}