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
104
105
106
107
108
109
110
111
112
113
| import PropTypes from 'ant-design-vue/es/_util/vue-types'
| import Option from './TagSelectOption.jsx'
| import { filterEmpty } from '@/components/_util/util'
|
| export default {
| Option,
| name: 'TagSelect',
| model: {
| prop: 'checked',
| event: 'change'
| },
| props: {
| prefixCls: {
| type: String,
| default: 'ant-pro-tag-select'
| },
| defaultValue: {
| type: PropTypes.array,
| default: null
| },
| value: {
| type: PropTypes.array,
| default: null
| },
| expandable: {
| type: Boolean,
| default: false
| },
| hideCheckAll: {
| type: Boolean,
| default: false
| }
| },
| data () {
| return {
| expand: false,
| localCheckAll: false,
| items: this.getItemsKey(filterEmpty(this.$slots.default)),
| val: this.value || this.defaultValue || []
| }
| },
| methods: {
| onChange (checked) {
| const key = Object.keys(this.items).filter(key => key === checked.value)
| this.items[key] = checked.checked
| const bool = Object.values(this.items).lastIndexOf(false)
| if (bool === -1) {
| this.localCheckAll = true
| } else {
| this.localCheckAll = false
| }
| },
| onCheckAll (checked) {
| Object.keys(this.items).forEach(v => {
| this.items[v] = checked.checked
| })
| this.localCheckAll = checked.checked
| },
| getItemsKey (items) {
| const totalItem = {}
| items.forEach(item => {
| totalItem[item.componentOptions.propsData && item.componentOptions.propsData.value] = false
| })
| return totalItem
| },
| // CheckAll Button
| renderCheckAll () {
| const props = {
| on: {
| change: (checked) => {
| this.onCheckAll(checked)
| checked.value = 'total'
| this.$emit('change', checked)
| }
| }
| }
| const checkAllElement = <Option key={'total'} checked={this.localCheckAll} {...props}>All</Option>
| return !this.hideCheckAll && checkAllElement || null
| },
| // expandable
| renderExpandable () {
|
| },
| // render option
| renderTags (items) {
| const listeners = {
| change: (checked) => {
| this.onChange(checked)
| this.$emit('change', checked)
| }
| }
|
| return items.map(vnode => {
| const options = vnode.componentOptions
| options.listeners = listeners
| return vnode
| })
| }
| },
| render () {
| const { $props: { prefixCls } } = this
| const classString = {
| [`${prefixCls}`]: true
| }
| const tagItems = filterEmpty(this.$slots.default)
| return (
| <div class={classString}>
| {this.renderCheckAll()}
| {this.renderTags(tagItems)}
| </div>
| )
| }
| }
|
|