time 时间
time 时间
输入或选择时间的控件。
注意事项
-
格式化分为:数据格式化表示表单数据和显示格式化显示数据(等同 nzFormat 值)
-
所有 数据格式化 单位,参考 date-fns format(国内镜像:moment format)
-
指定 schema.format 则必须遵守 RFC3339 时间格式,否则都视为格式错误,默认的数据格式化:
- time、full-time 默认 HH:mm:ss
-
不指定 schema.format 根据 schema.type 值按以下规则处理(允许通过全局配置替换)数据格式化:
-
string 默认 HH:mm:ss
-
number 默认 T 13位 Unix Timestamp
-
由于 disabledHours、disabledMinutes、disabledSeconds 组合导致时间格式被破坏,可能会导致无法正常显示或显示不正确时可以指定一个完整的 Date 对象给默认值(schema.default 或 formData)
代码演示
基础样例
最简单的用法。
import { Component } from '@angular/core';import { SFSchema, SFTimeWidgetSchema } from '@delon/form';import { NzMessageService } from 'ng-zorro-antd/message';@Component({ selector: 'form-time-simple', template: ` <sf [schema]="schema" (formSubmit)="submit($event)"></sf> `,})export class FormTimeSimpleComponent { schema: SFSchema = { properties: { time: { type: 'string', ui: { widget: 'time' } as SFTimeWidgetSchema, }, time_number: { type: 'number', ui: { widget: 'time' } as SFTimeWidgetSchema, }, time_format: { type: 'string', format: 'time', ui: { format: `HH:mm:ss+00:00`, } as SFTimeWidgetSchema, }, '12hours': { type: 'string', ui: { widget: 'time', format: 'h:mm:ss a', use12Hours: true, } as SFTimeWidgetSchema, }, }, }; constructor(private msg: NzMessageService) {} submit(value: any) { this.msg.success(JSON.stringify(value)); }}
API
schema 属性
| [readOnly] |
禁用状态 |
boolean |
- |
|
|
|
|
ui 属性
| [size] |
大小,等同 nzSize |
string |
- |
|
|
|
|
| [placeholder] |
在文字框中显示提示讯息 |
string |
- |
|
|
|
|
| [format] |
数据格式化 |
string |
HH:mm:ss |
|
|
|
|
| [displayFormat] |
显示格式化,(等同 nzFormat 值) |
string |
HH:mm:ss |
|
|
|
|
| [utcEpoch] |
是否UTC新纪元(表示从 1970 开始计毫秒数),当 type=’number’ 时有效 |
boolean |
false |
|
|
|
|
| [allowEmpty] |
是否展示清除按钮 |
boolean |
true |
|
|
|
|
| [clearText] |
清除按钮的提示文案 |
string |
清除 |
|
|
|
|
| [defaultOpenValue] |
设置面板打开时默认选中的值 |
Date |
new Date() |
|
|
|
|
| [disabledHours] |
禁止选择部分小时选项 |
() => number[] |
- |
|
|
|
|
| [disabledMinutes] |
禁止选择部分分钟选项 |
(hour: number) => number[] |
- |
|
|
|
|
| [disabledSeconds] |
禁止选择部分秒选项 |
(hour: number, minute: number) => number[] |
- |
|
|
|
|
| [hideDisabledOptions] |
隐藏禁止选择的选项 |
boolean |
false |
|
|
|
|
| [hourStep] |
小时选项间隔 |
number |
1 |
|
|
|
|
| [minuteStep] |
分钟选项间隔 |
number |
1 |
|
|
|
|
| [secondStep] |
秒选项间隔 |
number |
1 |
|
|
|
|
| [popupClassName] |
弹出层类名 |
string |
- |
|
|
|
|
| [change] |
时间发生变化的回调 |
(value: Date) => void |
- |
|
|
|
|
| [openChange] |
面板打开/关闭时的回调 |
(status: boolean) => void |
- |
|
|
|
|