From c37dc13c4d00bbd111358d58c919750221cc969f Mon Sep 17 00:00:00 2001 From: real-jacket <1762982273@qq.com> Date: Wed, 2 Apr 2025 00:29:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=9B=B4=E6=96=B0=E8=B4=A6=E6=88=B7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E8=BF=94=E5=9B=9E=E7=9A=84=E8=B4=A6=E6=88=B7?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=8C=85=E5=90=ABid=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E5=B9=B6=E8=BF=9B=E8=A1=8C=E5=BA=8F=E5=88=97=E5=8C=96=EF=BC=8C?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E4=BC=98=E5=8C=96=E5=89=8D=E7=AB=AF=E8=A1=A8?= =?UTF-8?q?=E6=A0=BC=E6=B8=B2=E6=9F=93=EF=BC=8C=E7=A1=AE=E4=BF=9D=E6=89=80?= =?UTF-8?q?=E6=9C=89=E5=AD=97=E6=AE=B5=E9=83=BD=E6=9C=89=E9=BB=98=E8=AE=A4?= =?UTF-8?q?=E5=80=BC=EF=BC=8C=E6=8F=90=E5=8D=87=E7=94=A8=E6=88=B7=E4=BD=93?= =?UTF-8?q?=E9=AA=8C=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.py | 17 ++++++++- static/js/app.js | 94 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 89 insertions(+), 22 deletions(-) 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(