forked from mt-fe-group/mt-yd-ui
update 质量实时
This commit is contained in:
parent
2e40570969
commit
626e543fa5
@ -6,143 +6,140 @@
|
||||
* @Description: 质量检查实时数据
|
||||
-->
|
||||
<template>
|
||||
<div>
|
||||
<div class="app-container">
|
||||
<small-title :size="'md'">质量检查实时数据</small-title>
|
||||
<base-table
|
||||
v-if="tableReady"
|
||||
:table-config="tableProps"
|
||||
:table-data="tableData.length ? tableData : []"
|
||||
:is-loading="listLoading"
|
||||
:index-config="{ align: 'left', fixed: 'left' }"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
// import BaseTable from '@/components/BaseTable/index-compound'
|
||||
import BaseTable from '@/components/base-table'
|
||||
import SmallTitle from '@/components/small-title'
|
||||
import moment from 'moment'
|
||||
// import fetchList from '@/api/factory-manage/realtimeData'
|
||||
|
||||
export default {
|
||||
name: 'RealtimeDataOfTeam',
|
||||
components: { BaseTable, SmallTitle },
|
||||
data() {
|
||||
return {
|
||||
tableReady: false,
|
||||
// dynamicPropSet: false,
|
||||
tableProps: [{ label: 'default', prop: 'default' }],
|
||||
tableData: [],
|
||||
testData,
|
||||
listLoading: false,
|
||||
intervalId: null
|
||||
}
|
||||
},
|
||||
name: 'RealtimeDataOfTeam',
|
||||
components: { BaseTable, SmallTitle },
|
||||
data() {
|
||||
return {
|
||||
loadTable: false,
|
||||
// dynamicPropSet: false,
|
||||
tableProps: [{ label: 'default', prop: 'default' }],
|
||||
tableData: [],
|
||||
testData: null,
|
||||
listLoading: false,
|
||||
intervalId: null
|
||||
}
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.clearData()
|
||||
mounted() {
|
||||
this.clearData()
|
||||
|
||||
// fetchList('quality').then(res => {
|
||||
// this.testData = res
|
||||
// this.handleData()
|
||||
// })
|
||||
this.fetchList().then(({ data: res }) => {
|
||||
this.testData = res
|
||||
this.handleData()
|
||||
})
|
||||
|
||||
// this.intervalId = setInterval(() => {
|
||||
// this.clearData()
|
||||
// fetchList('quality').then(res => {
|
||||
// this.testData = res
|
||||
// this.handleData()
|
||||
// })
|
||||
// }, 1000 * 60 * 5)
|
||||
this.intervalId = setInterval(() => {
|
||||
this.clearData()
|
||||
this.fetchList().then(res => {
|
||||
this.testData = res
|
||||
this.handleData()
|
||||
})
|
||||
}, 1000 * 60 * 5)
|
||||
},
|
||||
|
||||
this.$nextTick(() => {
|
||||
this.handleData()
|
||||
})
|
||||
},
|
||||
beforeDestroy() {
|
||||
if (this.intervalId) clearInterval(this.intervalId)
|
||||
},
|
||||
|
||||
beforeDestroy() {
|
||||
if (this.intervalId) clearInterval(this.intervalId)
|
||||
},
|
||||
methods: {
|
||||
fetchList() {
|
||||
// 获取质量数据
|
||||
return this.$http({
|
||||
url: this.$http.adornUrl('/monitoring/productionMonitoring/qualityInspectionRealTimeData'),
|
||||
method: 'post'
|
||||
})
|
||||
},
|
||||
|
||||
methods: {
|
||||
clearData() {
|
||||
this.tableReady = false
|
||||
// this.testData = null
|
||||
this.tableData.splice(0)
|
||||
this.tableProps.splice(0)
|
||||
},
|
||||
clearData() {
|
||||
this.loadTable = false
|
||||
this.testData = null
|
||||
this.tableData.splice(0)
|
||||
this.tableProps.splice(0)
|
||||
},
|
||||
|
||||
handleData() {
|
||||
// console.log('testData ===> ', this.testData)
|
||||
this.initProps()
|
||||
// console.log('props ===> ', this.tableProps)
|
||||
this.initData()
|
||||
// console.log('datas ===> ', this.tableData)
|
||||
this.tableReady = true
|
||||
},
|
||||
handleData() {
|
||||
// console.log('testData ===> ', this.testData)
|
||||
this.initProps()
|
||||
// console.log('props ===> ', this.tableProps)
|
||||
this.initData()
|
||||
// console.log('datas ===> ', this.tableData)
|
||||
this.loadTable = true
|
||||
},
|
||||
|
||||
handleRow(data) {
|
||||
// data: { data:[], checkType: '' }
|
||||
const item = {}
|
||||
item.checkType = data.checkType
|
||||
handleRow(data) {
|
||||
// data: { data:[], checkType: '' }
|
||||
const item = {}
|
||||
item.checkType = data.checkType
|
||||
|
||||
data.data.forEach(timepoint => {
|
||||
if (timepoint.children && timepoint.children.length) {
|
||||
timepoint.children.forEach(line => {
|
||||
// item[timepoint.dynamicValue + line.dynamicName] = line.dynamicValue
|
||||
item[timepoint.dynamicName + line.dynamicName] = line.dynamicValue
|
||||
})
|
||||
}
|
||||
})
|
||||
data.data.forEach(timepoint => {
|
||||
if (timepoint.children && timepoint.children.length) {
|
||||
timepoint.children.forEach(line => {
|
||||
// item[timepoint.dynamicValue + line.dynamicName] = line.dynamicValue
|
||||
item[timepoint.dynamicName + line.dynamicName] = line.dynamicValue
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
return item
|
||||
},
|
||||
return item
|
||||
},
|
||||
|
||||
initData() {
|
||||
this.tableData = this.testData.data.data.map(row => this.handleRow(row))
|
||||
},
|
||||
initData() {
|
||||
this.tableData = this.testData.data.data.map(row => this.handleRow(row))
|
||||
},
|
||||
|
||||
initProps() {
|
||||
this.tableProps = this.handlePropsEntry(this.testData.data.nameData)
|
||||
},
|
||||
initProps() {
|
||||
this.tableProps = this.handlePropsEntry(this.testData.data.nameData)
|
||||
},
|
||||
|
||||
handlePropsEntry(nameData) {
|
||||
const dynamicPropNames = []
|
||||
const timeMap = {}
|
||||
handlePropsEntry(nameData) {
|
||||
const dynamicPropNames = []
|
||||
const timeMap = {}
|
||||
|
||||
const parentNode = nameData.filter(item => item.tree === 1)
|
||||
const childNode = nameData.filter(item => item.tree === 2)
|
||||
const parentNode = nameData.filter(item => item.tree === 1)
|
||||
const childNode = nameData.filter(item => item.tree === 2)
|
||||
|
||||
const handleChild = function(prop) {
|
||||
const time = parentNode.find(item => item.id === prop.parentId).name
|
||||
// 填充 timeMap
|
||||
timeMap[time] = timeMap[time] ? timeMap[time] : {}
|
||||
timeMap[time][prop.name] = true
|
||||
}
|
||||
const handleChild = function(prop) {
|
||||
const time = parentNode.find(item => item.id === prop.parentId).name
|
||||
// 填充 timeMap
|
||||
timeMap[time] = timeMap[time] ? timeMap[time] : {}
|
||||
timeMap[time][prop.name] = true
|
||||
}
|
||||
|
||||
childNode.forEach(item => {
|
||||
handleChild(item)
|
||||
})
|
||||
childNode.forEach(item => {
|
||||
handleChild(item)
|
||||
})
|
||||
|
||||
// 对键值排序(时间排序)
|
||||
const sortedTime = Object.keys(timeMap).sort((a, b) => {
|
||||
if (moment(a).isBefore(b)) return -1
|
||||
else return 1
|
||||
})
|
||||
// 对键值排序(时间排序)
|
||||
const sortedTime = Object.keys(timeMap).sort((a, b) => {
|
||||
if (moment(a).isBefore(b)) return -1
|
||||
else return 1
|
||||
})
|
||||
|
||||
// 保存为 props
|
||||
for (const key of sortedTime) {
|
||||
const prop = { label: key, children: [] }
|
||||
for (const subKey in timeMap[key]) {
|
||||
prop.children.push({ label: subKey, prop: key + subKey })
|
||||
}
|
||||
dynamicPropNames.push(prop)
|
||||
}
|
||||
// 保存为 props
|
||||
for (const key of sortedTime) {
|
||||
const prop = { label: key, children: [] }
|
||||
for (const subKey in timeMap[key]) {
|
||||
prop.children.push({ label: subKey, prop: key + subKey })
|
||||
}
|
||||
dynamicPropNames.push(prop)
|
||||
}
|
||||
|
||||
return [{ prop: 'checkType', label: '检查类型', isFixed: true }, ...dynamicPropNames]
|
||||
}
|
||||
}
|
||||
return [{ prop: 'checkType', label: '检查类型', isFixed: true }, ...dynamicPropNames]
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user