ant-design-vue/components/vc-table/index.js

64 lines
1.7 KiB
JavaScript
Raw Normal View History

2018-03-29 10:18:41 +00:00
import T from './src/Table'
2018-03-24 14:02:24 +00:00
import Column from './src/Column'
import ColumnGroup from './src/ColumnGroup'
2018-03-29 10:18:41 +00:00
import { getOptionProps, getKey, getClass,
getStyle, getEvents, getSlotOptions, camelize, getSlots,
} from '../_util/props-util'
const Table = {
name: 'Table',
Column,
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).isTableColumnGroup) {
column.children = this.normalize(children)
} else {
2018-04-01 04:52:27 +00:00
const customRender = element.data && element.data.scopedSlots && element.data.scopedSlots.default
column.customRender = column.customRender || customRender
2018-03-29 10:18:41 +00:00
}
columns.push(column)
})
return columns
},
},
render () {
const { $listeners, $slots, normalize } = this
const props = getOptionProps(this)
const columns = props.columns || normalize($slots.default)
const tProps = {
props: {
...props,
columns,
},
on: $listeners,
}
return (
<T {...tProps}/>
)
},
}
2018-03-24 14:02:24 +00:00
export default Table
export { Column, ColumnGroup }