Files
tunnel-cloud-web/src/components/content/badGasInfo/BadGasInfo.vue
2023-12-14 16:41:51 +08:00

247 lines
5.7 KiB
Vue

<template>
<div id="bad-gas-info" :style="{ backgroundImage: 'url(' +getImageUrl(bgImage)+')' }">
<div class="title">有害气体</div>
<div class="info-list">
<gas-info-item v-for="item in badGasList" :key="item.equipmentId" :gasInfo="item" @click="handleOpenChart"/>
</div>
<div class="digital-tunnel">
<el-dialog v-model="isVisited" title="有害气体监控数据" width="1365px" :modal="false">
<div class="left-top-icon"></div>
<div class="right-top-icon"></div>
<div id="container"></div>
<div class="time-select">
<time-range-btn
:buttonList="timeList"
v-model="selectTimeButton"
@select="timeSelect"
width="124px"
/>
</div>
<div class="left-bottom-icon"></div>
<div class="right-bottom-icon"></div>
</el-dialog>
</div>
</div>
</template>
<script setup>
import GasInfoItem from "./childComps/GasInfoItem.vue";
import * as echarts from 'echarts';
import TimeRangeBtn from "@/components/timeRangeBtn/index.vue"
const props = defineProps({
list: Array,
badGasData: Array
});
const timeList = ref(["年", "月", "日"]);
const selectTimeButton = ref(0);
const isVisited = ref(false);
const badGasList = ref([])
let myEcharts = reactive({});
const bgImage = computed(() =>
isVisited.value
? "sp_active.png"
: "bg.png"
);
watch(() => props.list, (now) => {
badGasList.value.forEach(item => {
now.forEach(newItem => {
if (item.equipmentId === newItem.equipmentId) {
item.value = newItem.value
}
})
})
}, {deep: true});
watch(() => props.badGasData, (now) => {
getBadGasInfo(now.sensorList)
}, {deep: true});
const timeSelect = (index) => {
console.log('选择时间', index)
if(index===0){
console.log('--年')
}else if(index===1){
console.log('--月')
}else if(index===2){
console.log('--日')
}
};
const getBadGasInfo = (now) => {
let windPressureObj = {}
let windPressureArr = []
now.map(item => {
if (item.equipmentType === "carbonDioxide" || item.equipmentType === "carbonMonoxide" || item.equipmentType === "hydrogenSulfide" || item.equipmentType === "sulfurDioxide" || item.equipmentType === "sulfurMonoxide" || item.equipmentType === "nitrogenDioxide") {
windPressureObj = changeData(item)
windPressureArr.push(windPressureObj)
}
})
badGasList.value = windPressureArr
}
const changeData = (item) => {
return {
equipmentId: item.equipmentId,
name: item.equipmentName.slice(0, item.equipmentName.length - 2),
max: 120,
value: item.value,
point: item.valueThreshold,
unit: item.unit
}
}
const handleOpenChart = () => {
console.log('有害气体弹窗')
isVisited.value = true
nextTick(() => {
initChart()
})
}
const getImageUrl = (name) => {
return new URL(`../../../assets/images/badGasInfo/${name}`, import.meta.url).href
}
/**
* 初始化echarts实例方法
*/
const initChart = () => {
//3.初始化container容器
myEcharts = echarts.init(document.getElementById('container'));
//5.传入数据
let option = {
//图例
legend: {
left: 0,
textStyle: {
color: '#FFFFFF',
fontSize: 28
},
// itemWidth: 20,
// itemHeight: 20
},
//离容器四侧的距离
grid: {
left: 0, // 左边距
right: 0, // 右边距
top: 80, // 顶边距
bottom: 0, // 底边距
containLabel: true,
},
//提示框组件
tooltip: {
show: true,
trigger: 'axis'
},
//X轴
xAxis: {
type: 'category',
data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
axisLabel: {
textStyle: {
fontSize: 24,
color: '#D6F1FA'
},
},
},
//Y轴
yAxis: {
type: 'value',
axisLabel: {
textStyle: {
fontSize: 24,
color: '#D6F1FA'
},
},
},
//配置项
series: [
{
name: '二氧化碳',
data: [5, 9, 10, 7, 8, 15, 12],
type: 'line',
smooth: true,
symbolSize: 24,
lineStyle: {
width: 5
}
},
{
name: '一氧化碳',
data: [8, 15, 5, 9, 10, 7, 12],
type: 'line',
smooth: true,
symbolSize: 24,
lineStyle: {
width: 5
}
},
{
name: '二氧化氮',
data: [5, 15, 1, 9, 10, 7, 8],
type: 'line',
smooth: true,
symbolSize: 24,
lineStyle: {
width: 5
}
},
{
name: '二氧化硫',
data: [8, 15, 12, 5, 9, 2, 7],
type: 'line',
smooth: true,
symbolSize: 24,
lineStyle: {
width: 5
}
},
{
name: '硫化氢',
data: [2, 9, 10, 15, 12, 7, 8,],
type: 'line',
smooth: true,
symbolSize: 24,
lineStyle: {
width: 5
}
},
]
}
myEcharts.setOption(option);
//图表大小自适应窗口大小变化
window.onresize = () => {
myEcharts.resize();
}
}
</script>
<style lang="scss" scoped>
#bad-gas-info {
position: absolute;
z-index: 100;
width: 824px;
height: 621px;
top: 1441px;
right: 72px;
background-image: url(../../../assets/images/badGasInfo/bg.png);
.title {
width: 128px;
height: 45px;
font-size: 32px;
font-family: PingFang-SC, PingFang-SC;
font-weight: 800;
color: #38cafb;
line-height: 45px;
margin: 22px 0px 0px 62px;
}
.info-list {
width: 100%;
height: calc(621px - 45px - 22px);
display: flex;
flex-wrap: wrap;
justify-content: space-around;
padding: 10px 0px 0px 10px;
}
}
</style>