2017-11-01 09:03:42 +00:00
|
|
|
<script>
|
2017-12-13 09:58:05 +00:00
|
|
|
import { deepClone } from './util'
|
|
|
|
|
2017-11-01 09:03:42 +00:00
|
|
|
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
|
|
|
},
|
|
|
|
},
|
2017-12-13 09:58:05 +00:00
|
|
|
render (createElement) {
|
|
|
|
return createElement('li', {
|
|
|
|
attrs: {
|
|
|
|
class: this.getClassName,
|
|
|
|
},
|
|
|
|
on: {
|
|
|
|
'click': this.onClick,
|
|
|
|
'mousemove': this.onHover,
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
createElement('div', {
|
|
|
|
attrs: {
|
|
|
|
class: `${this.prefixCls}-first`,
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
...this.$slots.default,
|
|
|
|
]),
|
|
|
|
createElement('div', {
|
|
|
|
attrs: {
|
|
|
|
class: `${this.prefixCls}-second`,
|
|
|
|
},
|
|
|
|
}, [
|
|
|
|
...deepClone(this.$slots.default, createElement),
|
|
|
|
]),
|
|
|
|
])
|
|
|
|
},
|
2017-11-01 09:03:42 +00:00
|
|
|
}
|
|
|
|
</script>
|