Dashboard 仪表盘组件
仪表盘组件集包含 4 个常用的数据展示组件,适用于数据大屏、管理后台首页等场景。
组件路径
src/components/Dashboard/
├── index.ts
├── StatCard.vue # 统计卡片
├── QuickNav.vue # 快捷导航
├── RankTable.vue # 排行榜
└── ChartCard.vue # 图表卡片导入方式
import { StatCard, QuickNav, RankTable, ChartCard } from '@/components/Dashboard';1. StatCard 统计卡片
用于展示关键指标数据,支持趋势显示。
Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| title | 标题 | string | - |
| value | 数值 | number | string | - |
| suffix | 后缀单位 | string | - |
| trend | 趋势值(如:+10%, -5%) | string | - |
| loading | 加载状态 | boolean | false |
使用示例
<template>
<a-row :gutter="16">
<a-col :span="6">
<StatCard
title="总用户数"
:value="12345"
suffix="人"
trend="+12.5%"
/>
</a-col>
<a-col :span="6">
<StatCard
title="今日收入"
:value="67890"
suffix="元"
trend="-3.2%"
/>
</a-col>
<a-col :span="6">
<StatCard
title="订单数"
:value="856"
trend="+5.8%"
:loading="loading"
/>
</a-col>
<a-col :span="6">
<StatCard
title="转化率"
value="68.5"
suffix="%"
/>
</a-col>
</a-row>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { StatCard } from '@/components/Dashboard';
const loading = ref(false);
</script>趋势显示规则
- 上升趋势:
+开头或↑开头显示绿色向上箭头 - 下降趋势:
-开头或↓开头显示红色向下箭头 - 其他: 显示灰色横线
2. QuickNav 快捷导航
网格布局的快捷导航菜单,支持跳转到指定路由。
Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| items | 导航项数组 | QuickNavItem[] | [] |
| columns | 每行显示的列数 | number | 4 |
QuickNavItem 类型
interface QuickNavItem {
title: string; // 标题
icon: string; // 图标(Iconify 格式)
route: string; // 路由路径
}使用示例
<template>
<QuickNav
:items="navItems"
:columns="5"
/>
</template>
<script setup lang="ts">
import { QuickNav } from '@/components/Dashboard';
const navItems = [
{ title: '用户管理', icon: 'ant-design:user-outlined', route: '/system/user' },
{ title: '订单管理', icon: 'ant-design:shopping-cart-outlined', route: '/ec/order' },
{ title: '商品管理', icon: 'ant-design:gift-outlined', route: '/ec/product' },
{ title: '营销活动', icon: 'ant-design:rocket-outlined', route: '/marketing/activity' },
{ title: '数据报表', icon: 'ant-design:bar-chart-outlined', route: '/statistical/dashboard' },
];
</script>3. RankTable 排行榜
带排名徽章的表格组件,适用于 Top N 榜单展示。
Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| title | 表格标题 | string | - |
| columns | 列配置 | TableProps['columns'] | - |
| dataSource | 数据源 | any[] | - |
| loading | 加载状态 | boolean | false |
| pagination | 分页配置 | false | TableProps['pagination'] | false |
| scrollY | 滚动高度 | number | string | 300 |
插槽
| 插槽名 | 说明 |
|---|---|
| extra | 标题右侧额外内容 |
| bodyCell | 自定义单元格渲染 |
使用示例
<template>
<RankTable
title="销售排行榜"
:columns="columns"
:data-source="dataSource"
:scroll-y="240"
>
<template #extra>
<a-button type="link">查看全部</a-button>
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'sales'">
<a-statistic :value="record.sales" suffix="元" />
</template>
</template>
</RankTable>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { RankTable } from '@/components/Dashboard';
const columns = [
{ title: '排名', key: 'rank', width: 80, align: 'center' },
{ title: '商品名称', dataIndex: 'name' },
{ title: '销售额', dataIndex: 'sales' },
];
const dataSource = ref([
{ id: 1, name: 'iPhone 15 Pro', sales: 125800 },
{ id: 2, name: '小米14 Ultra', sales: 98500 },
{ id: 3, name: '华为 Mate 60', sales: 87600 },
{ id: 4, name: 'OPPO Find X7', sales: 65400 },
{ id: 5, name: 'vivo X100', sales: 54300 },
]);
</script>排名样式
- 第 1 名: 金色渐变背景
- 第 2 名: 银色渐变背景
- 第 3 名: 铜色渐变背景
- 其他: 灰色数字
4. ChartCard 图表卡片
基于 ECharts 的图表卡片组件,支持饼图、折线图、柱状图。
Props
| 参数 | 说明 | 类型 | 默认值 |
|---|---|---|---|
| title | 卡片标题 | string | - |
| type | 图表类型 | 'pie' | 'line' | 'bar' | - |
| data | 图表数据 | ChartData[] | [] |
| loading | 加载状态 | boolean | false |
| height | 图表高度 | string | '300px' |
ChartData 类型
interface ChartData {
name: string;
value: number;
[key: string]: any;
}插槽
| 插槽名 | 说明 |
|---|---|
| extra | 标题右侧额外内容 |
使用示例
<template>
<a-row :gutter="16">
<a-col :span="8">
<ChartCard
title="销售占比"
type="pie"
:data="pieData"
/>
</a-col>
<a-col :span="8">
<ChartCard
title="销售趋势"
type="line"
:data="lineData"
/>
</a-col>
<a-col :span="8">
<ChartCard
title="分类销售"
type="bar"
:data="barData"
/>
</a-col>
</a-row>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import { ChartCard } from '@/components/Dashboard';
const pieData = ref([
{ name: '电子产品', value: 1048 },
{ name: '服装配饰', value: 735 },
{ name: '家居用品', value: 580 },
{ name: '食品饮料', value: 484 },
]);
const lineData = ref([
{ name: '1月', value: 120 },
{ name: '2月', value: 200 },
{ name: '3月', value: 150 },
{ name: '4月', value: 80 },
{ name: '5月', value: 70 },
{ name: '6月', value: 110 },
]);
const barData = ref([
{ name: '华东', value: 520 },
{ name: '华北', value: 400 },
{ name: '华南', value: 380 },
{ name: '西南', value: 220 },
]);
</script>综合示例:仪表盘页面
<template>
<div class="dashboard-page">
<!-- 统计卡片 -->
<a-row :gutter="16" style="margin-bottom: 16px">
<a-col :span="6">
<StatCard title="总用户数" :value="userCount" suffix="人" trend="+12.5%" />
</a-col>
<a-col :span="6">
<StatCard title="今日订单" :value="orderCount" trend="+5.8%" />
</a-col>
<a-col :span="6">
<StatCard title="今日收入" :value="revenue" suffix="元" trend="-3.2%" />
</a-col>
<a-col :span="6">
<StatCard title="转化率" value="68.5" suffix="%" />
</a-col>
</a-row>
<!-- 快捷导航和图表 -->
<a-row :gutter="16" style="margin-bottom: 16px">
<a-col :span="12">
<QuickNav :items="navItems" :columns="4" />
</a-col>
<a-col :span="12">
<ChartCard title="销售占比" type="pie" :data="pieData" />
</a-col>
</a-row>
<!-- 排行榜 -->
<a-row :gutter="16">
<a-col :span="12">
<RankTable
title="商品销量榜"
:columns="productColumns"
:data-source="productRankData"
>
<template #extra>
<a-button type="link" @click="$router.push('/ec/product')">更多</a-button>
</template>
</RankTable>
</a-col>
<a-col :span="12">
<RankTable
title="用户消费榜"
:columns="userColumns"
:data-source="userRankData"
/>
</a-col>
</a-row>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { StatCard, QuickNav, RankTable, ChartCard } from '@/components/Dashboard';
const userCount = ref(0);
const orderCount = ref(0);
const revenue = ref(0);
const navItems = [
{ title: '用户管理', icon: 'ant-design:user-outlined', route: '/system/user' },
{ title: '订单管理', icon: 'ant-design:shopping-cart-outlined', route: '/ec/order' },
{ title: '商品管理', icon: 'ant-design:gift-outlined', route: '/ec/product' },
{ title: '数据报表', icon: 'ant-design:bar-chart-outlined', route: '/statistical/dashboard' },
];
const pieData = ref([
{ name: '电子产品', value: 1048 },
{ name: '服装配饰', value: 735 },
{ name: '家居用品', value: 580 },
{ name: '食品饮料', value: 484 },
]);
const productColumns = [
{ title: '排名', key: 'rank', width: 60, align: 'center' },
{ title: '商品名称', dataIndex: 'name' },
{ title: '销量', dataIndex: 'sales' },
];
const userColumns = [
{ title: '排名', key: 'rank', width: 60, align: 'center' },
{ title: '用户昵称', dataIndex: 'nickname' },
{ title: '消费金额', dataIndex: 'amount' },
];
const productRankData = ref([
{ id: 1, name: 'iPhone 15 Pro', sales: 1258 },
{ id: 2, name: '小米14 Ultra', sales: 985 },
{ id: 3, name: '华为 Mate 60', sales: 876 },
]);
const userRankData = ref([
{ id: 1, nickname: '用户A', amount: 12580 },
{ id: 2, nickname: '用户B', amount: 9850 },
{ id: 3, nickname: '用户C', amount: 8760 },
]);
onMounted(() => {
// 加载数据
loadDashboardData();
});
function loadDashboardData() {
// 模拟数据加载
userCount.value = 12345;
orderCount.value = 856;
revenue.value = 67890;
}
</script>样式定制
所有组件都使用了 scoped 样式,如需自定义样式,可以通过以下方式:
1. 全局样式覆盖
// 覆盖统计卡片样式
.stat-card {
background: #f5f5f5; // 修改背景色
}
// 覆盖排名徽章样式
.rank-badge--1 {
background: linear-gradient(135deg, #ff6b6b 0%, #ff8e8e 100%);
}2. 使用 CSS 变量
组件预留了 CSS 变量扩展点,可在全局样式中定义:
:root {
--dashboard-card-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
--dashboard-card-radius: 12px;
--dashboard-primary-color: #1890ff;
}注意事项
- ChartCard 依赖: ChartCard 使用了
useEChartshook,确保已正确配置 ECharts - 路由跳转: QuickNav 使用
vue-router进行跳转,确保路由已注册 - 响应式: RankTable 的
scrollY在移动端会自动调整 - 数据格式: ChartCard 的 data 必须包含
name和value字段
组件版本: 1.0.0 项目版本: 3.7.3