Rater 评分组件

对评价进行展示或对事物进行快速的评级操作。

使用指南

在 page.json 中引入组件

  1. {
  2. "navigationBarTitleText": "Rater",
  3. "usingComponents": {
  4. "wux-cell-group": "../../dist/cell-group/index",
  5. "wux-cell": "../../dist/cell/index",
  6. "wux-rater": "../../dist/rater/index"
  7. }
  8. }

示例

  1. <view class="page">
  2. <view class="page__hd">
  3. <view class="page__title">Rater</view>
  4. <view class="page__desc">评分组件</view>
  5. </view>
  6. <view class="page__bd">
  7. <wux-cell-group title="Normal Usage">
  8. <wux-cell title="Set default score = 5" hover-class="none">
  9. <wux-rater slot="footer" default-value="{{ 5 }}" />
  10. </wux-cell>
  11. <wux-cell title="Change color" hover-class="none">
  12. <wux-rater slot="footer" default-value="{{ 3 }}" active-color="#33cd5f" />
  13. </wux-cell>
  14. </wux-cell-group>
  15. <wux-cell-group title="AllowHalf & AllowClear">
  16. <wux-cell title="AllowHalf = true" hover-class="none">
  17. <wux-rater slot="footer" allow-half default-value="{{ 2.5 }}" />
  18. </wux-cell>
  19. <wux-cell title="AllowClear = true" hover-class="none">
  20. <wux-rater slot="footer" allow-half allow-clear default-value="{{ 2.5 }}" />
  21. </wux-cell>
  22. <wux-cell title="AllowTouchMove = true" hover-class="none">
  23. <wux-rater slot="footer" allow-half allow-clear allow-touch-move default-value="{{ 2.5 }}" />
  24. </wux-cell>
  25. </wux-cell-group>
  26. <wux-cell-group title="Disabled = true">
  27. <wux-cell title="Your history score" hover-class="none">
  28. <wux-rater slot="footer" default-value="{{ 3 }}" disabled />
  29. </wux-cell>
  30. <wux-cell title="Decimal score 3.7" hover-class="none">
  31. <wux-rater slot="footer" default-value="{{ 3.7 }}" disabled />
  32. </wux-cell>
  33. <wux-cell title="Custom font-size(15px)" hover-class="none">
  34. <wux-rater slot="footer" default-value="{{ 3 }}" font-size="{{ 15 }}" disabled />
  35. </wux-cell>
  36. </wux-cell-group>
  37. <wux-cell-group title="Custom star">
  38. <wux-cell title="Loving" hover-class="none">
  39. <wux-rater slot="footer" default-value="{{ 3 }}" margin="{{ 15 }}" star="♡" />
  40. </wux-cell>
  41. <wux-cell title="Sunshine" hover-class="none">
  42. <wux-rater slot="footer" default-value="{{ 3 }}" margin="{{ 15 }}" star="☼" />
  43. </wux-cell>
  44. <wux-cell title="Smilies" hover-class="none">
  45. <wux-rater slot="footer" default-value="{{ 3 }}" margin="{{ 15 }}" star="☻" />
  46. </wux-cell>
  47. </wux-cell-group>
  48. <wux-cell-group title="Custom Icon">
  49. <wux-cell title="Loving" hover-class="none">
  50. <wux-rater slot="footer" default-value="{{ 3 }}" margin="{{ 15 }}" icon="ios-heart" />
  51. </wux-cell>
  52. <wux-cell title="Sunshine" hover-class="none">
  53. <wux-rater slot="footer" default-value="{{ 3 }}" margin="{{ 15 }}" icon="ios-sunny" />
  54. </wux-cell>
  55. <wux-cell title="Smilies" hover-class="none">
  56. <wux-rater slot="footer" default-value="{{ 3 }}" margin="{{ 15 }}" icon="ios-happy" />
  57. </wux-cell>
  58. </wux-cell-group>
  59. <wux-cell-group title="Custom text">
  60. <wux-cell title="Star" hover-class="none">
  61. <view slot="footer">
  62. <wux-rater controlled value="{{ value }}" bind:change="onChange" />
  63. <text class="wux-rater__text">{{ value }} stars</text>
  64. </view>
  65. </wux-cell>
  66. </wux-cell-group>
  67. <wux-cell-group title="Set callback">
  68. <wux-cell title="How embarrass" hover-class="none">
  69. <wux-rater slot="footer" controlled value="{{ value }}" star="囧" bind:change="onChange" />
  70. </wux-cell>
  71. </wux-cell-group>
  72. <wux-cell-group title="Controlled">
  73. <wux-cell title="Very good" hover-class="none">
  74. <wux-rater slot="footer" controlled value="{{ slider }}" star="屌" bind:change="sliderChange" />
  75. </wux-cell>
  76. <wux-cell hover-class="none">
  77. <slider value="{{ slider }}" show-value min="0" max="5" bindchange="sliderChange" />
  78. </wux-cell>
  79. </wux-cell-group>
  80. <wux-cell-group title="Set callback">
  81. <block wx:for="{{ items }}" wx:key="">
  82. <wux-cell title="{{ item.text }}" hover-class="none">
  83. <wux-rater slot="footer" default-value="{{ item.value }}" />
  84. </wux-cell>
  85. </block>
  86. </wux-cell-group>
  87. </view>
  88. </view>
  1. Page({
  2. data: {
  3. items: [{
  4. id: '001',
  5. text: 'Face',
  6. value: 1,
  7. },
  8. {
  9. id: '002',
  10. text: 'Eye',
  11. value: 2,
  12. },
  13. ],
  14. slider: 0,
  15. },
  16. sliderChange(e) {
  17. this.setData({
  18. slider: e.detail.value,
  19. })
  20. },
  21. bindchange(e) {
  22. console.log(e)
  23. },
  24. })

视频演示

Rater

API

Rater props

参数 类型 描述 默认值
prefixCls string 自定义类名前缀 wux-rater
max number 最大值 5
icon string 图标名称,优先级高于 star -
star string 图标
defaultValue number 默认值,当 controlledfalse 时才生效 0
value number 当前数,当 controlledtrue 时才生效 0
activeColor string 图标激活的颜色 #ffc900
margin number 图标外边距 2
fontSize number 图标大小 25
disabled boolean 禁用点击 false
allowHalf boolean 是否允许半选 false
allowClear boolean 是否允许再次点击后清除 false
allowTouchMove boolean 是否允许触摸移动选中 false
controlled boolean 是否受控 说明文档 false
bind:change function 点击事件的回调函数 -

Rater externalClasses

名称 描述
wux-class 根节点样式类