File size: 18,159 Bytes
ce156e0
 
 
 
 
 
eaf2f47
 
 
ce156e0
c903c67
 
931e053
 
 
c903c67
 
931e053
 
 
c903c67
 
ce156e0
c903c67
ce156e0
931e053
c903c67
ce156e0
c903c67
 
ce156e0
 
 
c903c67
931e053
ce156e0
 
c903c67
931e053
 
 
 
 
c903c67
 
931e053
 
c903c67
 
 
931e053
 
 
 
 
 
 
 
 
 
 
ce156e0
931e053
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c903c67
 
931e053
 
 
 
c903c67
 
931e053
c903c67
931e053
c903c67
 
931e053
c903c67
 
 
931e053
c903c67
931e053
c903c67
 
 
 
931e053
c903c67
ce156e0
 
c903c67
ce156e0
 
931e053
 
 
 
 
 
 
 
ce156e0
 
931e053
 
c903c67
ce156e0
c903c67
931e053
c903c67
931e053
 
 
c903c67
931e053
 
 
 
 
 
ce156e0
 
 
931e053
c903c67
 
 
 
931e053
c903c67
931e053
 
 
 
c903c67
ce156e0
 
c903c67
931e053
 
 
c903c67
 
 
ce156e0
931e053
c903c67
931e053
ce156e0
931e053
 
c903c67
931e053
 
c903c67
 
 
 
 
ce156e0
931e053
ce156e0
 
931e053
 
c903c67
ce156e0
 
 
 
931e053
 
 
 
ce156e0
 
 
 
 
 
 
 
931e053
ce156e0
 
 
931e053
 
 
ce156e0
c903c67
 
 
 
 
 
 
 
 
 
 
 
 
 
ce156e0
931e053
ce156e0
 
 
 
 
 
 
931e053
ce156e0
 
931e053
c903c67
 
 
 
931e053
ce156e0
931e053
ce156e0
 
eaf2f47
931e053
ce156e0
931e053
 
ce156e0
931e053
ce156e0
c903c67
 
eaf2f47
c903c67
 
 
ce156e0
c903c67
 
ce156e0
 
 
c903c67
 
 
ce156e0
 
c903c67
931e053
c903c67
 
931e053
c903c67
ce156e0
931e053
 
 
 
ce156e0
 
 
931e053
ce156e0
931e053
 
 
 
 
ce156e0
931e053
 
ce156e0
 
 
 
 
 
 
 
 
c903c67
 
 
 
 
 
ce156e0
931e053
 
ce156e0
 
 
931e053
 
ce156e0
c903c67
931e053
 
ce156e0
 
931e053
 
ce156e0
931e053
 
 
ce156e0
 
931e053
 
 
ce156e0
931e053
ce156e0
 
931e053
 
 
ce156e0
 
 
 
 
 
 
931e053
 
 
ce156e0
 
931e053
 
 
ce156e0
931e053
ce156e0
 
 
 
 
 
eaf2f47
ce156e0
 
931e053
ce156e0
 
 
931e053
ce156e0
931e053
 
 
ce156e0
 
 
c903c67
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
<!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>