ant-design-vue/components/table/index.jsx

81 lines
2.3 KiB
React
Raw Normal View History

2018-04-01 04:52:27 +00:00
import T from './Table'
2018-03-29 14:08:04 +00:00
2018-04-01 04:52:27 +00:00
import { getOptionProps, getKey, getClass,
getStyle, getEvents, getSlotOptions, camelize, getSlots,
} from '../_util/props-util'
const Table = {
name: 'Table',
Column: T.Column,
ColumnGroup: T.ColumnGroup,
props: T.props,
methods: {
normalize (elements = []) {
const columns = []
elements.forEach(element => {
if (!element.tag) {
return
}
const key = getKey(element)
const style = getStyle(element)
const cls = getClass(element)
const props = getOptionProps(element)
const events = getEvents(element)
const listeners = {}
Object.keys(events).forEach(e => {
const k = `on_${e}`
listeners[camelize(k)] = events[e]
})
const { default: children, title } = getSlots(element)
const column = { title, ...props, style, class: cls, ...listeners }
if (key) {
column.key = key
}
if (getSlotOptions(element).__ANT_TABLE_COLUMN_GROUP) {
column.children = this.normalize(children)
} else {
const customRender = element.data && element.data.scopedSlots && element.data.scopedSlots.default
column.customRender = column.customRender || customRender
}
columns.push(column)
})
return columns
},
updateColumns (cols = []) {
const columns = []
const { $slots, $scopedSlots } = this
cols.forEach(col => {
const { slotTitle, slotScopeName, ...restProps } = col
const column = {
...restProps,
title: col.title || $slots[slotTitle],
}
if (slotScopeName && $scopedSlots[slotScopeName]) {
column.customRender = column.customRender || $scopedSlots[slotScopeName]
}
if (col.children) {
column.children = this.updateColumns(column.children)
}
columns.push(column)
})
return columns
},
},
render () {
const { $listeners, $slots, normalize } = this
const props = getOptionProps(this)
const columns = props.columns ? this.updateColumns(props.columns) : normalize($slots.default)
const tProps = {
props: {
...props,
columns,
},
on: $listeners,
}
return (
<T {...tProps}/>
)
},
}
2018-03-29 14:08:04 +00:00
export default Table