Commit e4ce99177deb8806eedee55dfa785a9eb2d00603

Authored by 梁灏
1 parent e4ebd304

update Select component

update Select component:filterable
components/select/option-group.vue
@@ -18,8 +18,7 @@ @@ -18,8 +18,7 @@
18 }, 18 },
19 data () { 19 data () {
20 return { 20 return {
21 - prefixCls: prefixCls,  
22 - hidden: false // for search 21 + prefixCls: prefixCls
23 } 22 }
24 } 23 }
25 } 24 }
components/select/select.vue
@@ -12,17 +12,21 @@ @@ -12,17 +12,21 @@
12 <span :class="[`${prefixCls}-selected-value`]" v-show="!showPlaceholder && !multiple && !filterable">{{ selectedSingle }}</span> 12 <span :class="[`${prefixCls}-selected-value`]" v-show="!showPlaceholder && !multiple && !filterable">{{ selectedSingle }}</span>
13 <input 13 <input
14 type="text" 14 type="text"
15 - :class="[`${prefixCls}-input`]"  
16 v-if="filterable" 15 v-if="filterable"
17 v-model="query" 16 v-model="query"
18 - :placeholder="placeholder" 17 + :class="[`${prefixCls}-input`]"
  18 + :placeholder="showPlaceholder ? placeholder : ''"
19 :style="inputStyle" 19 :style="inputStyle"
20 - @blur="handleBlur"> 20 + @blur="handleBlur"
  21 + @keydown="resetInputState"
  22 + @keydown.delete="handleInputDelete"
  23 + v-el:input>
21 <Icon type="ios-close" :class="[`${prefixCls}-arrow`]" v-show="showCloseIcon" @click.stop="clearSingleSelect"></Icon> 24 <Icon type="ios-close" :class="[`${prefixCls}-arrow`]" v-show="showCloseIcon" @click.stop="clearSingleSelect"></Icon>
22 <Icon type="arrow-down-b" :class="[`${prefixCls}-arrow`]"></Icon> 25 <Icon type="arrow-down-b" :class="[`${prefixCls}-arrow`]"></Icon>
23 </div> 26 </div>
24 <Dropdown v-show="visible" transition="slide-up" v-ref:dropdown> 27 <Dropdown v-show="visible" transition="slide-up" v-ref:dropdown>
25 - <ul :class="[`${prefixCls}-dropdown-list`]"><slot></slot></ul> 28 + <ul v-show="notFound" :class="[`${prefixCls}-not-found`]"><li>未找到</li></ul>
  29 + <ul v-else :class="[`${prefixCls}-dropdown-list`]"><slot></slot></ul>
26 </Dropdown> 30 </Dropdown>
27 </div> 31 </div>
28 </template> 32 </template>
@@ -85,7 +89,8 @@ @@ -85,7 +89,8 @@
85 selectedMultiple: [], 89 selectedMultiple: [],
86 focusIndex: 0, 90 focusIndex: 0,
87 query: '', 91 query: '',
88 - inputLength: 20 92 + inputLength: 20,
  93 + notFound: false
89 } 94 }
90 }, 95 },
91 computed: { 96 computed: {
@@ -124,7 +129,11 @@ @@ -124,7 +129,11 @@
124 let style = {}; 129 let style = {};
125 130
126 if (this.multiple) { 131 if (this.multiple) {
127 - style.width = `${this.inputLength}px`; 132 + if (this.showPlaceholder) {
  133 + style.width = '100%';
  134 + } else {
  135 + style.width = `${this.inputLength}px`;
  136 + }
128 } 137 }
129 138
130 return style; 139 return style;
@@ -245,6 +254,12 @@ @@ -245,6 +254,12 @@
245 return false; 254 return false;
246 } 255 }
247 this.model.splice(index, 1); 256 this.model.splice(index, 1);
  257 +
  258 + if (this.filterable && this.visible) {
  259 + this.$els.input.focus();
  260 + }
  261 +
  262 + this.$broadcast('on-update-popper');
