diff --git a/example/pages/rate/index.js b/example/pages/rate/index.js
index 2cfa2e28..27dd601a 100644
--- a/example/pages/rate/index.js
+++ b/example/pages/rate/index.js
@@ -1,4 +1,5 @@
import Page from '../../common/page';
+import Toast from '../../dist/toast/toast';
Page({
data: {
@@ -8,5 +9,10 @@ Page({
value4: 2.5,
value5: 4,
value6: 3,
+ value8: 2,
+ },
+
+ onChange(event) {
+ Toast('当前值:' + event.detail);
},
});
diff --git a/example/pages/rate/index.wxml b/example/pages/rate/index.wxml
index db5e2605..03a45ae0 100644
--- a/example/pages/rate/index.wxml
+++ b/example/pages/rate/index.wxml
@@ -19,9 +19,9 @@
custom-class="rate-position"
model:value="{{ value3 }}"
size="{{ 25 }}"
- color="#ee0a24"
- void-color="#eee"
+ color="#ffd21e"
void-icon="star"
+ void-color="#eee"
/>
@@ -29,11 +29,9 @@
@@ -60,3 +58,13 @@
readonly
/>
+
+
+
+
+
+
diff --git a/packages/common/style/var.less b/packages/common/style/var.less
index 0ef2d169..a2141438 100644
--- a/packages/common/style/var.less
+++ b/packages/common/style/var.less
@@ -387,6 +387,10 @@
// Rate
@rate-horizontal-padding: 2px;
@rate-icon-size: 20px;
+@rate-icon-void-color: @gray-5;
+@rate-icon-full-color: @red;
+@rate-icon-disabled-color: @gray-5;
+@rate-icon-gutter: @padding-base;
// Switch
@switch-width: 2em;
diff --git a/packages/rate/README.md b/packages/rate/README.md
index 582766a7..02a76446 100644
--- a/packages/rate/README.md
+++ b/packages/rate/README.md
@@ -53,9 +53,9 @@ Page({
```
@@ -65,15 +65,27 @@ Page({
```html
```
+```javascript
+Page({
+ data: {
+ value: 2.5,
+ },
+
+ onChange(event) {
+ this.setData({
+ value: event.detail,
+ });
+ },
+});
+```
+
### 自定义数量
```html
@@ -92,26 +104,46 @@ Page({
```
+### 监听 change 事件
+
+评分变化时,会触发 `change` 事件。
+
+```html
+
+```
+
+```javascript
+Page({
+ data: {
+ value: 2,
+ },
+
+ onChange(event) {
+ Toast('当前值:' + event.detail);
+ },
+});
+```
+
## API
### Props
-| 参数 | 说明 | 类型 | 默认值 | 版本 |
-| --- | --- | --- | --- | --- |
-| name | 在表单内提交时的标识符 | _string_ | - | - |
-| value | 当前分值 | _number_ | - | - |
-| count | 图标总数 | _number_ | `5` | - |
-| size | 图标大小,默认单位为 `px` | _string \| number_ | `20px` | - |
-| gutter | 图标间距,默认单位为 `px` | _string \| number_ | `4px` |
-| color | 选中时的颜色 | _string_ | `#ffd21e` | - |
-| void-color | 未选中时的颜色 | _string_ | `#c7c7c7` | - |
-| icon | 选中时的图标名称或图片链接,可选值见 [Icon 组件](#/icon) | _string_ | `star` | - |
-| void-icon | 未选中时的图标名称或图片链接,可选值见 [Icon 组件](#/icon) | _string_ | `star-o` | - |
-| allow-half | 是否允许半选 | _boolean_ | `false` | - |
-| readonly | 是否为只读状态 | _boolean_ | `false` | - |
-| disabled | 是否禁用评分 | _boolean_ | `false` | - |
-| disabled-color | 禁用时的颜色 | _string_ | `#bdbdbd` | - |
-| touchable | 是否可以通过滑动手势选择评分 | _boolean_ | `true` | - |
+| 参数 | 说明 | 类型 | 默认值 |
+| -------------- | ----------------------------------------------------------- | ------------------ | --------- |
+| name | 在表单内提交时的标识符 | _string_ | - |
+| value | 当前分值 | _number_ | - |
+| count | 图标总数 | _number_ | `5` |
+| size | 图标大小,默认单位为 `px` | _string \| number_ | `20px` |
+| gutter | 图标间距,默认单位为 `px` | _string \| number_ | `4px` |
+| color | 选中时的颜色 | _string_ | `#ffd21e` |
+| void-color | 未选中时的颜色 | _string_ | `#c7c7c7` |
+| icon | 选中时的图标名称或图片链接,可选值见 [Icon 组件](#/icon) | _string_ | `star` |
+| void-icon | 未选中时的图标名称或图片链接,可选值见 [Icon 组件](#/icon) | _string_ | `star-o` |
+| allow-half | 是否允许半选 | _boolean_ | `false` |
+| readonly | 是否为只读状态 | _boolean_ | `false` |
+| disabled | 是否禁用评分 | _boolean_ | `false` |
+| disabled-color | 禁用时的颜色 | _string_ | `#bdbdbd` |
+| touchable | 是否可以通过滑动手势选择评分 | _boolean_ | `true` |
### Events
diff --git a/packages/rate/index.less b/packages/rate/index.less
index abfaedfc..2fc09747 100644
--- a/packages/rate/index.less
+++ b/packages/rate/index.less
@@ -8,11 +8,16 @@
&__item {
position: relative;
.theme(padding, '0 @rate-horizontal-padding');
+
+ &:not(:last-child) {
+ .theme(padding-right, '@rate-icon-gutter');
+ }
}
&__icon {
display: block;
height: 1em;
+ .theme(color, '@rate-icon-void-color');
.theme(font-size, '@rate-icon-size');
&--half {
@@ -21,6 +26,15 @@
width: 0.5em;
overflow: hidden;
.theme(left, '@rate-horizontal-padding');
+ .theme(color, '@rate-icon-full-color');
+ }
+
+ &--full {
+ .theme(color, '@rate-icon-full-color');
+ }
+
+ &--disabled {
+ .theme(color, '@rate-icon-disabled-color');
}
}
}
diff --git a/packages/rate/index.ts b/packages/rate/index.ts
index a42bc152..6a95c658 100644
--- a/packages/rate/index.ts
+++ b/packages/rate/index.ts
@@ -28,18 +28,9 @@ VantComponent({
type: String,
value: 'star-o',
},
- color: {
- type: String,
- value: '#ffd21e',
- },
- voidColor: {
- type: String,
- value: '#c7c7c7',
- },
- disabledColor: {
- type: String,
- value: '#bdbdbd',
- },
+ color: String,
+ voidColor: String,
+ disabledColor: String,
count: {
type: Number,
value: 5,
diff --git a/packages/rate/index.wxml b/packages/rate/index.wxml
index 58eee5cd..049714c4 100644
--- a/packages/rate/index.wxml
+++ b/packages/rate/index.wxml
@@ -1,19 +1,20 @@
+