Commit 4e23e47c9494d1aa2be79d0fee94c0ab7c591770
1 parent
c1963810
update Cascader
Showing
2 changed files
with
9 additions
and
3 deletions
Show diff stats
src/components/cascader/cascader.vue
| @@ -36,7 +36,7 @@ | @@ -36,7 +36,7 @@ | ||
| 36 | [selectPrefixCls + '-item-disabled']: item.disabled | 36 | [selectPrefixCls + '-item-disabled']: item.disabled |
| 37 | }]" | 37 | }]" |
| 38 | v-for="(item, index) in querySelections" | 38 | v-for="(item, index) in querySelections" |
| 39 | - @click="handleSelectItem(index)">{{ item.label }}</li> | 39 | + @click="handleSelectItem(index)" v-html="item.display"></li> |
| 40 | </ul> | 40 | </ul> |
| 41 | </div> | 41 | </div> |
| 42 | </div> | 42 | </div> |
| @@ -179,6 +179,7 @@ | @@ -179,6 +179,7 @@ | ||
| 179 | selections.push({ | 179 | selections.push({ |
| 180 | label: item.__label, | 180 | label: item.__label, |
| 181 | value: item.__value, | 181 | value: item.__value, |
| 182 | + display: item.__label, | ||
| 182 | item: item, | 183 | item: item, |
| 183 | disabled: !!item.disabled | 184 | disabled: !!item.disabled |
| 184 | }); | 185 | }); |
| @@ -186,7 +187,10 @@ | @@ -186,7 +187,10 @@ | ||
| 186 | } | 187 | } |
| 187 | } | 188 | } |
| 188 | getSelections(this.data); | 189 | getSelections(this.data); |
| 189 | - selections = selections.filter(item => item.label.indexOf(this.query) > -1); | 190 | + selections = selections.filter(item => item.label.indexOf(this.query) > -1).map(item => { |
| 191 | + item.display = item.display.replace(new RegExp(this.query, 'g'), `<span>${this.query}</span>`); | ||
| 192 | + return item; | ||
| 193 | + }); | ||
| 190 | return selections; | 194 | return selections; |
| 191 | } | 195 | } |
| 192 | }, | 196 | }, |
| @@ -245,7 +249,6 @@ | @@ -245,7 +249,6 @@ | ||
| 245 | const item = this.querySelections[index]; | 249 | const item = this.querySelections[index]; |
| 246 | 250 | ||
| 247 | if (item.item.disabled) return false; | 251 | if (item.item.disabled) return false; |
| 248 | - // todo 还有bug,选完,删除后,失焦,不能回到上次选择的 | ||
| 249 | this.query = ''; | 252 | this.query = ''; |
| 250 | this.$refs.input.currentValue = ''; | 253 | this.$refs.input.currentValue = ''; |
| 251 | const oldVal = JSON.stringify(this.currentValue); | 254 | const oldVal = JSON.stringify(this.currentValue); |
src/styles/components/cascader.less
| @@ -71,6 +71,9 @@ | @@ -71,6 +71,9 @@ | ||
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | .select-item(@cascader-prefix-cls, @cascader-item-prefix-cls); | 73 | .select-item(@cascader-prefix-cls, @cascader-item-prefix-cls); |
| 74 | + .ivu-select-item span{ | ||
| 75 | + color: @error-color; | ||
| 76 | + } | ||
| 74 | 77 | ||
| 75 | &-dropdown{ | 78 | &-dropdown{ |
| 76 | padding: 5px 0; | 79 | padding: 5px 0; |