Skip to content

日期


image

介绍

基本表单组件,用于用户选择日期。

API

Props

参数名描述类型默认值
status状态'default' |'disabled'| 'hide'| 'readonly''default'
title标题string'日期'
showLabel显示标题booleantrue
placeholder占位提示string请选择
width字段占比'25%'|'50%'|'75%'|'100%''100%'
labelWidth标签宽度string-
name数据字段string${组件编码}_${长度为8的随机字符串}
type选择器类型'date'|'week'|'month'|'quarter'|'year''date'
format格式'YYYY-MM-DD'|'YYYY-MM-DD HH'|'YYYY-MM-DD HH:mm'|'YYYY-MM-DD HH:mm:ss''YYYY-MM-DD'
valueType默认值'custom' | 'formula''custom'
value编辑默认值string | {formulaValue:string,value:string}-
allowClear清除按钮booleanfalse
showNowBtn是否显示选择当前时间的按钮booleantrue
disabledDate不可选取的日期Function-
disabledTime不可选取的时间Function-
baseStyle自定义样式string-
customClass类名绑定string-
boxStyle盒模型 , margin,border,padding设置BoxStyle-
uniqueKey唯一标识 , 组件的唯一标识string-
customRender自定义日期单元格booleanfalse
renderFunc自定义日期单元格渲染函数Function-
extra补充说明string-
tip气泡提醒string-
validate校验Validate-
loop循环, 循环渲染设置Loop-

Events

事件名描述参数
onChange值发生改变时ctx
params: {value: string}
loop:LoopParams
onClear点击清除按钮时ctx
loop:LoopParams

常见场景配置

不可选取的日期示例

以限制用户只能选择当前日期前10天内的日期为例:

js
function disabledDate(ctx, params) {
  //校验日期是否不可选取,返回布尔值
  let currentIndex = params.current.valueOf();
  // 获取当前日期
  const nowDaysAfter = new Date();
  // 获取前一天的时间戳
  nowDaysAfter.setDate(nowDaysAfter.getDate() - 1);
  const timestampEnd = nowDaysAfter.valueOf();
  // 获取十天前的时间戳
  const tenDaysAgo = new Date();
  tenDaysAgo.setDate(tenDaysAgo.getDate() - 10);
  const timeStart = tenDaysAgo.valueOf();
  if (timestampEnd < currentIndex || timeStart > currentIndex) return true;
  return false;
}