2017-11-01 09:03:42 +00:00
|
|
|
<template>
|
|
|
|
<li
|
|
|
|
:class="getClassName()"
|
|
|
|
@click="onClick"
|
|
|
|
@mousemove="onHover">
|
|
|
|
<div :class="`${this.prefixCls}-first`"><slot></slot></div>
|
|
|
|
<div :class="`${this.prefixCls}-second`"><slot></slot></div>
|
|
|
|
</li>
|
|
|
|
</template>
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
name: 'Star',
|
|
|
|
props: {
|
|
|
|
index: Number,
|
|
|
|
disabled: Boolean,
|
|
|
|
prefixCls: String,
|
|
|
|
allowHalf: Boolean,
|
|
|
|
value: Number,
|
|
|
|
},
|
2017-11-02 07:05:31 +00:00
|
|
|
data () {
|
2017-11-01 09:03:42 +00:00
|
|
|
return {
|
|
|
|
}
|
|
|
|
},
|
|
|
|
methods: {
|
2017-11-02 07:05:31 +00:00
|
|
|
getClassName () {
|
|
|
|
const { prefixCls, index, value, allowHalf } = this
|
|
|
|
const starValue = index
|
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-02 07:05:31 +00:00
|
|
|
onClick (e) {
|
|
|
|
if (this.disabled) return
|
|
|
|
this.$emit('onClick', 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
|
|
|
|
this.$emit('onHover', e, this.index)
|
2017-11-01 09:03:42 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|