WTimePicker 组件
时间选择器组件,基于 WinDesignNext TimePicker Pro 封装(渲染层内部使用 WTimePickerPro),用于选择或输入时刻、时刻范围,支持数据绑定和事件响应。
推荐配合
valueFormat使用:建议设置valueFormat: "HH:mm:ss",使modelValue以字符串形式存储在 dataModel 中。
基础用法
Props API
| 属性名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
id | string | - | 组件唯一标识(必填) |
component | string | WTimePicker | 组件类型(必填) |
modelValue | object | - | 绑定值(A2UI 数据绑定,支持 path) |
isRange | boolean | false | 是否为时刻范围选择 |
size | string | default | 输入框尺寸 |
readonly | boolean | false | 是否只读 |
disabled | boolean | false | 是否禁用 |
editable | boolean | true | 文本框是否可输入 |
clearable | boolean | true | 是否可清空 |
placeholder | string | '' | 占位文本 |
startPlaceholder | string | - | 范围选择开始占位 |
endPlaceholder | string | - | 范围选择结束占位 |
format | string/object | - | 输入框显示格式(支持 path) |
valueFormat | string/object | - | 绑定值格式(支持 path) |
arrowControl | boolean | false | 是否使用箭头选择 |
rangeSeparator | string | - | 范围分隔符 |
teleported | boolean | true | 下拉层是否挂载到 body |
appendTo | string | - | 下拉层挂载目标 |
popperClass | string | - | 下拉框自定义类名 |
prefixIcon | string/object | - | 前缀图标 |
clearIcon | string/object | CircleCloseFilled | 清空图标 |
tabindex | string/number | 0 | Tab 键顺序 |
name | string | - | 原生 name 属性 |
ariaLabel | string | - | 无障碍标签 |
plain | boolean | false | 朴素模式 |
emitFormattedValue | boolean | false | change 事件是否附带格式化字符串 |
action | object | - | A2UI v0.9 事件定义 |
path 支持说明
通用绑定格式见 path 数据绑定速查。
| 属性 | 支持 path | 说明 |
|---|---|---|
modelValue | ✅ | 双向绑定选中值(单选或范围数组) |
format | ✅ | 动态控制输入框显示格式 |
valueFormat | ✅ | 动态控制绑定值格式 |
action.event.context[].value | ✅ | 事件上下文可引用 dataModel |
action.event.api.constParams[].value | ✅ | API 固定参数可引用 dataModel |
placeholder / isRange / disabled 等 | ❌ | 静态配置;动态变更请用 updateProp |
format / valueFormat 绑定示例:
json
{
"format": { "path": "/timeDisplayFormat" },
"valueFormat": { "path": "/timeValueFormat" },
"modelValue": { "path": "/startTime" }
}modelValue 绑定规则:
- 单选(
isRange: false):path 指向单个时刻值 - 范围选择(
isRange: true):path 指向长度为 2 的数组 - 设置
valueFormat后,值为对应格式字符串(如"09:30:00");未设置时在 dataModel 中以 ISO 8601 字符串存储
json
// 单选时刻
{ "modelValue": { "path": "/startTime" } }
// 时刻范围
{ "modelValue": { "path": "/timeRange" } }
// 初始值字面量
{ "modelValue": { "literalString": "09:30:00" } }modelValue 数据绑定
json
{
"id": "time_start",
"component": "WTimePicker",
"valueFormat": "HH:mm:ss",
"placeholder": "请选择开始时间",
"clearable": true,
"modelValue": { "path": "/startTime" },
"action": {
"event": {
"name": "onStartTimeChange",
"context": [{ "key": "startTime", "value": { "path": "/startTime" } }]
}
}
}action 定义
用户确认选定值时触发,默认 type 为 change。
json
{
"action": {
"event": {
"name": "onTimeChange",
"type": "change",
"context": [{ "key": "time", "value": { "path": "/startTime" } }]
}
}
}使用示例
基础时刻选择
json
{
"id": "time_001",
"component": "WTimePicker",
"valueFormat": "HH:mm:ss",
"placeholder": "请选择时间",
"clearable": true,
"modelValue": { "path": "/startTime" },
"action": {
"event": { "name": "onTimeChange" }
}
}时刻范围选择
json
{
"id": "time_range_001",
"component": "WTimePicker",
"isRange": true,
"valueFormat": "HH:mm:ss",
"startPlaceholder": "开始时间",
"endPlaceholder": "结束时间",
"modelValue": { "path": "/timeRange" },
"action": {
"event": {
"name": "onTimeRangeChange",
"context": [{ "key": "range", "value": { "path": "/timeRange" } }]
}
}
}配合 updateDataModel:
json
{
"version": "v0.9",
"updateDataModel": {
"surfaceId": "main",
"path": "/",
"value": {
"timeRange": ["09:00:00", "18:00:00"]
}
}
}箭头控制模式
json
{
"id": "time_arrow",
"component": "WTimePicker",
"arrowControl": true,
"valueFormat": "HH:mm:ss",
"placeholder": "请选择时间",
"modelValue": { "path": "/operatingTime" }
}配合 WForm 使用
json
[
{
"id": "form_item_time",
"component": "WFormItem",
"label": "手术时间",
"prop": "operatingTime",
"children": ["time_operating"]
},
{
"id": "time_operating",
"component": "WTimePicker",
"valueFormat": "HH:mm:ss",
"placeholder": "请选择",
"clearable": true,
"modelValue": { "path": "/operatingTime" },
"action": {
"event": {
"name": "onOperatingTimeChange",
"context": [{ "key": "time", "value": { "path": "/operatingTime" } }]
}
}
}
]事件处理
选择变化事件
typescript
processor.onEvent((event) => {
const eventName = event.message.userAction?.name;
const context = event.message.userAction?.context;
if (eventName === 'onTimeChange') {
// context: { time: "09:30:00" } 或 { range: ["09:00:00", "18:00:00"] }
console.log('选中值:', context);
event.resolve([]);
}
});数据同步
WTimePicker 在用户确认选择后会自动将值同步到 dataModel,流程与 WInput、WDatePicker 一致。
不支持 A2UI JSON 配置的能力
| 能力 | 原生属性 | 替代方案 |
|---|---|---|
| 禁用部分小时 | disabledHours | 暂不支持,需自定义渲染层扩展 |
| 禁用部分分钟 | disabledMinutes | 暂不支持 |
| 禁用部分秒 | disabledSeconds | 暂不支持 |
| 默认打开时刻 | defaultValue | 通过 updateDataModel 设置 modelValue 初始值 |