后台管理页面仪表板优化

This commit is contained in:
xiaowang
2026-02-25 11:28:42 +08:00
parent ca0af7af8c
commit 057db9ee76
2 changed files with 67 additions and 40 deletions
+19
View File
@@ -64,11 +64,30 @@ export interface AdminLoginResponse {
userInfo: any userInfo: any
} }
export interface HotProduct {
id: number
title: string
price: number
likeCount: number
collectCount: number
}
export interface RecentActivity {
id: number
type: string
title: string
description: string
time: string
color: string
}
export interface DashboardStats { export interface DashboardStats {
totalUsers: number totalUsers: number
totalProducts: number totalProducts: number
totalShops: number totalShops: number
todayOrders: number todayOrders: number
hotProducts: HotProduct[]
recentActivities: RecentActivity[]
} }
export const adminAuthApi = { export const adminAuthApi = {
+48 -40
View File
@@ -72,43 +72,39 @@
</a-col> </a-col>
<a-col :span="8"> <a-col :span="8">
<a-card title="热门商品" :bordered="false" class="chart-card"> <a-card title="热门商品" :bordered="false" class="chart-card">
<a-list :data-source="hotProducts" size="small"> <a-spin :spinning="loading">
<template #renderItem="{ item }"> <a-list :data-source="stats.hotProducts" size="small">
<a-list-item> <template #renderItem="{ item }">
<a-list-item-meta> <a-list-item>
<template #title> <a-list-item-meta>
<a href="#">{{ item.name }}</a> <template #title>
</template> <a href="#">{{ item.title }}</a>
<template #description> </template>
销量: {{ item.sales }} <template #description>
</template> 点赞: {{ item.likeCount }} | 收藏: {{ item.collectCount || 0 }}
</a-list-item-meta> </template>
</a-list-item> </a-list-item-meta>
</template> </a-list-item>
</a-list> </template>
</a-list>
</a-spin>
</a-card> </a-card>
</a-col> </a-col>
</a-row> </a-row>
<a-card title="最近活动" :bordered="false" class="activity-card"> <a-card title="最近活动" :bordered="false" class="activity-card">
<a-timeline> <a-spin :spinning="loading">
<a-timeline-item color="green"> <a-timeline>
<p>用户张三完成了订单 #1024</p> <a-timeline-item
<p style="font-size: 12px; color: #999;">2小时前</p> v-for="activity in stats.recentActivities"
</a-timeline-item> :key="activity.id"
<a-timeline-item color="blue"> :color="activity.color"
<p>新品"星空美甲"已上架</p> >
<p style="font-size: 12px; color: #999;">5小时前</p> <p>{{ activity.description }}</p>
</a-timeline-item> <p style="font-size: 12px; color: #999;">{{ formatTime(activity.time) }}</p>
<a-timeline-item color="red"> </a-timeline-item>
<p>店铺"时尚美甲店"信息已更新</p> </a-timeline>
<p style="font-size: 12px; color: #999;">昨天</p> </a-spin>
</a-timeline-item>
<a-timeline-item>
<p>新用户李四注册成功</p>
<p style="font-size: 12px; color: #999;">2天前</p>
</a-timeline-item>
</a-timeline>
</a-card> </a-card>
</div> </div>
</template> </template>
@@ -130,16 +126,28 @@ const stats = reactive<DashboardStats>({
totalUsers: 0, totalUsers: 0,
totalProducts: 0, totalProducts: 0,
totalShops: 0, totalShops: 0,
todayOrders: 0 todayOrders: 0,
hotProducts: [],
recentActivities: []
}) })
const hotProducts = ref([ const formatTime = (timeStr: string) => {
{ name: '法式美甲', sales: 156 }, if (!timeStr) return ''
{ name: '星空美甲', sales: 132 }, const time = new Date(timeStr)
{ name: '渐变美甲', sales: 98 }, const now = new Date()
{ name: '贴钻美甲', sales: 87 }, const diff = now.getTime() - time.getTime()
{ name: '纯色美甲', sales: 65 }
]) const minutes = Math.floor(diff / 60000)
const hours = Math.floor(diff / 3600000)
const days = Math.floor(diff / 86400000)
if (minutes < 1) return '刚刚'
if (minutes < 60) return `${minutes}分钟前`
if (hours < 24) return `${hours}小时前`
if (days < 7) return `${days}天前`
return time.toLocaleDateString('zh-CN')
}
const fetchStats = async () => { const fetchStats = async () => {
try { try {