|
@@ -1,44 +1,17 @@
|
|
|
'use client';
|
|
'use client';
|
|
|
|
|
|
|
|
import { useState, useEffect } from 'react';
|
|
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 api from '@/lib/api';
|
|
|
import { toast } from 'react-hot-toast';
|
|
import { toast } from 'react-hot-toast';
|
|
|
|
|
|
|
|
-// 引入拆分后的组件
|
|
|
|
|
import AccountTable from '@/components/admin/accounts/AccountTable';
|
|
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 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() {
|
|
export default function AdminAccountsPage() {
|
|
|
// === 1. 状态定义 ===
|
|
// === 1. 状态定义 ===
|
|
@@ -46,7 +19,7 @@ export default function AdminAccountsPage() {
|
|
|
const [data, setData] = useState<Account[]>([]);
|
|
const [data, setData] = useState<Account[]>([]);
|
|
|
|
|
|
|
|
// 分页与搜索
|
|
// 分页与搜索
|
|
|
- const [page, setPage] = useState(1); // 1-based UI
|
|
|
|
|
|
|
+ const [page, setPage] = useState(1);
|
|
|
const [pageSize] = useState(10);
|
|
const [pageSize] = useState(10);
|
|
|
const [total, setTotal] = useState(0);
|
|
const [total, setTotal] = useState(0);
|
|
|
const [keyword, setKeyword] = useState('');
|
|
const [keyword, setKeyword] = useState('');
|
|
@@ -58,24 +31,6 @@ export default function AdminAccountsPage() {
|
|
|
const [showEditModal, setShowEditModal] = useState(false);
|
|
const [showEditModal, setShowEditModal] = useState(false);
|
|
|
const [selectedAccount, setSelectedAccount] = useState<Account | null>(null);
|
|
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. 数据获取 ===
|
|
// === 2. 数据获取 ===
|
|
|
const fetchAccounts = async (targetPage: number = page) => {
|
|
const fetchAccounts = async (targetPage: number = page) => {
|
|
|
setLoading(true);
|
|
setLoading(true);
|
|
@@ -84,8 +39,8 @@ export default function AdminAccountsPage() {
|
|
|
params: {
|
|
params: {
|
|
|
page: targetPage,
|
|
page: targetPage,
|
|
|
size: pageSize,
|
|
size: pageSize,
|
|
|
- keyword: keyword
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ keyword: keyword,
|
|
|
|
|
+ },
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
const resData = res.data?.data || {};
|
|
const resData = res.data?.data || {};
|
|
@@ -99,13 +54,11 @@ export default function AdminAccountsPage() {
|
|
|
|
|
|
|
|
setPage(targetPage);
|
|
setPage(targetPage);
|
|
|
|
|
|
|
|
- // 翻页滚动优化
|
|
|
|
|
if (targetPage > 1) {
|
|
if (targetPage > 1) {
|
|
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
window.scrollTo({ top: 0, behavior: 'smooth' });
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
- console.error("Fetch accounts failed", error);
|
|
|
|
|
|
|
+ console.error('Fetch accounts failed', error);
|
|
|
toast.error('获取列表失败');
|
|
toast.error('获取列表失败');
|
|
|
setData([]);
|
|
setData([]);
|
|
|
} finally {
|
|
} finally {
|
|
@@ -124,91 +77,25 @@ export default function AdminAccountsPage() {
|
|
|
if (e.key === 'Enter') handleSearch();
|
|
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) => {
|
|
const handleEditClick = (account: Account) => {
|
|
|
setSelectedAccount(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);
|
|
setShowEditModal(true);
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const handleEditAccount = async () => {
|
|
|
|
|
- if (!selectedAccount) return;
|
|
|
|
|
|
|
+ const handleLockClick = async (account: Account, unlock: boolean, duration: number) => {
|
|
|
try {
|
|
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', {
|
|
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 ? '解锁成功' : '锁定成功');
|
|
toast.success(unlock ? '解锁成功' : '锁定成功');
|
|
|
fetchAccounts(page);
|
|
fetchAccounts(page);
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
toast.error(unlock ? '解锁失败' : '锁定失败');
|
|
toast.error(unlock ? '解锁失败' : '锁定失败');
|
|
|
|
|
+ throw error;
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -216,7 +103,7 @@ export default function AdminAccountsPage() {
|
|
|
if (!confirm(`确定要删除账号 ${account.username} 吗?此操作不可恢复。`)) return;
|
|
if (!confirm(`确定要删除账号 ${account.username} 吗?此操作不可恢复。`)) return;
|
|
|
try {
|
|
try {
|
|
|
await api.delete('/api/account/delete', {
|
|
await api.delete('/api/account/delete', {
|
|
|
- params: { account_id: account.id }
|
|
|
|
|
|
|
+ params: { account_id: account.id },
|
|
|
});
|
|
});
|
|
|
toast.success('删除成功');
|
|
toast.success('删除成功');
|
|
|
const nextPage = data.length === 1 && page > 1 ? page - 1 : page;
|
|
const nextPage = data.length === 1 && page > 1 ? page - 1 : page;
|
|
@@ -228,7 +115,6 @@ export default function AdminAccountsPage() {
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
<div className="p-4 md:p-6 space-y-6">
|
|
<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 className="flex flex-col md:flex-row md:items-center justify-between gap-4">
|
|
|
<div>
|
|
<div>
|
|
@@ -244,7 +130,7 @@ export default function AdminAccountsPage() {
|
|
|
placeholder="搜索账号 / Pool..."
|
|
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"
|
|
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}
|
|
value={keyword}
|
|
|
- onChange={e => setKeyword(e.target.value)}
|
|
|
|
|
|
|
+ onChange={(e) => setKeyword(e.target.value)}
|
|
|
onKeyDown={handleKeyDown}
|
|
onKeyDown={handleKeyDown}
|
|
|
/>
|
|
/>
|
|
|
<Search size={16} className="absolute left-3 top-2.5 text-gray-400" />
|
|
<Search size={16} className="absolute left-3 top-2.5 text-gray-400" />
|
|
@@ -286,185 +172,36 @@ export default function AdminAccountsPage() {
|
|
|
currentPage={page}
|
|
currentPage={page}
|
|
|
total={total}
|
|
total={total}
|
|
|
pageSize={pageSize}
|
|
pageSize={pageSize}
|
|
|
- onPageChange={fetchAccounts} // 传递函数,分页组件点击时回调
|
|
|
|
|
|
|
+ onPageChange={fetchAccounts}
|
|
|
/>
|
|
/>
|
|
|
</div>
|
|
</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>
|
|
</div>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|