组件说明
日期组件用于选择日期,支持多种日期格式。
用法示例
use plugin\xbCode\builder\Builder;
use plugin\xbCode\builder\Renders\Form;
Builder::form(function (Form $builder) {
// 基础日期选择
$builder->addRowDate('date', '日期', '', function($component) {
$component->valueFormat('YYYY-MM-DD');
$component->placeholder('请选择日期');
$component->clearable(true);
});
// 日期范围限制
$builder->addRowDate('birthday', '生日', '', [
'minDate' => '1900-01-01',
'maxDate' => '${TODAY}', // 使用变量
'shortcuts' => ['today', 'yesterday']
]);
// 日期时间选择
$builder->addRowDateTime('create_time', '创建时间', '', function($component) {
$component->format('YYYY-MM-DD HH:mm:ss');
$component->closeOnSelect(false); // 选择后不关闭
});
// 内联日历
$builder->addRowDate('inline_date', '内联日期', '', function($component) {
$component->embed(true); // 内联模式
$component->utc(false);
});
});
组件参数
| 参数名 | 类型 | 默认值 | 说明 |
|---|---|---|---|
| name | string | - | 字段名称 |
| label | string | - | 字段标签 |
| value | string | - | 默认值 |
| valueFormat | string | 'YYYY-MM-DD HH:mm:ss' | 日期值格式 |
| displayFormat | string | - | 日期显示格式 |
| closeOnSelect | bool | true | 点选日期后是否马上关闭选择框 |
| placeholder | string | - | 占位文本 |
| shortcuts | string|array | - | 日期快捷键 |
| minDate | string | - | 限制最小日期 |
| maxDate | string | - | 限制最大日期 |
| utc | bool | false | 是否保存UTC值 |
| clearable | bool | false | 是否可清除 |
| embed | bool | false | 是否内联模式 |
| disabledDate | string | - | 用字符函数控制哪些天不可选 |
| popOverContainerSelector | string | - | 弹层挂载位置选择器 |
| required | bool | false | 是否必填 |
| disabled | bool | false | 是否禁用 |
使用说明
- valueFormat控制提交给后端的日期格式
- displayFormat控制前端显示的日期格式,不设置时使用valueFormat
- format()方法可以同时设置valueFormat和displayFormat
- 使用datetime()方法切换为日期时间选择器
- shortcuts支持:today、yesterday、1dayago、7daysago、1weekago、1monthago等
- minDate和maxDate支持变量如:${TODAY}、${NOW}等
- embed为true时,日历会直接展开显示