仪表盘顶部增加车间产量卡片(降序排列)

main
haoliang 1 month ago
parent 44c008f450
commit 178b7e5641

@ -1,8 +1,8 @@
<template> <template>
<div class="dashboard-page"> <div class="dashboard-page">
<!-- 第1行 3个统计卡片 --> <!-- 第1行 2个统计卡片 -->
<el-row :gutter="16" class="stat-row"> <el-row :gutter="16" class="stat-row">
<el-col :span="8"> <el-col :span="12">
<el-card shadow="hover"> <el-card shadow="hover">
<div class="stat-card"> <div class="stat-card">
<div class="stat-label"> <div class="stat-label">
@ -15,7 +15,7 @@
</div> </div>
</el-card> </el-card>
</el-col> </el-col>
<el-col :span="8"> <el-col :span="12">
<el-card shadow="hover"> <el-card shadow="hover">
<div class="stat-card"> <div class="stat-card">
<div class="stat-label"> <div class="stat-label">
@ -29,6 +29,17 @@
</el-card> </el-card>
</el-col> </el-col>
</el-row> </el-row>
<!-- 车间产量卡片 -->
<el-row :gutter="16" class="stat-row">
<el-col v-for="w in sortedWorkshopData" :key="w.workshopName" :span="8">
<el-card shadow="hover">
<div class="stat-card">
<div class="stat-label">{{ w.workshopName }}</div>
<div class="stat-value">{{ w.quantity?.toLocaleString() }}<span class="stat-unit"> </span></div>
</div>
</el-card>
</el-col>
</el-row>
<!-- 第2行 双图表 --> <!-- 第2行 双图表 -->
<el-row :gutter="16" class="chart-row"> <el-row :gutter="16" class="chart-row">
@ -450,7 +461,7 @@ const workerSortOrder = ref<'asc' | 'desc'>('desc')
// ==================== ==================== // ==================== ====================
const workshopDateLabel = computed(() => dateLabels[workshopDateType.value]) const sortedWorkshopData = computed(() => [...workshopData.value].sort((a, b) => (b.quantity || 0) - (a.quantity || 0)))
const workshopDays = computed(() => { const workshopDays = computed(() => {
const { startDate, endDate } = getDateRange(workshopDateType.value, workshopDateRange.value) const { startDate, endDate } = getDateRange(workshopDateType.value, workshopDateRange.value)
@ -646,7 +657,7 @@ function initProgramDistChart() {
} }
function initWorkshopChart() { function initWorkshopChart() {
if (workshopChartRef.value && workshopData.value.length) { if (workshopChartRef.value && sortedWorkshopData.value.length) {
const unit = workshopUnit.value const unit = workshopUnit.value
const unitLabel = workshopUnitLabel.value const unitLabel = workshopUnitLabel.value
workshopChart = echarts.init(workshopChartRef.value) workshopChart = echarts.init(workshopChartRef.value)
@ -654,14 +665,14 @@ function initWorkshopChart() {
tooltip: { tooltip: {
trigger: 'axis', trigger: 'axis',
formatter: (params: { name: string; value: number; dataIndex: number }[]) => { formatter: (params: { name: string; value: number; dataIndex: number }[]) => {
const d = workshopData.value[params[0].dataIndex] const d = sortedWorkshopData.value[params[0].dataIndex]
return `${d.workshopName}<br/>${unitLabel}产量: ${Number(params[0].value).toFixed(2)} ${unit}<br/>总产量: ${d.quantity} 件<br/>机床数: ${d.machineCount}` return `${d.workshopName}<br/>${unitLabel}产量: ${Number(params[0].value).toFixed(2)} ${unit}<br/>总产量: ${d.quantity} 件<br/>机床数: ${d.machineCount}`
}, },
}, },
grid: { left: 60, right: 20, top: 20, bottom: 30 }, grid: { left: 60, right: 20, top: 20, bottom: 30 },
xAxis: { xAxis: {
type: 'category', type: 'category',
data: workshopData.value.map(i => i.workshopName), data: sortedWorkshopData.value.map(i => i.workshopName),
axisLabel: { fontSize: 12 }, axisLabel: { fontSize: 12 },
}, },
yAxis: { yAxis: {
@ -672,7 +683,7 @@ function initWorkshopChart() {
series: [ series: [
{ {
type: 'bar', type: 'bar',
data: workshopData.value.map(i => i.avgQuantity), data: sortedWorkshopData.value.map(i => i.avgQuantity),
itemStyle: { color: '#67C23A', borderRadius: [4, 4, 0, 0] }, itemStyle: { color: '#67C23A', borderRadius: [4, 4, 0, 0] },
barWidth: '40%', barWidth: '40%',
label: { label: {
@ -767,7 +778,7 @@ async function loadWorkshopData() {
'/admin/dashboard/workshop-production', '/admin/dashboard/workshop-production',
{ params: { startDate, endDate } } { params: { startDate, endDate } }
) )
workshopData.value = res.data?.items || [] workshopData.value = (res.data?.items || []).sort((a:any,b:any)=>(b.quantity||0)-(a.quantity||0))
workshopChart?.dispose() workshopChart?.dispose()
workshopChart = null workshopChart = null
await nextTick() await nextTick()

Loading…
Cancel
Save