el-date-picker,日期时间范围选择器默认只能选择7天

elementplus组件

html 复制代码
<el-date-picker
	style="width: 100%"
	v-model="dayTime"
	type="datetimerange"
	:start-placeholder="$t('public.startTime')"
	:end-placeholder="$t('public.endTime')"
	@change="changeEndDate"
	@calendar-change="calendarChange"
	format="YYYY/MM/DD HH:mm:ss"
	:disabled-date="disabledDateOption"
	:clearable="false"
/>

dayTime:用户选择的时间范围数组

disableDate:根据选择的第一个时间点来判断用户选择的前后7天的时间结束点

TypeScript 复制代码
const dayTime = ref<Array<string>>([]);
const disableDate = ref<string>("");

calendarChange事件,用户选择完第二个时间值后把之前用来判断的disableDate置空

TypeScript 复制代码
const calendarChange = (time: any[]) => {
	disableDate.value = time[0];
	if (time[1]) {
		disableDate.value = "";
	}
};

disabledDateOption:判断禁用的时间范围

TypeScript 复制代码
const disabledDateOption = (time: any) => {
	if (disableDate.value) {
		disableDate.value = moment(new Date(disableDate.value)).format("YYYY-MM-DD HH:mm:ss");
		return (
			moment(time).isAfter(moment(disableDate.value).add(7, "days"), "days") ||
			moment(time).isBefore(moment(disableDate.value).subtract(7, "days"), "days") ||
			moment().isBefore(time, "days")
		);
	} else {
		return moment().isBefore(time, "days");
	}
};
相关推荐
牛奶5 分钟前
Vue 基础理论 & API 使用
前端·vue.js·面试
牛奶11 分钟前
Vue 底层原理 & 新特性
前端·vue.js·面试
anOnion29 分钟前
构建无障碍组件之Radio group pattern
前端·html·交互设计
pe7er32 分钟前
状态提升:前端开发中的状态管理的设计思想
前端·vue.js·react.js
SoaringHeart2 小时前
Flutter调试组件:打印任意组件尺寸位置信息 NRenderBox
前端·flutter
晚风予星2 小时前
Ant Design Token Lens 迎来了全面升级!支持在 .tsx 或 .ts 文件中直接使用 Design Token
前端·react.js·visual studio code
sunny_2 小时前
⚡️ vite-plugin-oxc:从 Babel 到 Oxc,我为 Vite 写了一个高性能编译插件
前端·webpack·架构
GIS之路2 小时前
ArcPy 开发环境搭建
前端
林小帅4 小时前
【笔记】OpenClaw 架构浅析
前端·agent
林小帅4 小时前
【笔记】OpenClaw 生态系统的多语言实现对比分析
前端·agent