248 }, 263 },
249 // to select option for single 264 // to select option for single
250 toggleSingleSelected (value, init = false) { 265 toggleSingleSelected (value, init = false) {
@@ -404,6 +419,14 @@ @@ -404,6 +419,14 @@
404 } 419 }
405 } 420 }
406 }, 300); 421 }, 300);
  422 + },
  423 + resetInputState () {
  424 + this.inputLength = this.$els.input.value.length * 12 + 20;
  425 + },
  426 + handleInputDelete () {
  427 + if (this.multiple && this.model.length && this.query === '') {
  428 + this.removeTag(this.model.length - 1);
  429 + }
407 } 430 }
408 }, 431 },
409 ready () { 432 ready () {
@@ -423,6 +446,9 @@ @@ -423,6 +446,9 @@
423 }, 446 },
424 visible (val) { 447 visible (val) {
425 if (val) { 448 if (val) {
  449 + if (this.multiple && this.filterable) {
  450 + this.$els.input.focus();
  451 + }
426 this.$broadcast('on-update-popper'); 452 this.$broadcast('on-update-popper');
427 } else { 453 } else {
428 454
@@ -430,6 +456,16 @@ @@ -430,6 +456,16 @@
430 }, 456 },
431 query (val) { 457 query (val) {
432 this.$broadcast('on-query-change', val); 458 this.$broadcast('on-query-change', val);
  459 + let is_hidden = true;
  460 +
  461 + this.$nextTick(() => {
  462 + this.findChild((child) => {
  463 + if (!child.hidden) {
  464 + is_hidden = false;
  465 + }
  466 + });
  467 + this.notFound = is_hidden;
  468 + });
433 } 469 }
434 }, 470 },
435 events: { 471 events: {
@@ -443,6 +479,12 @@ @@ -443,6 +479,12 @@
443 this.removeTag(index); 479 this.removeTag(index);
444 } else { 480 } else {
445 this.model.push(value); 481 this.model.push(value);
  482 + this.$broadcast('on-update-popper');
  483 + }
  484 +
  485 + if (this.filterable) {
  486 + this.query = '';
  487 + this.$els.input.focus();
446 } 488 }
447 } else { 489 } else {
448 this.model = value; 490 this.model = value;
local/routers/select.vue
@@ -4,7 +4,7 @@ @@ -4,7 +4,7 @@
4 {{ city | json }}<br> 4 {{ city | json }}<br>
5 <Button @click="city = 'hangzhou'">切换城市</Button> 5 <Button @click="city = 'hangzhou'">切换城市</Button>
6 <br> 6 <br>
7 - <i-select v-if="true" :model.sync="city" style="width:200px" @on-change="change"> 7 + <i-select v-if="true" :model.sync="city" style="width:200px" filterable @on-change="change">
8 <i-option-group label="热门城市"> 8 <i-option-group label="热门城市">
9 <i-option value="beijing">北京市</i-option> 9 <i-option value="beijing">北京市</i-option>
10 <i-option value="shanghai" disabled label="上海市">上海市2</i-option> 10 <i-option value="shanghai" disabled label="上海市">上海市2</i-option>
@@ -13,31 +13,16 @@ @@ -13,31 +13,16 @@
13 <i-option-group label="二线城市"> 13 <i-option-group label="二线城市">
14 <i-option value="nanjing">南京市</i-option> 14 <i-option value="nanjing">南京市</i-option>
15 <i-option value="hangzhou">杭州市</i-option> 15 <i-option value="hangzhou">杭州市</i-option>
  16 + <i-option value="heilongjiang" disabled>黑龙江市</i-option>
16 </i-option-group> 17 </i-option-group>
17 - <i-option value="heilongjiang" disabled>黑龙江市</i-option>  
18 - <i-option-group label="热门城市">  
19 - <i-option value="beijing">北京市</i-option>  
20 - <i-option value="shanghai" disabled label="上海市">上海市2</i-option>  
21 - <i-option value="shenzhen">深圳市</i-option>  
22 - </i-option-group>  
23 - <i-option-group label="二线城市">  
24 - <i-option value="nanjing">南京市</i-option>  
25 - <i-option value="hangzhou">杭州市</i-option>  
26 - </i-option-group>  
27 - <i-option value="heilongjiang" disabled>黑龙江市</i-option>  
28 - <i-option-group label="热门城市">  
29 - <i-option value="beijing">北京市</i-option>  
30 - <i-option value="shanghai" disabled label="上海市">上海市2</i-option>  
31 - <i-option value="shenzhen">深圳市</i-option>  
32 - </i-option-group>  
33 - <i-option-group label="二线城市">  
34 - <i-option value="nanjing">南京市</i-option>  
35 - <i-option value="hangzhou">杭州市</i-option> 18 + <i-option-group label="其它城市">
  19 + <i-option value="jyg">嘉峪关市</i-option>
  20 + <i-option value="lanzhou">兰州市</i-option>
  21 + <i-option value="beijingxi">北京西</i-option>
36 </i-option-group> 22 </i-option-group>
37 - <i-option value="heilongjiang" disabled>黑龙江市</i-option>  
38 </i-select> 23 </i-select>
39 24
40 - <i-select :model.sync="focus" style="width:200px" @on-change="change" clearable filterable label-in-value> 25 + <i-select v-show="true" :model.sync="focus" style="width:200px" @on-change="change" clearable filterable label-in-value>
41 <i-option value="beijing">北京</i-option> 26 <i-option value="beijing">北京</i-option>
42 <i-option value="shanghai" label="上海市">上海市</i-option> 27 <i-option value="shanghai" label="上海市">上海市</i-option>
43 <i-option value="shenzhen" disabled>深圳市</i-option> 28 <i-option value="shenzhen" disabled>深圳市</i-option>
@@ -51,6 +36,19 @@ @@ -51,6 +36,19 @@
51 <i-option value="e">e市</i-option> 36 <i-option value="e">e市</i-option>
52 </i-select> 37 </i-select>
53 38
  39 + <i-select v-if="true" :model.sync="focus2" style="width:300px" @on-change="change" clearable filterable multiple>
  40 + <i-option value="beijing" label="北京市">北京2</i-option>
  41 + <i-option value="shanghai">上海市</i-option>
  42 + <i-option value="shenzhen" disabled>深圳市</i-option>
  43 + <i-option value="guangzhou">广州市</i-option>
  44 + <i-option value="shijiazhuang">石家庄市</i-option>
  45 + <i-option value="a">a1市</i-option>
  46 + <i-option value="b">b2市</i-option>
  47 + <i-option value="c">c1市</i-option>
  48 + <i-option value="d">d2市</i-option>
  49 + <i-option value="e">e1市</i-option>
  50 + </i-select>
  51 +
54 <i-select v-if="true" :model.sync="focus2" style="width:300px" @on-change="change" clearable multiple> 52 <i-select v-if="true" :model.sync="focus2" style="width:300px" @on-change="change" clearable multiple>
55 <i-option value="beijing" label="北京市">北京2</i-option> 53 <i-option value="beijing" label="北京市">北京2</i-option>
56 <i-option value="shanghai">上海市</i-option> 54 <i-option value="shanghai">上海市</i-option>
@@ -84,7 +82,7 @@ @@ -84,7 +82,7 @@
84 return { 82 return {
85 city: '', 83 city: '',
86 focus: '', 84 focus: '',
87 - focus2: ['beijing', 'guangzhou', 'b'] 85 + focus2: ['beijing']
88 // focus2: [] 86 // focus2: []
89 } 87 }
90 }, 88 },
styles/components/select.less
@@ -163,6 +163,17 @@ @@ -163,6 +163,17 @@
163 &-small &-input{ 163 &-small &-input{
164 height: @input-height-small; 164 height: @input-height-small;
165 } 165 }
  166 +
  167 + &-multiple &-input{
  168 + height: 25px;
  169 + line-height: 28px;
  170 + padding: 0 0 0 6px;
  171 + }
  172 +
  173 + &-not-found{
  174 + text-align: center;
  175 + color: @btn-disable-color;
  176 + }
166 } 177 }
167 178
168 .@{select-item-prefix-cls} { 179 .@{select-item-prefix-cls} {