|
|
|
@ -1,32 +1,7 @@
|
|
|
|
|
<template> |
|
|
|
|
<ul |
|
|
|
|
:class="classes" |
|
|
|
|
@mouseleave="onMouseLeave"> |
|
|
|
|
<template v-for="i in count"> |
|
|
|
|
<Star |
|
|
|
|
ref="stars" |
|
|
|
|
:index="i - 1" |
|
|
|
|
:disabled="disabled" |
|
|
|
|
:prefix-cls="`${prefixCls}-star`" |
|
|
|
|
:allowHalf="allowHalf" |
|
|
|
|
:value="hoverValue === undefined ? stateValue : hoverValue" |
|
|
|
|
@click="onClick" |
|
|
|
|
@hover="onHover" |
|
|
|
|
:key="i - 1"> |
|
|
|
|
<template slot-scope="props"> |
|
|
|
|
<slot> |
|
|
|
|
<span>{{character}}</span> |
|
|
|
|
</slot> |
|
|
|
|
</template> |
|
|
|
|
</Star> |
|
|
|
|
</template> |
|
|
|
|
</ul> |
|
|
|
|
</template> |
|
|
|
|
|
|
|
|
|
<script> |
|
|
|
|
import Star from './Star.vue' |
|
|
|
|
import Icon from '../icon' |
|
|
|
|
import { getOffsetLeft } from './util' |
|
|
|
|
import { getOffsetLeft, deepClone } from './util' |
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
name: 'Rate', |
|
|
|
@ -73,13 +48,17 @@ export default {
|
|
|
|
|
[`${prefixCls}-disabled`]: disabled, |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
countList () { |
|
|
|
|
return new Array(this.count).fill(1) |
|
|
|
|
}, |
|
|
|
|
hasDefaultSlot () { |
|
|
|
|
return !!this.$slots.default |
|
|
|
|
}, |
|
|
|
|
}, |
|
|
|
|
methods: { |
|
|
|
|
onClick (event, index) { |
|
|
|
|
const value = this.getStarValue(index, event.pageX) |
|
|
|
|
if (this.value === undefined) { |
|
|
|
|
this.stateValue = value |
|
|
|
|
} |
|
|
|
|
this.stateValue = value |
|
|
|
|
this.onMouseLeave() |
|
|
|
|
this.$emit('input', value) |
|
|
|
|
this.$emit('change', value) |
|
|
|
@ -90,7 +69,7 @@ export default {
|
|
|
|
|
this.$emit('hover-change', value) |
|
|
|
|
}, |
|
|
|
|
getStarDOM (index) { |
|
|
|
|
return this.$refs.stars[index].$el |
|
|
|
|
return this.$refs['stars' + index].$el |
|
|
|
|
}, |
|
|
|
|
getStarValue (index, x) { |
|
|
|
|
const { allowHalf, getStarDOM } = this |
|
|
|
@ -119,5 +98,36 @@ export default {
|
|
|
|
|
Star, |
|
|
|
|
Icon, |
|
|
|
|
}, |
|
|
|
|
render (createElement, a) { |
|
|
|
|
const self = this |
|
|
|
|
return createElement('ul', { |
|
|
|
|
class: self.classes, |
|
|
|
|
on: { |
|
|
|
|
'mouseleave': self.onMouseLeave, |
|
|
|
|
}, |
|
|
|
|
}, [ |
|
|
|
|
( |
|
|
|
|
self.countList.map((item, i) => { |
|
|
|
|
return createElement('Star', { |
|
|
|
|
attrs: { |
|
|
|
|
index: i, |
|
|
|
|
disabled: self.disabled, |
|
|
|
|
'prefix-cls': `${self.prefixCls}-star`, |
|
|
|
|
allowHalf: self.allowHalf, |
|
|
|
|
value: self.hoverValue === undefined ? self.stateValue : self.hoverValue, |
|
|
|
|
}, |
|
|
|
|
ref: 'stars' + i, |
|
|
|
|
key: i, |
|
|
|
|
on: { |
|
|
|
|
'click': self.onClick, |
|
|
|
|
'hover': self.onHover, |
|
|
|
|
}, |
|
|
|
|
}, [ |
|
|
|
|
((self.hasDefaultSlot) ? (deepClone(self.$slots.default, createElement)) : this.character), |
|
|
|
|
]) |
|
|
|
|
}) |
|
|
|
|
), |
|
|
|
|
]) |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
</script> |
|
|
|
|