驾驶舱

This commit is contained in:
2024-04-24 13:30:06 +08:00
parent 0fffed9b0e
commit 1d9e272f99
11 changed files with 674 additions and 463 deletions

View File

@@ -1,22 +1,26 @@
<template>
<div>
<NotMsg v-show="notMsg"/>
<div id='gasChart' class="gas-chart" style="width:600px;height:200px;" v-show='!notMsg'></div>
<NotMsg v-show="notMsg" />
<div
id="gasChart"
class="gas-chart"
style="width: 600px; height: 200px"
v-show="!notMsg"></div>
</div>
</template>
<script>
import * as echarts from 'echarts';
import resize from './../mixins/resize'
import NotMsg from './../components/NotMsg'
import resize from './../mixins/resize';
import NotMsg from './../components/NotMsg';
export default {
name: 'GasChart',
mixins: [resize],
components:{ NotMsg },
components: { NotMsg },
props: {
chartType: '', // 能源类型
chartTime: ''
chartTime: '',
},
data() {
const colors = [
@@ -31,159 +35,170 @@ export default {
];
return {
chart: null,
notMsg:false
notMsg: false,
};
},
computed: {
gasChartMsg() {
return this.$store.state.websocket.sumGasInfo
return this.$store.state.websocket.sumGasInfo;
},
energyWeekTrend() {
return this.$store.state.websocket.energyWeekTrend
return this.$store.state.websocket.energyWeekTrend;
},
energyMonthTrend() {
return this.$store.state.websocket.energyMonthTrend
return this.$store.state.websocket.energyMonthTrend;
},
energyYearTrend() {
return this.$store.state.websocket.energyYearTrend
}
return this.$store.state.websocket.energyYearTrend;
},
},
watch: {
energyWeekTrend: {// 监听周电能,更新图
energyWeekTrend: {
// 监听周电能,更新图
handler(newVal, oldVal) {
if (this.chartTime === '周' && this.chartType === '电耗能') {
this.updateChart()
this.$emit('emitFun')
this.updateChart();
this.$emit('emitFun');
}
}
},
},
energyMonthTrend: {// 监听月电能,更新图
energyMonthTrend: {
// 监听月电能,更新图
handler(newVal, oldVal) {
if (this.chartTime === '月' && this.chartType === '电耗能') {
this.updateChart()
this.$emit('emitFun')
this.updateChart();
this.$emit('emitFun');
}
}
},
},
energyYearTrend: {// 监听年电能,更新图
energyYearTrend: {
// 监听年电能,更新图
handler(newVal, oldVal) {
if (this.chartTime === '年' && this.chartType === '电耗能') {
this.updateChart()
this.$emit('emitFun')
this.updateChart();
this.$emit('emitFun');
}
}
},
},
gasChartMsg: {// 监听天然气,更新图
gasChartMsg: {
// 监听天然气,更新图
handler(newVal, oldVal) {
if (this.chartType === '天然气I' || this.chartType === '天然气II') {
this.updateChart()
this.$emit('emitFun')
this.updateChart();
this.$emit('emitFun');
}
}
},
},
chartTime: {// 监听时间变化,更新图
chartTime: {
// 监听时间变化,更新图
handler(newVal, oldVal) {
this.updateChart()
}
this.updateChart();
},
},
chartType: {// 监听能源类型变化,更新图
chartType: {
// 监听能源类型变化,更新图
handler(newVal, oldVal) {
this.updateChart()
}
}
this.updateChart();
},
},
},
mounted() {
this.$el.addEventListener('resize', () => {
console.log('resziing.....');
});
this.updateChart()
this.updateChart();
},
methods: {
updateChart() {
let gasName = ''
let gasName = '';
const colors = ['#FFCB59'];
let temp = []
let seriesData = []
let xData = []
let yData = []
let temp = [];
let seriesData = [];
let xData = [];
let yData = [];
switch (this.chartType) {
case '电耗能':{
gasName = '电耗能'
case '电耗能': {
gasName = '电耗能';
if (this.chartTime === '周') {
temp = this.energyWeekTrend || []
}else if(this.chartTime === '月') {
temp = this.energyMonthTrend || []
}else{
temp = this.energyYearTrend || []
temp = this.energyWeekTrend || [];
} else if (this.chartTime === '月') {
temp = this.energyMonthTrend || [];
} else {
temp = this.energyYearTrend || [];
}
temp && temp.map(i => {
xData.push(i.time)
yData.push(i.qty)
})
temp &&
temp.map((i) => {
xData.push(i.time);
yData.push(i.qty);
});
break;
}
case '天然气I':{
case '天然气I': {
if (this.chartTime === '周') {
yData = this.gasChartMsg.hisSumGas1For7Day || []
}else if(this.chartTime === '月') {
yData = this.gasChartMsg.sumGas1ForMonth || []
}else{
yData = this.gasChartMsg.sumGas1ForYear || []
yData = this.gasChartMsg.hisSumGas1For7Day || [];
} else if (this.chartTime === '月') {
yData = this.gasChartMsg.sumGas1ForMonth || [];
} else {
yData = this.gasChartMsg.sumGas1ForYear || [];
}
gasName = '天然气I'
xData = this.getXdata()
gasName = '天然气I';
xData = this.getXdata();
break;
}
default:
gasName = '天然气II'
if (this.chartTime === '周') {
yData = this.gasChartMsg.hisSumGas2For7Day || []
}else if(this.chartTime === '月') {
yData = this.gasChartMsg.sumGas2ForMonth || []
}else{
yData = this.gasChartMsg.sumGas2ForYear || []
gasName = '天然气II';
if (this.chartTime === '周') {
yData = this.gasChartMsg.hisSumGas2For7Day || [];
} else if (this.chartTime === '月') {
yData = this.gasChartMsg.sumGas2ForMonth || [];
} else {
yData = this.gasChartMsg.sumGas2ForYear || [];
}
xData = this.getXdata()
xData = this.getXdata();
}
if (yData.length === 0) {
this.notMsg = true
return
} else {
this.notMsg = false
}
this.notMsg = true;
return;
} else {
this.notMsg = false;
}
if (yData.length == 0) {
seriesData = []
}else {
seriesData = [{
name: gasName,
data: yData,
type: "line",
areaStyle: {
seriesData = [];
} else {
yData = yData.map((item) => {
return (item = Number(item.toFixed(2)));
});
seriesData = [
{
name: gasName,
data: yData,
type: 'line',
areaStyle: {
color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
{ offset: 0, color: '#FFCB59' + "40" },
{ offset: 0.5, color: '#FFCB59' + "20" },
{ offset: 1, color: '#FFCB59' + "00" },
{ offset: 0, color: '#FFCB59' + '40' },
{ offset: 0.5, color: '#FFCB59' + '20' },
{ offset: 1, color: '#FFCB59' + '00' },
]),
},
lineStyle: {
width: 1,
},
symbol: 'circle',
symbolSize: 5,
emphasis: {
focus: 'series',
},
},
lineStyle: {
width: 1
},
symbol: 'circle',
symbolSize: 5,
emphasis: {
focus: 'series'
}
}]
];
}
// 绘图
if (
this.chart !== null &&
this.chart !== '' &&
this.chart !== undefined
) {
this.chart.dispose() // 页面多次刷新会出现警告Dom已经初始化了一个实例这是销毁实例
}
this.chart !== null &&
this.chart !== '' &&
this.chart !== undefined
) {
this.chart.dispose(); // 页面多次刷新会出现警告Dom已经初始化了一个实例这是销毁实例
}
this.chart = echarts.init(document.getElementById('gasChart'));
var option = {
color: colors,
@@ -204,7 +219,7 @@ export default {
},
},
yAxis: {
name: this.chartType === '电耗能'?'单位kwh':'单位Nm³',
name: this.chartType === '电耗能' ? '单位kwh' : '单位Nm³',
nameTextStyle: {
color: '#fff',
fontSize: 10,
@@ -230,10 +245,10 @@ export default {
series: seriesData,
tooltip: {
trigger: 'axis',
className: "gas-tooltip"
className: 'gas-tooltip',
},
}
option && this.chart.setOption(option)
};
option && this.chart.setOption(option);
},
getXdata() {
const today = new Date();
@@ -242,31 +257,39 @@ export default {
let days = 30;
if (this.chartTime === '周') {
return Array(7)
.fill(1)
.map((_, index) => {
const today = new Date();
const dtimestamp = today - (index+1) * 24 * 60 * 60 * 1000;
return `${new Date(dtimestamp).getMonth()+1}.${new Date(dtimestamp).getDate()}`;}).reverse()
}else if (this.chartTime == "月") {
.fill(1)
.map((_, index) => {
const today = new Date();
const dtimestamp = today - (index + 1) * 24 * 60 * 60 * 1000;
return `${new Date(dtimestamp).getMonth() + 1}.${new Date(
dtimestamp
).getDate()}`;
})
.reverse();
} else if (this.chartTime == '月') {
if (currentMonth in [1, 3, 5, 7, 8, 10, 12]) {
days = 31;
} else if (currentMonth == 2) {
days = this.isLeapYear(currentYear) ? 29 : 28;
}
return Array(days)
.fill(1)
.map((_, index) => {
return `${currentMonth}.${days - index}`;}).reverse()
.fill(1)
.map((_, index) => {
return `${currentMonth}.${days - index}`;
})
.reverse();
} else {
return Array(12)
.fill(1)
.map((_, index) => {
return `${12 - index}`;}).reverse()
.fill(1)
.map((_, index) => {
return `${12 - index}`;
})
.reverse();
}
},
isLeapYear(year) {
return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
}
},
},
};
</script>
@@ -278,12 +301,12 @@ export default {
}
</style>
<style>
.gas-tooltip {
background: #0a2b4f77 !important;
border: none !important;
backdrop-filter: blur(12px);
}
.gas-tooltip * {
color: #fff !important;
}
.gas-tooltip {
background: #0a2b4f77 !important;
border: none !important;
backdrop-filter: blur(12px);
}
.gas-tooltip * {
color: #fff !important;
}
</style>

