Commit e4ce99177deb8806eedee55dfa785a9eb2d00603

Authored by 梁灏
1 parent e4ebd304

update Select component

update Select component:filterable
components/select/option-group.vue
... ... @@ -18,8 +18,7 @@
18 18 },
19 19 data () {
20 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 12 <span :class="[`${prefixCls}-selected-value`]" v-show="!showPlaceholder && !multiple && !filterable">{{ selectedSingle }}</span>
13 13 <input
14 14 type="text"
15   - :class="[`${prefixCls}-input`]"
16 15 v-if="filterable"
17 16 v-model="query"
18   - :placeholder="placeholder"
  17 + :class="[`${prefixCls}-input`]"
  18 + :placeholder="showPlaceholder ? placeholder : ''"
19 19 :style="inputStyle"
20   - @blur="handleBlur">
  20 + @blur="handleBlur"
  21 + @keydown="resetInputState"
  22 + @keydown.delete="handleInputDelete"
  23 + v-el:input>
21 24 <Icon type="ios-close" :class="[`${prefixCls}-arrow`]" v-show="showCloseIcon" @click.stop="clearSingleSelect"></Icon>
22 25 <Icon type="arrow-down-b" :class="[`${prefixCls}-arrow`]"></Icon>
23 26 </div>
24 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 30 </Dropdown>
27 31 </div>
28 32 </template>
... ... @@ -85,7 +89,8 @@
85 89 selectedMultiple: [],
86 90 focusIndex: 0,
87 91 query: '',
88   - inputLength: 20
  92 + inputLength: 20,
  93 + notFound: false
89 94 }
90 95 },
91 96 computed: {
... ... @@ -124,7 +129,11 @@
124 129 let style = {};
125 130  
126 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 139 return style;
... ... @@ -245,6 +254,12 @@
245 254 return false;
246 255 }
247 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 264 // to select option for single
250 265 toggleSingleSelected (value, init = false) {
... ... @@ -404,6 +419,14 @@
404 419 }
405 420 }
406 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 432 ready () {
... ... @@ -423,6 +446,9 @@
423 446 },
424 447 visible (val) {
425 448 if (val) {
  449 + if (this.multiple && this.filterable) {
  450 + this.$els.input.focus();
  451 + }
426 452 this.$broadcast('on-update-popper');
427 453 } else {
428 454  
... ... @@ -430,6 +456,16 @@
430 456 },
431 457 query (val) {
432 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 471 events: {
... ... @@ -443,6 +479,12 @@
443 479 this.removeTag(index);
444 480 } else {
445 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 489 } else {
448 490 this.model = value;
... ...
local/routers/select.vue
... ... @@ -4,7 +4,7 @@
4 4 {{ city | json }}<br>
5 5 <Button @click="city = 'hangzhou'">切换城市</Button>
6 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 8 <i-option-group label="热门城市">
9 9 <i-option value="beijing">北京市</i-option>
10 10 <i-option value="shanghai" disabled label="上海市">上海市2</i-option>
... ... @@ -13,31 +13,16 @@
13 13 <i-option-group label="二线城市">
14 14 <i-option value="nanjing">南京市</i-option>
15 15 <i-option value="hangzhou">杭州市</i-option>
  16 + <i-option value="heilongjiang" disabled>黑龙江市</i-option>
16 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 22 </i-option-group>
37   - <i-option value="heilongjiang" disabled>黑龙江市</i-option>
38 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 26 <i-option value="beijing">北京</i-option>
42 27 <i-option value="shanghai" label="上海市">上海市</i-option>
43 28 <i-option value="shenzhen" disabled>深圳市</i-option>
... ... @@ -51,6 +36,19 @@
51 36 <i-option value="e">e市</i-option>
52 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 52 <i-select v-if="true" :model.sync="focus2" style="width:300px" @on-change="change" clearable multiple>
55 53 <i-option value="beijing" label="北京市">北京2</i-option>
56 54 <i-option value="shanghai">上海市</i-option>
... ... @@ -84,7 +82,7 @@
84 82 return {
85 83 city: '',
86 84 focus: '',
87   - focus2: ['beijing', 'guangzhou', 'b']
  85 + focus2: ['beijing']
88 86 // focus2: []
89 87 }
90 88 },
... ...
styles/components/select.less
... ... @@ -163,6 +163,17 @@
163 163 &-small &-input{
164 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 179 .@{select-item-prefix-cls} {
... ...