feat: Dashboard访问趋势图
- 纯CSS柱状图(无第三方依赖) - 近7天访问趋势(随机模拟数据,可后续接入真实数据) - 渐变色柱状+过渡动画 - 暗色模式适配
This commit is contained in:
@@ -77,12 +77,22 @@
|
||||
</el-table>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<el-card style="margin-top:24px">
|
||||
<template #header><span>访问趋势(近7天)</span></template>
|
||||
<div class="chart-container">
|
||||
<div v-for="d in viewTrend" :key="d.date" class="chart-bar-wrap">
|
||||
<div class="chart-bar" :style="{ height: (d.count / maxViews * 120 || 0) + 'px' }" :title="d.date + ':' + d.count + '次'"></div>
|
||||
<span class="chart-label">{{ d.date.slice(5) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { Plus, FolderAdd, Setting, View } from '@element-plus/icons-vue'
|
||||
import { adminApi } from '@/api'
|
||||
|
||||
@@ -90,6 +100,19 @@ const stats = ref({ linkCount: 0, catCount: 0, totalViews: 0 })
|
||||
const settings = ref({})
|
||||
const categories = ref([])
|
||||
const loading = ref(true)
|
||||
const viewTrend = ref<{date:string,count:number}[]>([])
|
||||
|
||||
const maxViews = computed(() => Math.max(1, ...viewTrend.value.map(d => d.count)))
|
||||
|
||||
function generateTrend() {
|
||||
const now = new Date()
|
||||
viewTrend.value = Array.from({length:7}, (_, i) => {
|
||||
const d = new Date(now)
|
||||
d.setDate(d.getDate() - (6 - i))
|
||||
const dateStr = d.toISOString().slice(0,10)
|
||||
return { date: dateStr, count: Math.floor(Math.random() * 5 + 1) }
|
||||
})
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
try {
|
||||
@@ -104,6 +127,7 @@ onMounted(async () => {
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
generateTrend()
|
||||
})
|
||||
</script>
|
||||
|
||||
@@ -115,6 +139,32 @@ onMounted(async () => {
|
||||
.action-btn { width: 100%; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
.dashboard-loading { padding: 20px; }
|
||||
.chart-container {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 12px;
|
||||
height: 160px;
|
||||
padding: 0 8px;
|
||||
}
|
||||
.chart-bar-wrap {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
height: 100%;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.chart-bar {
|
||||
width: 100%;
|
||||
max-width: 40px;
|
||||
background: linear-gradient(to top, #6366f1, #818cf8);
|
||||
border-radius: 4px 4px 0 0;
|
||||
transition: height 0.5s ease;
|
||||
min-height: 4px;
|
||||
}
|
||||
.chart-label { font-size: 11px; color: #888; white-space: nowrap; }
|
||||
html.dark .chart-label { color: var(--text-secondary); }
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.stat-item .num { font-size: 28px; }
|
||||
|
||||
Reference in New Issue
Block a user