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 小时前
从 textarea 到 AI 输入框:用 Tiptap 实现 / 命令、@ 引用和结构化请求
前端·langchain·next.js
kyriewen7 小时前
程序员连夜带团队跑路,省了23万:这AI太贵,真的用不起了
前端·javascript·openai
kyriewen7 小时前
你写的代码没有测试,就像出门不锁门——Jest + Testing Library 从入门到不慌
前端·单元测试·jest
yuzhiboyouye8 小时前
web前端英语面试
前端·面试·状态模式
canonical_entropy9 小时前
下一代低代码渲染框架 nop-chaos-flux 的设计原则
前端·低代码·前端框架
东方小月9 小时前
5分钟搞懂Harness Engineering(驾驭工程):从提示词到AI Agent的进化之路
前端·后端·架构
我叫黑大帅9 小时前
为什么需要 @types/react?解决“无法找到模块 react 的声明文件”报错
前端·javascript·面试
之歆10 小时前
DAY_21JavaScript 深度解析:数组(Array)与函数(Function)(一)
前端·javascript
XinZong10 小时前
【AI社交】基于OpenClaw自研轻量化AI社交平台实战
前端
Le_ee11 小时前
ctfweb:php/php短标签/.haccess+图片马/XXE
开发语言·前端·php