Skip to content

Commit df1303d

Browse files
committed
新增:评分分级分层、评分半星显示
1 parent cc56616 commit df1303d

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

pages/componentsB/rate/index.vue

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<u-rate v-model="value" :count="count" @change="change"
77
:active-color="activeColor" :inaction-color="inactiveColor"
88
:active-icon="activeIcon" :inactive-icon="inactiveIcon"
9-
:disabled="disabled"></u-rate>
9+
:disabled="disabled" :colors="colors" :icons="icons"></u-rate>
1010
</view>
1111
</view>
1212
<view class="u-config-wrap">
@@ -29,6 +29,10 @@
2929
<view class="u-item-title">自定义图标</view>
3030
<u-subsection vibrateShort current="1" :list="['是', '否']" @change="iconChange"></u-subsection>
3131
</view>
32+
<view class="u-config-item">
33+
<view class="u-item-title">是否分层</view>
34+
<u-subsection vibrateShort current="1" :list="['是', '否']" @change="decimalChange"></u-subsection>
35+
</view>
3236
<view class="u-config-item">
3337
<view class="u-item-title">是否禁用</view>
3438
<u-subsection vibrateShort current="1" :list="['是', '否']" @change="disabledChange"></u-subsection>
@@ -53,7 +57,9 @@
5357
count: 5,
5458
customIcon: false,
5559
plain: false,
56-
value: 0
60+
value: 0,
61+
colors: [],
62+
icons: []
5763
}
5864
},
5965
watch: {
@@ -93,6 +99,15 @@
9399
this.inactiveColor = '#b2b2b2';
94100
}
95101
},
102+
decimalChange(index) {
103+
if(index == 0) {
104+
this.colors = ['#ffc454', '#ffb409', '#ff9500'];
105+
this.icons = ['thumb-down-fill', 'thumb-down-fill', 'thumb-up-fill', 'thumb-up-fill'];
106+
} else {
107+
this.colors = [];
108+
this.icons = [];
109+
}
110+
},
96111
iconChange(index) {
97112
this.customIcon = !index;
98113
},

uview-ui/components/u-rate/u-rate.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@
3131
* @property {String} inactive-icon 未选中时的图标名,只能为uView的内置图标(默认star)
3232
* @property {String} gutter 星星之间的距离(默认10)
3333
* @property {String Number} min-count 最少选中星星的个数(默认0)
34-
* @property {Array} colors 颜色分级显示,可以用不同颜色区分评分层级
35-
* @property {Array} icons 图标分级显示,可以用不同类型的icon区分评分层级
3634
* @property {Boolean} allow-half 是否允许半星选择(默认false)
3735
* @event {Function} change 选中的星星发生变化时触发
3836
* @example <u-rate :count="count" :current="2"></u-rate>
@@ -108,14 +106,12 @@ export default {
108106
type: String,
109107
default: 'uicon'
110108
},
111-
// 颜色分级显示,可以用不同颜色区分评分层级
112109
colors: {
113110
type: Array,
114111
default() {
115112
return []
116113
}
117114
},
118-
// 图标分级显示,可以用不同类型的icon区分评分层级
119115
icons: {
120116
type: Array,
121117
default() {
@@ -153,17 +149,19 @@ export default {
153149
},
154150
elActiveIcon() {
155151
const len = this.icons.length
156-
if (len) {
152+
if (len && len <= this.count) {
157153
const step = Math.round(this.activeIndex / Math.round(this.count / len))
154+
if (step < 1) return this.icons[0]
158155
if (step > len) return this.icons[len - 1]
159156
return this.icons[step - 1]
160157
}
161158
return this.activeIcon
162159
},
163160
elActiveColor() {
164161
const len = this.colors.length
165-
if (len) {
162+
if (len && len <= this.count) {
166163
const step = Math.round(this.activeIndex / Math.round(this.count / len))
164+
if (step < 1) return this.colors[0]
167165
if (step > len) return this.colors[len - 1]
168166
return this.colors[step - 1]
169167
}

0 commit comments

Comments
 (0)