-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.jsx
103 lines (100 loc) · 3 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import T from './Table'
import { getOptionProps, getKey, getClass,
getStyle, getEvents, getSlotOptions, camelize, getSlots,
} from '../_util/props-util'
const Table = {
name: 'ATable',
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, ...restSlots } = getSlots(element)
const column = { ...restSlots, ...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 { slots = {}, scopedSlots = {}, ...restProps } = col
const column = {
...restProps,
}
Object.keys(slots).forEach(key => {
const name = slots[key]
if (column[key] === undefined && $slots[name]) {
column[key] = $slots[name]
}
})
Object.keys(scopedSlots).forEach(key => {
const name = scopedSlots[key]
if (column[key] === undefined && $scopedSlots[name]) {
column[key] = $scopedSlots[name]
}
})
// 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, $scopedSlots } = this
const props = getOptionProps(this)
const columns = props.columns ? this.updateColumns(props.columns) : normalize($slots.default)
let { title, footer } = props
const {
title: slotTitle,
footer: slotFooter,
expandedRowRender = props.expandedRowRender,
} = $scopedSlots
title = title || slotTitle
footer = footer || slotFooter
const tProps = {
props: {
...props,
columns,
title,
footer,
expandedRowRender,
},
on: $listeners,
}
return (
<T {...tProps}/>
)
},
}
export default Table