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