From 85cb7bf0de33858af67c7d7d8204ae65aabd6720 Mon Sep 17 00:00:00 2001 From: LiuJiaNan <15703339975@163.com> Date: Wed, 15 Apr 2026 16:13:58 +0800 Subject: [PATCH] =?UTF-8?q?feat(utils):=20=E4=BC=98=E5=8C=96validatorEndTi?= =?UTF-8?q?me=E5=92=8CvalidatorTimeGTCurrentDay=EF=BC=8C=E6=96=B0=E5=A2=9E?= =?UTF-8?q?validatorTimeGECurrentDay?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/index.d.ts | 9 ++++++++- src/utils/index.js | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/utils/index.d.ts b/src/utils/index.d.ts index b3ad4fe..df86bd1 100644 --- a/src/utils/index.d.ts +++ b/src/utils/index.d.ts @@ -350,12 +350,19 @@ export function validatorEndTime(options: { startTime: string; message?: string; }; /** - * 验证时间是否大于等于当前时间 + * 验证时间是否大于当前时间 */ export function validatorTimeGTCurrentDay(options?: { message?: string; type?: "date" | "datetime" }): { validator: (_: any, value: any) => Promise; }; +/** + * 验证时间是否大于等于当前时间 + */ +export function validatorTimeGECurrentDay(options?: { message?: string; type?: "date" | "datetime" }): { + validator: (_: any, value: any) => Promise; +}; + /** * 动态加载js资源 */ diff --git a/src/utils/index.js b/src/utils/index.js index 2868d97..e23968d 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -487,7 +487,7 @@ export function processTreeDataForOnlyLastLevel(options) { * 验证结束时间是否大于开始时间 */ export function validatorEndTime(options) { - let { startTime, message = "结束时间不能早于开始时间", type = "" } = options; + let { startTime, message = "结束时间不能早于开始时间", type = "" } = options || {}; return { validator: (_, value) => { @@ -514,17 +514,45 @@ export function validatorEndTime(options) { } /** - * 验证时间是否大于等于当前时间 + * 验证时间是否大于当前时间 */ export function validatorTimeGTCurrentDay(options) { - const { message = "需要大于当前时间", type = "date" } = options; + const { message = "需要大于当前时间", type = "date" } = options || {}; return { validator: (_, value) => { if (!value) return Promise.resolve(); const selectedDate = dayjs.isDayjs(value) ? value : dayjs(value); - if (selectedDate.isBefore(dayjs(), type === "date" ? "day" : "seconds")) + const now = dayjs(); + const isAfter = type === "date" + ? selectedDate.isAfter(now, "day") + : selectedDate.isAfter(now, "seconds"); + + if (!isAfter) + return Promise.reject(message); + else + return Promise.resolve(); + }, + }; +} +/** + * 验证时间是否大于等于当前时间 + */ +export function validatorTimeGECurrentDay(options) { + const { message = "需要大于等于当前时间", type = "date" } = options || {}; + return { + validator: (_, value) => { + if (!value) + return Promise.resolve(); + + const selectedDate = dayjs.isDayjs(value) ? value : dayjs(value); + const now = dayjs(); + const isBefore = type === "date" + ? selectedDate.isBefore(now, "day") + : selectedDate.isBefore(now, "seconds"); + + if (isBefore) return Promise.reject(message); else return Promise.resolve();