172 lines
5.7 KiB
Vue
172 lines
5.7 KiB
Vue
<template>
|
||
<div class="dashboard">
|
||
<div v-if="loading" class="dashboard-loading">
|
||
<el-skeleton :rows="2" animated />
|
||
<el-skeleton style="margin-top:24px" :rows="2" animated />
|
||
<el-skeleton style="margin-top:24px" :rows="6" animated />
|
||
</div>
|
||
<template v-else>
|
||
<el-row :gutter="[16, 16]" class="stat-cards">
|
||
<el-col :xs="12" :sm="6">
|
||
<el-card shadow="hover">
|
||
<div class="stat-item">
|
||
<span class="num">{{ stats.linkCount }}</span>
|
||
<span class="label">网址总数</span>
|
||
</div>
|
||
</el-card>
|
||
</el-col>
|
||
<el-col :xs="12" :sm="6">
|
||
<el-card shadow="hover">
|
||
<div class="stat-item">
|
||
<span class="num">{{ stats.catCount }}</span>
|
||
<span class="label">分类数</span>
|
||
</div>
|
||
</el-card>
|
||
</el-col>
|
||
<el-col :xs="12" :sm="6">
|
||
<el-card shadow="hover">
|
||
<div class="stat-item">
|
||
<span class="num">{{ stats.totalViews }}</span>
|
||
<span class="label">总访问</span>
|
||
</div>
|
||
</el-card>
|
||
</el-col>
|
||
<el-col :xs="12" :sm="6">
|
||
<el-card shadow="hover">
|
||
<div class="stat-item">
|
||
<span class="num" style="font-size:20px">{{ settings.site_name || '言逍导航' }}</span>
|
||
<span class="label">站点名称</span>
|
||
</div>
|
||
</el-card>
|
||
</el-col>
|
||
</el-row>
|
||
|
||
<el-card style="margin-top:24px">
|
||
<template #header><span>快捷操作</span></template>
|
||
<el-row :gutter="[16, 16]">
|
||
<el-col :xs="12" :sm="6">
|
||
<el-button type="primary" class="action-btn" @click="$router.push('/admin/links')">
|
||
<el-icon><Plus /></el-icon> 管理网址
|
||
</el-button>
|
||
</el-col>
|
||
<el-col :xs="12" :sm="6">
|
||
<el-button type="success" class="action-btn" @click="$router.push('/admin/categories')">
|
||
<el-icon><FolderAdd /></el-icon> 管理分类
|
||
</el-button>
|
||
</el-col>
|
||
<el-col :xs="12" :sm="6">
|
||
<el-button type="warning" class="action-btn" @click="$router.push('/admin/settings')">
|
||
<el-icon><Setting /></el-icon> 站点配置
|
||
</el-button>
|
||
</el-col>
|
||
<el-col :xs="12" :sm="6">
|
||
<el-button class="action-btn" @click="() => window.open('/', '_blank')">
|
||
<el-icon><View /></el-icon> 预览前台
|
||
</el-button>
|
||
</el-col>
|
||
</el-row>
|
||
</el-card>
|
||
|
||
<el-card style="margin-top:24px">
|
||
<template #header><span>分类概览</span></template>
|
||
<div class="table-wrap">
|
||
<el-table :data="categories" style="width:100%">
|
||
<el-table-column prop="name" label="分类" />
|
||
<el-table-column prop="linkCount" label="网址数" width="100" />
|
||
<el-table-column prop="icon" label="图标" width="80" />
|
||
</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, computed, onMounted } from 'vue'
|
||
import { Plus, FolderAdd, Setting, View } from '@element-plus/icons-vue'
|
||
import { adminApi } from '@/api'
|
||
|
||
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 {
|
||
const [statsRes, setRes] = await Promise.all([
|
||
adminApi.getStats(),
|
||
adminApi.getSettings()
|
||
])
|
||
const d = statsRes.result.data
|
||
stats.value = { linkCount: d.linkCount, catCount: d.categories.length, totalViews: d.totalViews }
|
||
categories.value = d.categories
|
||
settings.value = setRes.result.data
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
generateTrend()
|
||
})
|
||
</script>
|
||
|
||
<style scoped>
|
||
.stat-cards { margin-bottom: 8px; }
|
||
.stat-item { text-align: center; }
|
||
.stat-item .num { display: block; font-size: 36px; font-weight: 700; color: #6366f1; margin-bottom: 8px; }
|
||
.stat-item .label { color: #888; font-size: 14px; }
|
||
.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; }
|
||
}
|
||
</style> |