Files
mini-yu/uni_modules/tdesign-uniapp/components/date-time-picker/README.md
lingxiao865 c5af079d8c first commit
2026-02-10 08:05:03 +08:00

106 lines
5.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: DateTimePicker 时间选择器
description: 用于选择一个时间点或者一个时间段。
spline: form
isComponent: true
---
## 引入
可在 `main.ts` 或在需要使用的页面或组件中引入。
```js
import TDateTimePicker from '@tdesign/uniapp/date-time-picker/date-time-picker.vue';
```
### 组件类型
#### 年月日选择器
{{ year-month-date }}
#### 年月选择器
{{ year-month }}
### 时间选择器
包括:`时分秒``时分`两个示例
{{ time }}
#### 年月日时分秒选择器
{{ date-all }}
### 组件用法
#### 调整步数
{{ steps }}
#### 不使用 Popup
{{ without-popup }}
## API
### DateTimePicker Props
名称 | 类型 | 默认值 | 描述 | 必传
-- | -- | -- | -- | --
custom-style | Object | - | 自定义样式 | N
auto-close | Boolean | false | 自动关闭;在确认、取消、点击遮罩层自动关闭,不需要手动设置 visible | N
cancel-btn | String | 取消 | 取消按钮文字 | N
confirm-btn | String | - | 确定按钮文字 | N
custom-locale | String | zh | 组件国际化语言,目前支持: 简体中文(zh)、(tc)、英文(en)、日语(ja)、韩语(ko)、俄语(ru)等六种语言 | N
end | String / Number | - | 选择器的最大可选时间,默认为当前时间+10年 | N
filter | Function | - | 列选项过滤函数,支持自定义列内容。(type 值可为: year, month, date, hour, minute, second)。TS 类型:`(type: TimeModeValues, columns: DateTimePickerColumn) => DateTimePickerColumn` `type DateTimePickerColumn = DateTimePickerColumnItem[]` `interface DateTimePickerColumnItem { label: string,value: string}`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/date-time-picker/type.ts) | N
format | String | 'YYYY-MM-DD HH:mm:ss' | 用于格式化 pick、change、confirm 事件返回的值,[详细文档](https://day.js.org/docs/en/display/format) | N
formatter | Function | - | 格式化标签。TS 类型:`(option: DateTimePickerColumnItem, columnIndex: number) => DateTimePickerColumnItem` | N
header | Boolean | true | 头部内容。值为 true 显示空白头部,值为 false 不显示任何内容 | N
mode | String / Array | 'date' | year = 年month = 年月date = 年月日hour = 年月日时; minute = 年月日时分当类型为数组时第一个值控制年月日第二个值控制时分秒。TS 类型:`DateTimePickerMode` `type DateTimePickerMode = TimeModeValues \| Array<TimeModeValues> ` `type TimeModeValues = 'year' \| 'month' \| 'date' \| 'hour' \| 'minute' \| 'second' \| 'null'`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/date-time-picker/type.ts) | N
popup-props | Object | {} | 透传 Popup 组件全部属性。TS 类型:`PopupProps`[Popup API Documents](./popup?tab=api)。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/date-time-picker/type.ts) | N
show-week | Boolean | false | 是否在日期旁边显示周几(如周一,周二,周日等) | N
start | String / Number | - | 选择器的最小可选时间,默认为当前时间-10年 | N
steps | Object | {} | 时间间隔步数,示例:`{ minute: 5 }`。TS 类型:`{ [key in TimeModeValues]?: number }` | N
title | String | - | 标题 | N
use-popup | Boolean | true | 是否使用弹出层包裹 | N
value | String / Number | - | 选中值。支持语法糖 `v-model:value`。TS 类型:`DateValue` `type DateValue = string \| number`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/date-time-picker/type.ts) | N
default-value | String / Number | - | 选中值。非受控属性。TS 类型:`DateValue` `type DateValue = string \| number`。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/date-time-picker/type.ts) | N
visible | Boolean | false | 是否显示 | N
### DateTimePicker Events
名称 | 参数 | 描述
-- | -- | --
cancel | \- | 取消按钮点击时触发
change | `(context: { value: DateValue })` | 确认按钮点击时触发
close | `(context: { trigger: DateTimePickerTriggerSource })` | 关闭时触发。[详细类型定义](https://github.com/Tencent/tdesign-miniprogram/tree/develop/packages/uniapp-components/date-time-picker/type.ts)。<br/>`type DateTimePickerTriggerSource = 'overlay' \| 'cancel-btn' \| 'confirm-btn'`<br/>
confirm | `(context: { value: DateValue })` | 确认按钮点击时触发
pick | `(context: { value: DateValue })` | 选中值发生变化时触发
### DateTimePicker Slots
名称 | 描述
-- | --
footer | 底部内容
header | 自定义 `header` 显示内容
### DateTimePicker External Classes
类名 | 描述
-- | --
t-class | 根节点样式类
t-class-cancel | 取消样式类
t-class-confirm | 确认样式类
t-class-title | 标题样式类
### CSS Variables
组件提供了下列 CSS 变量,可用于自定义样式。
名称 | 默认值 | 描述
-- | -- | --
--td-data-time-picker-year-width | 128rpx | -