更新记录
1.0.0(2025-10-29)
下载此版本
初始功能
平台兼容性
uni-app(4.66)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| √ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
| √ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
√ |
liaction-timepicker
组件介绍
liaction-timepicker 是一个功能丰富的时间选择器组件,支持时间段选择和单时间点选择两种模式,提供预设时间段快速选择功能,适用于各种需要时间选择的场景。
组件特点
- 支持时间段选择和单时间点选择两种模式
- 提供预设时间段快速选择功能
- 可自定义预设时间段内容
- 支持设置时间间隔
- 自动处理时间范围有效性检查
- 高度可定制的样式和文本内容
依赖说明
使用示例
基本使用 - 时间段选择模式
<template>
<view>
<liaction-timepicker
title="选择时间范围"
:value="['08:00', '12:00']" <!-- 数组格式,[开始时间, 结束时间] -->
@confirm="angeConfirm"
@cancel="onPickerCancel"
></liaction-timepicker>
</view>
</template>
<script>
export default {
methods: {
angeConfirm(e) {
console.log('选择的时间范围:', e.startTime, '~', e.endTime);
// 如果选择了预设时间段,还可以获取预设key
if (e.preset) {
console.log('选择的预设时间段:', e.preset);
}
},
onPickerCancel() {
console.log('取消选择');
}
}
}
</script>
单时间点选择模式 - 字符串格式
<template>
<view>
<liaction-timepicker
title="选择时间"
:enableTimeRange="false"
:value="'14:30'" <!-- 字符串格式 -->
@confirm="onTimeConfirm"
@cancel="onPickerCancel"
></liaction-timepicker>
</view>
</template>
<script>
export default {
methods: {
onTimeConfirm(e) {
// 单时间点模式下,时间通过 e.time 获取
console.log('选择的时间:', e.time);
},
onPickerCancel() {
console.log('取消选择');
}
}
}
</script>
单时间点选择模式 - 数组格式
<template>
<view>
<liaction-timepicker
title="选择时间"
:enableTimeRange="false"
:value="['14:30']" <!-- 数组格式,仅包含一个时间值 -->
@confirm="onTimeConfirm"
@cancel="onPickerCancel"
></liaction-timepicker>
</view>
</template>
<script>
export default {
methods: {
onTimeConfirm(e) {
console.log('选择的时间:', e.time);
},
onPickerCancel() {
console.log('取消选择');
}
}
}
</script>
自定义预设时间段
<template>
<view>
<liaction-timepicker
title="选择时间范围"
:customPresets="customPresets"
@confirm="angeConfirm"
></liaction-timepicker>
</view>
</template>
<script>
export default {
data() {
return {
customPresets: [
{ key: 'morning', label: '上午', start: '08:00', end: '12:00' },
{ key: 'afternoon', label: '下午', start: '14:00', end: '18:00' },
{ key: 'evening', label: '晚上', start: '18:00', end: '22:00' }
]
}
},
methods: {
angeConfirm(e) {
console.log('选择的时间范围:', e.startTime, '~', e.endTime);
}
}
}
</script>
响应式绑定示例
<template>
<view>
<liaction-timepicker
title="选择时间范围"
:value="[selectedStartTime, selectedEndTime]"
@confirm="angeConfirm"
></liaction-timepicker>
<view class="selected-time">
已选择: {{ selectedStartTime }} - {{ selectedEndTime }}
</view>
</view>
</template>
<script>
export default {
data() {
return {
selectedStartTime: '09:00',
selectedEndTime: '17:00'
}
},
methods: {
angeConfirm(e) {
this.selectedStartTime = e.startTime;
this.selectedEndTime = e.endTime;
console.log('更新后的时间范围:', e.startTime, '~', e.endTime);
}
}
}
</script>
属性说明
| 属性名 |
类型 |
默认值 |
说明 |
| value |
[Array, String] |
null |
设置选择器的默认值,时间段模式时为数组[startTime, endTime],单时间点模式时为字符串或数组 |
| title |
String |
"选择时间范围" |
组件标题,未选择时间时的显示文本 |
| cancelText |
String |
"取消" |
取消按钮文本 |
| confirmText |
String |
"确定" |
确定按钮文本 |
| startTimeLabel |
String |
"开始时间" |
开始时间标签文本 |
| endTimeLabel |
String |
"结束时间" |
结束时间标签文本 |
| separatorText |
String |
"至" |
分隔符文本 |
| separatorStyle |
String/Object |
"" |
分隔符样式 |
| pickerItemHeight |
Number |
50 |
picker选项高度(px) |
| minuteInterval |
Number |
1 |
时间间隔(分钟) |
| showPresets |
Boolean |
true |
是否显示预设时间段 |
| presetTitle |
String |
"快捷选择" |
预设时间段标题 |
| presetTitleStyle |
String/Object |
"" |
预设时间段标题样式 |
| customPresets |
Array |
[] |
自定义预设时间段 |
| enableTimeRange |
Boolean |
true |
是否启用时间段选择(true:时间段选择,false:单时间点选择) |
| presetItemStyle |
String/Object |
"" |
预设时间段项目样式 |
| presetActiveStyle |
String/Object |
"" |
预设时间段选中状态样式 |
| indicatorStyle |
String |
"" |
选择器指示器样式 |
| maskStyle |
String |
"" |
选择器遮罩样式 |
| immediateChange |
Boolean |
false |
是否在滚动时立即触发change事件 |
| defaultStartTime |
String |
"00:00" |
初始化的开始时间 |
| defaultEndTime |
String |
"23:59" |
初始化的结束时间 |
| popupType |
String |
"bottom" |
弹出层类型 |
| maskClick |
Boolean |
true |
是否允许点击遮罩关闭 |
| animation |
Boolean |
true |
是否启用动画 |
事件说明
| 事件名 |
说明 |
回调参数 |
| confirm |
确认选择时触发 |
时间段模式:{ startTime: String, endTime: String, preset: String } 单时间点模式:{ time: String } |
| cancel |
取消选择时触发 |
无 |
| change |
时间选择变化时触发 |
时间段模式:{ startTime: String, endTime: String } 单时间点模式:{ time: String } |
| open |
弹出层打开时触发 |
无 |
| close |
弹出层关闭时触发 |
无 |
方法说明
| 方法名 |
说明 |
参数 |
返回值 |
| open |
打开选择器 |
无 |
无 |
| close |
关闭选择器 |
无 |
无 |
| getTimeRange |
获取当前选中的时间范围 |
无 |
{ startTime: String, endTime: String, preset: String } |
注意事项
- 单时间点模式下,确认事件返回的是
e.time,而不是e.startTime
- 时间段模式下,开始时间不应大于结束时间,组件会自动处理这种情况
- 自定义预设时间段时,需要保证数据格式正确:[{ key: String, label: String, start: String, end: String }]
- 为了获得最佳体验,建议在移动设备上使用