Commit df1303d6 authored by TtTao's avatar TtTao

新增:评分分级分层、评分半星显示

parent cc56616c
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<u-rate v-model="value" :count="count" @change="change" <u-rate v-model="value" :count="count" @change="change"
:active-color="activeColor" :inaction-color="inactiveColor" :active-color="activeColor" :inaction-color="inactiveColor"
:active-icon="activeIcon" :inactive-icon="inactiveIcon" :active-icon="activeIcon" :inactive-icon="inactiveIcon"
:disabled="disabled"></u-rate> :disabled="disabled" :colors="colors" :icons="icons"></u-rate>
</view> </view>
</view> </view>
<view class="u-config-wrap"> <view class="u-config-wrap">
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
<view class="u-item-title">自定义图标</view> <view class="u-item-title">自定义图标</view>
<u-subsection vibrateShort current="1" :list="['是', '否']" @change="iconChange"></u-subsection> <u-subsection vibrateShort current="1" :list="['是', '否']" @change="iconChange"></u-subsection>
</view> </view>
<view class="u-config-item">
<view class="u-item-title">是否分层</view>
<u-subsection vibrateShort current="1" :list="['是', '否']" @change="decimalChange"></u-subsection>
</view>
<view class="u-config-item"> <view class="u-config-item">
<view class="u-item-title">是否禁用</view> <view class="u-item-title">是否禁用</view>
<u-subsection vibrateShort current="1" :list="['是', '否']" @change="disabledChange"></u-subsection> <u-subsection vibrateShort current="1" :list="['是', '否']" @change="disabledChange"></u-subsection>
...@@ -53,7 +57,9 @@ ...@@ -53,7 +57,9 @@
count: 5, count: 5,
customIcon: false, customIcon: false,
plain: false, plain: false,
value: 0 value: 0,
colors: [],
icons: []
} }
}, },
watch: { watch: {
...@@ -93,6 +99,15 @@ ...@@ -93,6 +99,15 @@
this.inactiveColor = '#b2b2b2'; this.inactiveColor = '#b2b2b2';
} }
}, },
decimalChange(index) {
if(index == 0) {
this.colors = ['#ffc454', '#ffb409', '#ff9500'];
this.icons = ['thumb-down-fill', 'thumb-down-fill', 'thumb-up-fill', 'thumb-up-fill'];
} else {
this.colors = [];
this.icons = [];
}
},
iconChange(index) { iconChange(index) {
this.customIcon = !index; this.customIcon = !index;
}, },
......
...@@ -31,8 +31,6 @@ ...@@ -31,8 +31,6 @@
* @property {String} inactive-icon 未选中时的图标名,只能为uView的内置图标(默认star) * @property {String} inactive-icon 未选中时的图标名,只能为uView的内置图标(默认star)
* @property {String} gutter 星星之间的距离(默认10) * @property {String} gutter 星星之间的距离(默认10)
* @property {String Number} min-count 最少选中星星的个数(默认0) * @property {String Number} min-count 最少选中星星的个数(默认0)
* @property {Array} colors 颜色分级显示,可以用不同颜色区分评分层级
* @property {Array} icons 图标分级显示,可以用不同类型的icon区分评分层级
* @property {Boolean} allow-half 是否允许半星选择(默认false) * @property {Boolean} allow-half 是否允许半星选择(默认false)
* @event {Function} change 选中的星星发生变化时触发 * @event {Function} change 选中的星星发生变化时触发
* @example <u-rate :count="count" :current="2"></u-rate> * @example <u-rate :count="count" :current="2"></u-rate>
...@@ -108,14 +106,12 @@ export default { ...@@ -108,14 +106,12 @@ export default {
type: String, type: String,
default: 'uicon' default: 'uicon'
}, },
// 颜色分级显示,可以用不同颜色区分评分层级
colors: { colors: {
type: Array, type: Array,
default() { default() {
return [] return []
} }
}, },
// 图标分级显示,可以用不同类型的icon区分评分层级
icons: { icons: {
type: Array, type: Array,
default() { default() {
...@@ -153,8 +149,9 @@ export default { ...@@ -153,8 +149,9 @@ export default {
}, },
elActiveIcon() { elActiveIcon() {
const len = this.icons.length const len = this.icons.length
if (len) { if (len && len <= this.count) {
const step = Math.round(this.activeIndex / Math.round(this.count / len)) const step = Math.round(this.activeIndex / Math.round(this.count / len))
if (step < 1) return this.icons[0]
if (step > len) return this.icons[len - 1] if (step > len) return this.icons[len - 1]
return this.icons[step - 1] return this.icons[step - 1]
} }
...@@ -162,8 +159,9 @@ export default { ...@@ -162,8 +159,9 @@ export default {
}, },
elActiveColor() { elActiveColor() {
const len = this.colors.length const len = this.colors.length
if (len) { if (len && len <= this.count) {
const step = Math.round(this.activeIndex / Math.round(this.count / len)) const step = Math.round(this.activeIndex / Math.round(this.count / len))
if (step < 1) return this.colors[0]
if (step > len) return this.colors[len - 1] if (step > len) return this.colors[len - 1]
return this.colors[step - 1] return this.colors[step - 1]
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment