chore: optimize the code of StandardTable.vue; 🌟

master
chenghongxing 4 years ago
parent 680300e4e6
commit 58e81ffad0
  1. 21
      src/components/table/StandardTable.vue

@ -61,26 +61,23 @@ export default {
this.$emit('selectedRowChange', selectedRowKeys, selectedRows) this.$emit('selectedRowChange', selectedRowKeys, selectedRows)
}, },
initTotalList (columns) { initTotalList (columns) {
const totalList = [] const totalList = columns.filter(item => item.needTotal)
columns.forEach(column => { .map(item => {
if (column.needTotal) { return {
totalList.push({...column, total: 0}) ...item,
} total: 0
}) }
})
return totalList return totalList
}, },
getScopedSlots(columns) { getScopedSlots(columns) {
let scopedSlots = columns.filter(item => item.scopedSlots).map(item => item.scopedSlots) let scopedSlots = columns.filter(item => item.scopedSlots).map(item => item.scopedSlots)
scopedSlots = scopedSlots.flatMap(item => { scopedSlots = scopedSlots.flatMap(item => Object.values(item))
return Object.keys(item).map(key => item[key])
})
return scopedSlots return scopedSlots
}, },
getSlots(columns) { getSlots(columns) {
let slots = columns.filter(item => item.slots).map(item => item.slots) let slots = columns.filter(item => item.slots).map(item => item.slots)
slots = slots.flatMap(item => { slots = slots.flatMap(item => Object.values(item))
return Object.keys(item).map(key => item[key])
})
return slots return slots
}, },
onClear() { onClear() {

Loading…
Cancel
Save