feat: update rate

pull/309/head
tangjinzhou 2018-12-10 22:38:49 +08:00
parent 1d72ddf6bc
commit e7319f3987
5 changed files with 63 additions and 77 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
import PropTypes from '../_util/vue-types' import PropTypes from '../_util/vue-types'
import { initDefaultProps, getOptionProps } from '../_util/props-util' import { initDefaultProps, getOptionProps, getComponentFromProp } from '../_util/props-util'
import VcRate from '../vc-rate' import VcRate from '../vc-rate'
import Icon from '../icon' import Icon from '../icon'
@ -34,27 +34,19 @@ const Rate = {
}, },
}, },
render () { render () {
const { character, ...restProps } = getOptionProps(this) const character = getComponentFromProp(this, 'character') || <Icon type='star' theme='filled' />
const slotCharacter = this.$slots.character
const rateProps = { const rateProps = {
props: { props: {
character, character,
...restProps, ...getOptionProps(this),
}, },
on: this.$listeners, on: this.$listeners,
ref: 'refRate', ref: 'refRate',
} }
const slotCharacterHtml = slotCharacter !== undefined ? (
<template slot='character'>{slotCharacter}</template>
) : <Icon slot='character' type='star' />
return ( return (
<VcRate <VcRate
{...rateProps} {...rateProps}
> />
{
character === undefined ? slotCharacterHtml : null
}
</VcRate>
) )
}, },
} }

View File

@ -1,7 +1,7 @@
import PropTypes from '../../_util/vue-types' import PropTypes from '../../_util/vue-types'
import classNames from 'classnames' import classNames from 'classnames'
import KeyCode from '../../_util/KeyCode' import KeyCode from '../../_util/KeyCode'
import { initDefaultProps, hasProp, getOptionProps } from '../../_util/props-util' import { initDefaultProps, hasProp, getOptionProps, getComponentFromProp } from '../../_util/props-util'
import BaseMixin from '../../_util/BaseMixin' import BaseMixin from '../../_util/BaseMixin'
import { getOffsetLeft } from './util' import { getOffsetLeft } from './util'
import Star from './Star' import Star from './Star'
@ -169,13 +169,12 @@ export default {
allowHalf, allowHalf,
prefixCls, prefixCls,
disabled, disabled,
character,
tabIndex, tabIndex,
} = getOptionProps(this) } = getOptionProps(this)
const { sValue, hoverValue, focused } = this const { sValue, hoverValue, focused } = this
const stars = [] const stars = []
const disabledClass = disabled ? `${prefixCls}-disabled` : '' const disabledClass = disabled ? `${prefixCls}-disabled` : ''
const slotCharacter = this.$slots.character const character = getComponentFromProp(this, 'character')
for (let index = 0; index < count; index++) { for (let index = 0; index < count; index++) {
const starProps = { const starProps = {
props: { props: {
@ -185,7 +184,7 @@ export default {
prefixCls: `${prefixCls}-star`, prefixCls: `${prefixCls}-star`,
allowHalf, allowHalf,
value: hoverValue === undefined ? sValue : hoverValue, value: hoverValue === undefined ? sValue : hoverValue,
character: slotCharacter === undefined ? character : undefined, character,
focused, focused,
}, },
on: { on: {
@ -198,11 +197,7 @@ export default {
stars.push( stars.push(
<Star <Star
{...starProps} {...starProps}
> />
{
slotCharacter !== undefined ? (<template slot='character'>{slotCharacter}</template>) : null
}
</Star>
) )
} }
return ( return (

View File

@ -1,5 +1,6 @@
import PropTypes from '../../_util/vue-types' import PropTypes from '../../_util/vue-types'
import BaseMixin from '../../_util/BaseMixin' import BaseMixin from '../../_util/BaseMixin'
import { getComponentFromProp } from '../../_util/props-util'
function noop () {} function noop () {}
export default { export default {
@ -52,10 +53,8 @@ export default {
}, },
render () { render () {
const { onHover, onClick, onKeyDown, disabled, prefixCls, index, count, value } = this const { onHover, onClick, onKeyDown, disabled, prefixCls, index, count, value } = this
let character = this.character
if (character === undefined) { const character = getComponentFromProp(this, 'character')
character = this.$slots.character
}
return ( return (
<li <li
class={this.getClassName()} class={this.getClassName()}