<template>
|
<div class="flexCon" @dblclick="dblclick">
|
<div class="con">
|
<div class="echarts-wrapper">
|
<div class="echarts-content" ref="chart">
|
|
</div>
|
</div>
|
</div>
|
</div>
|
</template>
|
|
<script>
|
import * as echarts from 'echarts';
|
//引入chart字体自适应
|
import {
|
chartFontsize
|
} from '@/assets/js/chartFontsize'
|
import { WebSocketClass } from '@/assets/js/socket'
|
import { checkboxs } from '@/assets/js/powerInfoData'
|
export default {
|
name: "abeamProChart",
|
chart: "",
|
chartData: {},
|
props: {
|
id: {
|
require: true,
|
type: String,
|
default: "",
|
},
|
},
|
data() {
|
return {
|
websock: null
|
}
|
},
|
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.$options.chart.resize();
|
},
|
toParentPage(value) {
|
if (typeof (value) == 'string') {
|
if (sessionStorage.getItem('newPlatform') == 1) {
|
window.parent.parent.postMessage({
|
cmd: "syncPage",
|
params: {
|
pageInfo: {
|
label: "设备状态查询",
|
name: "btsStatus",
|
src: "/dataTest/btsStatus?workStauts=" + value,
|
closable: true
|
},
|
}
|
}, "*");
|
} else {
|
window.parent.parent.postMessage({
|
cmd: "syncPage",
|
params: {
|
pageInfo: {
|
label: "设备状态查询",
|
name: "btsStatusTest",
|
src: "#/dataMager/btsStatus?workStauts=" + value,
|
closable: true
|
},
|
}
|
}, "*");
|
}
|
|
}
|
},
|
setOption(opt) {
|
this.$options.chart.setOption(opt);
|
this.$options.chart.on('click', (params) => {
|
let name = params.name;
|
checkboxs.sbzt.map(item => {
|
if (item.label == name) {
|
this.toParentPage(item.value)
|
}
|
})
|
})
|
},
|
organizeData(posData) {
|
let dataColor = posData.color;
|
let yData = posData.yData;
|
let radius = (this.$refs.chart.clientHeight / 4 - 7) > 0 ? this.$refs.chart.clientHeight / 4 - 7 : 0;
|
let data = posData.data;
|
let max = posData[0];
|
data.map(item => {
|
if (item > max) {
|
max = item;
|
}
|
});
|
max = max - (max % 10) + 20;
|
let maxData = []
|
data.map(() => {
|
maxData.push(max)
|
});
|
let option = {
|
grid: {
|
left: '2%',
|
right: '5%',
|
bottom: '0',
|
top: '0',
|
containLabel: true
|
},
|
tooltip: {
|
trigger: 'axis',
|
axisPointer: {
|
type: 'shadow'
|
}
|
},
|
xAxis: {
|
type: 'value',
|
axisLabel: {
|
show: true,
|
color: '#fff',
|
fontSize: chartFontsize(14),
|
},
|
splitLine: {
|
show: false
|
},
|
axisTick: {
|
show: false
|
},
|
axisLine: {
|
show: false
|
},
|
},
|
yAxis: [{
|
type: 'category',
|
inverse: true,
|
axisLabel: {
|
show: true,
|
color: '#fff',
|
fontSize: chartFontsize(14),
|
},
|
splitLine: {
|
show: false
|
},
|
axisTick: {
|
show: false
|
},
|
axisLine: {
|
show: false
|
},
|
data: yData
|
}],
|
series: [{
|
name: '',
|
type: 'bar',
|
zlevel: 1,
|
itemStyle: {
|
color: function (params) {
|
return dataColor[params.dataIndex];
|
},
|
borderRadius: [0, radius, radius, 0],
|
},
|
data: data
|
},
|
]
|
};
|
// 设置配置项
|
this.setOption(option);
|
},
|
setData(sendData) {
|
if (sendData) {
|
this.$options.chartData = sendData;
|
this.organizeData(sendData)
|
} else {
|
this.postData()
|
}
|
},
|
postData() {
|
let userId = localStorage.getItem('userId');
|
this.websock = new WebSocketClass(`/screen/battery/status/${userId}`, this.wsMessage)
|
},
|
wsMessage(res) {
|
if (res.code == 1) {
|
let optionData = {
|
yData: [],
|
color: ['#f58881', '#b4d465', '#ffcb29'],
|
bgColor: ['rgba(245,136,129,0.35)', 'rgba(255,255,255,0.35)', 'rgba(255,203,41,0.35)'],
|
data: []
|
}
|
let resData = res.data;
|
for (let key in resData) {
|
optionData.yData.push(key);
|
optionData.data.push(resData[key]);
|
}
|
this.$options.chartData = optionData;
|
this.organizeData(optionData)
|
}
|
},
|
resize() {
|
setTimeout(() => {
|
this.$options.chart.resize();
|
if (JSON.stringify(this.$options.chartData) != '{}') {
|
this.setData(this.$options.chartData);
|
}
|
}, 300)
|
},
|
outClear() {
|
this.websock.closeMyself()
|
this.websock = null
|
window.removeEventListener('resize', this.resize);
|
}
|
},
|
mounted() {
|
// 基于准备好的dom,初始化echarts实例
|
this.$options.chart = echarts.init(this.$refs.chart);
|
|
window.addEventListener('resize', this.resize);
|
},
|
destroyed() {
|
this.websock.closeMyself()
|
window.removeEventListener('resize', this.resize);
|
}
|
}
|
</script>
|
|
<style scoped>
|
.flexCon {
|
width: 100%;
|
height: 100%;
|
display: flex;
|
justify-content: center;
|
align-items: center;
|
}
|
|
.flexCon .con {
|
width: 100%;
|
height: 80%;
|
}
|
</style>
|