From 7a5788af7db037af113aea9a17953a2cc3ed35bd Mon Sep 17 00:00:00 2001 From: songguoqiang <765017469@qq.com> Date: Fri, 8 Mar 2024 11:14:35 +0800 Subject: [PATCH] =?UTF-8?q?=E8=83=BD=E8=80=97=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tjanalysis/energyconsumption/index.vue | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/views/tjanalysis/energyconsumption/index.vue b/src/views/tjanalysis/energyconsumption/index.vue index cead230..1b76306 100644 --- a/src/views/tjanalysis/energyconsumption/index.vue +++ b/src/views/tjanalysis/energyconsumption/index.vue @@ -10,6 +10,8 @@ end-placeholder="结束日期" start-placeholder="开始日期" type="daterange" + :disabled-date="disabledDate" + @change="changeTime" /> @@ -58,6 +60,7 @@ import * as TjanalysisApi from '@/api/tjanalysis' import { formatDate } from '@/utils/formatTime' import * as DictApi from '@/utils/dict' +import dayjs from 'dayjs' defineOptions({ name: 'energyconsumption' }) @@ -184,6 +187,25 @@ onMounted(async () => { getList() }) +function disabledDate(time){ + // 获取当前日期 + var currentDate = new Date(); + // 设置日期为30天前 + currentDate.setDate(currentDate.getDate() - 30); + return time.getTime() >= Date.now(); + // let range = [dayjs(queryParams.dateRange[0]).subtract(30, 'day'),dayjs(queryParams.dateRange[0]).subtract(30, 'day')]; + // let cur = dayjs(time); + // return time > range[0] || time < range[1]; +} + +function changeTime(val) { + if (new Date(val[1]) - new Date(val[0]) > 1 * 24 * 60 * 60 * 1000 * 31) { + message.alert("选择时间范围不能大于31天"); + queryParams.dateRange = [val[0],val[0]]; + } + +} +