Commit 3ae11e857694b70a572ca1b601d827924c8910ea
1 parent
2fcd34da
update Cascader
Showing
2 changed files
with
57 additions
and
5 deletions
Show diff stats
src/components/cascader/cascader.vue
| @@ -3,12 +3,17 @@ | @@ -3,12 +3,17 @@ | ||
| 3 | <div :class="[prefixCls + '-rel']" @click="toggleOpen"> | 3 | <div :class="[prefixCls + '-rel']" @click="toggleOpen"> |
| 4 | <slot> | 4 | <slot> |
| 5 | <i-input | 5 | <i-input |
| 6 | + ref="input" | ||
| 6 | :readonly="!filterable" | 7 | :readonly="!filterable" |
| 7 | :disabled="disabled" | 8 | :disabled="disabled" |
| 8 | - :value="displayRender" | 9 | + :value="displayInputRender" |
| 9 | @on-change="handleInput" | 10 | @on-change="handleInput" |
| 10 | :size="size" | 11 | :size="size" |
| 11 | - :placeholder="placeholder"></i-input> | 12 | + :placeholder="inputPlaceholder"></i-input> |
| 13 | + <div | ||
| 14 | + :class="[prefixCls + '-label']" | ||
| 15 | + v-show="filterable && query === ''" | ||
| 16 | + @click="handleFocus">{{ displayRender }}</div> | ||
| 12 | <Icon type="ios-close" :class="[prefixCls + '-arrow']" v-show="showCloseIcon" @click.native.stop="clearSelect"></Icon> | 17 | <Icon type="ios-close" :class="[prefixCls + '-arrow']" v-show="showCloseIcon" @click.native.stop="clearSelect"></Icon> |
| 13 | <Icon type="arrow-down-b" :class="[prefixCls + '-arrow']"></Icon> | 18 | <Icon type="arrow-down-b" :class="[prefixCls + '-arrow']"></Icon> |
| 14 | </slot> | 19 | </slot> |
| @@ -47,13 +52,14 @@ | @@ -47,13 +52,14 @@ | ||
| 47 | import clickoutside from '../../directives/clickoutside'; | 52 | import clickoutside from '../../directives/clickoutside'; |
| 48 | import { oneOf } from '../../utils/assist'; | 53 | import { oneOf } from '../../utils/assist'; |
| 49 | import Emitter from '../../mixins/emitter'; | 54 | import Emitter from '../../mixins/emitter'; |
| 55 | + import Locale from '../../mixins/locale'; | ||
| 50 | 56 | ||
| 51 | const prefixCls = 'ivu-cascader'; | 57 | const prefixCls = 'ivu-cascader'; |
| 52 | const selectPrefixCls = 'ivu-select'; | 58 | const selectPrefixCls = 'ivu-select'; |
| 53 | 59 | ||
| 54 | export default { | 60 | export default { |
| 55 | name: 'Cascader', | 61 | name: 'Cascader', |
| 56 | - mixins: [ Emitter ], | 62 | + mixins: [ Emitter, Locale ], |
| 57 | components: { iInput, Drop, Icon, Caspanel }, | 63 | components: { iInput, Drop, Icon, Caspanel }, |
| 58 | directives: { clickoutside }, | 64 | directives: { clickoutside }, |
| 59 | props: { | 65 | props: { |
| @@ -78,8 +84,7 @@ | @@ -78,8 +84,7 @@ | ||
| 78 | default: true | 84 | default: true |
| 79 | }, | 85 | }, |
| 80 | placeholder: { | 86 | placeholder: { |
| 81 | - type: String, | ||
| 82 | - default: '请选择' | 87 | + type: String |
| 83 | }, | 88 | }, |
| 84 | size: { | 89 | size: { |
| 85 | validator (value) { | 90 | validator (value) { |
| @@ -128,6 +133,7 @@ | @@ -128,6 +133,7 @@ | ||
| 128 | `${prefixCls}`, | 133 | `${prefixCls}`, |
| 129 | { | 134 | { |
| 130 | [`${prefixCls}-show-clear`]: this.showCloseIcon, | 135 | [`${prefixCls}-show-clear`]: this.showCloseIcon, |
| 136 | + [`${prefixCls}-size-${this.size}`]: !!this.size, | ||
| 131 | [`${prefixCls}-visible`]: this.visible, | 137 | [`${prefixCls}-visible`]: this.visible, |
| 132 | [`${prefixCls}-disabled`]: this.disabled | 138 | [`${prefixCls}-disabled`]: this.disabled |
| 133 | } | 139 | } |
| @@ -144,6 +150,19 @@ | @@ -144,6 +150,19 @@ | ||
| 144 | 150 | ||
| 145 | return this.renderFormat(label, this.selected); | 151 | return this.renderFormat(label, this.selected); |
| 146 | }, | 152 | }, |
| 153 | + displayInputRender () { | ||
| 154 | + return this.filterable ? '' : this.displayRender; | ||
| 155 | + }, | ||
| 156 | + localePlaceholder () { | ||
| 157 | + if (this.placeholder === undefined) { | ||
| 158 | + return this.t('i.select.placeholder'); | ||
| 159 | + } else { | ||
| 160 | + return this.placeholder; | ||
| 161 | + } | ||
| 162 | + }, | ||
| 163 | + inputPlaceholder () { | ||
| 164 | + return this.filterable && this.currentValue.length ? null : this.localePlaceholder; | ||
| 165 | + }, | ||
| 147 | querySelections () { | 166 | querySelections () { |
| 148 | let selections = []; | 167 | let selections = []; |
| 149 | function getSelections (arr, label, value) { | 168 | function getSelections (arr, label, value) { |
| @@ -226,11 +245,16 @@ | @@ -226,11 +245,16 @@ | ||
| 226 | const item = this.querySelections[index]; | 245 | const item = this.querySelections[index]; |
| 227 | 246 | ||
| 228 | if (item.item.disabled) return false; | 247 | if (item.item.disabled) return false; |
| 248 | + // todo 还有bug,选完,删除后,失焦,不能回到上次选择的 | ||
| 229 | this.query = ''; | 249 | this.query = ''; |
| 250 | + this.$refs.input.currentValue = ''; | ||
| 230 | const oldVal = JSON.stringify(this.currentValue); | 251 | const oldVal = JSON.stringify(this.currentValue); |
| 231 | this.currentValue = item.value.split(','); | 252 | this.currentValue = item.value.split(','); |
| 232 | this.emitValue(this.currentValue, oldVal); | 253 | this.emitValue(this.currentValue, oldVal); |
| 233 | this.handleClose(); | 254 | this.handleClose(); |
| 255 | + }, | ||
| 256 | + handleFocus () { | ||
| 257 | + this.$refs.input.focus(); | ||
| 234 | } | 258 | } |
| 235 | }, | 259 | }, |
| 236 | created () { | 260 | created () { |
| @@ -270,6 +294,11 @@ | @@ -270,6 +294,11 @@ | ||
| 270 | if (this.currentValue.length) { | 294 | if (this.currentValue.length) { |
| 271 | this.updateSelected(); | 295 | this.updateSelected(); |
| 272 | } | 296 | } |
| 297 | + } else { | ||
| 298 | + if (this.filterable) { | ||
| 299 | + this.query = ''; | ||
| 300 | + this.$refs.input.currentValue = ''; | ||
| 301 | + } | ||
| 273 | } | 302 | } |
| 274 | this.$emit('on-visible-change', val); | 303 | this.$emit('on-visible-change', val); |
| 275 | }, | 304 | }, |
src/styles/components/cascader.less
| @@ -19,6 +19,29 @@ | @@ -19,6 +19,29 @@ | ||
| 19 | cursor: @cursor-disabled; | 19 | cursor: @cursor-disabled; |
| 20 | } | 20 | } |
| 21 | 21 | ||
| 22 | + &-label{ | ||
| 23 | + width: 100%; | ||
| 24 | + height: 100%; | ||
| 25 | + line-height: 32px; | ||
| 26 | + padding: 0 7px; | ||
| 27 | + box-sizing: border-box; | ||
| 28 | + white-space: nowrap; | ||
| 29 | + text-overflow: ellipsis; | ||
| 30 | + overflow: hidden; | ||
| 31 | + cursor: pointer; | ||
| 32 | + font-size: @font-size-small; | ||
| 33 | + position: absolute; | ||
| 34 | + left: 0; | ||
| 35 | + top: 0; | ||
| 36 | + } | ||
| 37 | + &-size-large &-label{ | ||
| 38 | + line-height: 36px; | ||
| 39 | + font-size: @font-size-base; | ||
| 40 | + } | ||
| 41 | + &-size-small &-label{ | ||
| 42 | + line-height: 26px; | ||
| 43 | + } | ||
| 44 | + | ||
| 22 | .@{cascader-prefix-cls}-arrow:nth-of-type(1) { | 45 | .@{cascader-prefix-cls}-arrow:nth-of-type(1) { |
| 23 | display: none; | 46 | display: none; |
| 24 | cursor: pointer; | 47 | cursor: pointer; |