Skip to main content

Rating

WdRating

Applicable Scenarios

For rating input and display, using intuitive icons to represent the rating value.

Basic Capabilities Description

  1. The basic properties support selecting the component size and setting the current rating value.
  2. The advanced properties of the Rating component support configuring min value, max value, numerical adjustment step size, icon color (effective when using built-in icons), custom icons, and a tooltip copy generation function.

Extended Scenarios Description

How to Configure Step Size and Icon Display Style

Example

Configure the step size to 0.5, adjust the icon color, and set up custom icons.

Configuration Method

Configure Step Size: In the Scoring Attributes Area - Score Selector - Numerical Adjustment Step Size, enter 0.5 as the target step size.

Adjust icon color: In the Scoring Attributes Area - Score Selector - Icon Selected Color, enter rgb(255, 119, 158) as the target color; in the Icon Unselected Color input field below, enter rgb(132, 106, 165) as the target color.

Configure custom icons: In the Scoring Attributes Area - Score Selector - Default Icon, you can select the icon representing the current rating value; in the Scoring Attributes Area - Score Selector - Background Icon, you can select the icon to be displayed in the background. Both support selecting built-in icons and custom icons.

Example

Interactive Preview

Configure Minimum Value, Maximum Value, and Step Size

Custom Icon Color

Custom Icons

Configure Different Sizes

Custom Prompt Text

{
tooltip: ({ value }) => `Current rating value is: ${value}`;
}

Properties

组件接收的外部传入的属性

属性名
属性标识
类型
说明
显示标题labelVisibleboolean

默认值:true

标题对齐labelAlignstring

表单场景下默认会跟随表单容器的标题对齐配置

标题换行labelWrapboolean

如果标题内容过长关闭时只显示一行、溢出省略;开启时换行展示。表单场景下默认会跟随表单容器的标题换行配置

标题位置layoutstring

设置标题在表单组件的展示位置,表单场景下默认会跟随表单容器的标题的位置配置

标题宽度labelWidthstring

您可以输入数值 + px、%等单位,示例:200px

表单场景下默认会跟随表单容器的标题宽度配置

标题提示labelTipsstring

PC/H5端生效

配置标题的工具提示内容

最小值minnumber0
最大值maxnumber

默认值:5

数值调整步长stepnumber

控制单次评分变化的最小幅度

默认值:1

默认图标iconstring

默认评分图标

默认值:"td:star-filled"

自定义图标iconSrcstring

设置自定义图标地址

未选中图标backgroundIconstring

为空时,将使用默认图标显示未选中效果

评分背景图标

自定义未选中图标backgroundIconSrcstring

设置自定义图标地址

图标选中颜色foregroundColorstring

使用自定义图片作为图标时,颜色配置不生效

默认值:"#ffcf48"

图标未选中颜色backgroundColorstring

使用自定义图片作为图标时,颜色配置不生效

默认值:"#bfbfbf"

移动端显示下划线borderedH5boolean

关闭后移动端不显示底部下划线

默认值:true

callbacksobject

配置相关的函数

状态statusstring

默认值:"edit"

必填requiredboolean

启用后该组件强制必填,值不可为空

必填标识requiredFlagboolean

启用后,组件若要求必填,则会显示必填星号标记

默认值:true

必填校验提示requiredMsgstring

启用必填,但组件值为空时的提示信息

默认值:"该项为必填项"

绑定字段namestring

表单字段的Key值,用于提交数据时,匹配数据模型字段标识。页面内需保证唯一。

标题内容labelstring

示例:"标题"

评分值valuenumber

当前评分值

组件尺寸sizestring

控制评分组件的大小

默认值:"sm"

Events

组件暴露的事件,可以监听组件的事件来触发一些外部的动作

事件名
事件code
事件出参 event.detail
适用情况
说明
值改变changeobject
  • value: number

    评分值

兼容三端

-

Property API

通过属性 API,可以获取组件内部的状态和属性值,可以通过$w.componentId.propertyName 来访问组件内部的值,如 $w.input1.value ,详请请参考 属性 API

