const disabledDate = (date: Date) => {
//根据选择的日期,截止日期最大跨度三个月
let condition = false
if (startDate.value) {
condition ||=
dayjs(startDate.value).subtract(3, 'month').isAfter(date) ||
dayjs(startDate.value).add(3, 'month').isBefore(date)
}
condition ||= dayjs().isBefore(date)
return condition
//今天以前三个月
const curDate = new Date().getTime()
const three = 90 * 24 * 3600 * 1000
const threeMonths = curDate - three
return date.getTime() > Date.now() || date.getTime() < threeMonths
}
//禁用今天以后
const disabledDate = (time: { getTime: () => number }) => {
const pickerMaxDate = getUnixZero()
if (pickerMaxDate) {
return time.getTime() > pickerMaxDate * 1000
}
return false
}
/**
* 获取传入时间的00:00:00 的时间戳 默认 当前时间
* @returns
*/
export const getUnixZero = (date?: number) => {
const dateTime = typeof date === 'number' ? dayjs.unix(date) : dayjs(date)
return dateTime.hour(0).minute(0).second(0).unix()
}
el-date-pick时间禁用范围记录
于 2023-09-06 11:26:56 首次发布