日期时间范围

日期时间范围表单项

日期时间范围表单项组件,用于在表单中选择日期时间范围,支持快捷选择、范围限制等功能。

用法示例

<?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
  });
});

组件参数

参数名类型默认值说明
fieldstring-字段名,必填
titlestring-标题,必填
valuemixed''默认值
valueFormatstring'YYYY-MM-DD HH:mm:ss'日期选择器值格式
displayFormatstring-日期选择器显示格式
placeholderstring-占位文本
shortcutsstring|array-日期范围快捷键,如:['today', 'yesterday']
minDatestring-限制最小日期
maxDatestring-限制最大日期
minDurationstring-限制最小跨度,如:2days
maxDurationstring-限制最大跨度,如:1year
utcboolfalse是否保存UTC值
clearablebooltrue是否可清除
embedboolfalse是否内联模式
animationbooltrue是否启用游标动画
extraNamestring-是否存成两个字段,设置结束时间的字段名
transformstring-日期数据处理函数
popOverContainerSelectorstring-弹层挂载位置选择器

使用说明

  1. 基本使用:通过 addRowDateTimeRange() 方法添加日期时间范围选择器
  2. 格式设置:使用 valueFormat() 设置存储格式,displayFormat() 设置显示格式
  3. 快捷选择:通过 shortcuts() 配置快捷选择按钮,支持today/yesterday/thisweek等
  4. 范围限制:使用 minDate()maxDate() 限制可选日期范围
  5. 跨度限制:使用 minDuration()maxDuration() 限制选择的时间跨度
  6. 双字段存储:设置 extraName() 可将开始和结束时间分别存储到两个字段
  7. UTC模式:设置 utc(true) 可以UTC格式保存时间
  8. 内联模式:设置 embed(true) 可显示为内嵌日历面板