View File

@@ -1,68 +1,89 @@
<template>
<div>
<NotMsg v-show="notMsg"/>
<div id="israChart" class="isra-chart" style="width:600px;height:390px;" v-show='!notMsg'></div>
<NotMsg v-show="notMsg" />
<div
id="israChart"
class="isra-chart"
style="width: 600px; height: 390px"
v-show="!notMsg"></div>
</div>
</template>
<script>
import * as echarts from 'echarts';
import resize from './../mixins/resize'
import NotMsg from './../components/NotMsg'
import resize from './../mixins/resize';
import NotMsg from './../components/NotMsg';
export default {
name: 'ISRAChart',
mixins: [resize],
components:{ NotMsg },
components: { NotMsg },
props: {},
data() {
return {
chart: null,
notMsg:true,
colors:['#2760ff', '#518eec', '#0ee8e4', '#ddb523'],
chartData: []
notMsg: true,
colors: ['#2760ff', '#518eec', '#0ee8e4', '#ddb523'],
chartData: [],
};
},
activated() {
},
activated() {},
computed: {
israChartMsg() {
return this.$store.state.websocket.israKiln
}
return this.$store.state.websocket.israKiln;
},
},
watch: {
israChartMsg: {
handler(newVal, oldVal) {
this.chartData = newVal || []
this.updateChart()
this.$emit('emitFun')
}
}
this.chartData = newVal || [];
this.updateChart();
this.$emit('emitFun');
},
},
},
methods: {
getEqualNewlineString(params, length) {
let text = '';
let count = Math.ceil(params.length / length); // 向上取整数
// 一行展示length个
if (count > 1) {
for (let z = 1; z <= count; z++) {
text += params.substr((z - 1) * length, length);
if (z < count) {
text += '\n';
}
}
} else {
text += params.substr(0, length);
}
return text;
},
updateChart() {
console.log('update')
let num = 0
this.chartData && this.chartData.length > 0 && this.chartData.map(i => {
num+=i.num
})
console.log('update');
let num = 0;
this.chartData &&
this.chartData.length > 0 &&
this.chartData.map((i) => {
num += i.num;
});
if (
this.chart !== null &&
this.chart !== '' &&
this.chart !== undefined
) {
this.chart.dispose()
}
this.chart !== null &&
this.chart !== '' &&
this.chart !== undefined
) {
this.chart.dispose();
}
if (this.chartData && this.chartData.length > 0) {
this.notMsg = false
} else {
this.notMsg = true
return
}
this.notMsg = false;
} else {
this.notMsg = true;
return;
}
this.chart = echarts.init(document.getElementById('israChart'));
var option = {
color:this.colors,
title:{
color: this.colors,
title: {
text: num,
subtext: '总数',
top: '32%',
@@ -81,55 +102,92 @@ export default {
bottom: '2%',
left: 'center',
itemWidth: 18,
itemHeight:18,
itemHeight: 18,
icon: 'circle',
textStyle: {
color: '#fff'
color: '#fff',
},
data:this.chartData && this.chartData.length > 0 && this.chartData.map((item,index)=>({
name:item.name,
itemStyle:{
color: this.colors[index%4]
}
}))
data:
this.chartData &&
this.chartData.length > 0 &&
this.chartData.map((item, index) => ({
name: item.name,
itemStyle: {
color: this.colors[index % 4],
},
})),
},
series:[{
series: [
{
name: 'ISRA缺陷检测',
type: 'pie',
center: ['50%', '40%'],
radius: ['45%', '70%'],
avoidLabelOverlap: true,
// label: {
// show: true,
// },
// labelLine: {
// show: true,
// },
label: {
show: false
show: true,
normal: {
alignTo: 'labelLine',
margin: 10,
edgeDistance: 10,
lineHeight: 16,
formatter: (params) => {
//调用自定义显示格式
return this.getEqualNewlineString(
params.value + ' | ' + params.percent.toFixed(0) + '%'
);
},
textStyle: {
// 提示文字的样式
// color: '#595959',
fontSize: 16,
},
},
},
labelLine: {
show: true,
length: 25,
length2: 10,
},
data: this.chartData && this.chartData.length > 0 && this.chartData.map((item, index) => ({
name:item.name,
value: item.num,
itemStyle:{
color:{
type: 'linear',
x: 1,
y: 1,
x2: 0,
y2: 0,
global: false,
colorStops:[
{offset: 0,color: this.colors[index%4]},
{offset: 1,color: this.colors[index%4]+'33'}
]
}
}
}))}],
tooltip: {
trigger: 'item',
className: "isra-chart-tooltip"
data:
this.chartData &&
this.chartData.length > 0 &&
this.chartData.map((item, index) => ({
name: item.name,
value: item.num,
label: {
color: this.colors[index % 4],
},
itemStyle: {
color: {
type: 'linear',
x: 1,
y: 1,
x2: 0,
y2: 0,
global: false,
colorStops: [
{ offset: 0, color: this.colors[index % 4] },
{ offset: 1, color: this.colors[index % 4] + '33' },
],
},
},
})),
},
}
],
tooltip: {
trigger: 'item',
className: 'isra-chart-tooltip',
},
};
this.chart.setOption(option);
}
},
},
};
</script>
@@ -141,12 +199,12 @@ export default {
}
</style>
<style>
.isra-chart-tooltip {
background: #0a2b4f77 !important;
border: none !important;
backdrop-filter: blur(12px);
}
.isra-chart-tooltip * {
color: #fff !important;
}
.isra-chart-tooltip {
background: #0a2b4f77 !important;
border: none !important;
backdrop-filter: blur(12px);
}
.isra-chart-tooltip * {
color: #fff !important;
}
</style>