-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdashboard.html
More file actions
572 lines (532 loc) · 25.9 KB
/
Copy pathdashboard.html
File metadata and controls
572 lines (532 loc) · 25.9 KB
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
<!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 href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
<style>
:root {
--primary: #4361ee;
--secondary: #3f37c9;
--success: #4cc9f0;
--info: #4895ef;
--warning: #f72585;
--bg: #f8f9fa;
--card-bg: #ffffff;
}
body {
background-color: var(--bg);
font-family: "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
color: #2b2d42;
padding-bottom: 50px;
}
/* 顶部导航 */
.glass-header {
background: rgba(255, 255, 255, 0.9);
backdrop-filter: blur(10px);
position: sticky;
top: 0;
z-index: 1000;
border-bottom: 1px solid rgba(0,0,0,0.05);
padding: 15px 0;
margin-bottom: 30px;
}
/* 卡片通用样式 */
.stat-card {
background: var(--card-bg);
border-radius: 16px;
border: none;
box-shadow: 0 4px 20px rgba(0,0,0,0.03);
transition: transform 0.3s ease, box-shadow 0.3s ease;
height: 100%;
overflow: hidden;
}
.stat-card:hover {
transform: translateY(-5px);
box-shadow: 0 8px 25px rgba(0,0,0,0.06);
}
.card-header-custom {
background: transparent;
padding: 20px 25px 0;
border: none;
}
.card-title {
font-weight: 700;
color: #1a1a1a;
font-size: 1.1rem;
margin: 0;
display: flex;
align-items: center;
gap: 10px;
}
/* KPI 数字卡片 */
.kpi-box {
display: flex;
align-items: center;
padding: 20px;
background: white;
border-radius: 16px;
box-shadow: 0 4px 15px rgba(0,0,0,0.02);
}
.kpi-icon {
width: 50px; height: 50px;
border-radius: 12px;
display: flex; align-items: center; justify-content: center;
font-size: 1.5rem;
margin-right: 15px;
background: #f0f4ff;
color: var(--primary);
}
.kpi-data h3 { font-weight: 800; margin: 0; font-size: 1.8rem; letter-spacing: -1px; }
.kpi-data p { margin: 0; color: #6c757d; font-size: 0.85rem; font-weight: 600; text-transform: uppercase; }
/* 趣味榜单文字样式 */
.fun-fact-item {
padding: 15px;
border-bottom: 1px solid #f1f1f1;
}
.fun-fact-item:last-child { border-bottom: none; }
.fun-label { font-size: 0.9rem; color: #666; margin-bottom: 4px; display: flex; justify-content: space-between; }
.fun-value { font-weight: 700; color: var(--primary); font-size: 1.1rem; }
.fun-sub { font-size: 0.8rem; color: #999; }
/* === ✨ 新增:高级加载动画样式 === */
.loading-overlay {
position: fixed;
top: 0; left: 0; width: 100%; height: 100%;
background: rgba(248, 249, 250, 0.98);
z-index: 2000;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.loader-icon-container {
position: relative;
width: 80px;
height: 80px;
margin-bottom: 30px;
}
.world-icon {
font-size: 3rem;
color: #e2e8f0;
position: absolute;
top: 50%; left: 50%;
transform: translate(-50%, -50%);
}
.plane-icon {
position: absolute;
font-size: 2rem;
color: var(--primary);
top: 0; left: 0;
animation: flight 2.5s infinite linear;
}
.loading-text {
font-weight: 700;
color: #64748b;
letter-spacing: 1px;
animation: pulse-text 1.5s infinite ease-in-out;
}
.loading-bar-container {
width: 200px;
height: 4px;
background: #e2e8f0;
border-radius: 10px;
margin-top: 15px;
overflow: hidden;
}
.loading-bar {
height: 100%;
width: 50%;
background: var(--primary);
border-radius: 10px;
animation: loading-slide 1.5s infinite ease-in-out;
}
@keyframes flight {
0% { transform: translate(10px, 40px) rotate(0deg); opacity: 0; }
20% { opacity: 1; }
80% { opacity: 1; }
100% { transform: translate(60px, -20px) rotate(-45deg); opacity: 0; }
}
@keyframes loading-slide {
0% { transform: translateX(-100%); }
100% { transform: translateX(200%); }
}
@keyframes pulse-text {
0%, 100% { opacity: 0.6; }
50% { opacity: 1; }
}
/* 隐藏 Vue 未编译内容 */
[v-cloak] { display: none; }
</style>
</head>
<body>
<div id="app" v-cloak>
<div v-if="loading" class="loading-overlay">
<div class="loader-icon-container">
<i class="fa-solid fa-earth-asia world-icon"></i>
<i class="fa-solid fa-paper-plane plane-icon"></i>
</div>
<div class="loading-text">正在加载足迹...</div>
<div class="loading-bar-container">
<div class="loading-bar"></div>
</div>
</div>
<div v-else>
<header class="glass-header">
<div class="container d-flex justify-content-between align-items-center">
<div class="h4 mb-0 fw-bold"><i class="fa-solid fa-chart-pie me-2 text-primary"></i>数据中心</div>
<div class="d-flex gap-2">
<a href="timeline.html" class="btn btn-outline-primary btn-sm rounded-pill px-3 fw-bold">
<i class="fa-solid fa-calendar-days me-1"></i>日期筛选
</a>
<a href="index.html" class="btn btn-success btn-sm rounded-pill px-4 fw-bold shadow-sm">
<i class="fa-solid fa-images me-2"></i>返回明信片墙
</a>
</div>
</div>
</header>
<div class="container">
<div class="row g-3 mb-4">
<div class="col-6 col-md-3">
<div class="kpi-box">
<div class="kpi-icon"><i class="fa-solid fa-layer-group"></i></div>
<div class="kpi-data">
<h3>{{ stats.total }}</h3>
<p>Total Cards</p>
</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="kpi-box">
<div class="kpi-icon" style="color: #4cc9f0; background: #e0f7fa;"><i class="fa-solid fa-inbox"></i></div>
<div class="kpi-data">
<h3>{{ stats.receive }}</h3>
<p>Received</p>
</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="kpi-box">
<div class="kpi-icon" style="color: #4895ef; background: #e3f2fd;"><i class="fa-solid fa-paper-plane"></i></div>
<div class="kpi-data">
<h3>{{ stats.sent }}</h3>
<p>Sent Out</p>
</div>
</div>
</div>
<div class="col-6 col-md-3">
<div class="kpi-box">
<div class="kpi-icon" style="color: #f72585; background: #fce4ec;"><i class="fa-solid fa-plane-departure"></i></div>
<div class="kpi-data">
<h3>{{ stats.avgDuration }}<small style="font-size:1rem"> 天</small></h3>
<p>Avg Duration</p>
</div>
</div>
</div>
</div>
<div class="row mb-4">
<div class="col-12">
<div class="stat-card">
<div class="card-header-custom">
<h5 class="card-title"><i class="fa-solid fa-arrow-trend-up text-primary"></i> 收发趋势 Timeline</h5>
</div>
<div class="card-body">
<div id="chart-trend" style="width: 100%; height: 350px;"></div>
</div>
</div>
</div>
</div>
<div class="row g-4">
<div class="col-lg-8">
<div class="row g-4">
<div class="col-12">
<div class="stat-card">
<div class="card-header-custom">
<h5 class="card-title"><i class="fa-solid fa-map-location-dot text-warning"></i> 热门地区 Top 10</h5>
</div>
<div class="card-body">
<div id="chart-geo" style="width: 100%; height: 350px;"></div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="stat-card">
<div class="card-header-custom">
<h5 class="card-title"><i class="fa-regular fa-clock text-info"></i> 漂流时长分布</h5>
</div>
<div class="card-body">
<div id="chart-duration" style="width: 100%; height: 300px;"></div>
</div>
</div>
</div>
<div class="col-md-6">
<div class="stat-card">
<div class="card-header-custom">
<h5 class="card-title"><i class="fa-solid fa-ticket text-success"></i> 平台占比</h5>
</div>
<div class="card-body">
<div id="chart-platform" style="width: 100%; height: 300px;"></div>
</div>
</div>
</div>
</div>
</div>
<div class="col-lg-4">
<div class="row g-4">
<div class="col-12">
<div class="stat-card">
<div class="card-header-custom">
<h5 class="card-title"><i class="fa-solid fa-scale-balanced text-secondary"></i> 收支平衡</h5>
</div>
<div class="card-body">
<div id="chart-balance" style="width: 100%; height: 250px;"></div>
</div>
</div>
</div>
<div class="col-12">
<div class="stat-card h-100">
<div class="card-header-custom border-bottom pb-3">
<h5 class="card-title">🏆 趣味之最 Fun Facts</h5>
</div>
<div class="card-body p-0">
<div class="fun-fact-item">
<div class="fun-label"><span>🐢 最漫长的旅程</span> <i class="fa-solid fa-route text-muted"></i></div>
<div class="fun-value" v-if="funFacts.longest">{{ funFacts.longest.days }} 天</div>
<div class="fun-sub" v-if="funFacts.longest">
{{ funFacts.longest.card.region }} | {{ funFacts.longest.card.person }}
<a :href="'detail.html?id='+funFacts.longest.card.id" target="_blank" class="ms-1"><i class="fa-solid fa-arrow-up-right-from-square"></i></a>
</div>
</div>
<div class="fun-fact-item">
<div class="fun-label"><span>🚀 最速传说</span> <i class="fa-solid fa-bolt text-muted"></i></div>
<div class="fun-value" v-if="funFacts.shortest">{{ funFacts.shortest.days }} 天</div>
<div class="fun-sub" v-if="funFacts.shortest">
{{ funFacts.shortest.card.region }} | {{ funFacts.shortest.card.person }}
<a :href="'detail.html?id='+funFacts.shortest.card.id" target="_blank" class="ms-1"><i class="fa-solid fa-arrow-up-right-from-square"></i></a>
</div>
</div>
<div class="fun-fact-item">
<div class="fun-label"><span>🤝 最佳片友 (互动最多)</span> <i class="fa-solid fa-user-group text-muted"></i></div>
<div class="fun-value" v-if="funFacts.topFriend">{{ funFacts.topFriend.name }}</div>
<div class="fun-sub" v-if="funFacts.topFriend">共交换 {{ funFacts.topFriend.count }} 张明信片</div>
</div>
<div class="fun-fact-item">
<div class="fun-label"><span>📅 最忙碌的一天</span> <i class="fa-regular fa-calendar-check text-muted"></i></div>
<div class="fun-value" v-if="funFacts.busyDay">{{ funFacts.busyDay.date }}</div>
<div class="fun-sub" v-if="funFacts.busyDay">处理了 {{ funFacts.busyDay.count }} 张</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/@supabase/supabase-js@2"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/echarts/5.4.3/echarts.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
<script>
// ⚠️ Supabase 配置
const supabaseUrl = 'https://twrdvfeswnywkgqjbjdz.supabase.co';
const supabaseKey = 'sb_publishable_NQpsX76wlKtglbYskxwhiQ_T024LL_X';
const supabaseClient = supabase.createClient(supabaseUrl, supabaseKey);
new Vue({
el: '#app',
data: {
postcards: [],
loading: true,
charts: {}
},
computed: {
stats() {
const total = this.postcards.length;
const receive = this.postcards.filter(c => c.type === '收到').length;
const sent = total - receive;
let totalDays = 0, count = 0;
this.postcards.forEach(c => {
const days = this.getDuration(c);
if (days !== null) { totalDays += days; count++; }
});
return { total, receive, sent, avgDuration: count ? Math.round(totalDays / count) : 0 };
},
funFacts() {
if (!this.postcards.length) return {};
let validCards = this.postcards.map(c => ({...c, _days: this.getDuration(c)})).filter(c => c._days !== null);
validCards.sort((a,b) => b._days - a._days);
const longest = validCards.length ? { days: validCards[0]._days, card: validCards[0] } : null;
const shortest = validCards.length ? { days: validCards[validCards.length-1]._days, card: validCards[validCards.length-1] } : null;
const friends = {};
this.postcards.forEach(c => { if(c.person) friends[c.person] = (friends[c.person] || 0) + 1; });
const topFriendName = Object.keys(friends).sort((a,b) => friends[b] - friends[a])[0];
const topFriend = topFriendName ? { name: topFriendName, count: friends[topFriendName] } : null;
const dates = {};
this.postcards.forEach(c => { const d = c.receiveDate || c.sendDate; if(d) dates[d] = (dates[d] || 0) + 1; });
const busyDate = Object.keys(dates).sort((a,b) => dates[b] - dates[a])[0];
const busyDay = busyDate ? { date: busyDate, count: dates[busyDate] } : null;
return { longest, shortest, topFriend, busyDay };
}
},
mounted() {
this.fetchData();
},
methods: {
async fetchData() {
try {
let { data, error } = await supabaseClient
.from('postcard')
.select('*');
if (error) throw error;
this.postcards = data.map(item => {
let tags = item.tags;
if (typeof tags === 'string') {
tags = tags.replace(/[\[\]"]/g, '').split(',').filter(t => t.trim() !== '');
} else if (!tags) tags = [];
return {
...item,
id: item.id,
type: item.type,
country: item.country,
region: item.region,
note: item.note,
tags: tags,
imgFront: item.imgFront || item.imgfront || item.image_path,
sendDate: item.sendDate || item.senddate || item.send_date,
receiveDate: item.receiveDate || item.receivedate || item.receive_date,
person: item.person,
platform: item.platform
};
});
// 延迟一点点,让用户欣赏一下你的新飞机动画 :)
setTimeout(() => {
this.loading = false;
this.$nextTick(() => {
this.initCharts();
window.addEventListener('resize', this.resizeCharts);
});
}, 1500); // 1.5秒动画展示时间
} catch (e) {
console.error('Data Load Error:', e);
this.loading = false;
alert("加载出错,请检查网络或配置");
}
},
// --- 图表逻辑保持不变 ---
initCharts() {
if(document.getElementById('chart-trend')) this.initTrendChart();
if(document.getElementById('chart-geo')) this.initGeoChart();
if(document.getElementById('chart-platform')) this.initPlatformChart();
if(document.getElementById('chart-balance')) this.initBalanceChart();
if(document.getElementById('chart-duration')) this.initDurationChart();
},
getDuration(card) {
if (!card.receiveDate || !card.sendDate) return null;
const start = new Date(card.sendDate);
const end = new Date(card.receiveDate);
const diff = Math.floor((end - start) / (1000 * 60 * 60 * 24));
return diff >= 0 ? diff : 0;
},
extractRegion(c) {
if (c.country && c.country !== '中国') return c.country;
if (!c.region) return '未知';
let name = c.region.substring(0, 2);
if (['内蒙', '黑龙'].includes(name)) name = c.region.substring(0, 3);
return name;
},
resizeCharts() { Object.values(this.charts).forEach(c => c && c.resize()); },
initTrendChart() {
const chart = echarts.init(document.getElementById('chart-trend'));
this.charts.trend = chart;
const monthMap = {};
this.postcards.forEach(c => {
const d = c.receiveDate || c.sendDate;
if(!d) return;
const m = d.substring(0, 7);
if(!monthMap[m]) monthMap[m] = { send: 0, receive: 0 };
c.type === '收到' ? monthMap[m].receive++ : monthMap[m].send++;
});
const months = Object.keys(monthMap).sort();
chart.setOption({
tooltip: { trigger: 'axis' },
legend: { bottom: 0 },
grid: { left: '3%', right: '4%', bottom: '10%', containLabel: true },
xAxis: { type: 'category', data: months },
yAxis: { type: 'value', minInterval: 1 },
series: [
{ name: '收到', type: 'line', smooth: true, data: months.map(m => monthMap[m].receive), itemStyle: { color: '#4cc9f0' }, areaStyle: { opacity: 0.1 } },
{ name: '寄出', type: 'line', smooth: true, data: months.map(m => monthMap[m].send), itemStyle: { color: '#4361ee' }, areaStyle: { opacity: 0.1 } }
]
});
},
initGeoChart() {
const chart = echarts.init(document.getElementById('chart-geo'));
this.charts.geo = chart;
const counts = {};
this.postcards.forEach(c => {
const key = this.extractRegion(c);
counts[key] = (counts[key] || 0) + 1;
});
const sorted = Object.entries(counts).sort((a,b) => b[1] - a[1]).slice(0, 10);
chart.setOption({
tooltip: { trigger: 'axis', axisPointer: { type: 'shadow' } },
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
xAxis: { type: 'value', minInterval: 1 },
yAxis: { type: 'category', data: sorted.map(i => i[0]).reverse() },
series: [{
type: 'bar', data: sorted.map(i => i[1]).reverse(),
itemStyle: { color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{ offset: 0, color: '#4361ee' }, { offset: 1, color: '#f72585' }]), borderRadius: [0, 10, 10, 0] },
label: { show: true, position: 'right' }
}]
});
},
initPlatformChart() {
const chart = echarts.init(document.getElementById('chart-platform'));
this.charts.platform = chart;
const counts = {};
this.postcards.forEach(c => {
const p = c.platform || '其他';
counts[p] = (counts[p] || 0) + 1;
});
const data = Object.keys(counts).map(k => ({ name: k, value: counts[k] }));
chart.setOption({
tooltip: { trigger: 'item' },
legend: { bottom: 0 },
series: [{ type: 'pie', radius: ['40%', '70%'], avoidLabelOverlap: false, itemStyle: { borderRadius: 10, borderColor: '#fff', borderWidth: 2 }, data: data, color: ['#4361ee', '#3a0ca3', '#7209b7', '#f72585', '#4cc9f0'] }]
});
},
initBalanceChart() {
const chart = echarts.init(document.getElementById('chart-balance'));
this.charts.balance = chart;
chart.setOption({
tooltip: { trigger: 'item' },
series: [{ type: 'pie', radius: '70%', center: ['50%', '50%'], data: [{ value: this.stats.receive, name: '收到', itemStyle: { color: '#4cc9f0' } }, { value: this.stats.sent, name: '寄出', itemStyle: { color: '#4361ee' } }], label: { formatter: '{b}: {c} ({d}%)' } }]
});
},
initDurationChart() {
const chart = echarts.init(document.getElementById('chart-duration'));
this.charts.duration = chart;
const bins = { '0-3天': 0, '4-7天': 0, '8-14天': 0, '15-30天': 0, '30天+': 0 };
this.postcards.forEach(c => {
const days = this.getDuration(c);
if(days === null) return;
if (days <= 3) bins['0-3天']++;
else if (days <= 7) bins['4-7天']++;
else if (days <= 14) bins['8-14天']++;
else if (days <= 30) bins['15-30天']++;
else bins['30天+']++;
});
chart.setOption({
tooltip: { trigger: 'axis' },
grid: { left: '3%', right: '4%', bottom: '3%', containLabel: true },
xAxis: { type: 'category', data: Object.keys(bins) },
yAxis: { type: 'value', minInterval: 1 },
series: [{ type: 'bar', data: Object.values(bins), itemStyle: { color: '#7209b7', borderRadius: [5, 5, 0, 0] }, label: { show: true, position: 'top' } }]
});
}
}
});
</script>
</body>
</html>