c9b86944
Sergio Crisostomo
Refactor Select!
|
1
|
<template>
|
9013c49d
梁灏
update Select sty...
|
2
|
<div @click="onHeaderClick" :class="headCls">
|
2739fc29
梁灏
Select add prefix...
|
3
4
5
6
7
|
<span :class="[prefixCls + '-prefix']" v-if="$slots.prefix || prefix">
<slot name="prefix">
<Icon :type="prefix" v-if="prefix" />
</slot>
</span>
|
90399f84
梁灏
fix #5568 ,close ...
|
8
9
10
11
|
<div
class="ivu-tag ivu-tag-checked"
v-for="(item, index) in selectedMultiple"
v-if="maxTagCount === undefined || index < maxTagCount">
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
12
|
<span class="ivu-tag-text">{{ item.label }}</span>
|
9eba26fe
梁灏
update Select Icons
|
13
|
<Icon type="ios-close" @click.native.stop="removeTag(item)"></Icon>
|
90399f84
梁灏
fix #5568 ,close ...
|
14
15
|
</div><div class="ivu-tag ivu-tag-checked" v-if="maxTagCount !== undefined && selectedMultiple.length > maxTagCount">
<span class="ivu-tag-text ivu-select-max-tag">
|
38b5b760
梁灏
update Select max...
|
16
|
<template v-if="maxTagPlaceholder">{{ maxTagPlaceholder(selectedMultiple.length - maxTagCount) }}</template>
|
90399f84
梁灏
fix #5568 ,close ...
|
17
18
|
<template v-else>+ {{ selectedMultiple.length - maxTagCount }}...</template>
</span>
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
</div>
<span
:class="singleDisplayClasses"
v-show="singleDisplayValue"
>{{ singleDisplayValue }}</span>
<input
:id="inputElementId"
type="text"
v-if="filterable"
v-model="query"
:disabled="disabled"
:class="[prefixCls + '-input']"
:placeholder="showPlaceholder ? localePlaceholder : ''"
:style="inputStyle"
autocomplete="off"
spellcheck="false"
@keydown="resetInputState"
@keydown.delete="handleInputDelete"
@focus="onInputFocus"
|
32349491
梁灏
fix #5155 close #...
|
38
|
@blur="onInputBlur"
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
39
40
|
ref="input">
|
9eba26fe
梁灏
update Select Icons
|
41
|
<Icon type="ios-close-circle" :class="[prefixCls + '-arrow']" v-if="resetSelect" @click.native.stop="onClear"></Icon>
|
5fe59e3a
梁灏
select add global...
|
42
|
<Icon :type="arrowType" :custom="customArrowType" :size="arrowSize" :class="[prefixCls + '-arrow']" v-if="!resetSelect && !remote"></Icon>
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
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
|
</div>
</template>
<script>
import Icon from '../icon';
import Emitter from '../../mixins/emitter';
import Locale from '../../mixins/locale';
const prefixCls = 'ivu-select';
export default {
name: 'iSelectHead',
mixins: [ Emitter, Locale ],
components: { Icon },
props: {
disabled: {
type: Boolean,
default: false
},
filterable: {
type: Boolean,
default: false
},
multiple: {
type: Boolean,
default: false
},
remote: {
type: Boolean,
default: false
},
initialLabel: {
|
21f69406
郑敏
fixed #3817 #3836
|
74
|
type: [String, Number, Array],
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
},
values: {
type: Array,
default: () => []
},
clearable: {
type: [Function, Boolean],
default: false,
},
inputElementId: {
type: String
},
placeholder: {
type: String
},
queryProp: {
type: String,
default: ''
|
2739fc29
梁灏
Select add prefix...
|
93
94
95
96
|
},
prefix: {
type: String
},
|
90399f84
梁灏
fix #5568 ,close ...
|
97
98
99
100
101
102
|
// 3.4.0
maxTagCount: {
type: Number
},
// 3.4.0
maxTagPlaceholder: {
|
38b5b760
梁灏
update Select max...
|
103
|
type: Function
|
90399f84
梁灏
fix #5568 ,close ...
|
104
|
}
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
},
data () {
return {
prefixCls: prefixCls,
query: '',
inputLength: 20,
remoteInitialLabel: this.initialLabel,
preventRemoteCall: false,
};
},
computed: {
singleDisplayClasses(){
const {filterable, multiple, showPlaceholder} = this;
return [{
|
2739fc29
梁灏
Select add prefix...
|
119
|
[prefixCls + '-head-with-prefix']: this.$slots.prefix || this.prefix,
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
[prefixCls + '-placeholder']: showPlaceholder && !filterable,
[prefixCls + '-selected-value']: !showPlaceholder && !multiple && !filterable,
}];
},
singleDisplayValue(){
if ((this.multiple && this.values.length > 0) || this.filterable) return '';
return `${this.selectedSingle}` || this.localePlaceholder;
},
showPlaceholder () {
let status = false;
if (!this.multiple) {
const value = this.values[0];
if (typeof value === 'undefined' || String(value).trim() === ''){
status = !this.remoteInitialLabel;
}
} else {
if (!this.values.length > 0) {
status = true;
}
}
return status;
},
resetSelect(){
return !this.showPlaceholder && this.clearable;
},
inputStyle () {
let style = {};
if (this.multiple) {
if (this.showPlaceholder) {
style.width = '100%';
} else {
style.width = `${this.inputLength}px`;
}
}
return style;
},
localePlaceholder () {
if (this.placeholder === undefined) {
return this.t('i.select.placeholder');
} else {
return this.placeholder;
}
},
selectedSingle(){
const selected = this.values[0];
return selected ? selected.label : (this.remoteInitialLabel || '');
},
selectedMultiple(){
return this.multiple ? this.values : [];
|
9013c49d
梁灏
update Select sty...
|
171
172
173
174
175
176
|
},
// 使用 prefix 时,在 filterable
headCls () {
return {
[`${prefixCls}-head-flex`]: this.filterable && (this.$slots.prefix || this.prefix)
};
|
5fe59e3a
梁灏
select add global...
|
177
178
179
180
181
182
183
184
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
|
},
// 3.4.0, global setting customArrow 有值时,arrow 赋值空
arrowType () {
let type = 'ios-arrow-down';
if (this.$IVIEW) {
if (this.$IVIEW.select.customArrow) {
type = '';
} else if (this.$IVIEW.select.arrow) {
type = this.$IVIEW.select.arrow;
}
}
return type;
},
// 3.4.0, global setting
customArrowType () {
let type = '';
if (this.$IVIEW) {
if (this.$IVIEW.select.customArrow) {
type = this.$IVIEW.select.customArrow;
}
}
return type;
},
// 3.4.0, global setting
arrowSize () {
let size = '';
if (this.$IVIEW) {
if (this.$IVIEW.select.arrowSize) {
size = this.$IVIEW.select.arrowSize;
}
}
return size;
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
212
213
214
|
}
},
methods: {
|
32349491
梁灏
fix #5155 close #...
|
215
216
217
218
219
220
|
onInputFocus(){
this.$emit('on-input-focus');
},
onInputBlur () {
if (!this.values.length) this.query = ''; // #5155
this.$emit('on-input-blur');
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
221
222
223
224
225
226
227
|
},
removeTag (value) {
if (this.disabled) return false;
this.dispatch('iSelect', 'on-select-selected', value);
},
resetInputState () {
this.inputLength = this.$refs.input.value.length * 12 + 20;
|
47f03c54
梁灏
fix #4273
|
228
|
this.$emit('on-keydown');
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
229
230
231
232
233
234
235
236
237
238
|
},
handleInputDelete () {
if (this.multiple && this.selectedMultiple.length && this.query === '') {
this.removeTag(this.selectedMultiple[this.selectedMultiple.length - 1]);
}
},
onHeaderClick(e){
if (this.filterable && e.target === this.$el){
this.$refs.input.focus();
}
|
7dbde804
Sergio Crisostomo
add on-clear event
|
239
240
241
|
},
onClear(){
this.$emit('on-clear');
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
}
},
watch: {
values ([value]) {
if (!this.filterable) return;
this.preventRemoteCall = true;
if (this.multiple){
this.query = '';
this.preventRemoteCall = false; // this should be after the query change setter above
return;
}
// #982
if (typeof value === 'undefined' || value === '' || value === null) this.query = '';
else this.query = value.label;
|
c3304bce
Sergio Crisostomo
correct unchanged...
|
256
|
this.$nextTick(() => this.preventRemoteCall = false); // this should be after the query change setter above
|
c9b86944
Sergio Crisostomo
Refactor Select!
|
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
},
query (val) {
if (this.preventRemoteCall) {
this.preventRemoteCall = false;
return;
}
this.$emit('on-query-change', val);
},
queryProp(query){
if (query !== this.query) this.query = query;
},
}
};
</script>
|