<template>
|
<div class="chartCon" @dblclick="dblclick">
|
<div class="chartItem">
|
<pross-pie-chart id="prossPieChart0" ref="prossPieChart0"></pross-pie-chart>
|
</div>
|
<div class="chartItem">
|
<pross-pie-chart id="prossPieChart1" ref="prossPieChart1"></pross-pie-chart>
|
</div>
|
<div class="chartItem">
|
<pross-pie-chart id="prossPieChart2" ref="prossPieChart2"></pross-pie-chart>
|
</div>
|
<div class="chartItem">
|
<pross-pie-chart id="prossPieChart3" ref="prossPieChart3"></pross-pie-chart>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import prossPieChart from "./prossPieChart"
|
import { WebSocketClass } from '@/assets/js/socket'
|
|
export default {
|
components: {
|
prossPieChart
|
},
|
data() {
|
return {
|
websock: null
|
}
|
},
|
mounted() {
|
|
},
|
methods: {
|
findParents(node, select) {
|
var parent = node.parentNode;
|
if (parent === null || parent.className.indexOf(select) != -1) {
|
return parent;
|
} else {
|
return this.findParents(parent, select);
|
}
|
},
|
dblclick(e) {
|
this.isAllScreen = !this.isAllScreen
|
let parents = this.findParents(e.currentTarget, 'vdr')
|
if (this.isAllScreen) {
|
this.parentsStyle = JSON.parse(JSON.stringify(parents.style));
|
parents.style.transform = 'none';
|
parents.style.width = '100%';
|
parents.style.height = '100%';
|
parents.style.position = 'fixed';
|
parents.style.left = 0;
|
parents.style.right = 0;
|
parents.style.bottom = 0;
|
parents.style.top = 0;
|
parents.style.zIndex = 99999;
|
} else {
|
parents.style.transform = this.parentsStyle.transform;
|
parents.style.width = this.parentsStyle.width;
|
parents.style.height = this.parentsStyle.height;
|
parents.style.position = this.parentsStyle.position;
|
parents.style.left = 'initial';
|
parents.style.right = 'initial';
|
parents.style.bottom = 'initial';
|
parents.style.top = 'initial';
|
parents.style.zIndex = 'auto';
|
}
|
this.$refs.prossPieChart0.resize();
|
this.$refs.prossPieChart1.resize();
|
this.$refs.prossPieChart2.resize();
|
this.$refs.prossPieChart3.resize();
|
},
|
setData(data) {
|
this.$nextTick(() => {
|
if (data) {
|
data.map((item, i) => {
|
let chart = this.$refs[`prossPieChart${i}`];
|
chart.setData(item);
|
chart.resize();
|
})
|
} else {
|
this.postData()
|
}
|
|
})
|
},
|
postData() {
|
let userId = localStorage.getItem('userId');
|
this.websock = new WebSocketClass(`/screen/powerAlarm/status/${userId}`, this.wsMessage)
|
},
|
wsMessage(res) {
|
if (res.code == 1) {
|
let optionData = [{
|
title: '',
|
name: '',
|
data: 0,
|
unit: '',
|
color: '#37a9b3',
|
}, {
|
title: '',
|
name: '',
|
data: 0,
|
unit: '',
|
color: '#f3535f'
|
}, {
|
title: '',
|
name: '',
|
data: 0,
|
unit: '',
|
color: '#ff8b00'
|
}, {
|
title: '',
|
name: '',
|
data: 0,
|
unit: '',
|
color: '#757ffb'
|
},]
|
let index = 0;
|
let resData = res.data;
|
for (let key in resData) {
|
optionData[index].title = key;
|
optionData[index].name = key;
|
if (typeof resData[key] == 'string') {
|
optionData[index].data = Number(resData[key].split('%')[0]);
|
optionData[index].unit = '%';
|
} else {
|
optionData[index].data = resData[key];
|
}
|
index++;
|
}
|
optionData.map((item, i) => {
|
let chart = this.$refs[`prossPieChart${i}`];
|
chart.setData(item);
|
chart.resize();
|
})
|
}
|
},
|
outClear() {
|
this.websock.closeMyself()
|
this.websock = null
|
window.removeEventListener('resize', this.resize);
|
},
|
resize() {
|
this.$refs.prossPieChart0.resize();
|
this.$refs.prossPieChart1.resize();
|
this.$refs.prossPieChart2.resize();
|
this.$refs.prossPieChart3.resize();
|
}
|
}
|
}
|
</script>
|
|
<style scoped>
|
.chartCon {
|
width: 100%;
|
height: 100%;
|
box-sizing: border-box;
|
}
|
|
.chartCon .chartItem {
|
width: 50%;
|
height: 48%;
|
float: left;
|
margin-bottom: 2%;
|
}
|
</style>
|