e355dd49
梁灏
add Select Component
|
1
|
<template>
|
2fbe636b
梁灏
Select support a ...
|
2
3
4
5
6
|
<div
tabindex="0"
@keydown.down="handleFocus"
:class="classes"
v-clickoutside="handleClose">
|
e355dd49
梁灏
add Select Component
|
7
|
<div
|
fed3e09d
梁灏
add AutoComplete ...
|
8
|
:class="selectionCls"
|
4aec6a66
梁灏
support Select
|
9
|
ref="reference"
|
e355dd49
梁灏
add Select Component
|
10
|
@click="toggleMenu">
|
fed3e09d
梁灏
add AutoComplete ...
|
11
|
<slot name="input">
|
0460a1e8
梁灏
fixed #812
|
12
|
<input type="hidden" :name="name" :value="model">
|
51939f89
梁灏
update Select tag
|
13
|
<div class="ivu-tag ivu-tag-checked" v-for="(item, index) in selectedMultiple">
|
fed3e09d
梁灏
add AutoComplete ...
|
14
15
16
17
18
19
|
<span class="ivu-tag-text">{{ item.label }}</span>
<Icon type="ios-close-empty" @click.native.stop="removeTag(index)"></Icon>
</div>
<span :class="[prefixCls + '-placeholder']" v-show="showPlaceholder && !filterable">{{ localePlaceholder }}</span>
<span :class="[prefixCls + '-selected-value']" v-show="!showPlaceholder && !multiple && !filterable">{{ selectedSingle }}</span>
<input
|
acb79ba3
梁灏
fixed #433
|
20
|
:id="elementId"
|
fed3e09d
梁灏
add AutoComplete ...
|
21
22
23
24
25
26
27
|
type="text"
v-if="filterable"
v-model="query"
:disabled="disabled"
:class="[prefixCls + '-input']"
:placeholder="showPlaceholder ? localePlaceholder : ''"
:style="inputStyle"
|
c17c5ad6
Sergio Crisostomo
normalize autocom...
|
28
29
|
autocomplete="off"
spellcheck="false"
|
fed3e09d
梁灏
add AutoComplete ...
|
30
31
32
33
34
35
36
|
@blur="handleBlur"
@keydown="resetInputState"
@keydown.delete="handleInputDelete"
ref="input">
<Icon type="ios-close" :class="[prefixCls + '-arrow']" v-show="showCloseIcon" @click.native.stop="clearSingleSelect"></Icon>
<Icon type="arrow-down-b" :class="[prefixCls + '-arrow']" v-if="!remote"></Icon>
</slot>
|
e355dd49
梁灏
add Select Component
|
37
|
</div>
|
f89dd9c2
梁灏
Paeg、Select add p...
|
38
|
<transition :name="transitionName">
|
595cfa72
梁灏
fixed #1187 #844 ...
|
39
|
<Drop
|
ecaf8d51
梁灏
Date add transfer...
|
40
|
:class="dropdownCls"
|
595cfa72
梁灏
fixed #1187 #844 ...
|
41
42
43
44
45
|
v-show="dropVisible"
:placement="placement"
ref="dropdown"
:data-transfer="transfer"
v-transfer-dom>
|
fed3e09d
梁灏
add AutoComplete ...
|
46
|
<ul v-show="notFoundShow" :class="[prefixCls + '-not-found']"><li>{{ localeNotFoundText }}</li></ul>
|
0b916a32
梁灏
update Select
|
47
|
<ul v-show="(!notFound && !remote) || (remote && !loading && !notFound)" :class="[prefixCls + '-dropdown-list']"><slot></slot></ul>
|
01b54e30
梁灏
Select support re...
|
48
|
<ul v-show="loading" :class="[prefixCls + '-loading']">{{ localeLoadingText }}</ul>
|
4aec6a66
梁灏
support Select
|
49
50
|
</Drop>
</transition>
|
e355dd49
梁灏
add Select Component
|
51
52
53
54
|
</div>
</template>
<script>
import Icon from '../icon';
|
4aec6a66
梁灏
support Select
|
55
|
import Drop from './dropdown.vue';
|
e355dd49
梁灏
add Select Component
|
56
|
import clickoutside from '../../directives/clickoutside';
|
595cfa72
梁灏
fixed #1187 #844 ...
|
57
|
import TransferDom from '../../directives/transfer-dom';
|
ed91d9b0
梁灏
update Select
|
58
|
import { oneOf, findComponentDownward } from '../../utils/assist';
|
4aec6a66
梁灏
support Select
|
59
|
import Emitter from '../../mixins/emitter';
|
e5337c81
梁灏
fixed some compon...
|
60
|
import Locale from '../../mixins/locale';
|
4b338397
梁灏
update Select exa...
|
61
|
import { debounce } from './utils';
|
e355dd49
梁灏
add Select Component
|
62
63
64
65
|
const prefixCls = 'ivu-select';
export default {
|
8f5b1686
梁灏
fixed #196
|
66
|
name: 'iSelect',
|
e5337c81
梁灏
fixed some compon...
|
67
|
mixins: [ Emitter, Locale ],
|
4aec6a66
梁灏
support Select
|
68
|
components: { Icon, Drop },
|
595cfa72
梁灏
fixed #1187 #844 ...
|
69
|
directives: { clickoutside, TransferDom },
|
e355dd49
梁灏
add Select Component
|
70
|
props: {
|
4aec6a66
梁灏
support Select
|
71
|
value: {
|
e355dd49
梁灏
add Select Component
|
72
73
74
|
type: [String, Number, Array],
default: ''
},
|
98bf25b3
梁灏
fixed #1286
|
75
|
// 使用时,也得设置 value 才行
|
ddc35c9a
梁灏
fixed #952
|
76
77
78
79
|
label: {
type: [String, Number, Array],
default: ''
},
|
e355dd49
梁灏
add Select Component
|
80
81
82
83
84
85
86
87
88
89
90
91
92
|
multiple: {
type: Boolean,
default: false
},
disabled: {
type: Boolean,
default: false
},
clearable: {
type: Boolean,
default: false
},
placeholder: {
|
e5337c81
梁灏
fixed some compon...
|
93
|
type: String
|
e355dd49
梁灏
add Select Component
|
94
95
96
97
98
99
100
101
|
},
filterable: {
type: Boolean,
default: false
},
filterMethod: {
type: Function
},
|
01b54e30
梁灏
Select support re...
|
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
remote: {
type: Boolean,
default: false
},
remoteMethod: {
type: Function
},
loading: {
type: Boolean,
default: false
},
loadingText: {
type: String
},
|
e355dd49
梁灏
add Select Component
|
116
117
|
size: {
validator (value) {
|
6932b4d7
梁灏
update Page compo...
|
118
|
return oneOf(value, ['small', 'large', 'default']);
|
e355dd49
梁灏
add Select Component
|
119
120
121
122
123
|
}
},
labelInValue: {
type: Boolean,
default: false
|
294e2412
梁灏
update Select com...
|
124
125
|
},
notFoundText: {
|
e5337c81
梁灏
fixed some compon...
|
126
|
type: String
|
f89dd9c2
梁灏
Paeg、Select add p...
|
127
128
129
130
131
132
|
},
placement: {
validator (value) {
return oneOf(value, ['top', 'bottom']);
},
default: 'bottom'
|
595cfa72
梁灏
fixed #1187 #844 ...
|
133
134
135
136
|
},
transfer: {
type: Boolean,
default: false
|
fed3e09d
梁灏
add AutoComplete ...
|
137
138
139
140
141
|
},
// Use for AutoComplete
autoComplete: {
type: Boolean,
default: false
|
0460a1e8
梁灏
fixed #812
|
142
143
144
|
},
name: {
type: String
|
acb79ba3
梁灏
fixed #433
|
145
146
147
|
},
elementId: {
type: String
|
e355dd49
梁灏
add Select Component
|
148
149
150
151
152
153
154
155
156
157
158
159
|
}
},
data () {
return {
prefixCls: prefixCls,
visible: false,
options: [],
optionInstances: [],
selectedSingle: '', // label
selectedMultiple: [],
focusIndex: 0,
query: '',
|
c70ff0f2
梁灏
fixed #915
|
160
|
lastQuery: '',
|
01b54e30
梁灏
Select support re...
|
161
|
selectToChangeQuery: false, // when select an option, set this first and set query, because query is watching, it will emit event
|
e4ce9917
梁灏
update Select com...
|
162
|
inputLength: 20,
|
3e855e34
梁灏
fixed #46
|
163
|
notFound: false,
|
4aec6a66
梁灏
support Select
|
164
|
slotChangeDuration: false, // if slot change duration and in multiple, set true and after slot change, set false
|
e9932043
Aresn
fixed #978
|
165
166
|
model: this.value,
currentLabel: this.label
|
b0893113
jingsam
add eslint
|
167
|
};
|
e355dd49
梁灏
add Select Component
|
168
169
170
171
|
},
computed: {
classes () {
return [
|
4b7138b9
梁灏
fixed some bugs
|
172
|
`${prefixCls}`,
|
e355dd49
梁灏
add Select Component
|
173
|
{
|
4b7138b9
梁灏
fixed some bugs
|
174
175
176
177
178
179
|
[`${prefixCls}-visible`]: this.visible,
[`${prefixCls}-disabled`]: this.disabled,
[`${prefixCls}-multiple`]: this.multiple,
[`${prefixCls}-single`]: !this.multiple,
[`${prefixCls}-show-clear`]: this.showCloseIcon,
[`${prefixCls}-${this.size}`]: !!this.size
|
e355dd49
梁灏
add Select Component
|
180
|
}
|
b0893113
jingsam
add eslint
|
181
|
];
|
e355dd49
梁灏
add Select Component
|
182
|
},
|
ecaf8d51
梁灏
Date add transfer...
|
183
184
185
|
dropdownCls () {
return {
[prefixCls + '-dropdown-transfer']: this.transfer,
|
fed3e09d
梁灏
add AutoComplete ...
|
186
187
188
189
190
191
192
|
[prefixCls + '-multiple']: this.multiple && this.transfer,
['ivu-auto-complete']: this.autoComplete,
};
},
selectionCls () {
return {
[`${prefixCls}-selection`]: !this.autoComplete
|
ecaf8d51
梁灏
Date add transfer...
|
193
194
|
};
},
|
e355dd49
梁灏
add Select Component
|
195
196
197
198
199
200
201
202
203
204
205
|
showPlaceholder () {
let status = false;
if ((typeof this.model) === 'string') {
if (this.model === '') {
status = true;
}
} else if (Array.isArray(this.model)) {
if (!this.model.length) {
status = true;
}
|
92214573
WJD
Update Select.vue
|
206
207
|
} else if( this.model === null){
status = true;
|
e355dd49
梁灏
add Select Component
|
208
209
210
211
212
213
214
215
216
217
218
|
}
return status;
},
showCloseIcon () {
return !this.multiple && this.clearable && !this.showPlaceholder;
},
inputStyle () {
let style = {};
if (this.multiple) {
|
e4ce9917
梁灏
update Select com...
|
219
220
221
|
if (this.showPlaceholder) {
style.width = '100%';
} else {
|
4b7138b9
梁灏
fixed some bugs
|
222
|
style.width = `${this.inputLength}px`;
|
e4ce9917
梁灏
update Select com...
|
223
|
}
|
e355dd49
梁灏
add Select Component
|
224
225
226
|
}
return style;
|
e5337c81
梁灏
fixed some compon...
|
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
},
localePlaceholder () {
if (this.placeholder === undefined) {
return this.t('i.select.placeholder');
} else {
return this.placeholder;
}
},
localeNotFoundText () {
if (this.notFoundText === undefined) {
return this.t('i.select.noMatch');
} else {
return this.notFoundText;
}
|
f89dd9c2
梁灏
Paeg、Select add p...
|
241
|
},
|
01b54e30
梁灏
Select support re...
|
242
243
244
245
246
247
248
|
localeLoadingText () {
if (this.loadingText === undefined) {
return this.t('i.select.loading');
} else {
return this.loadingText;
}
},
|
f89dd9c2
梁灏
Paeg、Select add p...
|
249
250
|
transitionName () {
return this.placement === 'bottom' ? 'slide-up' : 'slide-down';
|
ec98f3c3
梁灏
update Select
|
251
252
253
|
},
dropVisible () {
let status = true;
|
13a940ee
梁灏
update Select
|
254
255
|
const options = this.$slots.default || [];
if (!this.loading && this.remote && this.query === '' && !options.length) status = false;
|
fed3e09d
梁灏
add AutoComplete ...
|
256
257
258
|
if (this.autoComplete && !options.length) status = false;
|
ec98f3c3
梁灏
update Select
|
259
|
return this.visible && status;
|
29264399
梁灏
update Select
|
260
|
},
|
fed3e09d
梁灏
add AutoComplete ...
|
261
|
notFoundShow () {
|
29264399
梁灏
update Select
|
262
263
|
const options = this.$slots.default || [];
return (this.notFound && !this.remote) || (this.remote && !this.loading && !options.length);
|
e355dd49
梁灏
add Select Component
|
264
265
266
|
}
},
methods: {
|
2fbe636b
梁灏
Select support a ...
|
267
268
269
270
|
// open when focus on Select and press `down` key
handleFocus () {
if (!this.visible) this.toggleMenu();
},
|
e355dd49
梁灏
add Select Component
|
271
|
toggleMenu () {
|
fed3e09d
梁灏
add AutoComplete ...
|
272
|
if (this.disabled || this.autoComplete) {
|
e355dd49
梁灏
add Select Component
|
273
274
|
return false;
}
|
e355dd49
梁灏
add Select Component
|
275
276
277
278
279
|
this.visible = !this.visible;
},
hideMenu () {
this.visible = false;
this.focusIndex = 0;
|
4aec6a66
梁灏
support Select
|
280
|
this.broadcast('iOption', 'on-select-close');
|
e355dd49
梁灏
add Select Component
|
281
282
283
|
},
// find option component
findChild (cb) {
|
e355dd49
梁灏
add Select Component
|
284
285
286
287
288
289
|
const find = function (child) {
const name = child.$options.componentName;
if (name) {
cb(child);
} else if (child.$children.length) {
|
7dcfe45d
梁灏
update Select
|
290
291
|
child.$children.forEach((innerChild) => {
find(innerChild, cb);
|
ec98f3c3
梁灏
update Select
|
292
|
});
|
e355dd49
梁灏
add Select Component
|
293
294
295
296
297
298
|
}
};
if (this.optionInstances.length) {
this.optionInstances.forEach((child) => {
find(child);
|
b0893113
jingsam
add eslint
|
299
|
});
|
e355dd49
梁灏
add Select Component
|
300
301
302
303
304
305
|
} else {
this.$children.forEach((child) => {
find(child);
});
}
},
|
89828b5b
梁灏
update Select
|
306
|
updateOptions (slot = false) {
|
e355dd49
梁灏
add Select Component
|
307
308
309
310
311
312
|
let options = [];
let index = 1;
this.findChild((child) => {
options.push({
value: child.value,
|
a9e0f79d
Sergio Crisostomo
Use textContent t...
|
313
|
label: (child.label === undefined) ? child.$el.textContent : child.label
|
e355dd49
梁灏
add Select Component
|
314
315
316
|
});
child.index = index++;
|
89828b5b
梁灏
update Select
|
317
|
this.optionInstances.push(child);
|
e355dd49
梁灏
add Select Component
|
318
319
320
321
|
});
this.options = options;
|
89828b5b
梁灏
update Select
|
322
323
324
|
if (!this.remote) {
this.updateSingleSelected(true, slot);
this.updateMultipleSelected(true, slot);
|
e355dd49
梁灏
add Select Component
|
325
326
|
}
},
|
3e855e34
梁灏
fixed #46
|
327
|
updateSingleSelected (init = false, slot = false) {
|
e355dd49
梁灏
add Select Component
|
328
329
330
|
const type = typeof this.model;
if (type === 'string' || type === 'number') {
|
3e855e34
梁灏
fixed #46
|
331
332
|
let findModel = false;
|
e355dd49
梁灏
add Select Component
|
333
334
335
|
for (let i = 0; i < this.options.length; i++) {
if (this.model === this.options[i].value) {
this.selectedSingle = this.options[i].label;
|
3e855e34
梁灏
fixed #46
|
336
|
findModel = true;
|
e355dd49
梁灏
add Select Component
|
337
338
339
|
break;
}
}
|
3e855e34
梁灏
fixed #46
|
340
341
342
343
344
|
if (slot && !findModel) {
this.model = '';
this.query = '';
}
|
e355dd49
梁灏
add Select Component
|
345
346
347
348
349
350
351
352
353
354
|
}
this.toggleSingleSelected(this.model, init);
},
clearSingleSelect () {
if (this.showCloseIcon) {
this.findChild((child) => {
child.selected = false;
});
this.model = '';
|
e4ebd304
梁灏
update Select com...
|
355
356
357
358
|
if (this.filterable) {
this.query = '';
}
|
e355dd49
梁灏
add Select Component
|
359
360
|
}
},
|
3e855e34
梁灏
fixed #46
|
361
|
updateMultipleSelected (init = false, slot = false) {
|
e355dd49
梁灏
add Select Component
|
362
|
if (this.multiple && Array.isArray(this.model)) {
|
d87ce40a
梁灏
update Select
|
363
|
let selected = this.remote ? this.selectedMultiple : [];
|
e355dd49
梁灏
add Select Component
|
364
365
366
367
368
369
370
371
372
373
374
|
for (let i = 0; i < this.model.length; i++) {
const model = this.model[i];
for (let j = 0; j < this.options.length; j++) {
const option = this.options[j];
if (model === option.value) {
selected.push({
value: option.value,
label: option.label
|
b0893113
jingsam
add eslint
|
375
|
});
|
e355dd49
梁灏
add Select Component
|
376
377
378
379
|
}
}
}
|
d87ce40a
梁灏
update Select
|
380
381
|
const selectedArray = [];
const selectedObject = {};
|
45103ca4
梁灏
fixed #2066
|
382
|
|
d87ce40a
梁灏
update Select
|
383
384
385
386
387
388
389
|
selected.forEach(item => {
if (!selectedObject[item.value]) {
selectedArray.push(item);
selectedObject[item.value] = 1;
}
});
|
45103ca4
梁灏
fixed #2066
|
390
391
|
// #2066
this.selectedMultiple = this.remote ? this.model.length ? selectedArray : [] : selected;
|
e355dd49
梁灏
add Select Component
|
392
|
|
3e855e34
梁灏
fixed #46
|
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
|
if (slot) {
let selectedModel = [];
for (let i = 0; i < selected.length; i++) {
selectedModel.push(selected[i].value);
}
// if slot change and remove a selected option, emit user
if (this.model.length === selectedModel.length) {
this.slotChangeDuration = true;
}
this.model = selectedModel;
}
}
|
e355dd49
梁灏
add Select Component
|
408
409
410
411
412
413
|
this.toggleMultipleSelected(this.model, init);
},
removeTag (index) {
if (this.disabled) {
return false;
}
|
d87ce40a
梁灏
update Select
|
414
415
416
417
418
419
|
if (this.remote) {
const tag = this.model[index];
this.selectedMultiple = this.selectedMultiple.filter(item => item.value !== tag);
}
|
e355dd49
梁灏
add Select Component
|
420
|
this.model.splice(index, 1);
|
e4ce9917
梁灏
update Select com...
|
421
422
|
if (this.filterable && this.visible) {
|
4aec6a66
梁灏
support Select
|
423
|
this.$refs.input.focus();
|
e4ce9917
梁灏
update Select com...
|
424
425
|
}
|
4aec6a66
梁灏
support Select
|
426
|
this.broadcast('Drop', 'on-update-popper');
|
e355dd49
梁灏
add Select Component
|
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
|
},
// to select option for single
toggleSingleSelected (value, init = false) {
if (!this.multiple) {
let label = '';
this.findChild((child) => {
if (child.value === value) {
child.selected = true;
label = (child.label === undefined) ? child.$el.innerHTML : child.label;
} else {
child.selected = false;
}
});
this.hideMenu();
if (!init) {
if (this.labelInValue) {
this.$emit('on-change', {
value: value,
label: label
});
|
cd78c9c4
梁灏
some comps suppor...
|
450
451
452
453
|
this.dispatch('FormItem', 'on-form-change', {
value: value,
label: label
});
|
e355dd49
梁灏
add Select Component
|
454
455
|
} else {
this.$emit('on-change', value);
|
cd78c9c4
梁灏
some comps suppor...
|
456
|
this.dispatch('FormItem', 'on-form-change', value);
|
e355dd49
梁灏
add Select Component
|
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
|
}
}
}
},
// to select option for multiple
toggleMultipleSelected (value, init = false) {
if (this.multiple) {
let hybridValue = [];
for (let i = 0; i < value.length; i++) {
hybridValue.push({
value: value[i]
});
}
this.findChild((child) => {
const index = value.indexOf(child.value);
if (index >= 0) {
child.selected = true;
hybridValue[index].label = (child.label === undefined) ? child.$el.innerHTML : child.label;
} else {
child.selected = false;
}
});
if (!init) {
if (this.labelInValue) {
this.$emit('on-change', hybridValue);
|
cd78c9c4
梁灏
some comps suppor...
|
485
486
|
this.dispatch('FormItem', 'on-form-change', hybridValue);
} else {
|
e355dd49
梁灏
add Select Component
|
487
|
this.$emit('on-change', value);
|
cd78c9c4
梁灏
some comps suppor...
|
488
|
this.dispatch('FormItem', 'on-form-change', value);
|
e355dd49
梁灏
add Select Component
|
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
|
}
}
}
},
handleClose () {
this.hideMenu();
},
handleKeydown (e) {
if (this.visible) {
const keyCode = e.keyCode;
// Esc slide-up
if (keyCode === 27) {
e.preventDefault();
this.hideMenu();
}
// next
if (keyCode === 40) {
e.preventDefault();
this.navigateOptions('next');
}
// prev
if (keyCode === 38) {
e.preventDefault();
this.navigateOptions('prev');
}
// enter
if (keyCode === 13) {
e.preventDefault();
this.findChild((child) => {
if (child.isFocus) {
child.select();
}
});
}
}
},
navigateOptions (direction) {
if (direction === 'next') {
const next = this.focusIndex + 1;
this.focusIndex = (this.focusIndex === this.options.length) ? 1 : next;
} else if (direction === 'prev') {
const prev = this.focusIndex - 1;
this.focusIndex = (this.focusIndex <= 1) ? this.options.length : prev;
}
let child_status = {
|
e4ebd304
梁灏
update Select com...
|
536
537
|
disabled: false,
hidden: false
|
e355dd49
梁灏
add Select Component
|
538
539
|
};
|
e4ebd304
梁灏
update Select com...
|
540
541
|
let find_deep = false; // can next find allowed
|
e355dd49
梁灏
add Select Component
|
542
543
544
|
this.findChild((child) => {
if (child.index === this.focusIndex) {
child_status.disabled = child.disabled;
|
e4ebd304
梁灏
update Select com...
|
545
|
child_status.hidden = child.hidden;
|
e355dd49
梁灏
add Select Component
|
546
|
|
e4ebd304
梁灏
update Select com...
|
547
|
if (!child.disabled && !child.hidden) {
|
e355dd49
梁灏
add Select Component
|
548
549
550
551
552
|
child.isFocus = true;
}
} else {
child.isFocus = false;
}
|
e4ebd304
梁灏
update Select com...
|
553
554
555
556
|
if (!child.hidden && !child.disabled) {
find_deep = true;
}
|
e355dd49
梁灏
add Select Component
|
557
558
559
560
|
});
this.resetScrollTop();
|
e4ebd304
梁灏
update Select com...
|
561
|
if ((child_status.disabled || child_status.hidden) && find_deep) {
|
e355dd49
梁灏
add Select Component
|
562
563
564
565
566
|
this.navigateOptions(direction);
}
},
resetScrollTop () {
const index = this.focusIndex - 1;
|
500694ba
梁灏
fixed Select bug ...
|
567
|
if (!this.optionInstances.length) return;
|
e355dd49
梁灏
add Select Component
|
568
569
570
571
572
573
574
575
576
|
let bottomOverflowDistance = this.optionInstances[index].$el.getBoundingClientRect().bottom - this.$refs.dropdown.$el.getBoundingClientRect().bottom;
let topOverflowDistance = this.optionInstances[index].$el.getBoundingClientRect().top - this.$refs.dropdown.$el.getBoundingClientRect().top;
if (bottomOverflowDistance > 0) {
this.$refs.dropdown.$el.scrollTop += bottomOverflowDistance;
}
if (topOverflowDistance < 0) {
this.$refs.dropdown.$el.scrollTop += topOverflowDistance;
}
|
e4ebd304
梁灏
update Select com...
|
577
578
579
|
},
handleBlur () {
setTimeout(() => {
|
fed3e09d
梁灏
add AutoComplete ...
|
580
|
if (this.autoComplete) return;
|
e4ebd304
梁灏
update Select com...
|
581
582
583
|
const model = this.model;
if (this.multiple) {
|
eda30489
huangliangxiang
可搜索下拉菜单 输入无匹配时,移出...
|
584
|
this.query = '';
|
e4ebd304
梁灏
update Select com...
|
585
586
587
588
|
} else {
if (model !== '') {
this.findChild((child) => {
if (child.value === model) {
|
1363abdc
Rijn
fixed #178
|
589
|
this.query = child.label === undefined ? child.searchLabel : child.label;
|
e4ebd304
梁灏
update Select com...
|
590
591
|
}
});
|
c70ff0f2
梁灏
fixed #915
|
592
593
|
// 如果删除了搜索词,下拉列表也清空了,所以强制调用一次remoteMethod
if (this.remote && this.query !== this.lastQuery) {
|
0b916a32
梁灏
update Select
|
594
|
this.$nextTick(() => {
|
c70ff0f2
梁灏
fixed #915
|
595
|
this.query = this.lastQuery;
|
6f8608bb
梁灏
update Select
|
596
|
});
|
0b916a32
梁灏
update Select
|
597
|
}
|
eda30489
huangliangxiang
可搜索下拉菜单 输入无匹配时,移出...
|
598
599
|
} else {
this.query = '';
|
e4ebd304
梁灏
update Select com...
|
600
601
602
|
}
}
}, 300);
|
e4ce9917
梁灏
update Select com...
|
603
604
|
},
resetInputState () {
|
4aec6a66
梁灏
support Select
|
605
|
this.inputLength = this.$refs.input.value.length * 12 + 20;
|
e4ce9917
梁灏
update Select com...
|
606
607
608
609
610
|
},
handleInputDelete () {
if (this.multiple && this.model.length && this.query === '') {
this.removeTag(this.model.length - 1);
}
|
3e855e34
梁灏
fixed #46
|
611
612
613
614
615
|
},
// use when slot changed
slotChange () {
this.options = [];
this.optionInstances = [];
|
2f0b086d
梁灏
fixed #116
|
616
617
618
619
|
},
setQuery (query) {
if (!this.filterable) return;
this.query = query;
|
9c3a3e7d
YikaJ
更新 Select 组件
|
620
621
|
},
modelToQuery() {
|
83b73885
梁灏
fixed #718
|
622
|
if (!this.multiple && this.filterable && this.model !== undefined) {
|
7db4e70d
YikaJ
Update select.vue
|
623
624
625
626
627
628
629
630
631
632
633
634
|
this.findChild((child) => {
if (this.model === child.value) {
if (child.label) {
this.query = child.label;
} else if (child.searchLabel) {
this.query = child.searchLabel;
} else {
this.query = child.value;
}
}
});
}
|
15b72d31
梁灏
fixed #566
|
635
636
637
638
639
640
641
642
|
},
broadcastQuery (val) {
if (findComponentDownward(this, 'OptionGroup')) {
this.broadcast('OptionGroup', 'on-query-change', val);
this.broadcast('iOption', 'on-query-change', val);
} else {
this.broadcast('iOption', 'on-query-change', val);
}
|
98bf25b3
梁灏
fixed #1286
|
643
|
},
|
721dc691
Sergio Crisostomo
fix debounce context
|
644
645
646
647
648
649
650
|
debouncedAppendRemove(){
return debounce(function(){
if (!this.remote) {
this.modelToQuery();
this.$nextTick(() => this.broadcastQuery(''));
} else {
this.findChild((child) => {
|
e1b86bcf
梁灏
fixed #1865
|
651
|
child.updateSearchLabel(); // #1865
|
721dc691
Sergio Crisostomo
fix debounce context
|
652
653
654
655
|
child.selected = this.multiple ? this.model.indexOf(child.value) > -1 : this.model === child.value;
});
}
this.slotChange();
|
89828b5b
梁灏
update Select
|
656
|
this.updateOptions(true);
|
721dc691
Sergio Crisostomo
fix debounce context
|
657
658
|
});
},
|
98bf25b3
梁灏
fixed #1286
|
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
|
// 处理 remote 初始值
updateLabel () {
if (this.remote) {
if (!this.multiple && this.model !== '') {
this.selectToChangeQuery = true;
if (this.currentLabel === '') this.currentLabel = this.model;
this.lastQuery = this.currentLabel;
this.query = this.currentLabel;
} else if (this.multiple && this.model.length) {
if (this.currentLabel.length !== this.model.length) this.currentLabel = this.model;
this.selectedMultiple = this.model.map((item, index) => {
return {
value: item,
label: this.currentLabel[index]
};
});
|
60314959
梁灏
fixed #1743 and c...
|
675
676
|
} else if (this.multiple && !this.model.length) {
this.selectedMultiple = [];
|
98bf25b3
梁灏
fixed #1286
|
677
678
|
}
}
|
e355dd49
梁灏
add Select Component
|
679
680
|
}
},
|
4aec6a66
梁灏
support Select
|
681
|
mounted () {
|
7db4e70d
YikaJ
Update select.vue
|
682
|
this.modelToQuery();
|
ddc35c9a
梁灏
fixed #952
|
683
|
// 处理 remote 初始值
|
98bf25b3
梁灏
fixed #1286
|
684
|
this.updateLabel();
|
83b73885
梁灏
fixed #718
|
685
686
687
|
this.$nextTick(() => {
this.broadcastQuery('');
});
|
e2006187
梁灏
fixed #159
|
688
|
|
f77b1964
梁灏
update Select
|
689
|
this.updateOptions();
|
e355dd49
梁灏
add Select Component
|
690
|
document.addEventListener('keydown', this.handleKeydown);
|
3e855e34
梁灏
fixed #46
|
691
|
|
721dc691
Sergio Crisostomo
fix debounce context
|
692
693
|
this.$on('append', this.debouncedAppendRemove());
this.$on('remove', this.debouncedAppendRemove());
|
4aec6a66
梁灏
support Select
|
694
695
696
|
this.$on('on-select-selected', (value) => {
if (this.model === value) {
|
7af00356
梁灏
update AutoComplete
|
697
|
if (this.autoComplete) this.$emit('on-change', value);
|
4aec6a66
梁灏
support Select
|
698
699
700
701
702
703
704
705
706
707
708
709
|
this.hideMenu();
} else {
if (this.multiple) {
const index = this.model.indexOf(value);
if (index >= 0) {
this.removeTag(index);
} else {
this.model.push(value);
this.broadcast('Drop', 'on-update-popper');
}
if (this.filterable) {
|
f10b27f9
梁灏
update Select
|
710
711
|
// remote&filterable&multiple时,一次点多项,不应该设置true,因为无法置为false,下次的搜索会失效
if (this.query !== '') this.selectToChangeQuery = true;
|
4aec6a66
梁灏
support Select
|
712
713
714
715
716
717
718
719
720
|
this.query = '';
this.$refs.input.focus();
}
} else {
this.model = value;
if (this.filterable) {
this.findChild((child) => {
if (child.value === value) {
|
f10b27f9
梁灏
update Select
|
721
|
if (this.query !== '') this.selectToChangeQuery = true;
|
c70ff0f2
梁灏
fixed #915
|
722
|
this.lastQuery = this.query = child.label === undefined ? child.searchLabel : child.label;
|
4aec6a66
梁灏
support Select
|
723
724
725
726
727
728
|
}
});
}
}
}
});
|
e355dd49
梁灏
add Select Component
|
729
730
731
|
},
beforeDestroy () {
document.removeEventListener('keydown', this.handleKeydown);
|
e355dd49
梁灏
add Select Component
|
732
733
|
},
watch: {
|
4aec6a66
梁灏
support Select
|
734
735
|
value (val) {
this.model = val;
|
d4a0b944
herton7362
Fix #982 issue.Ma...
|
736
737
|
// #982
if (val === '' || val === null) this.query = '';
|
4aec6a66
梁灏
support Select
|
738
|
},
|
98bf25b3
梁灏
fixed #1286
|
739
740
741
742
|
label (val) {
this.currentLabel = val;
this.updateLabel();
},
|
e355dd49
梁灏
add Select Component
|
743
|
model () {
|
4aec6a66
梁灏
support Select
|
744
|
this.$emit('input', this.model);
|
7db4e70d
YikaJ
Update select.vue
|
745
|
this.modelToQuery();
|
e355dd49
梁灏
add Select Component
|
746
|
if (this.multiple) {
|
3e855e34
梁灏
fixed #46
|
747
748
749
750
751
|
if (this.slotChangeDuration) {
this.slotChangeDuration = false;
} else {
this.updateMultipleSelected();
}
|
e355dd49
梁灏
add Select Component
|
752
753
754
|
} else {
this.updateSingleSelected();
}
|
219e5c92
梁灏
fixed #957
|
755
756
757
758
759
760
|
// #957
if (!this.visible && this.filterable) {
this.$nextTick(() => {
this.broadcastQuery('');
});
}
|
e355dd49
梁灏
add Select Component
|
761
762
763
|
},
visible (val) {
if (val) {
|
15b72d31
梁灏
fixed #566
|
764
765
766
767
|
if (this.filterable) {
if (this.multiple) {
this.$refs.input.focus();
} else {
|
fed3e09d
梁灏
add AutoComplete ...
|
768
|
if (!this.autoComplete) this.$refs.input.select();
|
15b72d31
梁灏
fixed #566
|
769
|
}
|
393d8551
梁灏
update Select
|
770
771
|
if (this.remote) {
this.findChild(child => {
|
13a940ee
梁灏
update Select
|
772
|
child.selected = this.multiple ? this.model.indexOf(child.value) > -1 : this.model === child.value;
|
393d8551
梁灏
update Select
|
773
|
});
|
ddc35c9a
梁灏
fixed #952
|
774
775
776
777
778
|
// remote下,设置了默认值,第一次打开时,搜索一次
const options = this.$slots.default || [];
if (this.query !== '' && !options.length) {
this.remoteMethod(this.query);
}
|
393d8551
梁灏
update Select
|
779
|
}
|
e4ce9917
梁灏
update Select com...
|
780
|
}
|
4aec6a66
梁灏
support Select
|
781
|
this.broadcast('Drop', 'on-update-popper');
|
e355dd49
梁灏
add Select Component
|
782
|
} else {
|
b7cf983e
梁灏
update Select com...
|
783
|
if (this.filterable) {
|
fed3e09d
梁灏
add AutoComplete ...
|
784
|
if (!this.autoComplete) this.$refs.input.blur();
|
15b72d31
梁灏
fixed #566
|
785
786
787
788
|
// #566 reset options visible
setTimeout(() => {
this.broadcastQuery('');
}, 300);
|
b7cf983e
梁灏
update Select com...
|
789
|
}
|
4aec6a66
梁灏
support Select
|
790
|
this.broadcast('Drop', 'on-destroy-popper');
|
e355dd49
梁灏
add Select Component
|
791
|
}
|
e4ebd304
梁灏
update Select com...
|
792
793
|
},
query (val) {
|
01b54e30
梁灏
Select support re...
|
794
795
796
797
798
|
if (this.remote && this.remoteMethod) {
if (!this.selectToChangeQuery) {
this.$emit('on-query-change', val);
this.remoteMethod(val);
}
|
f10b27f9
梁灏
update Select
|
799
800
801
802
|
this.focusIndex = 0;
this.findChild(child => {
child.isFocus = false;
});
|
01b54e30
梁灏
Select support re...
|
803
804
805
806
807
|
} else {
if (!this.selectToChangeQuery) {
this.$emit('on-query-change', val);
}
this.broadcastQuery(val);
|
d8bb1771
windywany
let select compon...
|
808
|
|
01b54e30
梁灏
Select support re...
|
809
|
let is_hidden = true;
|
e4ce9917
梁灏
update Select com...
|
810
|
|
01b54e30
梁灏
Select support re...
|
811
812
813
814
815
816
817
|
this.$nextTick(() => {
this.findChild((child) => {
if (!child.hidden) {
is_hidden = false;
}
});
this.notFound = is_hidden;
|
e4ce9917
梁灏
update Select com...
|
818
|
});
|
01b54e30
梁灏
Select support re...
|
819
820
|
}
this.selectToChangeQuery = false;
|
4aec6a66
梁灏
support Select
|
821
|
this.broadcast('Drop', 'on-update-popper');
|
e355dd49
梁灏
add Select Component
|
822
823
|
}
}
|
b0893113
jingsam
add eslint
|
824
|
};
|
d6342fe1
jingsam
fixed ie bug
|
825
|
</script>
|