日期时间范围表单项
日期时间范围表单项组件,用于在表单中选择日期时间范围,支持快捷选择、范围限制等功能。
用法示例
<?php
use plugin\xbCode\builder\Builder;
use plugin\xbCode\builder\Renders\Form;
// 创建表单
Builder::form(function (Form $builder) {
// 基本日期时间范围选择
$builder->addRowDateTimeRange('time_range', '时间范围', '', function ($component) {
$component->placeholder('请选择时间范围');
$component->valueFormat('YYYY-MM-DD HH:mm:ss');
});
// 限制日期范围
$builder->addRowDateTimeRange('create_time', '创建时间', '', function ($component) {
$component->minDate('2024-01-01 00:00:00');
$component->maxDate('2024-12-31 23:59:59');
$component->placeholder('限制2024年范围');
});
// 限制跨度
$builder->addRowDateTimeRange('activity_time', '活动时间', '', function ($component) {
$component->minDuration('1days'); // 最小跨度1天
$component->maxDuration('30days'); // 最大跨度30天
});
// 快捷选择配置
$builder->addRowDateTimeRange('query_time', '查询时间', '', function ($component) {
$component->shortcuts(['today', 'yesterday', 'thisweek', 'lastweek']);
$component->clearable(true);
});
// 存储为两个字段
$builder->addRowDateTimeRange('date_range', '日期范围', '', function ($component) {
$component->extraName('end_time'); // 开始时间用date_range,结束时间用end_time
});
});
组件参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| field | string | - | 字段名,必填 |
| title | string | - | 标题,必填 |
| value | mixed | '' | 默认值 |
| valueFormat | string | 'YYYY-MM-DD HH:mm:ss' | 日期选择器值格式 |
| displayFormat | string | - | 日期选择器显示格式 |
| placeholder | string | - | 占位文本 |
| shortcuts | string|array | - | 日期范围快捷键,如:['today', 'yesterday'] |
| minDate | string | - | 限制最小日期 |
| maxDate | string | - | 限制最大日期 |
| minDuration | string | - | 限制最小跨度,如:2days |
| maxDuration | string | - | 限制最大跨度,如:1year |
| utc | bool | false | 是否保存UTC值 |
| clearable | bool | true | 是否可清除 |
| embed | bool | false | 是否内联模式 |
| animation | bool | true | 是否启用游标动画 |
| extraName | string | - | 是否存成两个字段,设置结束时间的字段名 |
| transform | string | - | 日期数据处理函数 |
| popOverContainerSelector | string | - | 弹层挂载位置选择器 |
使用说明
- 基本使用:通过
addRowDateTimeRange()方法添加日期时间范围选择器 - 格式设置:使用
valueFormat()设置存储格式,displayFormat()设置显示格式 - 快捷选择:通过
shortcuts()配置快捷选择按钮,支持today/yesterday/thisweek等 - 范围限制:使用
minDate()、maxDate()限制可选日期范围 - 跨度限制:使用
minDuration()、maxDuration()限制选择的时间跨度 - 双字段存储:设置
extraName()可将开始和结束时间分别存储到两个字段 - UTC模式:设置
utc(true)可以UTC格式保存时间 - 内联模式:设置
embed(true)可显示为内嵌日历面板