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");
	}
};
相关推荐
be or not to be27 分钟前
深入理解 CSS 浮动布局(float)
前端·css
LYFlied1 小时前
【每日算法】LeetCode 1143. 最长公共子序列
前端·算法·leetcode·职场和发展·动态规划
老华带你飞1 小时前
农产品销售管理|基于java + vue农产品销售管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
小徐_23331 小时前
2025 前端开源三年,npm 发包卡我半天
前端·npm·github
C_心欲无痕1 小时前
vue3 - 类与样式的绑定
javascript·vue.js·vue3
GIS之路2 小时前
GIS 数据转换:使用 GDAL 将 Shp 转换为 GeoJSON 数据
前端
JIngJaneIL2 小时前
基于springboot + vue房屋租赁管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·后端
天天扭码2 小时前
以浏览器多进程的角度解构页面渲染的整个流程
前端·面试·浏览器
你们瞎搞2 小时前
Cesium加载20GB航测影像.tif
前端·cesium·gdal·地图切片
milanleon3 小时前
使用Spring Security进行登录认证
java·前端·spring