|
@@ -1,447 +0,0 @@
|
|
|
-<!--监测设备统计分析-->
|
|
|
|
|
-<template>
|
|
|
|
|
- <div class="device-statistics-dashboard">
|
|
|
|
|
- <!-- 顶部概览:三项关键指标 -->
|
|
|
|
|
- <div class="summary-row">
|
|
|
|
|
- <div v-for="item in summaryItems" :key="item.label" class="summary-card">
|
|
|
|
|
- <div class="summary-icon" :style="{ background: item.bg, color: item.color }">
|
|
|
|
|
- <el-icon>
|
|
|
|
|
- <component :is="item.icon" />
|
|
|
|
|
- </el-icon>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div class="summary-body">
|
|
|
|
|
- <div class="summary-value">{{ item.value }}<span class="summary-unit">{{ item.unit }}</span></div>
|
|
|
|
|
- <div class="summary-label">{{ item.label }}</div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
-
|
|
|
|
|
- <!-- 图表展示区域:左右两列 -->
|
|
|
|
|
- <div class="charts-container">
|
|
|
|
|
- <!-- 左侧:区域分布柱状图 -->
|
|
|
|
|
- <div class="chart-card">
|
|
|
|
|
- <div class="card-header">
|
|
|
|
|
- <span class="card-title">
|
|
|
|
|
- <el-icon>
|
|
|
|
|
- <Location />
|
|
|
|
|
- </el-icon>
|
|
|
|
|
- 设备区域分布
|
|
|
|
|
- </span>
|
|
|
|
|
- <el-radio-group v-model="barChartType" size="small" :disabled="!hasRegionData">
|
|
|
|
|
- <el-radio-button label="count">设备数量</el-radio-button>
|
|
|
|
|
- <el-radio-button label="percent">占比 (%)</el-radio-button>
|
|
|
|
|
- </el-radio-group>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div class="chart-body">
|
|
|
|
|
- <div ref="regionBarRef" class="chart-wrapper"></div>
|
|
|
|
|
- <div v-if="!hasRegionData" class="empty-tip empty-tip--bar">
|
|
|
|
|
- <el-icon class="empty-icon">
|
|
|
|
|
- <Histogram />
|
|
|
|
|
- </el-icon>
|
|
|
|
|
- <p class="empty-title">暂无设备数据</p>
|
|
|
|
|
- <p class="empty-desc">当前筛选条件下没有窨井设备</p>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
-
|
|
|
|
|
- <!-- 右侧:设备类型分布饼图 -->
|
|
|
|
|
- <div class="chart-card">
|
|
|
|
|
- <div class="card-header">
|
|
|
|
|
- <span class="card-title">
|
|
|
|
|
- <el-icon>
|
|
|
|
|
- <PieChart />
|
|
|
|
|
- </el-icon>
|
|
|
|
|
- 设备类型分布
|
|
|
|
|
- </span>
|
|
|
|
|
- <el-radio-group v-model="pieChartType" size="small" :disabled="!hasTypeData">
|
|
|
|
|
- <el-radio-button label="normal">标准饼图</el-radio-button>
|
|
|
|
|
- <el-radio-button label="doughnut">环形图</el-radio-button>
|
|
|
|
|
- </el-radio-group>
|
|
|
|
|
- </div>
|
|
|
|
|
- <div class="chart-body">
|
|
|
|
|
- <div ref="typePieRef" class="chart-wrapper"></div>
|
|
|
|
|
- <div v-if="!hasTypeData" class="empty-tip">
|
|
|
|
|
- <el-icon class="empty-icon">
|
|
|
|
|
- <PieChart />
|
|
|
|
|
- </el-icon>
|
|
|
|
|
- <p class="empty-title">暂无设备数据</p>
|
|
|
|
|
- <p class="empty-desc">设备台账中还没有窨井设备</p>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
- </div>
|
|
|
|
|
-</template>
|
|
|
|
|
-
|
|
|
|
|
-<script setup>
|
|
|
|
|
-import { ref, computed, watch, nextTick, onMounted, onBeforeUnmount } from 'vue'
|
|
|
|
|
-import { Location, PieChart, Histogram, Monitor } from '@element-plus/icons-vue'
|
|
|
|
|
-import { getManholeDeviceStatistics } from '@/api/pipeNetwork/basic'
|
|
|
|
|
-import { ElMessage } from 'element-plus'
|
|
|
|
|
-import * as echarts from 'echarts'
|
|
|
|
|
-
|
|
|
|
|
-// 图表显示模式
|
|
|
|
|
-const barChartType = ref('count') // count / percent
|
|
|
|
|
-const pieChartType = ref('normal') // normal / doughnut
|
|
|
|
|
-
|
|
|
|
|
-// 统计数据(来自接口)
|
|
|
|
|
-const totalDevices = ref(0)
|
|
|
|
|
-const regionDistribution = ref([])
|
|
|
|
|
-const typeDistribution = ref([])
|
|
|
|
|
-
|
|
|
|
|
-// 图表实例
|
|
|
|
|
-let regionBarChart = null
|
|
|
|
|
-let typePieChart = null
|
|
|
|
|
-const regionBarRef = ref(null)
|
|
|
|
|
-const typePieRef = ref(null)
|
|
|
|
|
-
|
|
|
|
|
-// 无数据时仍展示的区域维度,取自 DistrictEnum(0-城南 1-城北 2-太常)
|
|
|
|
|
-const DEFAULT_REGIONS = ['城南', '城北', '太常']
|
|
|
|
|
-
|
|
|
|
|
-const hasRegionData = computed(() => regionDistribution.value.some(item => Number(item.count) > 0))
|
|
|
|
|
-const hasTypeData = computed(() => typeDistribution.value.some(item => Number(item.count) > 0))
|
|
|
|
|
-
|
|
|
|
|
-// 顶部概览指标
|
|
|
|
|
-const summaryItems = computed(() => {
|
|
|
|
|
- const regionCount = regionDistribution.value.filter(item => Number(item.count) > 0).length
|
|
|
|
|
- const typeCount = typeDistribution.value.filter(item => Number(item.count) > 0).length
|
|
|
|
|
- return [
|
|
|
|
|
- { label: '设备总数', value: totalDevices.value, unit: '台', icon: Monitor, color: '#409eff', bg: '#ecf5ff' },
|
|
|
|
|
- { label: '覆盖区域', value: regionCount, unit: '个', icon: Location, color: '#67c23a', bg: '#f0f9eb' },
|
|
|
|
|
- { label: '设备类型', value: typeCount, unit: '种', icon: PieChart, color: '#e6a23c', bg: '#fdf6ec' }
|
|
|
|
|
- ]
|
|
|
|
|
-})
|
|
|
|
|
-
|
|
|
|
|
-// 加载统计数据(默认全部窨井设备)
|
|
|
|
|
-async function loadStatistics() {
|
|
|
|
|
- try {
|
|
|
|
|
- const res = await getManholeDeviceStatistics({})
|
|
|
|
|
- totalDevices.value = Number(res.data?.total) || 0
|
|
|
|
|
- regionDistribution.value = res.data?.regionDistribution || []
|
|
|
|
|
- typeDistribution.value = res.data?.typeDistribution || []
|
|
|
|
|
- } catch (e) {
|
|
|
|
|
- ElMessage.error('统计数据加载失败')
|
|
|
|
|
- } finally {
|
|
|
|
|
- // 接口失败或返回空时也要重绘,避免图表区停留在初始空白
|
|
|
|
|
- renderCharts()
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// 柱状图配置:设备区域分布(数量/占比)
|
|
|
|
|
-const regionBarOption = computed(() => {
|
|
|
|
|
- const hasData = hasRegionData.value
|
|
|
|
|
- const regions = hasData ? regionDistribution.value.map(item => item.name) : DEFAULT_REGIONS
|
|
|
|
|
- const counts = hasData ? regionDistribution.value.map(item => Number(item.count) || 0) : DEFAULT_REGIONS.map(() => 0)
|
|
|
|
|
- const percentages = hasData ? regionDistribution.value.map(item => Number(item.percent) || 0) : DEFAULT_REGIONS.map(() => 0)
|
|
|
|
|
-
|
|
|
|
|
- const seriesData = barChartType.value === 'count' ? counts : percentages
|
|
|
|
|
- const seriesName = barChartType.value === 'count' ? '设备数量' : '设备占比'
|
|
|
|
|
-
|
|
|
|
|
- return {
|
|
|
|
|
- tooltip: {
|
|
|
|
|
- trigger: 'axis',
|
|
|
|
|
- axisPointer: { type: 'shadow' },
|
|
|
|
|
- formatter: function (params) {
|
|
|
|
|
- if (barChartType.value === 'count') {
|
|
|
|
|
- return `${params[0].axisValue}<br/>${params[0].seriesName}: ${params[0].value} 台`
|
|
|
|
|
- } else {
|
|
|
|
|
- return `${params[0].axisValue}<br/>${params[0].seriesName}: ${params[0].value}%`
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- grid: {
|
|
|
|
|
- left: 10,
|
|
|
|
|
- right: 20,
|
|
|
|
|
- top: 36,
|
|
|
|
|
- bottom: 6,
|
|
|
|
|
- containLabel: true
|
|
|
|
|
- },
|
|
|
|
|
- // 空态只保留区域分类轴,y 轴 0~1 的刻度反而显得空荡
|
|
|
|
|
- yAxis: {
|
|
|
|
|
- type: 'value',
|
|
|
|
|
- show: hasData,
|
|
|
|
|
- minInterval: 1,
|
|
|
|
|
- axisLabel: { color: '#909399', fontSize: 11 },
|
|
|
|
|
- splitLine: { lineStyle: { color: '#f0f2f5' } }
|
|
|
|
|
- },
|
|
|
|
|
- xAxis: {
|
|
|
|
|
- type: 'category',
|
|
|
|
|
- data: regions,
|
|
|
|
|
- axisTick: { alignWithLabel: true, show: hasData },
|
|
|
|
|
- axisLine: { lineStyle: { color: '#dcdfe6' } },
|
|
|
|
|
- axisLabel: { interval: 0, fontSize: 12, color: hasData ? '#606266' : '#c0c4cc' }
|
|
|
|
|
- },
|
|
|
|
|
- series: [
|
|
|
|
|
- {
|
|
|
|
|
- name: seriesName,
|
|
|
|
|
- type: 'bar',
|
|
|
|
|
- data: seriesData,
|
|
|
|
|
- barMaxWidth: 48,
|
|
|
|
|
- itemStyle: {
|
|
|
|
|
- borderRadius: [4, 4, 0, 0],
|
|
|
|
|
- color: '#409eff',
|
|
|
|
|
- shadowColor: 'rgba(64,158,255,0.25)',
|
|
|
|
|
- shadowBlur: 6
|
|
|
|
|
- },
|
|
|
|
|
- label: {
|
|
|
|
|
- show: hasData,
|
|
|
|
|
- position: 'top',
|
|
|
|
|
- fontSize: 12,
|
|
|
|
|
- color: '#606266',
|
|
|
|
|
- formatter: ({ value }) => barChartType.value === 'count' ? value : value + '%'
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- ]
|
|
|
|
|
- }
|
|
|
|
|
-})
|
|
|
|
|
-
|
|
|
|
|
-// 饼图配置:设备类型分布(标准/环形)
|
|
|
|
|
-const typePieOption = computed(() => {
|
|
|
|
|
- const hasData = hasTypeData.value
|
|
|
|
|
- const pieData = typeDistribution.value.map(item => ({
|
|
|
|
|
- name: item.name,
|
|
|
|
|
- value: Number(item.count) || 0
|
|
|
|
|
- }))
|
|
|
|
|
-
|
|
|
|
|
- return {
|
|
|
|
|
- tooltip: { show: hasData, trigger: 'item', formatter: '{b}: {c}台 ({d}%)' },
|
|
|
|
|
- legend: {
|
|
|
|
|
- show: hasData,
|
|
|
|
|
- orient: 'vertical',
|
|
|
|
|
- left: 'left',
|
|
|
|
|
- top: 'middle',
|
|
|
|
|
- itemWidth: 10,
|
|
|
|
|
- itemHeight: 10,
|
|
|
|
|
- itemGap: 12,
|
|
|
|
|
- textStyle: { fontSize: 12, color: '#606266' },
|
|
|
|
|
- data: pieData.map(d => d.name)
|
|
|
|
|
- },
|
|
|
|
|
- // 无数据时不挂 series,否则 echarts 会在中心留一个灰色空心圆压住提示文字
|
|
|
|
|
- series: hasData ? [
|
|
|
|
|
- {
|
|
|
|
|
- name: '设备类型占比',
|
|
|
|
|
- type: 'pie',
|
|
|
|
|
- radius: pieChartType.value === 'doughnut' ? ['42%', '64%'] : '64%',
|
|
|
|
|
- center: ['62%', '52%'],
|
|
|
|
|
- data: pieData,
|
|
|
|
|
- emphasis: {
|
|
|
|
|
- scale: true,
|
|
|
|
|
- label: { show: true, formatter: '{b}: {d}%' }
|
|
|
|
|
- },
|
|
|
|
|
- label: {
|
|
|
|
|
- show: true,
|
|
|
|
|
- formatter: '{b}: {d}%',
|
|
|
|
|
- fontSize: 12,
|
|
|
|
|
- color: '#606266',
|
|
|
|
|
- position: 'outside'
|
|
|
|
|
- },
|
|
|
|
|
- labelLine: { length: 10, length2: 8 },
|
|
|
|
|
- itemStyle: {
|
|
|
|
|
- borderRadius: 6,
|
|
|
|
|
- borderColor: '#fff',
|
|
|
|
|
- borderWidth: 2
|
|
|
|
|
- },
|
|
|
|
|
- color: ['#409eff', '#67c23a', '#e6a23c', '#f56c6c', '#909399', '#9b59b6', '#1abc9c']
|
|
|
|
|
- }
|
|
|
|
|
- ] : []
|
|
|
|
|
- }
|
|
|
|
|
-})
|
|
|
|
|
-
|
|
|
|
|
-// 统一渲染,空态也要走一次,否则接口失败时图表区一片空白
|
|
|
|
|
-function renderCharts() {
|
|
|
|
|
- if (regionBarChart) regionBarChart.setOption(regionBarOption.value, true)
|
|
|
|
|
- if (typePieChart) typePieChart.setOption(typePieOption.value, true)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// 图表配置变化时刷新
|
|
|
|
|
-watch([regionBarOption, typePieOption], renderCharts, { deep: true })
|
|
|
|
|
-
|
|
|
|
|
-// 窗口变化自适应(防抖)
|
|
|
|
|
-let resizeTimer = null
|
|
|
|
|
-const handleResize = () => {
|
|
|
|
|
- clearTimeout(resizeTimer)
|
|
|
|
|
- resizeTimer = setTimeout(() => {
|
|
|
|
|
- regionBarChart && regionBarChart.resize()
|
|
|
|
|
- typePieChart && typePieChart.resize()
|
|
|
|
|
- }, 100)
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-onMounted(async () => {
|
|
|
|
|
- await nextTick()
|
|
|
|
|
- regionBarChart = echarts.init(regionBarRef.value)
|
|
|
|
|
- typePieChart = echarts.init(typePieRef.value)
|
|
|
|
|
- // 先铺空态,接口慢或失败时也不会留一片空白
|
|
|
|
|
- renderCharts()
|
|
|
|
|
- window.addEventListener('resize', handleResize)
|
|
|
|
|
- loadStatistics()
|
|
|
|
|
-})
|
|
|
|
|
-
|
|
|
|
|
-onBeforeUnmount(() => {
|
|
|
|
|
- window.removeEventListener('resize', handleResize)
|
|
|
|
|
- clearTimeout(resizeTimer)
|
|
|
|
|
- regionBarChart && regionBarChart.dispose()
|
|
|
|
|
- typePieChart && typePieChart.dispose()
|
|
|
|
|
-})
|
|
|
|
|
-</script>
|
|
|
|
|
-
|
|
|
|
|
-<style scoped>
|
|
|
|
|
-.device-statistics-dashboard {
|
|
|
|
|
- padding: 20px 24px;
|
|
|
|
|
- background: #f5f7fb;
|
|
|
|
|
- min-height: calc(100vh - 84px);
|
|
|
|
|
- box-sizing: border-box;
|
|
|
|
|
- font-family: 'Segoe UI', 'PingFang SC', Roboto, Helvetica, Arial, sans-serif;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/* ==================== 顶部概览 ==================== */
|
|
|
|
|
-.summary-row {
|
|
|
|
|
- display: grid;
|
|
|
|
|
- grid-template-columns: repeat(3, 1fr);
|
|
|
|
|
- gap: 20px;
|
|
|
|
|
- margin-bottom: 20px;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.summary-card {
|
|
|
|
|
- display: flex;
|
|
|
|
|
- align-items: center;
|
|
|
|
|
- gap: 14px;
|
|
|
|
|
- padding: 18px 20px;
|
|
|
|
|
- background: #fff;
|
|
|
|
|
- border-radius: 12px;
|
|
|
|
|
- box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.summary-icon {
|
|
|
|
|
- width: 44px;
|
|
|
|
|
- height: 44px;
|
|
|
|
|
- flex-shrink: 0;
|
|
|
|
|
- display: flex;
|
|
|
|
|
- align-items: center;
|
|
|
|
|
- justify-content: center;
|
|
|
|
|
- border-radius: 10px;
|
|
|
|
|
- font-size: 22px;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.summary-body {
|
|
|
|
|
- min-width: 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.summary-value {
|
|
|
|
|
- font-size: 24px;
|
|
|
|
|
- font-weight: 600;
|
|
|
|
|
- line-height: 1.2;
|
|
|
|
|
- color: #303133;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.summary-unit {
|
|
|
|
|
- margin-left: 3px;
|
|
|
|
|
- font-size: 13px;
|
|
|
|
|
- font-weight: 400;
|
|
|
|
|
- color: #909399;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.summary-label {
|
|
|
|
|
- margin-top: 2px;
|
|
|
|
|
- font-size: 13px;
|
|
|
|
|
- color: #909399;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/* ==================== 图表区域 ==================== */
|
|
|
|
|
-.charts-container {
|
|
|
|
|
- display: grid;
|
|
|
|
|
- grid-template-columns: 1fr 1fr;
|
|
|
|
|
- gap: 20px;
|
|
|
|
|
- /* 固定高度,避免图表被拉伸到整个视口 */
|
|
|
|
|
- height: 380px;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.chart-card {
|
|
|
|
|
- background: #fff;
|
|
|
|
|
- border-radius: 12px;
|
|
|
|
|
- box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
|
|
|
|
|
- overflow: hidden;
|
|
|
|
|
- display: flex;
|
|
|
|
|
- flex-direction: column;
|
|
|
|
|
- min-height: 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.card-header {
|
|
|
|
|
- display: flex;
|
|
|
|
|
- justify-content: space-between;
|
|
|
|
|
- align-items: center;
|
|
|
|
|
- padding: 14px 18px;
|
|
|
|
|
- border-bottom: 1px solid #f0f2f5;
|
|
|
|
|
- flex-shrink: 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.card-title {
|
|
|
|
|
- display: flex;
|
|
|
|
|
- align-items: center;
|
|
|
|
|
- gap: 8px;
|
|
|
|
|
- font-weight: 600;
|
|
|
|
|
- font-size: 15px;
|
|
|
|
|
- color: #303133;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.chart-body {
|
|
|
|
|
- position: relative;
|
|
|
|
|
- flex: 1;
|
|
|
|
|
- min-height: 0;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.chart-wrapper {
|
|
|
|
|
- width: 100%;
|
|
|
|
|
- height: 100%;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/* 空态提示:叠在图表上方,柱状图保留底部分类轴 */
|
|
|
|
|
-.empty-tip {
|
|
|
|
|
- position: absolute;
|
|
|
|
|
- inset: 0;
|
|
|
|
|
- display: flex;
|
|
|
|
|
- flex-direction: column;
|
|
|
|
|
- align-items: center;
|
|
|
|
|
- justify-content: center;
|
|
|
|
|
- gap: 4px;
|
|
|
|
|
- pointer-events: none;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/* 柱状图空态让出 x 轴标签的高度 */
|
|
|
|
|
-.empty-tip--bar {
|
|
|
|
|
- padding-bottom: 34px;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.empty-icon {
|
|
|
|
|
- margin-bottom: 4px;
|
|
|
|
|
- font-size: 40px;
|
|
|
|
|
- color: #dcdfe6;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.empty-title {
|
|
|
|
|
- margin: 0;
|
|
|
|
|
- font-size: 14px;
|
|
|
|
|
- color: #909399;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-.empty-desc {
|
|
|
|
|
- margin: 0;
|
|
|
|
|
- font-size: 12px;
|
|
|
|
|
- color: #c0c4cc;
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-/* 窄屏改为上下排列 */
|
|
|
|
|
-@media (max-width: 1280px) {
|
|
|
|
|
- .summary-row {
|
|
|
|
|
- grid-template-columns: 1fr;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- .charts-container {
|
|
|
|
|
- grid-template-columns: 1fr;
|
|
|
|
|
- height: auto;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- .chart-card {
|
|
|
|
|
- height: 340px;
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-</style>
|
|
|