只读属性名
属性标识
类型
说明
绑定字段namestring

表单字段的Key值,用于提交数据时,匹配数据模型字段标识。页面内需保证唯一。

标题内容labelstring
评分值valuenumber

当前评分值

最小值minnumber
最大值maxnumber
数值调整步长stepnumber

控制单次评分变化的最小幅度

是否展示visibleboolean

组件是否展示

是否禁用disabledboolean

组件是否禁用

是否只读readOnlyboolean

组件是否只读

Method API

通过方法 API,可以通过程序触发组件内部的方法,比如提交表单,显示弹窗等, 可以通过$w.componentId.methodName来调用组件方法,如 $w.form1.submit()

方法名
方法标识
参数
方法说明
设置值setValuenumber

通过 $w.id1.setValue("weda") 设置组件值

设置显隐setVisibleboolean显示

通过 $w.id1.setVisible(false) 设置组件为隐藏

设置禁用setDisabledboolean禁用

通过 $w.id1.setDisabled(true) 设置组件为禁用

清空值clearValue

通过 $w.id1.clearValue() 清空组件值

设置只读setReadOnlyboolean只读

通过 $w.id1.setReadOnly(true) 设置组件为只读

触发校验handleValidate

通过 $w.id1.handleValidate() 校验组件值

清除校验clearValidate

通过 $w.id1.clearValidate() 清除组件校验

Style API

通过样式 API,可以覆盖组件中内部元素的样式来实现自定义,例如在低代码编辑器中中通过 #wd-page-root .wd-btn 即可为所有的按钮组件编写样式,通过 :scope 可以控制单个组件样式, 详细说明请参考样式 API

名称
类名
说明和示例
根元素.wd-rating-root组件最外层元素
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope.wd-rating-root {
  /* 在这里编写CSS 样式 */
}
H5 端根元素.wd-h5-rating-root可设定 H5 端的根元素样式
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope.wd-h5-rating-root {
  /* 在这里编写CSS 样式 */
}
PC 端根元素.wd-pc-rating-root可设定 PC 端的根元素样式
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope.wd-pc-rating-root {
  /* 在这里编写CSS 样式 */
}
小程序端根元素.wd-mp-rating-root可设定小程序端的根元素样式
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope.wd-mp-rating-root {
  /* 在这里编写CSS 样式 */
}
组件标题样式.wd-rating-root .wd-form-item-wrap__label组件标题元素

:scope .wd-form-item-wrap__label {
  font-size: 20px;
  color: gray;
  padding: 0;
  display: flex;
  align-items: center;
}
编辑态-校验信息.wd-rating-root .wd-g-text-error设置组件校验信息样式

:scope .wd-g-text-error {
    font-size: 20px;
    color: gray;
  }
提示文字.wd-rating-root .wd-form-item__help-text设置组件提示文字样式

:scope .wd-form-item__help-text {
    font-size: 20px;
    color: gray;
  }
评分组件.wd-rating
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope .wd-rating {
  /* 在这里编写CSS 样式 */
}
禁用态评分组件.wd-rating.is-disabled
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope .wd-rating.is-disabled {
  /* 在这里编写CSS 样式 */
}
禁用态评分组件.wd-rating.is-readonly
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope .wd-rating.is-readonly {
  /* 在这里编写CSS 样式 */
}
填充图标容器.wd-rating__full-icons-container填充图标元素们的父容器元素
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope .wd-rating__full-icons-container {
  /* 在这里编写CSS 样式 */
}
背景图标容器.wd-rating__empty-icons-container背景图标元素们的父容器元素
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope .wd-rating__empty-icons-container {
  /* 在这里编写CSS 样式 */
}
图标容器.wd-rating__icon-container图标元素的父容器元素
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope .wd-rating__icon-container {
  /* 在这里编写CSS 样式 */
}
图标.wd-rating__icon图标元素
/* :scope 指的是当前组件元素 */
/* 具体可参考样式 API 文档 */
:scope .wd-rating__icon {
  /* 在这里编写CSS 样式 */
}

了解样式 API