add spanMethod to base-table

This commit is contained in:
g7hoo 2022-08-23 11:11:51 +08:00
parent 4297798d44
commit 8f124e06b1
2 changed files with 220 additions and 201 deletions

View File

@ -1,6 +1,14 @@
<template> <template>
<div class="base-table"> <div class="base-table">
<el-table :data="data" style="width: 100%" fit border :header-cell-style="{ background: '#FAFAFA', color: '#606266', height: '40px' }" :max-height="maxHeight"> <el-table
:data="data"
style="width: 100%"
fit
border
:header-cell-style="{ background: '#FAFAFA', color: '#606266', height: '40px' }"
:max-height="maxHeight"
:span-method="spanMethod || null"
>
<!-- 表格头定义 --> <!-- 表格头定义 -->
<template v-for="(head, idx) in tableHeadConfigs"> <template v-for="(head, idx) in tableHeadConfigs">
<!-- 带type的表头 --> <!-- 带type的表头 -->
@ -61,6 +69,13 @@ export default {
maxHeight: { maxHeight: {
type: Number, type: Number,
default: 500 default: 500
},
spanMethod: {
type: Function,
default: () => {
() => [0, 0]
},
required: false
} }
}, },
filters: { filters: {

View File

@ -10,11 +10,22 @@
<div class="app-container"> <div class="app-container">
<!-- <small-title :size="'md'">{{ $t('module.factory.realtime.equipment.name') }}</small-title> --> <!-- <small-title :size="'md'">{{ $t('module.factory.realtime.equipment.name') }}</small-title> -->
<small-title :size="'md'">设备生产实时数据</small-title> <small-title :size="'md'">设备生产实时数据</small-title>
<!-- <base-table v-if="loadTable" :table-head-configs="tableProps" :data="tableData.length ? tableData : []" :span-method="spanMethod" /> -->
<base-table <base-table
v-if="loadTable" v-if="loadTable"
:table-head-configs="tableProps" :table-head-configs="[
:data="tableData.length ? tableData : []" { type: 'index', label: '序号' },
:span-method="spanMethod" { prop: 'name', label: '名称' },
{ prop: 'code', label: '编码' },
{ prop: 'brand', label: '品牌' }
]"
:data="[
{ name: '汽车', code: 'Car', brand: 'Benz' },
{ name: '汽车', code: 'Car2', brand: 'Audi' },
{ name: '汽车', code: 'Car3', brand: 'Maclaren' },
{ name: '火车', code: 'Train', brand: 'Harmony' }
]"
:span-method="testSpan"
/> />
</div> </div>
</div> </div>
@ -28,7 +39,6 @@ import moment from 'moment'
const fetchList = () => {} const fetchList = () => {}
export default { export default {
name: 'RealtimeDataOfEquipment', name: 'RealtimeDataOfEquipment',
components: { BaseTable, SmallTitle }, components: { BaseTable, SmallTitle },
@ -48,25 +58,25 @@ export default {
}, },
created() { created() {
this.clearData() this.clearData()
fetchList('equipment').then(res => { // fetchList('equipment').then(res => {
this.testData = res // this.testData = res
this.handleData() // this.handleData()
}) // })
this.loadTable = true
this.intervalId = setInterval(() => { // this.intervalId = setInterval(() => {
this.$message({ // this.$message({
// message: this.$t('module.factory.realtime.equipment.refresh'), // // message: this.$t('module.factory.realtime.equipment.refresh'),
type: 'warning', // type: 'warning',
duration: 1500, // duration: 1500,
onClose: () => { // onClose: () => {
this.clearData() // this.clearData()
fetchList('equipment').then(res => { // fetchList('equipment').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)
@ -92,39 +102,33 @@ export default {
}, },
fetchList() { fetchList() {
//
},
testSpan({ row, column, rowIndex, columnIndex }) {
console.log('rowIndex', rowIndex)
if (columnIndex === 1 && rowIndex % 2 === 0) {
return [2, 1]
}
if (columnIndex === 1 && rowIndex % 2 !== 0) {
return [0, 0]
}
}, },
expandDataStepOne() { expandDataStepOne() {
// this.rowNum = 0
//
this.stepOneArray = this.testData.data.map(item => { this.stepOneArray = this.testData.data.map(item => {
// console.log('handle row: ', this.rowNum)
if (item.equDet) { if (item.equDet) {
// let count = 0
let newItem
const newItemArray = []
item.equDet.forEach((equipment, index) => { item.equDet.forEach((equipment, index) => {
// count += 1 equipment.lineName = item.lineName
newItem = {
...equipment,
lineName: item.lineName,
orderName: item.orderName,
productSize: item.productSize
}
newItemArray.push(newItem)
}) })
// this.equipmentCountArray.push({ rowNum: this.rowNum, eqCount: count })
// this.$set(this.equipmentCount, [this.rowNum], count)
// this.rowNum += count
return newItemArray
} }
return item.equDet
}) })
}, },
expandDataStepTwo() { expandDataStepTwo() {
// //
// console.log('before step two: ', this.stepOneArray) console.log('before step two: ', this.stepOneArray)
this.rowNum = 0 this.rowNum = 0
this.stepOneArray.forEach(arrayItem => { this.stepOneArray.forEach(arrayItem => {