|
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>账户仪表盘</title>
|
|
<link rel="preconnect" href="https://fonts.googleapis.com">
|
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">
|
|
<style>
|
|
:root {
|
|
--bg-color: #ffffff;
|
|
--text-color: #111827;
|
|
--secondary-text-color: #6b7280;
|
|
--border-color: #e5e7eb;
|
|
--card-bg-color: #ffffff;
|
|
--accent-color: #000000;
|
|
--error-color: #ef4444;
|
|
--success-color: #10b981;
|
|
--summary-bar-bg: #f9fafb;
|
|
}
|
|
|
|
body {
|
|
font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
margin: 0;
|
|
background-color: var(--summary-bar-bg);
|
|
color: var(--text-color);
|
|
line-height: 1.6;
|
|
-webkit-font-smoothing: antialiased;
|
|
-moz-osx-font-smoothing: grayscale;
|
|
}
|
|
.container {
|
|
max-width: 1200px;
|
|
margin: 0 auto;
|
|
padding: 32px 20px;
|
|
}
|
|
header {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-bottom: 16px;
|
|
padding-bottom: 24px;
|
|
border-bottom: 1px solid var(--border-color);
|
|
}
|
|
header h1 {
|
|
margin: 0;
|
|
font-size: 28px;
|
|
color: var(--text-color);
|
|
font-weight: 700;
|
|
}
|
|
.header-actions button {
|
|
padding: 8px 16px;
|
|
background-color: var(--accent-color);
|
|
color: var(--bg-color);
|
|
border: 1px solid var(--accent-color);
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
font-size: 14px;
|
|
font-weight: 500;
|
|
margin-left: 12px;
|
|
transition: background-color 0.2s ease;
|
|
}
|
|
.header-actions button:hover {
|
|
background-color: #333333;
|
|
}
|
|
.header-actions button#logout-btn {
|
|
background-color: var(--bg-color);
|
|
color: var(--secondary-text-color);
|
|
border: 1px solid var(--border-color);
|
|
}
|
|
.header-actions button#logout-btn:hover {
|
|
background-color: #f3f4f6;
|
|
border-color: #d1d5db;
|
|
}
|
|
#last-updated {
|
|
font-size: 0.875em;
|
|
color: var(--secondary-text-color);
|
|
margin-bottom: 24px;
|
|
text-align: right;
|
|
}
|
|
#summary-bar {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
|
gap: 20px;
|
|
background-color: var(--card-bg-color);
|
|
padding: 20px;
|
|
border-radius: 8px;
|
|
margin-bottom: 30px;
|
|
border: 1px solid var(--border-color);
|
|
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
}
|
|
.summary-item {
|
|
text-align: left;
|
|
}
|
|
.summary-label {
|
|
display: block;
|
|
font-size: 0.875em;
|
|
color: var(--secondary-text-color);
|
|
margin-bottom: 4px;
|
|
font-weight: 500;
|
|
}
|
|
.summary-value {
|
|
display: block;
|
|
font-size: 1.5em;
|
|
color: var(--text-color);
|
|
font-weight: 600;
|
|
}
|
|
|
|
#account-cards-container {
|
|
display: grid;
|
|
grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
|
|
gap: 20px;
|
|
}
|
|
.account-card-link {
|
|
text-decoration: none;
|
|
color: inherit;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.account-card {
|
|
padding: 20px;
|
|
flex-grow: 1;
|
|
background-color: var(--card-bg-color);
|
|
border-radius: 8px;
|
|
border: 1px solid var(--border-color);
|
|
box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
|
|
transition: box-shadow 0.2s ease, transform 0.2s ease;
|
|
height: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
.account-card-link:hover .account-card {
|
|
box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
|
|
transform: translateY(-2px);
|
|
}
|
|
.account-info {
|
|
flex-grow: 1;
|
|
}
|
|
.account-info h3 {
|
|
margin-top: 0;
|
|
font-size: 1.125em;
|
|
color: var(--text-color);
|
|
border-bottom: 1px solid var(--border-color);
|
|
padding-bottom: 12px;
|
|
margin-bottom: 12px;
|
|
font-weight: 600;
|
|
}
|
|
.account-info p { margin: 8px 0; font-size: 0.875em; color: var(--secondary-text-color); }
|
|
.account-info p strong {
|
|
color: var(--text-color);
|
|
min-width: 110px;
|
|
display: inline-block;
|
|
font-weight: 500;
|
|
}
|
|
.account-info .highlight-balance {
|
|
font-weight: 600;
|
|
font-size: 1.1em;
|
|
color: var(--text-color);
|
|
}
|
|
.status-ok { color: var(--success-color); font-weight: 500; }
|
|
.status-error { color: var(--error-color); font-weight: 500; }
|
|
.error-details {
|
|
font-size: 0.8em;
|
|
color: var(--error-color);
|
|
margin-left: 0;
|
|
white-space: pre-wrap;
|
|
background-color: rgba(239, 68, 68, 0.05);
|
|
padding: 6px 8px;
|
|
border-radius: 4px;
|
|
margin-top: 4px;
|
|
border: 1px solid rgba(239, 68, 68, 0.1);
|
|
}
|
|
.account-info .card-details-integrated {
|
|
margin-top: 15px;
|
|
padding-top: 15px;
|
|
border-top: 1px solid var(--border-color);
|
|
}
|
|
|
|
#loading-indicator {
|
|
text-align: center;
|
|
padding: 40px 0;
|
|
font-size: 1em;
|
|
color: var(--secondary-text-color);
|
|
display: none;
|
|
width: 100%;
|
|
}
|
|
#loading-indicator::before {
|
|
content: ''; display: inline-block; width: 24px; height: 24px;
|
|
border: 3px solid rgba(0,0,0, 0.1); border-radius: 50%;
|
|
border-top-color: var(--text-color); animation: spin 0.8s linear infinite;
|
|
margin-right: 12px; position: relative; top: 4px;
|
|
}
|
|
@keyframes spin { to { transform: rotate(360deg); } }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<header>
|
|
<h1>账户仪表盘</h1>
|
|
<div class="header-actions">
|
|
<button id="refresh-btn">刷新数据</button>
|
|
<button id="logout-btn">登出</button>
|
|
</div>
|
|
</header>
|
|
|
|
<div id="last-updated">最后更新时间: N/A</div>
|
|
|
|
<div id="summary-bar">
|
|
<div class="summary-item">
|
|
<span class="summary-label">总账户数</span>
|
|
<span id="total-accounts-value" class="summary-value">0</span>
|
|
</div>
|
|
<div class="summary-item">
|
|
<span class="summary-label">总可用余额</span>
|
|
<span id="total-balance-value" class="summary-value">$0.00</span>
|
|
</div>
|
|
<div class="summary-item">
|
|
<span class="summary-label">总今日消费</span>
|
|
<span id="total-daily-consumption-value" class="summary-value">$0.00</span>
|
|
</div>
|
|
</div>
|
|
|
|
<div id="loading-indicator">正在加载账户数据...</div>
|
|
<div id="account-cards-container">
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const accountCardsContainer = document.getElementById('account-cards-container');
|
|
const mainLoadingIndicator = document.getElementById('loading-indicator');
|
|
const refreshButton = document.getElementById('refresh-btn');
|
|
const logoutButton = document.getElementById('logout-btn');
|
|
const lastUpdatedElem = document.getElementById('last-updated');
|
|
const totalAccountsValueElem = document.getElementById('total-accounts-value');
|
|
const totalBalanceValueElem = document.getElementById('total-balance-value');
|
|
const totalDailyConsumptionValueElem = document.getElementById('total-daily-consumption-value');
|
|
|
|
let autoRefreshAccountsInterval;
|
|
|
|
function formatGeneralDateTime(isoString) {
|
|
if (!isoString) return 'N/A';
|
|
try {
|
|
return new Date(isoString).toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false });
|
|
} catch (e) { return 'Invalid Date'; }
|
|
}
|
|
|
|
function displayAccountData(data) {
|
|
accountCardsContainer.innerHTML = '';
|
|
mainLoadingIndicator.style.display = 'none';
|
|
|
|
const numAccounts = Object.keys(data).length;
|
|
totalAccountsValueElem.textContent = numAccounts;
|
|
const currentTime = new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false });
|
|
lastUpdatedElem.textContent = `最后更新时间: ${currentTime}`;
|
|
|
|
if (numAccounts === 0) {
|
|
accountCardsContainer.innerHTML = '<p style="text-align:center; color: #888; grid-column: 1 / -1;">没有可显示的账户数据。</p>';
|
|
totalBalanceValueElem.textContent = '$0.00';
|
|
totalDailyConsumptionValueElem.textContent = '$0.00';
|
|
return;
|
|
}
|
|
|
|
let totalAvailableBalance = 0;
|
|
let totalDailyConsumption = 0;
|
|
|
|
for (const email in data) {
|
|
const account = data[email];
|
|
if (account.cards_info && account.cards_info.available_balance) {
|
|
totalAvailableBalance += parseFloat(account.cards_info.available_balance) || 0;
|
|
}
|
|
if (account.profile && account.profile.daily_consumption) {
|
|
totalDailyConsumption += parseFloat(String(account.profile.daily_consumption).replace('$', '')) || 0;
|
|
}
|
|
|
|
const accountCardLink = document.createElement('a');
|
|
accountCardLink.classList.add('account-card-link');
|
|
accountCardLink.href = `/dashboard/statements?email=${encodeURIComponent(email)}`;
|
|
|
|
const accountCard = document.createElement('div');
|
|
accountCard.classList.add('account-card');
|
|
|
|
let contentHTML = `<div class="account-info"><h3>${email}</h3>`;
|
|
contentHTML += `<p><strong>Token 状态:</strong> ${account.token_present ? '<span class="status-ok">存在</span>' : '<span class="status-error">不存在</span>'}</p>`;
|
|
contentHTML += `<p><strong>最后登录:</strong> ${formatGeneralDateTime(account.last_login_attempt)} - ${account.last_login_success === true ? '<span class="status-ok">成功</span>' : (account.last_login_success === false ? '<span class="status-error">失败</span>' : 'N/A')}</p>`;
|
|
if (account.login_error) contentHTML += `<p class="error-details">登录错误: ${account.login_error}</p>`;
|
|
|
|
contentHTML += `<p><strong>Profile 获取:</strong> ${formatGeneralDateTime(account.last_profile_attempt)} - ${account.last_profile_success === true ? '<span class="status-ok">成功</span>' : (account.last_profile_success === false ? '<span class="status-error">失败</span>' : 'N/A')}</p>`;
|
|
if (account.profile_error) contentHTML += `<p class="error-details">Profile 错误: ${account.profile_error}</p>`;
|
|
|
|
contentHTML += `<p><strong>卡片获取:</strong> ${formatGeneralDateTime(account.last_card_info_attempt)} - ${account.last_card_info_success === true ? '<span class="status-ok">成功</span>' : (account.last_card_info_success === false ? '<span class="status-error">失败</span>' : 'N/A')}</p>`;
|
|
if (account.card_info_error) contentHTML += `<p class="error-details">卡片错误: ${account.card_info_error}</p>`;
|
|
|
|
if (account.profile) {
|
|
contentHTML += `<p><strong>UID:</strong> ${account.profile.uid || 'N/A'}</p>`;
|
|
contentHTML += `<p><strong>邀请码:</strong> ${account.profile.invitation_code || 'N/A'}</p>`;
|
|
contentHTML += `<p><strong>账户状态:</strong> ${account.profile.status || 'N/A'}</p>`;
|
|
}
|
|
|
|
if (account.cards_info) {
|
|
const card = account.cards_info;
|
|
contentHTML += `<div class="card-details-integrated">`;
|
|
contentHTML += `<p><strong>卡号:</strong> ${ (card.provider_bin && card.card_last_four_digits) ? `${card.provider_bin}xxxxxx${card.card_last_four_digits}` : (card.provider_bin ? `${card.provider_bin}xxxxxx` : (card.card_last_four_digits ? `xxxxxx${card.card_last_four_digits}` : '-')) }</p>`;
|
|
contentHTML += `<p><strong>可用余额:</strong> <span class="highlight-balance">$${card.available_balance || '0.00'}</span></p>`;
|
|
if (account.profile) {
|
|
contentHTML += `<p><strong>每日消耗:</strong> $${account.profile.daily_consumption || '0.00'}</p>`;
|
|
contentHTML += `<p><strong>总收益:</strong> $${account.profile.total_earn_balance || '0.00'}</p>`;
|
|
}
|
|
let dailyLimitDisplay = (card.consumption_limit === null || card.consumption_limit === undefined) ? '-' : (String(card.consumption_limit) === '-1' ? '无限制' : `$${card.consumption_limit}`);
|
|
contentHTML += `<p><strong>卡日限额:</strong> ${dailyLimitDisplay}</p></div>`;
|
|
}
|
|
contentHTML += `</div>`;
|
|
accountCard.innerHTML = contentHTML;
|
|
accountCardLink.appendChild(accountCard);
|
|
accountCardsContainer.appendChild(accountCardLink);
|
|
}
|
|
|
|
totalBalanceValueElem.textContent = `$${totalAvailableBalance.toFixed(2)}`;
|
|
totalDailyConsumptionValueElem.textContent = `$${totalDailyConsumption.toFixed(2)}`;
|
|
}
|
|
|
|
async function fetchInitialAccountData() {
|
|
mainLoadingIndicator.style.display = 'block';
|
|
try {
|
|
const response = await fetch('/api/data');
|
|
if (response.status === 401) { window.location.href = '/'; return; }
|
|
if (!response.ok) { throw new Error(`HTTP error! status: ${response.status}`);}
|
|
const data = await response.json();
|
|
if (data.error) {
|
|
console.error("Error fetching account data:", data.error);
|
|
mainLoadingIndicator.style.display = 'none';
|
|
accountCardsContainer.innerHTML = `<p style="text-align:center; color: var(--error-color);">获取账户数据失败: ${data.error}</p>`;
|
|
} else {
|
|
displayAccountData(data);
|
|
}
|
|
} catch (error) {
|
|
console.error('Error fetching account data:', error);
|
|
mainLoadingIndicator.style.display = 'none';
|
|
accountCardsContainer.innerHTML = `<p style="text-align:center; color: var(--error-color);">获取账户数据时发生网络错误。</p>`;
|
|
}
|
|
}
|
|
|
|
refreshButton.addEventListener('click', async () => {
|
|
const originalButtonText = refreshButton.textContent;
|
|
refreshButton.textContent = '正在刷新...';
|
|
refreshButton.disabled = true;
|
|
mainLoadingIndicator.textContent = '手动刷新中...';
|
|
mainLoadingIndicator.style.display = 'block';
|
|
accountCardsContainer.innerHTML = '';
|
|
|
|
try {
|
|
const refreshApiResponse = await fetch('/api/refresh', { method: 'POST' });
|
|
if (refreshApiResponse.status === 401) { window.location.href = '/'; return; }
|
|
|
|
setTimeout(async () => {
|
|
await fetchInitialAccountData();
|
|
refreshButton.textContent = originalButtonText;
|
|
refreshButton.disabled = false;
|
|
}, 3000);
|
|
|
|
} catch (error) {
|
|
console.error('Error triggering refresh:', error);
|
|
lastUpdatedElem.textContent = `手动刷新失败: ${new Date().toLocaleString('zh-CN', { timeZone: 'Asia/Shanghai', hour12: false })}`;
|
|
refreshButton.textContent = originalButtonText;
|
|
refreshButton.disabled = false;
|
|
mainLoadingIndicator.style.display = 'none';
|
|
}
|
|
});
|
|
|
|
logoutButton.addEventListener('click', () => { window.location.href = '/logout'; });
|
|
|
|
fetchInitialAccountData();
|
|
if (autoRefreshAccountsInterval) clearInterval(autoRefreshAccountsInterval);
|
|
autoRefreshAccountsInterval = setInterval(fetchInitialAccountData, 600000);
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|