123 lines
4.2 KiB
Vue
123 lines
4.2 KiB
Vue
<template>
|
|
<div class="page-container db-page">
|
|
<section class="panel">
|
|
<div class="db-dashboard-body" v-loading="loading">
|
|
<div class="db-dashboard-stats">
|
|
<div v-for="stat in statsList" :key="stat.title" class="db-stat-card">
|
|
<p class="db-stat-title">{{ stat.title }}</p>
|
|
<p class="db-stat-value">
|
|
{{ stat.value }}<span class="db-stat-suffix">{{ stat.suffix }}</span>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
|
|
<el-row :gutter="16" class="db-dashboard-charts">
|
|
<el-col :xs="24" :lg="12">
|
|
<DualBarChart title="今日入库量(按货物,t)" :data="inboundByCargo" />
|
|
</el-col>
|
|
<el-col :xs="24" :lg="12">
|
|
<DualBarChart title="今日出库量(按货物,t)" :data="outboundByCargo" />
|
|
</el-col>
|
|
</el-row>
|
|
|
|
<el-row :gutter="16" class="db-dashboard-charts">
|
|
<el-col :xs="24" :lg="12">
|
|
<DualBarChart title="今日入库量(按往来单位+货物,t)" :data="inboundByPartnerCargo" />
|
|
</el-col>
|
|
<el-col :xs="24" :lg="12">
|
|
<DualBarChart title="今日出库量(按往来单位+货物,t)" :data="outboundByPartnerCargo" />
|
|
</el-col>
|
|
</el-row>
|
|
</div>
|
|
</section>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
/**
|
|
* UI 模式:统计仪表盘(Fresh Mint 面板 + 图表区,无独立 P 编号)
|
|
* 参考:/#/demo/console · src/views/dashboard/console/index.vue
|
|
*/
|
|
import DualBarChart from '@/components/business/db/DualBarChart.vue'
|
|
import {
|
|
dashboardApi,
|
|
type DashboardCargoStat,
|
|
type DashboardPartnerCargoStat
|
|
} from '@/api/db/dashboard'
|
|
|
|
defineOptions({ name: 'DbDashboard' })
|
|
|
|
const loading = ref(false)
|
|
const inboundByCargo = ref<DashboardCargoStat[]>([])
|
|
const outboundByCargo = ref<DashboardCargoStat[]>([])
|
|
const inboundByPartnerCargo = ref<DashboardPartnerCargoStat[]>([])
|
|
const outboundByPartnerCargo = ref<DashboardPartnerCargoStat[]>([])
|
|
|
|
const loadData = async () => {
|
|
loading.value = true
|
|
try {
|
|
const [inCargo, outCargo, inPartner, outPartner] = await Promise.all([
|
|
dashboardApi.getInboundByCargo(),
|
|
dashboardApi.getOutboundByCargo(),
|
|
dashboardApi.getInboundByPartnerCargo(),
|
|
dashboardApi.getOutboundByPartnerCargo()
|
|
])
|
|
inboundByCargo.value = inCargo
|
|
outboundByCargo.value = outCargo
|
|
inboundByPartnerCargo.value = inPartner
|
|
outboundByPartnerCargo.value = outPartner
|
|
} catch (error) {
|
|
console.error('获取仪表盘数据失败', error)
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
onMounted(() => {
|
|
loadData()
|
|
})
|
|
|
|
const todayInboundVehicles = computed(() => {
|
|
const cargoSet = new Set<string>()
|
|
inboundByCargo.value.forEach((item) => {
|
|
if (item.planned > 0) cargoSet.add(item.label)
|
|
})
|
|
return cargoSet.size
|
|
})
|
|
|
|
const todayOutboundVehicles = computed(() => {
|
|
const cargoSet = new Set<string>()
|
|
outboundByCargo.value.forEach((item) => {
|
|
if (item.planned > 0) cargoSet.add(item.label)
|
|
})
|
|
return cargoSet.size
|
|
})
|
|
|
|
const todayInboundTotal = computed(() => {
|
|
const planned = inboundByCargo.value.reduce((sum, item) => sum + item.planned, 0)
|
|
const actual = inboundByCargo.value.reduce((sum, item) => sum + item.actual, 0)
|
|
return { actual, planned }
|
|
})
|
|
|
|
const todayOutboundTotal = computed(() => {
|
|
const planned = outboundByCargo.value.reduce((sum, item) => sum + item.planned, 0)
|
|
const actual = outboundByCargo.value.reduce((sum, item) => sum + item.actual, 0)
|
|
return { actual, planned }
|
|
})
|
|
|
|
const statsList = computed(() => [
|
|
{ title: '今日入库', value: todayInboundVehicles.value, suffix: '车' },
|
|
{
|
|
title: '今日入库总量',
|
|
value: `${todayInboundTotal.value.actual.toFixed(2)} / ${todayInboundTotal.value.planned.toFixed(2)}`,
|
|
suffix: '吨'
|
|
},
|
|
{ title: '今日出库', value: todayOutboundVehicles.value, suffix: '车' },
|
|
{
|
|
title: '今日出库总量',
|
|
value: `${todayOutboundTotal.value.actual.toFixed(2)} / ${todayOutboundTotal.value.planned.toFixed(2)}`,
|
|
suffix: '吨'
|
|
}
|
|
])
|
|
</script>
|