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");
	}
};
相关推荐
anOnion3 小时前
构建无障碍组件之Carousel Pattern
前端·html·交互设计
ssshooter3 小时前
Tauri 2 iOS 开发避坑指南:文件保存、Dialog 和 Documents 目录的那些坑
前端·后端·ios
Можно4 小时前
深入理解 ES6 Proxy:与 Object.defineProperty 的全面对比
前端·javascript·vue.js
Birdy_x4 小时前
接口自动化项目实战(1):requests请求封装
开发语言·前端·python
天天向上10246 小时前
vue el-table实现拖拽排序
前端·javascript·vue.js
柳杉7 小时前
Three.js × Blender:从建模到 Web 3D 的完整工作流深度解析
前端·javascript·数据可视化
reembarkation8 小时前
vue3中使用howler播放音频列表
前端·vue.js·音视频
手握风云-8 小时前
基于 Java 的网页聊天室(三)
服务器·前端·数据库
weixin199701080168 小时前
《识货商品详情页前端性能优化实战》
前端·性能优化
Forever7_8 小时前
重磅!Vue3 手势工具正式发布!免费使用!
前端·前端框架·前端工程化