ant-design-vue/components/rate/Star.vue

42 lines
991 B
Vue
Raw Normal View History

2017-11-01 09:03:42 +00:00
<template>
<li
2017-11-09 09:24:00 +00:00
:class="getClassName"
2017-11-01 09:03:42 +00:00
@click="onClick"
@mousemove="onHover">
2017-11-09 09:24:00 +00:00
<div :class="`${prefixCls}-first`"><slot></slot></div>
<div :class="`${prefixCls}-second`"><slot></slot></div>
2017-11-01 09:03:42 +00:00
</li>
</template>
<script>
export default {
name: 'Star',
props: {
index: Number,
disabled: Boolean,
prefixCls: String,
allowHalf: Boolean,
value: Number,
},
2017-11-09 09:24:00 +00:00
computed: {
2017-11-02 07:05:31 +00:00
getClassName () {
const { prefixCls, index, value, allowHalf } = this
2017-11-09 09:24:00 +00:00
const starValue = index + 1
2017-11-01 09:03:42 +00:00
if (allowHalf && value + 0.5 === starValue) {
2017-11-02 07:05:31 +00:00
return `${prefixCls} ${prefixCls}-half ${prefixCls}-active`
2017-11-01 09:03:42 +00:00
}
2017-11-02 07:05:31 +00:00
return starValue <= value ? `${prefixCls} ${prefixCls}-full` : `${prefixCls} ${prefixCls}-zero`
2017-11-01 09:03:42 +00:00
},
2017-11-09 09:24:00 +00:00
},
methods: {
2017-11-02 07:05:31 +00:00
onClick (e) {
if (this.disabled) return
2017-11-09 09:24:00 +00:00
this.$emit('click', e, this.index)
2017-11-01 09:03:42 +00:00
},
2017-11-02 07:05:31 +00:00
onHover (e) {
if (this.disabled) return
2017-11-09 09:24:00 +00:00
this.$emit('hover', e, this.index)
2017-11-01 09:03:42 +00:00
},
},
}
</script>