跳到主要内容

时间选择器 DateTimePicker

用于选择时间,支持日期、时分等时间维度,通常与弹出层组件配合使用

安装使用

import { TiDatetimePicker } from '@titian-design/mobile-vue'

用法示例

基础用法

<template>
<TiPopup :visible="visible" position="bottom">
<TiDatetimePicker :value="value" :on-confirm="onConfirm" />
</TiPopup>
</template>

<script lang="ts" setup>
import { TiDatetimePicker, TiPopup } from '@titian-design/mobile-vue';
</script>

不同时间类型

<template>
<TiPopup :visible="visible" position="bottom">
// 年月日
<TiDatetimePicker type="date" />
// 时分
<TiDatetimePicker type="time" />
// 年月日 - 时分
<TiDatetimePicker type="datetime" />
// 年月
<TiDatetimePicker type="year-month" />
</TiPopup>
</template>

<script lang="ts" setup>
import { TiDatetimePicker, TiPopup } from '@titian-design/mobile-vue';
</script>

选项格式化

<template>
<TiPopup :visible="visible" position="bottom">
<TiDatetimePicker :formatter="formatter" />
</TiPopup>
</template>

<script lang="ts" setup>
import { TiDatetimePicker, TiPopup } from '@titian-design/mobile-vue';
enum columnType { YEAR = "year", MONTH = "month", DAY = "day", HOUR = "hour", MINUTE = "minute" }
const formatter = (type: columnType, value: number) => {
const pipe = {
year: `${value}`,
month: `${value}`,
day: `${value}`,
hour: `${value}`,
minute: `${value}`,
}
return pipe[type]
}
</script>

选项过滤器

<template>
<TiPopup :visible="visible" position="bottom">
<TiDatetimePicker :filter="filter" />
</TiPopup>
</template>

<script lang="ts" setup>
import { TiDatetimePicker, TiPopup } from '@titian-design/mobile-vue';
enum columnType { YEAR = "year", MONTH = "month", DAY = "day", HOUR = "hour", MINUTE = "minute" }
const filter = (type: columnType, options: Array<{value: number}>) => {
if (type === "year") {
return options.filter((options) => options.value % 2 === (\s)([a-z]+)([A-Z])([a-z]+)(=)(\{)\s*(.*?)\s*(\})0);
}
return options;
}
</script>

设置边界

<template>
<TiPopup :visible="visible" position="bottom">
<TiDatetimePicker :value="value" :min-date="minDate" :max-date="maxDate" />
</TiPopup>
</template>

<script lang="ts" setup>
import { TiDatetimePicker, TiPopup } from '@titian-design/mobile-vue';
</script>

时间项排序

sort项取值应该和type类型对应

<template>
<TiPopup :visible="visible" position="bottom">
<TiDatetimePicker :sort="['month', 'year']" type="year-month" />
</TiPopup>
</template>

<script lang="ts" setup>
import { TiDatetimePicker, TiPopup } from '@titian-design/mobile-vue';
</script>

TiDatetimePicker API

属性 Properties

名称类型是否必填默认值说明备注
valuestring---
typestringdata年月日date 年月year-month 时分time 年月日 - 时分datetime-
min-datenumber十年前毫秒数最小边界-
max-datenumber十年后毫秒数最大边界-
sortarray-sort 需要与 type 匹配,匹配关系-
loadingbooleanfalse加载动画-
formatterfunction-格式化内容-
filterfunction-过滤时间-
titlestring-标题-
sub-titlestring-副标题-
confirm-textstring-确认按钮文案-
cancel-textstring-取消按钮文案-
option-item-heightnumber | string108展示项高度-
visible-item-countnumber5可见展示项数-
ext-stylestring-容器样式-
ext-option-stylestring-子器样式-

sort排序的取值和type对应关系

typesort
date['year', 'month', 'day']
year-month['year', 'month']
time['hour', 'minute']
datetime['year', 'month', 'day', 'hour', 'minute']

事件 Events

名称参数列表描述备注
confirm(e: CustomEvent<{type: string, value: number}>) => void点击确定按钮后触发----
change(e: CustomEvent<{type: string, value: number}) => void列表变化是触发----
cancel(e: CustomEvent<{type: string, value: number}) => void点击取消按钮后触发----

外部样式类 External Classes

名称说明备注
ext-hairline-class时间选择器中间线样式----
ext-mask-class时间选择器蒙层样式----
ext-option-class时间选择器纵列容器样式----
ext-option-item-class时间选择器纵列单项样式----
ext-class时间选择容器样式----

CSS 变量 CSS Variable

变量默认值说明备注
--datetime-picker-mask-bg-image#ffffffpicker 组件 --picker-mask-bg-image--
--datetime-picker-loading-bg-color#ffffffpicker 组件 --picker-loading-bg-color--
--datetime-picker-row-color#212121picker-column 组件 --picker-column-row-color--
--datetime-picker-row-selected-color#212121picker-column 组件 --picker-column-row-selected-color--
--datetime-picker-row-disabled-color#212121picker-column 组件 --picker-column-row-disabled-color--