update Cascader

update Cascader
This commit is contained in:
梁灏 2016-11-16 10:07:03 +08:00
parent bd4e3b9b0a
commit 165bb7c9ed
7 changed files with 54 additions and 31 deletions

View file

@ -92,7 +92,8 @@
return [ return [
`${prefixCls}`, `${prefixCls}`,
{ {
[`${prefixCls}-show-clear`]: this.showCloseIcon [`${prefixCls}-show-clear`]: this.showCloseIcon,
[`${prefixCls}-visible`]: this.visible
} }
] ]
}, },
@ -105,28 +106,42 @@
label.push(this.selected[i].label); label.push(this.selected[i].label);
} }
return this.renderFormat(label); return this.renderFormat(label, this.selected);
} }
}, },
methods: { methods: {
clearSelect () { clearSelect () {
const oldVal = JSON.stringify(this.value);
this.value = this.selected = this.tmpSelected = [];
this.handleClose();
this.emitValue(this.value, oldVal);
this.$broadcast('on-clear');
}, },
handleClose () { handleClose () {
this.visible = false; this.visible = false;
}, },
onFocus () { onFocus () {
this.visible = true; this.visible = true;
if (!this.value.length) {
this.$broadcast('on-clear');
}
}, },
updateResult (result) { updateResult (result) {
this.tmpSelected = result; this.tmpSelected = result;
}, },
updateSelected () { updateSelected (init = false) {
if (!this.changeOnSelect || init) {
this.$broadcast('on-find-selected', this.value); this.$broadcast('on-find-selected', this.value);
} }
}, },
emitValue (val, oldVal) {
if (JSON.stringify(val) !== oldVal) {
this.$emit('on-change', this.value, JSON.parse(JSON.stringify(this.selected)));
}
}
},
ready () { ready () {
this.updateSelected(); this.updateSelected(true);
}, },
events: { events: {
// lastValue: is click the final val // lastValue: is click the final val
@ -140,10 +155,10 @@
this.selected.forEach((item) => { this.selected.forEach((item) => {
newVal.push(item.value); newVal.push(item.value);
}); });
this.value = newVal;
if (JSON.stringify(this.value) !== oldVal) { if (!fromInit) {
this.$emit('on-change', this.value); this.value = newVal;
this.emitValue(this.value, oldVal);
} }
} }
if (lastValue && !fromInit) { if (lastValue && !fromInit) {

View file

@ -18,9 +18,6 @@
} }
] ]
} }
},
ready () {
} }
} }
</script> </script>

View file

@ -105,6 +105,10 @@
} }
} }
} }
},
'on-clear' () {
this.sublist = [];
this.tmpItem = {};
} }
} }
} }

View file

@ -24,14 +24,10 @@
} }
&-arrow { &-arrow {
position: absolute; .inner-arrow();
top: 50%; }
right: 8px; &-visible &-arrow:nth-of-type(2){
line-height: 1; .transform(rotate(180deg));
margin-top: -6px;
font-size: @font-size-base;
color: @subsidiary-color;
.transition(all @transition-time @ease-in-out);
} }
.@{select-dropdown-prefix-cls} { .@{select-dropdown-prefix-cls} {
@ -78,7 +74,7 @@
&-active{ &-active{
background-color: @background-color-select-hover; background-color: @background-color-select-hover;
font-weight: bold; color: @primary-color;
} }
} }
} }

View file

@ -41,13 +41,7 @@
} }
&-arrow { &-arrow {
position: absolute; .inner-arrow();
top: 50%;
right: 8px;
line-height: 1;
margin-top: -6px;
color: @subsidiary-color;
.transition(all @transition-time @ease-in-out);
} }
&-visible{ &-visible{

View file

@ -19,3 +19,15 @@
-moz-user-select: @type; -moz-user-select: @type;
user-select: @type; user-select: @type;
} }
// for select and input like component's arrow
.inner-arrow() {
position: absolute;
top: 50%;
right: 8px;
line-height: 1;
margin-top: -7px;
font-size: @font-size-base;
color: @subsidiary-color;
.transition(all @transition-time @ease-in-out);
}

View file

@ -1,6 +1,7 @@
<template> <template>
<div style="margin: 50px;width:300px"> <div style="margin: 50px;width:300px">
<Cascader :data="data" :value.sync="value" @on-change="change" trigger="click"></Cascader> {{ value | json }}
<Cascader size="large" :data="data" :value.sync="value" @on-change="change" trigger="hover" :render-format="format"></Cascader>
</div> </div>
</template> </template>
<script> <script>
@ -50,8 +51,12 @@
}, },
methods: { methods: {
change (data) { change (data, opts) {
console.log(data) console.log(data);
console.log(opts)
},
format (label, data) {
return label[label.length - 1];
} }
} }
} }