<template>
|
<div>
|
<PanelHeader title="近6个月隐患排查与整改趋势" />
|
<div class="panel-item-customers">
|
<Echarts
|
ref="chart"
|
:chartStyle="chartStyle"
|
:grid="grid"
|
:legend="legend"
|
:series="series"
|
:tooltip="tooltip"
|
:xAxis="xAxis"
|
:yAxis="yAxis"
|
:options="chartOptions"
|
style="height: 380px"
|
/>
|
<div v-if="showEmpty" class="empty-tip">近6个月暂无隐患数据</div>
|
<span v-if="refreshFailed" class="refresh-error">刷新失败</span>
|
</div>
|
</div>
|
</template>
|
|
<script setup>
|
import { ref, computed, onMounted, inject, watch } from 'vue'
|
import Echarts from '@/components/Echarts/echarts.vue'
|
import PanelHeader from '@/views/reportAnalysis/dataDashboard/components/PanelHeader.vue'
|
import { getHiddenTrend } from '@/api/reportAnalysis/safetyDashboard.js'
|
|
const chart = ref(null)
|
const trendData = ref([])
|
const loaded = ref(false)
|
const loading = ref(false)
|
const refreshFailed = ref(false)
|
|
const chartStyle = {
|
width: '100%',
|
height: '100%'
|
}
|
|
const chartOptions = {
|
backgroundColor: 'transparent',
|
textStyle: { color: '#B8C8E0' }
|
}
|
|
const showEmpty = computed(() => {
|
if (!loaded.value || loading.value) return false
|
return trendData.value.every(
|
(item) => !Number(item.reportedCount) && !Number(item.completedCount)
|
)
|
})
|
|
const categories = computed(() =>
|
trendData.value.map((item) => {
|
const month = String(item.month || '')
|
return month.length >= 7 ? `${month.slice(5)}月` : month
|
})
|
)
|
|
const series = computed(() => [
|
{
|
name: '上报数',
|
type: 'bar',
|
barWidth: 18,
|
itemStyle: {
|
color: {
|
type: 'linear',
|
x: 0,
|
y: 1,
|
x2: 0,
|
y2: 0,
|
colorStops: [
|
{ offset: 0, color: 'rgba(0,164,237,0)' },
|
{ offset: 1, color: '#4EE4FF' }
|
]
|
}
|
},
|
data: trendData.value.map((item) => Number(item.reportedCount) || 0)
|
},
|
{
|
name: '整改完成数',
|
type: 'bar',
|
barWidth: 18,
|
itemStyle: {
|
color: {
|
type: 'linear',
|
x: 0,
|
y: 1,
|
x2: 0,
|
y2: 0,
|
colorStops: [
|
{ offset: 0, color: 'rgba(38,255,203,0)' },
|
{ offset: 1, color: '#26FFCB' }
|
]
|
}
|
},
|
data: trendData.value.map((item) => Number(item.completedCount) || 0)
|
}
|
])
|
|
const legend = {
|
show: true,
|
right: '4%',
|
top: '0%',
|
itemWidth: 10,
|
itemHeight: 10,
|
icon: 'circle',
|
textStyle: { color: '#B8C8E0', fontSize: 13 },
|
data: ['上报数', '整改完成数']
|
}
|
|
const grid = {
|
left: '3%',
|
right: '4%',
|
bottom: '3%',
|
top: '18%',
|
containLabel: true
|
}
|
|
const tooltip = {
|
trigger: 'axis',
|
axisPointer: { type: 'shadow' },
|
formatter: function (params) {
|
let result = `${params[0].axisValueLabel}<br/>`
|
params.forEach((item) => {
|
result += `<div>${item.marker} ${item.seriesName}:${item.value} 项</div>`
|
})
|
return result
|
}
|
}
|
|
const xAxis = computed(() => [
|
{
|
type: 'category',
|
axisTick: { show: false },
|
axisLine: { lineStyle: { color: 'rgba(255,255,255,0.2)' } },
|
axisLabel: { color: '#B8C8E0' },
|
data: categories.value
|
}
|
])
|
|
const yAxis = [
|
{
|
type: 'value',
|
minInterval: 1,
|
axisLabel: { color: '#B8C8E0' },
|
splitLine: { lineStyle: { color: 'rgba(255,255,255,0.08)' } }
|
}
|
]
|
|
const loadData = async () => {
|
if (loading.value) return
|
loading.value = true
|
try {
|
const res = await getHiddenTrend()
|
trendData.value = Array.isArray(res?.data) ? res.data : []
|
refreshFailed.value = false
|
loaded.value = true
|
} catch (e) {
|
console.error('获取隐患趋势失败:', e)
|
refreshFailed.value = true
|
} finally {
|
loading.value = false
|
}
|
}
|
|
const safetyDashboardRefreshTick = inject('safetyDashboardRefreshTick', null)
|
if (safetyDashboardRefreshTick) {
|
watch(safetyDashboardRefreshTick, () => {
|
loadData()
|
})
|
}
|
|
onMounted(() => {
|
loadData()
|
})
|
</script>
|
|
<style scoped>
|
.panel-item-customers {
|
position: relative;
|
border: 1px solid #1a58b0;
|
padding: 18px;
|
width: 100%;
|
height: 478px;
|
box-sizing: border-box;
|
}
|
|
.empty-tip {
|
position: absolute;
|
left: 0;
|
right: 0;
|
top: 50%;
|
text-align: center;
|
font-size: 16px;
|
color: #8aa4c8;
|
pointer-events: none;
|
}
|
|
.refresh-error {
|
position: absolute;
|
right: 16px;
|
top: 8px;
|
font-size: 12px;
|
color: #ff9a9a;
|
}
|
</style>
|