WRate 组件
评分组件,基于 WinDesignNext Rate 封装,用于对事物进行评级操作,支持 modelValue 数据绑定和 action 事件响应。
基础用法
API
| 属性 | 类型 | 默认值 | 说明 |
|---|---|---|---|
component | string | WRate | 组件类型(必填) |
modelValue | DataBindingValue | 0 | 当前分值,支持 path 双向绑定 |
max | number | 5 | 最大分值 |
allowHalf | boolean | false | 是否允许半星 |
disabled | boolean | false | 是否禁用 |
showScore | boolean | false | 是否显示当前分数 |
showText | boolean | false | 是否显示辅助文字 |
texts | string[] | - | 各分数段辅助文字 |
colors | string[] | object | - | 各分数段颜色 |
voidColor | string | - | 未选中颜色 |
lowThreshold | number | 2 | 低分阈值 |
highThreshold | number | 4 | 高分阈值 |
scoreTemplate | string | {value} | 分数显示模板 |
clearable | boolean | false | 再次点击是否可清空 |
size | string | default | 尺寸:large / default / small / mini |
action | Action | - | 评分变化事件 |
path 支持说明
通用绑定格式见 path 数据绑定速查。
| 属性 | path 支持 | 说明 |
|---|---|---|
modelValue | ✅ | 评分值双向绑定 |
action.event.context[].value | ✅ | 事件上下文可引用 dataModel |
max / texts / allowHalf 等 | ❌ | 静态配置;动态变更请用 updateProp |
modelValue 数据绑定
json
{
"id": "rate_satisfaction",
"component": "WRate",
"allowHalf": true,
"showText": true,
"modelValue": { "path": "/satisfaction" },
"action": {
"event": {
"name": "onSatisfactionChange",
"context": [{ "key": "satisfaction", "value": { "path": "/satisfaction" } }]
}
}
}配合 updateDataModel 设置初始值:
json
{
"version": "v0.9",
"updateDataModel": {
"surfaceId": "main",
"path": "/",
"value": {
"satisfaction": 4
}
}
}action 定义
评分变化时触发,默认 type 为 change。
json
{
"action": {
"event": {
"name": "onSatisfactionChange",
"type": "change",
"context": [{ "key": "satisfaction", "value": { "path": "/satisfaction" } }]
}
}
}配合 WForm 使用
json
[
{
"id": "form_item_satisfaction",
"component": "WFormItem",
"label": "就诊满意度",
"prop": "satisfaction",
"children": ["rate_satisfaction"]
},
{
"id": "rate_satisfaction",
"component": "WRate",
"allowHalf": true,
"modelValue": { "path": "/satisfaction" },
"action": {
"event": {
"name": "onSatisfactionChange",
"context": [{ "key": "satisfaction", "value": { "path": "/satisfaction" } }]
}
}
}
]事件处理
评分变化事件
typescript
processor.onEvent((event) => {
const { name, context } = event.message.userAction ?? {};
if (name === 'onSatisfactionChange') {
console.log('满意度已更新:', context?.satisfaction);
}
});数据同步机制
WRate 在评分变化后会自动将值同步到 dataModel,流程与 WInputNumber、WSwitch 一致:
- 用户点击星级
- 组件触发
change事件 modelValue.path指向的 dataModel 字段自动更新- 若配置了
action,同步派发 A2UI 客户端事件