2020-07-28 10:03:53 +08:00
|
|
|
|
---
|
2021-06-03 22:09:30 +08:00
|
|
|
|
title: InputTime 时间
|
2020-08-04 19:21:46 +08:00
|
|
|
|
description:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
type: 0
|
|
|
|
|
group: null
|
2021-06-03 22:09:30 +08:00
|
|
|
|
menuName: InputTime 时间
|
2020-08-04 19:21:46 +08:00
|
|
|
|
icon:
|
2020-07-28 10:03:53 +08:00
|
|
|
|
order: 58
|
|
|
|
|
---
|
2020-08-04 19:21:46 +08:00
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 基本用法
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-time",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"name": "time",
|
|
|
|
|
"label": "时间"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
## 显示格式
|
|
|
|
|
|
|
|
|
|
选中任意时间,可以看到默认显示时间的格式是像`01:01`这样的格式,如果你想要自定义显示格式,那么可以配置`inputFormat`。
|
|
|
|
|
|
|
|
|
|
例如你想显示`01时01分`这样的格式,查找 moment 文档可知配置格式应为 `HH时mm分`,即:
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-time",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"name": "time",
|
|
|
|
|
"label": "时间",
|
|
|
|
|
"inputFormat": "HH时mm分"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
调整时间,观察显示格式
|
|
|
|
|
|
|
|
|
|
## 值格式
|
|
|
|
|
|
|
|
|
|
选中任意时间,可以看到默认表单项的值格式是像`1591862818`这样的时间戳格式。
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-time",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"name": "time",
|
|
|
|
|
"label": "时间"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-01-21 18:13:04 +08:00
|
|
|
|
如果你想要其他格式的日期值,那么可以配置`format`参数用于调整表单项的值格式。
|
2020-07-28 10:03:53 +08:00
|
|
|
|
|
|
|
|
|
例如你调整值为`01:11`这样的格式,查找 moment 文档可知配置格式应为 `HH:mm`,即:
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-time",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"name": "time",
|
|
|
|
|
"label": "时间",
|
|
|
|
|
"format": "HH:mm"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
调整时间,观察数据域中表单项值的变化
|
|
|
|
|
|
2020-11-12 16:46:20 +08:00
|
|
|
|
## 显示秒
|
|
|
|
|
|
|
|
|
|
默认显示的是时和分,要显示秒请参考以下配置
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-11-12 16:46:20 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-11-12 16:46:20 +08:00
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-time",
|
2020-11-12 16:46:20 +08:00
|
|
|
|
"name": "time",
|
|
|
|
|
"label": "时间",
|
|
|
|
|
"format": "HH:mm:ss",
|
|
|
|
|
"timeFormat": "HH:mm:ss",
|
|
|
|
|
"inputFormat": "HH:mm:ss"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 默认值
|
|
|
|
|
|
|
|
|
|
可以设置`value`属性,设置日期选择器的默认值
|
|
|
|
|
|
|
|
|
|
### 基本配置
|
|
|
|
|
|
|
|
|
|
配置符合当前 [值格式](./date#%E5%80%BC%E6%A0%BC%E5%BC%8F) 的默认值。
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-time",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"name": "time",
|
|
|
|
|
"label": "时间",
|
|
|
|
|
"value": "1591862818"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 相对值
|
|
|
|
|
|
|
|
|
|
`value` 还支持类似像`"+1hours"`这样的相对值,更加便捷的配置默认值
|
|
|
|
|
|
2021-01-07 23:35:03 +08:00
|
|
|
|
```schema: scope="body"
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2020-07-28 10:03:53 +08:00
|
|
|
|
{
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"type": "input-time",
|
2020-07-28 10:03:53 +08:00
|
|
|
|
"name": "time",
|
|
|
|
|
"label": "时间",
|
|
|
|
|
"value": "+1hours"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
上例中配置了`"value": "+1hours"`,默认就会选中一小时后。
|
|
|
|
|
|
|
|
|
|
支持的相对值关键字有:
|
|
|
|
|
|
|
|
|
|
- `now`: 当前时间
|
|
|
|
|
- `hour`或`hours`: 时
|
|
|
|
|
- `minute`或`minutes`: 分
|
|
|
|
|
- `second`或`seconds`: 秒
|
|
|
|
|
|
2022-03-17 16:07:51 +08:00
|
|
|
|
## 控制输入范围
|
|
|
|
|
|
|
|
|
|
通过 `timeConstraints` 属性可以控制输入范围
|
|
|
|
|
|
|
|
|
|
默认值是
|
|
|
|
|
|
|
|
|
|
```json
|
|
|
|
|
{
|
|
|
|
|
"hours": {
|
|
|
|
|
"min": 0,
|
|
|
|
|
"max": 23,
|
|
|
|
|
"step": 1
|
|
|
|
|
},
|
|
|
|
|
"minutes": {
|
|
|
|
|
"min": 0,
|
|
|
|
|
"max": 59,
|
|
|
|
|
"step": 1
|
|
|
|
|
},
|
|
|
|
|
"seconds": {
|
|
|
|
|
"min": 0,
|
|
|
|
|
"max": 59,
|
|
|
|
|
"step": 1
|
|
|
|
|
},
|
|
|
|
|
"milliseconds": {
|
|
|
|
|
"min": 0,
|
|
|
|
|
"max": 999,
|
|
|
|
|
"step": 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
可以只修改其中的部分值,比如下面的示例将分钟每次加减改成了 15,小时的范围限制在 9 到 17
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
|
|
|
|
"debug": true,
|
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
|
|
|
|
"body": [
|
|
|
|
|
{
|
|
|
|
|
"type": "input-time",
|
|
|
|
|
"name": "time",
|
|
|
|
|
"label": "时间",
|
|
|
|
|
"timeConstraints": {
|
|
|
|
|
"hours": {
|
|
|
|
|
"min": 9,
|
|
|
|
|
"max": 17
|
|
|
|
|
},
|
|
|
|
|
"minutes": {
|
|
|
|
|
"step": 15
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2021-03-26 14:23:45 +08:00
|
|
|
|
## 原生时间组件
|
|
|
|
|
|
|
|
|
|
原生时间组件将直接使用浏览器的实现,最终展现效果和浏览器有关,而且只支持 `min`、`max`、`step` 这几个属性设置。
|
|
|
|
|
|
|
|
|
|
```schema: scope="body"
|
|
|
|
|
{
|
|
|
|
|
"type": "form",
|
2021-08-09 18:05:01 +08:00
|
|
|
|
"api": "/api/mock2/form/saveForm",
|
2021-06-03 22:09:30 +08:00
|
|
|
|
"body": [
|
2021-03-26 14:23:45 +08:00
|
|
|
|
{
|
|
|
|
|
"type": "native-time",
|
|
|
|
|
"name": "time",
|
|
|
|
|
"label": "时间"
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
2020-07-28 10:03:53 +08:00
|
|
|
|
## 属性表
|
|
|
|
|
|
|
|
|
|
除了支持 [普通表单项属性表](./formitem#%E5%B1%9E%E6%80%A7%E8%A1%A8) 中的配置以外,还支持下面一些配置
|
|
|
|
|
|
|
|
|
|
| 属性名 | 类型 | 默认值 | 说明 |
|
|
|
|
|
| --------------- | --------- | -------------- | ----------------------------------------------------------------------------------- |
|
|
|
|
|
| value | `string` | | [默认值](./date#%E9%BB%98%E8%AE%A4%E5%80%BC) |
|
2020-11-12 16:46:20 +08:00
|
|
|
|
| timeFormat | `string` | `HH:mm` | 时间选择器值格式,更多格式类型请参考 [moment](http://momentjs.com/) |
|
2020-07-28 10:03:53 +08:00
|
|
|
|
| format | `string` | `X` | 时间选择器值格式,更多格式类型请参考 [moment](http://momentjs.com/) |
|
|
|
|
|
| inputFormat | `string` | `HH:mm` | 时间选择器显示格式,即时间戳格式,更多格式类型请参考 [moment](http://momentjs.com/) |
|
|
|
|
|
| placeholder | `string` | `"请选择时间"` | 占位文本 |
|
|
|
|
|
| clearable | `boolean` | `true` | 是否可清除 |
|
2022-04-26 21:12:00 +08:00
|
|
|
|
| timeConstraints | `object` | `true` | |
|
2022-03-17 21:25:12 +08:00
|
|
|
|
|
|
|
|
|
## 事件表
|
|
|
|
|
|
2022-04-26 21:12:00 +08:00
|
|
|
|
| 事件名称 | 事件参数 | 说明 |
|
|
|
|
|
| -------- | ---------------------- | -------------------- |
|
|
|
|
|
| change | `value: string` 时间值 | 值变化 |
|
2022-04-29 16:59:23 +08:00
|
|
|
|
| focus | `value: string` 时间值 | 获得焦点(非内嵌模式) |
|
|
|
|
|
| blur | `value: string` 时间值 | 失去焦点(非内嵌模式) |
|
2022-03-17 21:25:12 +08:00
|
|
|
|
|
|
|
|
|
## 动作表
|
|
|
|
|
|
2022-04-26 21:12:00 +08:00
|
|
|
|
| 动作名称 | 动作配置 | 说明 |
|
|
|
|
|
| -------- | ---------------------------- | ------------------------------------------------------ |
|
|
|
|
|
| clear | - | 清空 |
|
|
|
|
|
| reset | - | 将值重置为`resetValue`,若没有配置`resetValue`,则清空 |
|
|
|
|
|
| setValue | `value: string` 更新的时间值 | 更新数据,依赖格式`format`,例如:'1648746120' |
|