This commit is contained in:
梁灏 2018-06-21 16:05:40 +08:00
parent 1ead5bb6c4
commit b9ecbd5384
3 changed files with 45 additions and 9 deletions

View file

@ -9,6 +9,7 @@
show-text show-text
v-model="characterValue" v-model="characterValue"
character="好"/> character="好"/>
<Rate allow-half v-model="cv" icon="ios-heart" />
<!--<Rate show-text v-model="valueText"></Rate>--> <!--<Rate show-text v-model="valueText"></Rate>-->
<!--<Rate show-text allow-half v-model="valueCustomText">--> <!--<Rate show-text allow-half v-model="valueCustomText">-->
<!--<span style="color: #f5a623">{{ valueCustomText }}</span>--> <!--<span style="color: #f5a623">{{ valueCustomText }}</span>-->
@ -27,7 +28,8 @@
valueDisabled: 2.4, valueDisabled: 2.4,
valueClear: 1, valueClear: 1,
valueClearHalf: 1.5, valueClearHalf: 1.5,
characterValue: 2.5 characterValue: 2.5,
cv: 3.5
} }
} }
} }

View file

@ -7,13 +7,23 @@
@mousemove="handleMousemove(item, $event)" @mousemove="handleMousemove(item, $event)"
:key="item" :key="item"
@click="handleClick(item)"> @click="handleClick(item)">
<div :class="starCls(item)" v-if="!character"> <template v-if="!showCharacter">
<span :class="[prefixCls + '-star-content']" type="half"></span> <span :class="[prefixCls + '-star-content']" type="half"></span>
</div> </template>
<div :class="starCls(item)" v-else> <template v-else>
<template v-if="character !== ''">
<span :class="[prefixCls + '-star-first']" type="half">{{ character }}</span> <span :class="[prefixCls + '-star-first']" type="half">{{ character }}</span>
<span :class="[prefixCls + '-star-second']">{{ character }}</span> <span :class="[prefixCls + '-star-second']">{{ character }}</span>
</div> </template>
<template v-else>
<span :class="[prefixCls + '-star-first']" type="half">
<i :class="iconClasses" type="half"></i>
</span>
<span :class="[prefixCls + '-star-second']">
<i :class="iconClasses"></i>
</span>
</template>
</template>
</div> </div>
<div :class="[prefixCls + '-text']" v-if="showText" v-show="currentValue > 0"> <div :class="[prefixCls + '-text']" v-if="showText" v-show="currentValue > 0">
<slot><span>{{ currentValue }}</span> <span v-if="currentValue <= 1">{{ t('i.rate.star') }}</span><span v-else>{{ t('i.rate.stars') }}</span></slot> <slot><span>{{ currentValue }}</span> <span v-if="currentValue <= 1">{{ t('i.rate.star') }}</span><span v-else>{{ t('i.rate.stars') }}</span></slot>
@ -24,11 +34,14 @@
import Locale from '../../mixins/locale'; import Locale from '../../mixins/locale';
import Emitter from '../../mixins/emitter'; import Emitter from '../../mixins/emitter';
import Icon from '../icon/icon.vue';
const prefixCls = 'ivu-rate'; const prefixCls = 'ivu-rate';
export default { export default {
name: 'Rate', name: 'Rate',
mixins: [ Locale, Emitter ], mixins: [ Locale, Emitter ],
components: { Icon },
props: { props: {
count: { count: {
type: Number, type: Number,
@ -60,6 +73,14 @@
character: { character: {
type: String, type: String,
default: '' default: ''
},
icon: {
type: String,
default: ''
},
customIcon: {
type: String,
default: ''
} }
}, },
data () { data () {
@ -79,6 +100,18 @@
[`${prefixCls}-disabled`]: this.disabled [`${prefixCls}-disabled`]: this.disabled
} }
]; ];
},
iconClasses () {
return [
`ivu-icon`,
{
[`ivu-icon-${this.icon}`]: this.icon !== '',
[`${this.customIcon}`]: this.customIcon !== '',
}
];
},
showCharacter () {
return this.character !== '' || this.icon !== '' || this.customIcon !== '';
} }
}, },
watch: { watch: {
@ -107,8 +140,8 @@
return [ return [
{ {
[`${prefixCls}-star`]: !this.character, [`${prefixCls}-star`]: !this.showCharacter,
[`${prefixCls}-star-chart`]: this.character, [`${prefixCls}-star-chart`]: this.showCharacter,
[`${prefixCls}-star-full`]: (!isLast && full) || (isLast && !this.isHalf), [`${prefixCls}-star-full`]: (!isLast && full) || (isLast && !this.isHalf),
[`${prefixCls}-star-half`]: isLast && this.isHalf, [`${prefixCls}-star-half`]: isLast && this.isHalf,
[`${prefixCls}-star-zero`]: !full [`${prefixCls}-star-zero`]: !full

View file

@ -36,6 +36,7 @@
user-select: none; user-select: none;
transition: all .3s ease; transition: all .3s ease;
color: #e9e9e9; color: #e9e9e9;
cursor: pointer;
} }
&-star-chart { &-star-chart {