update 产线实时

This commit is contained in:
g7hoo 2022-08-23 14:16:05 +08:00
parent 70485d293c
commit 2e40570969
2 changed files with 137 additions and 151 deletions

View File

@ -38,7 +38,7 @@ export default {
}, },
created() { created() {
this.clearData() this.clearData()
this.fetchList('equipment').then(({ data: res }) => { this.fetchList().then(({ data: res }) => {
this.testData = res.data.filter(item => !!item.equDet) this.testData = res.data.filter(item => !!item.equDet)
this.handleData() this.handleData()
}) })
@ -48,7 +48,7 @@ export default {
duration: 1500, duration: 1500,
onClose: () => { onClose: () => {
this.clearData() this.clearData()
fetchList('equipment').then(({ data: res }) => { this.fetchList().then(({ data: res }) => {
this.testData = res.data.filter(item => !!item.equDet) this.testData = res.data.filter(item => !!item.equDet)
this.handleData() this.handleData()
}) })
@ -87,7 +87,7 @@ export default {
}, },
expandDataStepOne() { expandDataStepOne() {
console.log('testdata: ', this.testData) // console.log('testdata: ', this.testData)
this.stepOneArray = this.testData.map(item => { this.stepOneArray = this.testData.map(item => {
if (item.equDet) { if (item.equDet) {
item.equDet.forEach((equipment, index) => { item.equDet.forEach((equipment, index) => {

View File

@ -6,171 +6,157 @@
* @Description: 产线生产实时数据 * @Description: 产线生产实时数据
--> -->
<template> <template>
<div> <div>
<div class="app-container"> <div class="app-container">
<small-title :size="'md'">{{ $t('module.factory.realtime.productLine.name') }}</small-title> <small-title :size="'md'">产线生产实时数据</small-title>
<base-table <base-table v-if="loadTable" :table-head-configs="tableProps" :data="tableData.length ? tableData : []" />
v-if="tableReady" </div>
:table-config="tableProps" </div>
:table-data="tableData.length ? tableData : []"
:is-loading="listLoading"
:index-config="{ align: 'left', fixed: 'left' }"
/>
</div>
</div>
</template> </template>
<script> <script>
// import BaseTable from '@/components/BaseTable/index-compound' import BaseTable from '@/components/base-table'
import SmallTitle from '@/components/small-title' import SmallTitle from '@/components/small-title'
import moment from 'moment' import moment from 'moment'
// import fetchList from '@/api/factory-manage/realtimeData'
export default { export default {
name: 'RealtimeDataOfLine', name: 'RealtimeDataOfLine',
components: { BaseTable, SmallTitle }, components: { BaseTable, SmallTitle },
data() { data() {
return { return {
tableReady: false, loadTable: false,
dynamicPropSet: false, dynamicPropSet: false,
tableProps: [{ label: 'default', prop: 'default' }], tableProps: [{ label: 'default', prop: 'default' }],
tableData: [], tableData: [],
testData: null, testData: null,
listLoading: false, listLoading: false,
intervalId: null intervalId: null
} }
}, },
mounted() { mounted() {
this.clearData() this.clearData()
fetchList('line').then(res => { this.fetchList().then(({ data: res }) => {
this.testData = res // console.log('fetchlist:', res)
this.handleData() this.testData = res
}) this.handleData()
})
this.intervalId = setInterval(() => { this.intervalId = setInterval(() => {
this.$message({ this.$message({
message: this.$t('module.factory.realtime.productLine.refresh'), message: this.$t('module.factory.realtime.productLine.refresh'),
type: 'warning', type: 'warning',
onClose: () => { onClose: () => {
this.clearData() this.clearData()
fetchList('line').then(res => { this.fetchList().then(res => {
this.testData = res this.testData = res
this.handleData() this.handleData()
}) })
} }
}) })
}, 1000 * 60 * 5) }, 1000 * 60 * 5)
}, },
beforeDestroy() { beforeDestroy() {
if (this.intervalId) clearInterval(this.intervalId) if (this.intervalId) clearInterval(this.intervalId)
}, },
methods: { methods: {
clearData() { fetchList() {
this.dynamicPropSet = false return this.$http({
this.tableReady = false url: this.$http.adornUrl('/monitoring/productionMonitoring/lineProductionRealTimeData'),
this.testData = null method: 'post'
this.tableData.splice(0) })
this.tableProps.splice(0) },
this.setStaticTableProps()
},
handleData() { clearData() {
this.expandDataStepOne() this.dynamicPropSet = false
// this.expandDataStepTwo() this.loadTable = false
if (this.tableData.length > 0) this.tableReady = true this.testData = null
else { this.tableData.splice(0)
this.$message({ this.tableProps.splice(0)
message: '没有查询到相关数据!', this.setStaticTableProps()
type: 'error', },
duration: 2000
})
}
},
expandDataStepOne() { handleData() {
// this.expandDataStepOne()
console.log('create new one') // this.expandDataStepTwo()
this.tableData = this.testData.data.map(item => { if (this.tableData.length > 0) this.loadTable = true
const newItem = { else {
lineName: item.lineName, this.$message({
orderName: item.orderName, message: '没有查询到相关数据!',
productSize: item.productSize ?? '-' type: 'error',
} duration: 2000
})
}
},
if (item.det) { expandDataStepOne() {
item.det.forEach(obj => { //
// Step2: props // console.log('create new one')
if (!this.dynamicPropSet) { this.tableData = this.testData.data.map(item => {
this.tableProps.push({ const newItem = {
label: moment(obj.recordTime).format('YYYY-MM-DD HH:mm:ss'), lineName: item.lineName,
children: [ orderName: item.orderName,
{ prop: obj.recordTime + '-inputNum', label: this.$t('module.factory.realtime.productLine.input') }, productSize: item.productSize ?? '-'
{ prop: obj.recordTime + '-outputNum', label: this.$t('module.factory.realtime.productLine.output') }, }
{
prop: obj.recordTime + '-passArea',
label: this.$t('module.factory.realtime.productLine.passArea')
},
{
prop: obj.recordTime + '-scrapNum',
label: this.$t('module.factory.realtime.productLine.scrapNum')
},
{
prop: obj.recordTime + '-scrapRate',
label: this.$t('module.factory.realtime.productLine.scrapRate')
}
]
})
}
Object.defineProperty(newItem, obj.recordTime + '-inputNum', { if (item.det) {
value: obj.inputNum ?? '-', item.det.forEach(obj => {
enumerable: true, // Step2: props
writable: true if (!this.dynamicPropSet) {
}) this.tableProps.push({
Object.defineProperty(newItem, obj.recordTime + '-outputNum', { label: moment(obj.recordTime).format('YYYY-MM-DD HH:mm:ss'),
value: obj.outputNum ?? '-', children: [
enumerable: true, { prop: obj.recordTime + '-inputNum', label: '进数据' },
writable: true { prop: obj.recordTime + '-outputNum', label: '出数据' },
}) { prop: obj.recordTime + '-passArea', label: '良品率' },
Object.defineProperty(newItem, obj.recordTime + '-scrapNum', { { prop: obj.recordTime + '-scrapNum', label: '报废数量' },
value: obj.scrapNum ?? '-', { prop: obj.recordTime + '-scrapRate', label: '报废比例' }
enumerable: true, ]
writable: true })
}) }
const scrapRate = obj.scrapRate ?? '-' Object.defineProperty(newItem, obj.recordTime + '-inputNum', {
Object.defineProperty(newItem, obj.recordTime + '-scrapRate', { value: obj.inputNum ?? '-',
value: scrapRate === '-' ? '-' : scrapRate * 100 + '%', enumerable: true,
enumerable: true, writable: true
writable: true })
}) Object.defineProperty(newItem, obj.recordTime + '-outputNum', {
Object.defineProperty(newItem, obj.recordTime + '-passArea', { value: obj.outputNum ?? '-',
value: obj.passArea ?? '-', enumerable: true,
enumerable: true, writable: true
writable: true })
}) Object.defineProperty(newItem, obj.recordTime + '-scrapNum', {
}) value: obj.scrapNum ?? '-',
enumerable: true,
writable: true
})
this.dynamicPropSet = true const scrapRate = obj.scrapRate ?? '-'
return newItem Object.defineProperty(newItem, obj.recordTime + '-scrapRate', {
} else { value: scrapRate === '-' ? '-' : scrapRate * 100 + '%',
// console.log('item.det') enumerable: true,
} writable: true
}) })
}, Object.defineProperty(newItem, obj.recordTime + '-passArea', {
value: obj.passArea ?? '-',
enumerable: true,
writable: true
})
})
setStaticTableProps() { this.dynamicPropSet = true
// Step1: table props return newItem
const staticTableProps = [ }
{ prop: 'lineName', label: this.$t('module.factory.realtime.productLine.pl'), fixed: true }, })
{ prop: 'orderName', label: this.$t('module.factory.realtime.productLine.currOrder'), fixed: true }, },
{ prop: 'productSize', label: this.$t('module.factory.realtime.productLine.pSpecs'), fixed: true }
] setStaticTableProps() {
this.tableProps = staticTableProps // Step1: table props
} const staticTableProps = [{ prop: 'lineName', label: '产线', fixed: true }]
} this.tableProps = staticTableProps
}
}
} }
</script> </script>