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

165 lines
4.1 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 14:16:05 +08:00
<div>
<div class="app-container">
<small-title :size="'md'">产线生产实时数据</small-title>
<base-table v-if="loadTable" :table-head-configs="tableProps" :data="tableData.length ? tableData : []" />
</div>
</div>
2022-08-22 14:25:01 +08:00
</template>
<script>
2022-08-23 14:16:05 +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'
2022-08-31 11:32:50 +08:00
import { calcMaxHeight } from '@/utils'
2022-09-01 09:16:51 +08:00
import { timeFilter } from '@/utils/filters'
2022-08-22 14:25:01 +08:00
export default {
2022-08-23 14:16:05 +08:00
name: 'RealtimeDataOfLine',
components: { BaseTable, SmallTitle },
data() {
return {
2022-09-01 08:50:46 +08:00
calcMaxHeight,
2022-08-23 14:16:05 +08:00
loadTable: false,
dynamicPropSet: false,
tableProps: [{ label: 'default', prop: 'default' }],
tableData: [],
testData: null,
listLoading: false,
intervalId: null
}
},
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
mounted() {
this.clearData()
this.fetchList().then(({ data: res }) => {
// console.log('fetchlist:', res)
this.testData = res
this.handleData()
})
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
this.intervalId = setInterval(() => {
this.$message({
message: this.$t('module.factory.realtime.productLine.refresh'),
type: 'warning',
onClose: () => {
this.clearData()
this.fetchList().then(res => {
this.testData = res
this.handleData()
})
}
})
}, 1000 * 60 * 5)
},
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
beforeDestroy() {
if (this.intervalId) clearInterval(this.intervalId)
},
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
methods: {
fetchList() {
return this.$http({
url: this.$http.adornUrl('/monitoring/productionMonitoring/lineProductionRealTimeData'),
method: 'post'
})
},
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
clearData() {
this.dynamicPropSet = false
this.loadTable = false
this.testData = null
this.tableData.splice(0)
this.tableProps.splice(0)
this.setStaticTableProps()
},
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
handleData() {
this.expandDataStepOne()
// this.expandDataStepTwo()
if (this.tableData.length > 0) this.loadTable = true
else {
this.$message({
message: '没有查询到相关数据!',
type: 'error',
duration: 2000
})
}
},
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
expandDataStepOne() {
// 扩展服务器返回的数据第一阶段
// console.log('create new one')
this.tableData = this.testData.data.map(item => {
const newItem = {
lineName: item.lineName,
orderName: item.orderName,
productSize: item.productSize ?? '-'
}
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
if (item.det) {
item.det.forEach(obj => {
// Step2: 设置动态props
if (!this.dynamicPropSet) {
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 + '-passArea', label: '良品率' },
{ prop: obj.recordTime + '-scrapNum', label: '报废数量' },
{ prop: obj.recordTime + '-scrapRate', label: '报废比例' }
]
})
}
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +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
})
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
const scrapRate = obj.scrapRate ?? '-'
Object.defineProperty(newItem, obj.recordTime + '-scrapRate', {
value: scrapRate === '-' ? '-' : scrapRate * 100 + '%',
enumerable: true,
writable: true
})
Object.defineProperty(newItem, obj.recordTime + '-passArea', {
value: obj.passArea ?? '-',
enumerable: true,
writable: true
})
})
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
this.dynamicPropSet = true
return newItem
}
})
},
setStaticTableProps() {
// Step1: 设置静态的 table props
const staticTableProps = [{ prop: 'lineName', label: '产线', fixed: true }]
this.tableProps = staticTableProps
}
}
2022-08-22 14:25:01 +08:00
}
</script>