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

182 lines
4.9 KiB
Vue
Raw Normal View History

2022-08-22 14:25:01 +08:00
<!--
* @Author: lb
* @Date: 2022-06-22 14:00:17
2023-02-03 16:44:47 +08:00
* @LastEditors: fzq
2023-02-09 10:31:00 +08:00
* @LastEditTime: 2023-02-09 09:53:57
2022-08-22 14:25:01 +08:00
* @Description: 产线生产实时数据
-->
<template>
2022-08-23 14:16:05 +08:00
<div>
<div class="app-container">
<small-title :size="'md'">{{ $t('realtime.pl') }}</small-title>
2022-08-23 14:16:05 +08:00
<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-09-01 15:01:25 +08:00
import i18n from '@/i18n'
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() {
2023-02-09 10:31:00 +08:00
// console.log('this.$route', this.$route)
2022-08-23 14:16:05 +08:00
this.clearData()
2023-02-09 10:31:00 +08:00
this.fetchList().then(({ data: res }) => {
this.testData = res
this.handleData()
console.log('res', res)
let loading = this.$loading({
lock: true, //lock的修改符--默认是false
text: this.$t('loading'), //显示在加载图标下方的加载文案
background: 'rgba(0,0,0,0.8)', //遮罩层颜色
spinner: 'el-icon-loading' //自定义加载图标类名
})
console.log('testData:', this.testData)
if (this.testData || this.$route.fullPath !== '/monitoring-realtimeProductLine') {
// 获取数据显示成功后关闭loading
loading.close()
} else {
this.$message.error(this.$t('err'))
}
})
2022-08-23 14:16:05 +08:00
this.intervalId = setInterval(() => {
this.$message({
2022-09-27 09:21:44 +08:00
message: this.$t('realtime.refresh'),
2022-08-23 14:16:05 +08:00
type: 'warning',
onClose: () => {
this.clearData()
2022-09-27 15:52:03 +08:00
this.fetchList().then(({ data: res }) => {
2022-08-23 14:16:05 +08:00
this.testData = res
this.handleData()
})
}
})
}, 1000 * 60 * 5)
},
2022-08-22 14:25:01 +08:00
2022-09-27 09:21:44 +08:00
deactivated() {
2022-08-23 14:16:05 +08:00
if (this.intervalId) clearInterval(this.intervalId)
},
2023-02-09 10:31:00 +08:00
created() {
// console.log('this.tableData', this.tableData)
},
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({
2022-09-02 11:33:34 +08:00
message: i18n.t('errors.nodata'),
type: 'info',
2022-08-23 14:16:05 +08:00
duration: 2000
})
}
},
2022-08-22 14:25:01 +08:00
2022-08-23 14:16:05 +08:00
expandDataStepOne() {
// 扩展服务器返回的数据第一阶段
// console.log('create new one')
2023-02-08 18:13:08 +08:00
this.tableData = this.testData.data.map((item) => {
2022-08-23 14:16:05 +08:00
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) {
2023-02-08 18:13:08 +08:00
item.det.forEach((obj) => {
2022-08-23 14:16:05 +08:00
// Step2: 设置动态props
if (!this.dynamicPropSet) {
this.tableProps.push({
2023-02-08 18:13:08 +08:00
label: moment(obj.recordTime).format('YYYY-MM-DD HH') + moment(obj.recordTime).add(1, 'hours').format('-HH') + i18n.t('hourTime'),
2022-08-23 14:16:05 +08:00
children: [
2022-09-02 11:33:34 +08:00
{ prop: obj.recordTime + '-inputNum', label: i18n.t('realtime.in') },
2023-02-08 18:13:08 +08:00
{ prop: obj.recordTime + '-outputNum', label: i18n.t('realtime.out') }
2022-09-26 17:01:15 +08:00
// { prop: obj.recordTime + '-passArea', label: i18n.t('realtime.goodrate') },
// { prop: obj.recordTime + '-scrapNum', label: i18n.t('realtime.num') },
// { prop: obj.recordTime + '-scrapRate', label: i18n.t('realtime.rate') }
2022-08-23 14:16:05 +08:00
]
})
}
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
2022-09-02 10:59:44 +08:00
const staticTableProps = [{ prop: 'lineName', label: i18n.t('pl.title'), fixed: true }]
2022-08-23 14:16:05 +08:00
this.tableProps = staticTableProps
}
}
2022-08-22 14:25:01 +08:00
}
</script>