后台管理页面仪表板优化
This commit is contained in:
@@ -64,6 +64,13 @@ export interface AdminLoginResponse {
|
||||
userInfo: any
|
||||
}
|
||||
|
||||
export interface DashboardStats {
|
||||
totalUsers: number
|
||||
totalProducts: number
|
||||
totalShops: number
|
||||
todayOrders: number
|
||||
}
|
||||
|
||||
export const adminAuthApi = {
|
||||
login: (data: AdminLoginRequest) => {
|
||||
return adminApi.post<AdminLoginResponse>('/admin/auth/login', data)
|
||||
@@ -74,4 +81,10 @@ export const adminAuthApi = {
|
||||
}
|
||||
}
|
||||
|
||||
export const adminDashboardApi = {
|
||||
getStats: () => {
|
||||
return adminApi.get<DashboardStats>('/admin/dashboard/stats')
|
||||
}
|
||||
}
|
||||
|
||||
export default adminApi
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="总用户数"
|
||||
:value="128"
|
||||
:value="stats.totalUsers"
|
||||
:value-style="{ color: '#3f8600' }"
|
||||
:loading="loading"
|
||||
>
|
||||
<template #prefix>
|
||||
<UserOutlined />
|
||||
@@ -20,8 +21,9 @@
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="商品总数"
|
||||
:value="56"
|
||||
:value="stats.totalProducts"
|
||||
:value-style="{ color: '#1890ff' }"
|
||||
:loading="loading"
|
||||
>
|
||||
<template #prefix>
|
||||
<ShopOutlined />
|
||||
@@ -33,8 +35,9 @@
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="店铺数量"
|
||||
:value="8"
|
||||
:value="stats.totalShops"
|
||||
:value-style="{ color: '#722ed1' }"
|
||||
:loading="loading"
|
||||
>
|
||||
<template #prefix>
|
||||
<HomeOutlined />
|
||||
@@ -46,8 +49,9 @@
|
||||
<a-card>
|
||||
<a-statistic
|
||||
title="今日订单"
|
||||
:value="24"
|
||||
:value="stats.todayOrders"
|
||||
:value-style="{ color: '#cf1322' }"
|
||||
:loading="loading"
|
||||
>
|
||||
<template #prefix>
|
||||
<ShoppingOutlined />
|
||||
@@ -110,7 +114,8 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue'
|
||||
import { ref, reactive, onMounted } from 'vue'
|
||||
import { message } from 'ant-design-vue'
|
||||
import {
|
||||
UserOutlined,
|
||||
ShopOutlined,
|
||||
@@ -118,6 +123,15 @@ import {
|
||||
ShoppingOutlined,
|
||||
BarChartOutlined
|
||||
} from '@ant-design/icons-vue'
|
||||
import { adminDashboardApi, type DashboardStats } from '@/api/admin'
|
||||
|
||||
const loading = ref(false)
|
||||
const stats = reactive<DashboardStats>({
|
||||
totalUsers: 0,
|
||||
totalProducts: 0,
|
||||
totalShops: 0,
|
||||
todayOrders: 0
|
||||
})
|
||||
|
||||
const hotProducts = ref([
|
||||
{ name: '法式美甲', sales: 156 },
|
||||
@@ -126,6 +140,23 @@ const hotProducts = ref([
|
||||
{ name: '贴钻美甲', sales: 87 },
|
||||
{ name: '纯色美甲', sales: 65 }
|
||||
])
|
||||
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
const data = await adminDashboardApi.getStats()
|
||||
Object.assign(stats, data)
|
||||
} catch (error) {
|
||||
console.error('获取统计数据失败:', error)
|
||||
message.error('获取统计数据失败')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchStats()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in New Issue
Block a user