mt-yd-ui/src/views/modules/monitoring/realtimeEquipment.vue

201 lines
5.2 KiB
Vue
Raw Normal View History

2022-08-22 14:25:01 +08:00
<!--
* @Author: lb
* @Date: 2022-06-22 14:00:17
* @LastEditors: lb
* @LastEditTime: 2022-06-22 14:00:17
* @Description: 设备生产实时数据
-->
<template>
2022-08-23 11:11:51 +08:00
<div>
<div class="app-container">
<small-title :size="'md'">设备生产实时数据</small-title>
2022-08-23 11:27:32 +08:00
<base-table v-if="loadTable" :table-head-configs="tableProps" :data="tableData.length ? tableData : []" :span-method="spanMethod" />
2022-08-23 11:11:51 +08:00
</div>
</div>
2022-08-22 14:25:01 +08:00
</template>
<script>
2022-08-22 16:59:23 +08:00
import BaseTable from '@/components/base-table'
2022-08-22 14:25:01 +08:00
import SmallTitle from '@/components/small-title'
import moment from 'moment'
export default {
2022-08-23 11:11:51 +08:00
name: 'RealtimeDataOfEquipment',
components: { BaseTable, SmallTitle },
data() {
return {
loadTable: false,
tableProps: [{ label: 'default', prop: 'default' }],
stepOneArray: [],
tableData: [],
testData: null,
equipmentCount: {}, // 每个产线的设备数量记录
dynamicPropSet: false, // 是否设置过动态prop
listLoading: false,
rowNum: 0,
intervalId: null
}
},
created() {
this.clearData()
2022-08-23 14:16:05 +08:00
this.fetchList().then(({ data: res }) => {
2022-08-23 11:27:32 +08:00
this.testData = res.data.filter(item => !!item.equDet)
this.handleData()
})
2022-08-23 14:00:45 +08:00
this.intervalId = setInterval(() => {
this.$message({
type: 'warning',
duration: 1500,
onClose: () => {
this.clearData()
2022-08-23 14:16:05 +08:00
this.fetchList().then(({ data: res }) => {
2022-08-23 14:00:45 +08:00
this.testData = res.data.filter(item => !!item.equDet)
this.handleData()
})
}
})
}, 1000 * 60 * 5)
2022-08-23 11:11:51 +08:00
},
beforeDestroy() {
if (this.intervalId) clearInterval(this.intervalId)
},
methods: {
clearData() {
this.tableData.splice(0)
this.tableProps.splice(0)
this.stepOneArray.splice(0)
this.dynamicPropSet = false
this.rowNum = 0
this.testData = null
this.loadTable = false
this.equipmentCount = {}
this.setStaticTableProps()
},
handleData() {
this.expandDataStepOne()
this.expandDataStepTwo()
this.loadTable = true
},
fetchList() {
// 获取设备实时数据
2022-08-23 11:27:32 +08:00
return this.$http({
url: this.$http.adornUrl('/monitoring/productionMonitoring/equipmentProductionRealTimeData'),
method: 'post'
})
2022-08-23 11:11:51 +08:00
},
expandDataStepOne() {
2022-08-23 14:16:05 +08:00
// console.log('testdata: ', this.testData)
2022-08-23 14:00:45 +08:00
this.stepOneArray = this.testData.map(item => {
if (item.equDet) {
item.equDet.forEach((equipment, index) => {
equipment.lineName = item.lineName
})
}
return item.equDet
})
2022-08-23 11:11:51 +08:00
},
expandDataStepTwo() {
// 扩展服务器返回的数据第二阶段
this.rowNum = 0
2022-08-23 14:00:45 +08:00
this.stepOneArray.forEach(line => {
let avaliableEquipmentCount = 0
2022-08-23 11:11:51 +08:00
2022-08-23 14:00:45 +08:00
line.forEach(equipment => {
2022-08-23 11:11:51 +08:00
const newItem = {
2022-08-23 14:00:45 +08:00
equId: equipment.equId,
lineName: equipment.lineName,
equName: equipment.equName,
externalCode: equipment.externalCode,
totalProduction: equipment.totalProduction ?? '-'
2022-08-23 11:11:51 +08:00
}
2022-08-23 14:00:45 +08:00
if (equipment.det) {
avaliableEquipmentCount += 1
equipment.det.forEach(obj => {
2022-08-23 11:11:51 +08:00
if (!this.dynamicPropSet) {
2022-08-23 14:00:45 +08:00
if (obj.recordTime) {
// 如果 obj.recordTime 是有效的
this.tableProps.push({
label: moment(obj.recordTime).format('YYYY-MM-DD HH:mm:ss'),
children: [
{ prop: obj.recordTime + '-inputNum', label: '进数据' },
{ prop: obj.recordTime + '-outputNum', label: '出数据' },
{ prop: obj.recordTime + '-scrapNum', label: '报废数据' },
{ prop: obj.recordTime + '-scrapRate', label: '报废比例' }
]
})
}
2022-08-23 11:11:51 +08:00
}
Object.defineProperty(newItem, obj.recordTime + '-inputNum', {
value: obj.inputNum ?? '-',
enumerable: true,
writable: true
})
Object.defineProperty(newItem, obj.recordTime + '-outputNum', {
value: obj.outputNum ?? '-',
enumerable: true,
writable: true
})
Object.defineProperty(newItem, obj.recordTime + '-scrapNum', {
value: obj.scrapNum ?? '-',
enumerable: true,
writable: true
})
Object.defineProperty(newItem, obj.recordTime + '-scrapRate', {
value: obj.scrapRate ?? '-',
enumerable: true,
writable: true
})
Object.defineProperty(newItem, 'recordTime', {
value: obj.recordTime,
enumerable: true,
writable: true
})
})
if (!this.dynamicPropSet) this.dynamicPropSet = true
this.tableData.push(newItem)
}
})
2022-08-23 14:00:45 +08:00
this.$set(this.equipmentCount, [this.rowNum], avaliableEquipmentCount)
this.rowNum += avaliableEquipmentCount
2022-08-23 11:11:51 +08:00
})
},
2022-08-23 14:00:45 +08:00
2022-08-23 11:11:51 +08:00
setStaticTableProps() {
// Step1: 设置静态的 table props
const staticTableProps = [
2022-08-23 14:00:45 +08:00
{ prop: 'lineName', label: '产线', fixed: true },
{ prop: 'equName', label: '设备', fixed: true },
{ prop: 'totalProduction', label: '总产量', fixed: true }
2022-08-23 11:11:51 +08:00
]
this.tableProps = staticTableProps
},
spanMethod({ row, column, rowIndex, columnIndex }) {
// 设置合并行列的方式
2022-08-23 14:00:45 +08:00
if (columnIndex === 0) {
2022-08-23 11:11:51 +08:00
if (this.equipmentCount[rowIndex]) {
// 如果找到需要合并的行号
return {
rowspan: this.equipmentCount[rowIndex],
colspan: 1
}
} else {
return {
rowspan: 0,
colspan: 0
}
}
}
}
}
2022-08-22 14:25:01 +08:00
}
</script>