lb #19

Merged
g7hoo merged 80 commits from lb into test 2023-09-11 15:05:16 +08:00
3 changed files with 173 additions and 41 deletions
Showing only changes of commit a505f34abc - Show all commits

View File

@ -0,0 +1,49 @@
<!--
filename: lineChart.vue
author: liubin
date: 2023-09-04 13:45:00
description:
-->
<template>
<div class="line-chart"></div>
</template>
<script>
import * as echarts from 'echarts';
export default {
name: 'LineChart',
components: {},
props: ['config'],
data() {
return {
chart: null,
};
},
computed: {},
mounted() {
this.init();
},
beforeDestroy() {
if (this.chart) {
this.chart.dispose();
}
},
methods: {
init() {
console.log('thsi el', this.$el);
if (!this.chart) this.chart = echarts.init(this.$el);
this.chart.setOption(this.config);
},
},
};
</script>
<style scoped lang="scss">
.line-chart {
padding: 0 12px;
// background: #e1e1e1;
min-height: 320px;
}
</style>

View File

@ -15,46 +15,10 @@
@headBtnClick="handleSearchBarBtnClick" /> @headBtnClick="handleSearchBarBtnClick" />
<div class="main-area"> <div class="main-area">
<div class="legend-row">
<div class="legend">
<div class="icon running"></div>
<div>运行中</div>
</div>
<!-- <div class="legend">
<div class="icon waiting"></div>
<div>待机</div>
</div> -->
<div class="legend">
<div class="icon fault"></div>
<div>故障</div>
</div>
<!-- <div class="legend">
<div class="icon lack"></div>
<div>缺料</div>
</div>
<div class="legend">
<div class="icon full"></div>
<div>满料</div>
</div> -->
<div class="legend">
<div class="icon stop"></div>
<div>计划停机</div>
</div>
</div>
<div class="graphs" v-if="graphList.length"> <div class="graphs" v-if="graphList.length">
<div class="graph" v-for="eq in graphList" :key="eq.key"> <div class="graph" v-for="eq,index in graphList" :key="eq.key">
<h2 class="graph-title">{{ eq.key }}</h2> <h2 class="graph-title">{{ eq.key }}</h2>
<div <LineChart :key="eq.key + '__linechart'" :config="getRealConfig(index)" />
v-for="blc in eq"
:key="blc.startTime"
class="graph-item-fixed tick"
:class="{
running: blc.status == 0,
fault: blc.status == 2,
stop: blc.status == 1,
}"
:style="{ width: blc.duration * 2 + 'px' }"
:data-time="new Date(blc.startTime).toLocaleTimeString()"></div>
</div> </div>
</div> </div>
<h2 v-else>请添加设备</h2> <h2 v-else>请添加设备</h2>
@ -63,9 +27,11 @@
</template> </template>
<script> <script>
import LineChart from './components/lineChart.vue';
export default { export default {
name: 'SGProduction', name: 'SGProduction',
components: {}, components: { LineChart },
props: {}, props: {},
data() { data() {
return { return {
@ -119,9 +85,57 @@ export default {
queryParams: { queryParams: {
lineId: null, lineId: null,
sectionId: null, sectionId: null,
equipmentId: null,
recordTime: [], recordTime: [],
}, },
graphList: [], graphList: [],
templateConfig: {
grid: {
top: 88,
left: 56,
right: 56,
bottom: 56,
},
legend: {
top: 0,
left: 0,
padding: 5,
icon: 'roundRect',
itemWidth: 12,
itemHeight: 12,
itemGap: 20,
textStyle: {
fontSize: 14,
lineHeight: 14,
},
},
xAxis: {
type: 'category',
data: Array(24)
.fill(1)
.map((item, index) => `${index}:00`),
},
yAxis: {
type: 'value',
name: '产量',
nameLocation: 'end',
nameTextStyle: {
fontSize: 14,
align: 'right',
},
nameGap: 26,
},
series: [
{
name: '产线1',
data: Array(24)
.fill(1)
.map(() => Math.random() * 100),
type: 'line',
smooth: true,
},
],
},
}; };
}, },
created() { created() {
@ -130,25 +144,91 @@ export default {
this.getList(); this.getList();
}, },
methods: { methods: {
handleSearchBarBtnClick({ btnName, ...payload }) {
switch (btnName) {
case 'search':
this.queryParams.lineId = payload.lineId || null;
this.queryParams.sectionId = payload.sectionId || null;
this.queryParams.equipmentId = payload.equipmentId || null;
this.queryParams.recordTime = payload.recordTime || null;
this.getList();
break;
case 'compare':
this.$message.info('暂未实现该接口');
break;
}
},
/** 重置查询条件 */ /** 重置查询条件 */
initQuery() { initQuery() {
this.queryParams.lineId = null; this.queryParams.lineId = null;
this.queryParams.sectionId = null; this.queryParams.sectionId = null;
this.queryParams.equipmentId = null;
this.queryParams.recordTime = []; this.queryParams.recordTime = [];
}, },
/** 对象到数组的转换 */
objectToArray(obj) {
return Object.keys(obj).map((key) => {
obj[key].sort((a, b) => a.startTime - b.startTime);
obj[key].key = key;
return obj[key];
});
},
async getList() { async getList() {
const { code, data } = await this.$axios({ const { code, data } = await this.$axios({
url: '/analysis/equipment-analysis/status', url: '/analysis/equipment-analysis/quantity',
method: 'get', method: 'get',
params: this.queryParams, params: this.queryParams,
}); });
if (code == 0) { if (code == 0) {
this.graphList = data; this.graphList = this.objectToArray(data);
// const eq1 = [
// { totalQuantity: 20, startTime: 1693964578000 },
// { totalQuantity: 43, startTime: 1693964678000 },
// { totalQuantity: 12, startTime: 1693964778000 },
// { totalQuantity: 11, startTime: 1693964878000 },
// { totalQuantity: 98, startTime: 1693965478000 },
// { totalQuantity: 87, startTime: 1693965578000 },
// ];
// eq1.key = 'SS1';
// const eq2 = [
// { totalQuantity: 23, startTime: 1693961578000 },
// { totalQuantity: 42, startTime: 1693964578000 },
// { totalQuantity: 51, startTime: 1693965578000 },
// { totalQuantity: 18, startTime: 1693966578000 },
// { totalQuantity: 77, startTime: 1693966778000 },
// { totalQuantity: 38, startTime: 1693967578000 },
// { totalQuantity: 57, startTime: 1693969578000 },
// ];
// eq2.key = 'SS2';
// this.graphList = [eq1, eq2];
console.log('graph list', this.graphList); console.log('graph list', this.graphList);
} }
}, },
/** 获得设备产量 */
getEquipmentQuantity(equipmentArr) {
return equipmentArr.map((item) => item.totalQuantity);
},
/** 获得设备产量的时间 */
getTimeinfo(equipmentArr) {
return equipmentArr.map((item) => new Date(item.startTime).toLocaleTimeString());
},
getRealConfig(index) {
// if (!this.graphList || this.graphList.length == 0) return;
const config = JSON.parse(JSON.stringify(this.templateConfig));
// config.legend.data = this.graphList[index].key;
config.series[0].name = this.graphList[index]?.key;
// console.log("this.graphList?.[index]", this.graphList?.[index]);
config.series[0].data = this.getEquipmentQuantity(this.graphList?.[index] || []);
config.xAxis.data = this.getTimeinfo(this.graphList?.[index] || []);
return config;
},
/** 准备产线数据 */ /** 准备产线数据 */
async initProductline() { async initProductline() {
const { code, data } = await this.$axios({ const { code, data } = await this.$axios({

View File

@ -173,6 +173,7 @@ export default {
queryParams: { queryParams: {
lineId: null, lineId: null,
sectionId: null, sectionId: null,
equipmentId: null,
recordTime: [], recordTime: [],
}, },
graphList: [], graphList: [],
@ -208,6 +209,7 @@ export default {
/** 重置查询条件 */ /** 重置查询条件 */
initQuery() { initQuery() {
this.queryParams.lineId = null; this.queryParams.lineId = null;
this.queryParams.equipmentId = null;
this.queryParams.sectionId = null; this.queryParams.sectionId = null;
this.queryParams.recordTime = []; this.queryParams.recordTime = [];
}, },
@ -270,6 +272,7 @@ export default {
case 'search': case 'search':
this.queryParams.lineId = payload.lineId || null; this.queryParams.lineId = payload.lineId || null;
this.queryParams.sectionId = payload.sectionId || null; this.queryParams.sectionId = payload.sectionId || null;
this.queryParams.equipmentId = payload.equipmentId || null;
this.queryParams.recordTime = payload.recordTime || null; this.queryParams.recordTime = payload.recordTime || null;
this.getList(); this.getList();
break; break;