Support rate
This commit is contained in:
parent
49dd45f46f
commit
6aa7272260
5 changed files with 62 additions and 21 deletions
|
@ -7,18 +7,19 @@
|
||||||
@click="handleClick(item)">
|
@click="handleClick(item)">
|
||||||
<span :class="[prefixCls + '-star-content']" type="half"></span>
|
<span :class="[prefixCls + '-star-content']" type="half"></span>
|
||||||
</div>
|
</div>
|
||||||
<div :class="[prefixCls + '-text']" v-if="showText" v-show="value > 0">
|
<div :class="[prefixCls + '-text']" v-if="showText" v-show="currentValue > 0">
|
||||||
<slot>{{ value }} <template v-if="value <= 1">{{ t('i.rate.star') }}</template><template v-else>{{ t('i.rate.stars') }}</template></slot>
|
<slot>{{ currentValue }} <template v-if="currentValue <= 1">{{ t('i.rate.star') }}</template><template v-else>{{ t('i.rate.stars') }}</template></slot>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
import Locale from '../../mixins/locale';
|
import Locale from '../../mixins/locale';
|
||||||
|
import Emitter from '../../mixins/emitter';
|
||||||
|
|
||||||
const prefixCls = 'ivu-rate';
|
const prefixCls = 'ivu-rate';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
mixins: [ Locale ],
|
mixins: [ Locale, Emitter ],
|
||||||
props: {
|
props: {
|
||||||
count: {
|
count: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
@ -46,9 +47,16 @@
|
||||||
prefixCls: prefixCls,
|
prefixCls: prefixCls,
|
||||||
hoverIndex: -1,
|
hoverIndex: -1,
|
||||||
isHover: false,
|
isHover: false,
|
||||||
isHalf: false
|
isHalf: false,
|
||||||
|
currentValue: 0
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
// created () {
|
||||||
|
// this.currentValue = this.value;
|
||||||
|
// this.setHalf(this.currentValue);
|
||||||
|
// },
|
||||||
|
mounted () {
|
||||||
|
},
|
||||||
computed: {
|
computed: {
|
||||||
classes () {
|
classes () {
|
||||||
return [
|
return [
|
||||||
|
@ -63,24 +71,38 @@
|
||||||
value: {
|
value: {
|
||||||
immediate: true,
|
immediate: true,
|
||||||
handler (val) {
|
handler (val) {
|
||||||
this.setHalf(val);
|
this.currentValue = val;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// valur (val) {
|
||||||
|
// console.log(val);
|
||||||
|
// this.currentValue = val;
|
||||||
|
// console.log(this.currentValue);
|
||||||
|
// },
|
||||||
|
currentValue: {
|
||||||
|
immediate: true,
|
||||||
|
handler (val) {
|
||||||
|
this.setHalf(this.currentValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// currentValue () {
|
||||||
|
// this.setHalf(this.currentValue);
|
||||||
|
// }
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
starCls (value) {
|
starCls (value) {
|
||||||
const hoverIndex = this.hoverIndex;
|
const hoverIndex = this.hoverIndex;
|
||||||
const currentIndex = this.isHover ? hoverIndex : this.value;
|
const currentIndex = this.isHover ? hoverIndex : this.currentValue;
|
||||||
|
|
||||||
let full = false;
|
let full = false;
|
||||||
let isLast = false;
|
let isLast = false;
|
||||||
|
|
||||||
if (currentIndex > value) full = true;
|
if (currentIndex >= value) full = true;
|
||||||
|
|
||||||
if (this.isHover) {
|
if (this.isHover) {
|
||||||
isLast = currentIndex === value + 1;
|
isLast = currentIndex === value;
|
||||||
} else {
|
} else {
|
||||||
isLast = Math.ceil(this.value) === value + 1;
|
isLast = Math.ceil(this.currentValue) === value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
|
@ -102,13 +124,13 @@
|
||||||
} else {
|
} else {
|
||||||
this.isHalf = false;
|
this.isHalf = false;
|
||||||
}
|
}
|
||||||
this.hoverIndex = value + 1;
|
this.hoverIndex = value;
|
||||||
},
|
},
|
||||||
handleMouseleave () {
|
handleMouseleave () {
|
||||||
if (this.disabled) return;
|
if (this.disabled) return;
|
||||||
|
|
||||||
this.isHover = false;
|
this.isHover = false;
|
||||||
this.setHalf(this.value);
|
this.setHalf(this.currentValue);
|
||||||
this.hoverIndex = -1;
|
this.hoverIndex = -1;
|
||||||
},
|
},
|
||||||
setHalf (val) {
|
setHalf (val) {
|
||||||
|
@ -116,11 +138,13 @@
|
||||||
},
|
},
|
||||||
handleClick (value) {
|
handleClick (value) {
|
||||||
if (this.disabled) return;
|
if (this.disabled) return;
|
||||||
value++;
|
// value++;
|
||||||
if (this.isHalf) value -= 0.5;
|
if (this.isHalf) value -= 0.5;
|
||||||
this.value = value;
|
this.currentValue = value;
|
||||||
this.$emit('on-change', value);
|
this.$emit('on-change', this.currentValue);
|
||||||
this.$dispatch('on-form-change', value);
|
this.$emit('input', this.currentValue);
|
||||||
|
// @todo
|
||||||
|
// this.$dispatch('on-form-change', value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,7 +28,7 @@ import InputNumber from './components/input-number';
|
||||||
// import Poptip from './components/poptip';
|
// import Poptip from './components/poptip';
|
||||||
import Progress from './components/progress';
|
import Progress from './components/progress';
|
||||||
import Radio from './components/radio';
|
import Radio from './components/radio';
|
||||||
// import Rate from './components/rate';
|
import Rate from './components/rate';
|
||||||
// import Slider from './components/slider';
|
// import Slider from './components/slider';
|
||||||
// import Spin from './components/spin';
|
// import Spin from './components/spin';
|
||||||
import Steps from './components/steps';
|
import Steps from './components/steps';
|
||||||
|
@ -91,7 +91,7 @@ const iview = {
|
||||||
Progress,
|
Progress,
|
||||||
Radio,
|
Radio,
|
||||||
RadioGroup: Radio.Group,
|
RadioGroup: Radio.Group,
|
||||||
// Rate,
|
Rate,
|
||||||
Row,
|
Row,
|
||||||
// iSelect: Select,
|
// iSelect: Select,
|
||||||
// Slider,
|
// Slider,
|
||||||
|
|
|
@ -32,6 +32,7 @@ li + li { border-left: solid 1px #bbb; padding-left: 10px; margin-left: 10px; }
|
||||||
<li><router-link to="/carousel">Carousel</router-link></li>
|
<li><router-link to="/carousel">Carousel</router-link></li>
|
||||||
<li><router-link to="/card">Card</router-link></li>
|
<li><router-link to="/card">Card</router-link></li>
|
||||||
<li><router-link to="/tree">Tree</router-link></li>
|
<li><router-link to="/tree">Tree</router-link></li>
|
||||||
|
<li><router-link to="/rate">Rate</router-link></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<router-view></router-view>
|
<router-view></router-view>
|
||||||
|
|
|
@ -92,6 +92,10 @@ const router = new VueRouter({
|
||||||
{
|
{
|
||||||
path: '/tree',
|
path: '/tree',
|
||||||
component: require('./routers/tree.vue')
|
component: require('./routers/tree.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/rate',
|
||||||
|
component: require('./routers/rate.vue')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,19 @@
|
||||||
<template>
|
<template>
|
||||||
<Row>
|
<Row>
|
||||||
<i-col span="12">
|
<i-col span="12">
|
||||||
<Rate show-text :value.sync="valueText"></Rate>
|
<Rate show-text :value="valueText"></Rate>
|
||||||
</i-col>
|
</i-col>
|
||||||
<i-col span="12">
|
<i-col span="12">
|
||||||
<Rate show-text :value.sync="valueCustomText">
|
<Rate show-text v-model="valueCustomText" >
|
||||||
<span style="color: #f5a623">{{ valueCustomText }}</span>
|
<span style="color: #f5a623">{{ valueCustomText }}</span>
|
||||||
</Rate>
|
</Rate>
|
||||||
</i-col>
|
</i-col>
|
||||||
|
<i-col span="12">
|
||||||
|
<Rate disabled :value="valueDisabled"></Rate>
|
||||||
|
</i-col>
|
||||||
|
<i-col span="12">
|
||||||
|
<Rate allow-half :value="valueHalf" v-on:on-change="changeValue"></Rate>
|
||||||
|
</i-col>
|
||||||
</Row>
|
</Row>
|
||||||
</template>
|
</template>
|
||||||
<script>
|
<script>
|
||||||
|
@ -16,10 +22,16 @@
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
valueText: 3,
|
valueText: 3,
|
||||||
valueCustomText: 3.8
|
valueCustomText: 3.8,
|
||||||
|
valueDisabled: 2,
|
||||||
|
valueHalf: 2.5
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
computed: {},
|
computed: {},
|
||||||
methods: {}
|
methods: {
|
||||||
|
changeValue (val) {
|
||||||
|
console.log(val);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
Loading…
Add table
Reference in a new issue