77f7bb95
梁灏
add Transfer comp...
|
1
2
3
|
<script>
import List from './list.vue';
import Operation from './operation.vue';
|
e5337c81
梁灏
fixed some compon...
|
4
|
import Locale from '../../mixins/locale';
|
cd78c9c4
梁灏
some comps suppor...
|
5
|
import Emitter from '../../mixins/emitter';
|
77f7bb95
梁灏
add Transfer comp...
|
6
7
8
9
|
const prefixCls = 'ivu-transfer';
export default {
|
e5337c81
梁灏
fixed some compon...
|
10
|
mixins: [ Emitter, Locale ],
|
16a87cde
jingsam
fix transfer
|
11
12
13
|
render (createElement) {
function cloneVNode (vnode) {
|
92a0f30c
jingsam
fixup
|
14
|
const clonedChildren = vnode.children && vnode.children.map(vnode => cloneVNode(vnode));
|
16a87cde
jingsam
fix transfer
|
15
16
17
18
19
20
21
22
23
24
25
26
27
|
const cloned = createElement(vnode.tag, vnode.data, clonedChildren);
cloned.text = vnode.text;
cloned.isComment = vnode.isComment;
cloned.componentOptions = vnode.componentOptions;
cloned.elm = vnode.elm;
cloned.context = vnode.context;
cloned.ns = vnode.ns;
cloned.isStatic = vnode.isStatic;
cloned.key = vnode.key;
return cloned;
}
|
84a8a413
梁灏
fixed bug of Tran...
|
28
29
|
const vNodes = this.$slots.default === undefined ? [] : this.$slots.default;
const clonedVNodes = this.$slots.default === undefined ? [] : vNodes.map(vnode => cloneVNode(vnode));
|
16a87cde
jingsam
fix transfer
|
30
31
32
33
34
35
36
37
38
39
40
41
42
|
return createElement('div', {
'class': this.classes
}, [
createElement('List', {
ref: 'left',
props: {
prefixCls: this.prefixCls + '-list',
data: this.leftData,
renderFormat: this.renderFormat,
checkedKeys: this.leftCheckedKeys,
validKeysCount: this.leftValidKeysCount,
style: this.listStyle,
|
e5337c81
梁灏
fixed some compon...
|
43
|
title: this.localeTitles[0],
|
16a87cde
jingsam
fix transfer
|
44
|
filterable: this.filterable,
|
e5337c81
梁灏
fixed some compon...
|
45
|
filterPlaceholder: this.localeFilterPlaceholder,
|
16a87cde
jingsam
fix transfer
|
46
|
filterMethod: this.filterMethod,
|
e5337c81
梁灏
fixed some compon...
|
47
|
notFoundText: this.localeNotFoundText
|
16a87cde
jingsam
fix transfer
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
},
on: {
'on-checked-keys-change': this.handleLeftCheckedKeysChange
}
}, vNodes),
createElement('Operation', {
props: {
prefixCls: this.prefixCls,
operations: this.operations,
leftActive: this.leftValidKeysCount > 0,
rightActive: this.rightValidKeysCount > 0
}
}),
createElement('List', {
ref: 'right',
props: {
prefixCls: this.prefixCls + '-list',
data: this.rightData,
renderFormat: this.renderFormat,
checkedKeys: this.rightCheckedKeys,
validKeysCount: this.rightValidKeysCount,
style: this.listStyle,
|
e5337c81
梁灏
fixed some compon...
|
72
|
title: this.localeTitles[1],
|
16a87cde
jingsam
fix transfer
|
73
|
filterable: this.filterable,
|
e5337c81
梁灏
fixed some compon...
|
74
|
filterPlaceholder: this.localeFilterPlaceholder,
|
16a87cde
jingsam
fix transfer
|
75
|
filterMethod: this.filterMethod,
|
e5337c81
梁灏
fixed some compon...
|
76
|
notFoundText: this.localeNotFoundText
|
16a87cde
jingsam
fix transfer
|
77
78
79
80
|
},
on: {
'on-checked-keys-change': this.handleRightCheckedKeysChange
}
|
aa9fc758
梁灏
update Transfer
|
81
|
}, clonedVNodes)
|
16a87cde
jingsam
fix transfer
|
82
83
84
|
]);
},
|
77f7bb95
梁灏
add Transfer comp...
|
85
86
87
88
89
|
components: { List, Operation },
props: {
data: {
type: Array,
default () {
|
b0893113
jingsam
add eslint
|
90
|
return [];
|
77f7bb95
梁灏
add Transfer comp...
|
91
92
93
94
95
96
97
98
99
100
101
|
}
},
renderFormat: {
type: Function,
default (item) {
return item.label || item.key;
}
},
targetKeys: {
type: Array,
default () {
|
b0893113
jingsam
add eslint
|
102
|
return [];
|
77f7bb95
梁灏
add Transfer comp...
|
103
104
105
106
107
|
}
},
selectedKeys: {
type: Array,
default () {
|
b0893113
jingsam
add eslint
|
108
|
return [];
|
77f7bb95
梁灏
add Transfer comp...
|
109
110
111
112
113
|
}
},
listStyle: {
type: Object,
default () {
|
b0893113
jingsam
add eslint
|
114
|
return {};
|
77f7bb95
梁灏
add Transfer comp...
|
115
116
117
|
}
},
titles: {
|
e5337c81
梁灏
fixed some compon...
|
118
|
type: Array
|
77f7bb95
梁灏
add Transfer comp...
|
119
120
121
122
|
},
operations: {
type: Array,
default () {
|
b0893113
jingsam
add eslint
|
123
|
return [];
|
77f7bb95
梁灏
add Transfer comp...
|
124
125
126
127
128
129
130
|
}
},
filterable: {
type: Boolean,
default: false
},
filterPlaceholder: {
|
e5337c81
梁灏
fixed some compon...
|
131
|
type: String
|
77f7bb95
梁灏
add Transfer comp...
|
132
133
134
135
136
137
138
139
140
|
},
filterMethod: {
type: Function,
default (data, query) {
const type = ('label' in data) ? 'label' : 'key';
return data[type].indexOf(query) > -1;
}
},
notFoundText: {
|
e5337c81
梁灏
fixed some compon...
|
141
|
type: String
|
77f7bb95
梁灏
add Transfer comp...
|
142
143
144
145
146
147
148
149
150
|
}
},
data () {
return {
prefixCls: prefixCls,
leftData: [],
rightData: [],
leftCheckedKeys: [],
rightCheckedKeys: []
|
b0893113
jingsam
add eslint
|
151
|
};
|
77f7bb95
梁灏
add Transfer comp...
|
152
153
154
155
156
|
},
computed: {
classes () {
return [
`${prefixCls}`
|
b0893113
jingsam
add eslint
|
157
|
];
|
77f7bb95
梁灏
add Transfer comp...
|
158
159
160
161
162
163
|
},
leftValidKeysCount () {
return this.getValidKeys('left').length;
},
rightValidKeysCount () {
return this.getValidKeys('right').length;
|
e5337c81
梁灏
fixed some compon...
|
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
|
},
localeFilterPlaceholder () {
if (this.filterPlaceholder === undefined) {
return this.t('i.transfer.filterPlaceholder');
} else {
return this.filterPlaceholder;
}
},
localeNotFoundText () {
if (this.notFoundText === undefined) {
return this.t('i.transfer.notFoundText');
} else {
return this.notFoundText;
}
},
localeTitles () {
if (this.titles === undefined) {
return [this.t('i.transfer.titles.source'), this.t('i.transfer.titles.target')];
} else {
return this.titles;
}
|
77f7bb95
梁灏
add Transfer comp...
|
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
}
},
methods: {
getValidKeys (direction) {
return this[`${direction}Data`].filter(data => !data.disabled && this[`${direction}CheckedKeys`].indexOf(data.key) > -1).map(data => data.key);
},
splitData (init = false) {
this.leftData = [...this.data];
this.rightData = [];
if (this.targetKeys.length > 0) {
this.targetKeys.forEach((targetKey) => {
this.rightData.push(
this.leftData.filter((data, index) => {
if (data.key === targetKey) {
this.leftData.splice(index, 1);
return true;
}
return false;
})[0]);
});
}
if (init) {
this.splitSelectedKey();
}
},
splitSelectedKey () {
const selectedKeys = this.selectedKeys;
if (selectedKeys.length > 0) {
this.leftCheckedKeys = this.leftData
.filter(data => selectedKeys.indexOf(data.key) > -1)
.map(data => data.key);
this.rightCheckedKeys = this.rightData
.filter(data => selectedKeys.indexOf(data.key) > -1)
.map(data => data.key);
}
},
moveTo (direction) {
const targetKeys = this.targetKeys;
const opposite = direction === 'left' ? 'right' : 'left';
const moveKeys = this.getValidKeys(opposite);
const newTargetKeys = direction === 'right' ?
moveKeys.concat(targetKeys) :
targetKeys.filter(targetKey => !moveKeys.some(checkedKey => targetKey === checkedKey));
this.$refs[opposite].toggleSelectAll(false);
this.$emit('on-change', newTargetKeys, direction, moveKeys);
|
cd78c9c4
梁灏
some comps suppor...
|
231
232
233
234
235
|
this.dispatch('FormItem', 'on-form-change', {
tarketKeys: newTargetKeys,
direction: direction,
moveKeys: moveKeys
});
|
5b19b5f5
梁灏
support Transfer
|
236
237
238
239
240
241
|
},
handleLeftCheckedKeysChange (keys) {
this.leftCheckedKeys = keys;
},
handleRightCheckedKeysChange (keys) {
this.rightCheckedKeys = keys;
|
77f7bb95
梁灏
add Transfer comp...
|
242
243
244
245
246
247
248
249
250
251
|
}
},
watch: {
targetKeys () {
this.splitData(false);
}
},
created () {
this.splitData(true);
}
|
b0893113
jingsam
add eslint
|
252
253
|
};
</script>
|