From 849e77b4013306f3fae0a019aaaee70bc6034e45 Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Fri, 19 Dec 2025 00:06:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(datepicker):=20=E6=B7=BB=E5=8A=A0=E6=97=A5?= =?UTF-8?q?=E6=9C=9F=E7=A6=81=E7=94=A8=E5=8A=9F=E8=83=BD=EF=BC=8C=E9=99=90?= =?UTF-8?q?=E5=88=B6=E6=97=A5=E6=9C=9F=E8=8C=83=E5=9B=B4=E4=B8=BA=E4=B8=80?= =?UTF-8?q?=E5=B9=B4=E5=86=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 disabledDate 函数用于禁用超出当前日期前后一年范围的日期 - 在日期选择组件中绑定 disabledDate 函数 - 优化用户选择日期的有效范围,防止选取过早或过晚的日期 - 通过代码注释清晰说明禁用逻辑实现细节 --- web/index.html | 1 + web/main.js | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/web/index.html b/web/index.html index eb3c54d..afd2deb 100644 --- a/web/index.html +++ b/web/index.html @@ -240,6 +240,7 @@ value-format="YYYY-MM-DD HH:mm:ss" :shortcuts="dateShortcuts" :default-time="dateDefaultTime" + :disabled-date="disabledDate" style="width:100%" /> diff --git a/web/main.js b/web/main.js index 5159c77..8aca80d 100644 --- a/web/main.js +++ b/web/main.js @@ -188,6 +188,19 @@ const app = createApp({ new Date(2000, 0, 1, 23, 59, 59), ]; + /** + * 禁用超过一年的日期 + * @param {Date} date - 要检查的日期 + * @returns {boolean} 是否禁用 + */ + const disabledDate = (date) => { + if (!date) return false; + const today = new Date(); + const oneYearAgo = new Date(today.getFullYear() - 1, today.getMonth(), today.getDate()); + const oneYearLater = new Date(today.getFullYear() + 1, today.getMonth(), today.getDate()); + return date < oneYearAgo || date > oneYearLater; + }; + const dateShortcuts = [ { text: '本日', @@ -1010,6 +1023,7 @@ const app = createApp({ exportRules, dateDefaultTime, dateShortcuts, + disabledDate, // 表单引用 createFormRef, editFormRef,