diff --git a/api.py b/api.py index 4500a83..c254110 100644 --- a/api.py +++ b/api.py @@ -401,10 +401,25 @@ async def get_accounts( result = await session.execute(query) accounts = result.scalars().all() + # 转换为可序列化的数据,确保包含id字段 + accounts_data = [] + for account in accounts: + account_dict = { + "id": account.id, # 确保包含id字段 + "email": account.email, + "password": account.password, + "token": account.token, + "user": account.user if hasattr(account, "user") else "", + "usage_limit": account.usage_limit, + "created_at": account.created_at, + "status": account.status + } + accounts_data.append(account_dict) + # 构建分页响应 return { "success": True, - "data": accounts, + "data": accounts_data, # 使用序列化后的数据 "pagination": { "page": page, "per_page": per_page, diff --git a/static/js/app.js b/static/js/app.js index d3abbea..92873eb 100644 --- a/static/js/app.js +++ b/static/js/app.js @@ -11,6 +11,9 @@ $(document).ready(function () { // 初始化应用 initializeApplication(); + // 每60秒检查一次服务状态 + setInterval(checkTaskStatus, 60 * 1000); + // 绑定遮罩关闭按钮事件 - 使用事件委托确保对动态元素也有效 $(document).on('click', '.close-overlay', function () { hideLoading(); @@ -590,18 +593,35 @@ function updateAccountsTable(accounts) { const accountsBody = $('#accounts-tbody'); accountsBody.empty(); + // 计算当前页的起始索引 + const startIndex = (currentPage - 1) * itemsPerPage; + + // 确保每个账号都有ID并且所有字段都有值 + accounts.forEach((account, index) => { + if (!account.id) account.id = Date.now() + index; + + // 确保所有字段都不为undefined,防止jQuery错误 + account.email = account.email || ''; + account.token = account.token || ''; + account.password = account.password || ''; + account.status = account.status || 'active'; + account.usage_limit = account.usage_limit || ''; + account.created_at = account.created_at || ''; + account.user = account.user || ''; + }); + + // 如果没有数据,显示空状态 if (accounts.length === 0) { - // 添加空状态提示 accountsBody.html(` - - -
- -

暂无账号数据

-
- - - `); + + +
+ +

暂无账号数据

+
+ + + `); return; } @@ -609,7 +629,9 @@ function updateAccountsTable(accounts) { accounts.forEach((account, index) => { // 完整的行模板,包含所有单元格内容 const row = ` - + ${ + startIndex + index + 1 + } ${account.email} - - @@ -2348,9 +2397,14 @@ function bindModalEvents() { .on( 'click', throttle(function () { - const accountId = $(this).data('account-id'); + // 直接从DOM元素获取属性 + const accountId = + document + .getElementById('useTokenBtn') + .getAttribute('data-account-id') || ''; + if (!accountId) { - showAlert('账号ID无效', 'danger'); + showAlert('无法获取账号ID,请刷新页面后重试', 'danger'); return; } @@ -2369,9 +2423,7 @@ function bindModalEvents() { if (data.success) { showAlert(data.message, 'success'); $('#tokenViewModal').modal('hide'); - cleanupModalBackdrops(); // 添加清理 - - // 成功使用Token后刷新账号列表 + cleanupModalBackdrops(); setTimeout(() => fetchAccounts(), 1000); } else { showAlert(