Browse Source

feat(utils): 优化时间验证逻辑以支持同一天的选择

- 在 eleValidate.ts 中为时间范围验证函数添加 allowSameDay 参数
- 更新时间比较逻辑以允许相同日期的选择
- 修改 newCoupon.vue 中的时间验证规则调用
- 调整禁用日期逻辑以支持同一天选择场景
congxuesong 2 weeks ago
parent
commit
4b6b212fb3
2 changed files with 10 additions and 5 deletions
  1. 6 3
      src/utils/eleValidate.ts
  2. 4 2
      src/views/ticketManagement/newCoupon.vue

+ 6 - 3
src/utils/eleValidate.ts

@@ -203,7 +203,8 @@ export function validateDateRange(
   startErrorMessage: string = "开始时间不能早于当前时间",
   endErrorMessage: string = "结束时间不能早于当前时间",
   rangeErrorMessage: string = "开始时间必须早于结束时间",
-  checkToday: boolean = true
+  checkToday: boolean = true,
+  allowSameDay: boolean = false
 ) {
   return (rule: any, value: any, callback: any) => {
     if (!value) {
@@ -254,7 +255,8 @@ export function validateDateRange(
       if (endDate) {
         const end = new Date(endDate);
         end.setHours(0, 0, 0, 0);
-        if (selectedDate >= end) {
+        const isInvalid = allowSameDay ? selectedDate > end : selectedDate >= end;
+        if (isInvalid) {
           callback(new Error(rangeErrorMessage));
           return;
         }
@@ -265,7 +267,8 @@ export function validateDateRange(
       if (startDate) {
         const start = new Date(startDate);
         start.setHours(0, 0, 0, 0);
-        if (selectedDate <= start) {
+        const isInvalid = allowSameDay ? selectedDate < start : selectedDate <= start;
+        if (isInvalid) {
           callback(new Error(rangeErrorMessage));
           return;
         }

+ 4 - 2
src/views/ticketManagement/newCoupon.vue

@@ -139,6 +139,7 @@ const rules = reactive({
         "开始领取时间不能早于当前时间",
         "结束领取时间不能早于当前时间",
         "开始领取时间必须早于结束领取时间",
+        true,
         true
       ),
       trigger: "change"
@@ -153,6 +154,7 @@ const rules = reactive({
         "开始领取时间不能早于当前时间",
         "结束领取时间不能早于当前时间",
         "开始领取时间必须早于结束领取时间",
+        true,
         true
       ),
       trigger: "change"
@@ -380,7 +382,7 @@ const disabledStartDate = (time: Date) => {
 
 /**
  * 禁用结束领取时间的日期
- * 不能选择早于当前时间的日期,也不能选择早于或等于开始领取时间的日期
+ * 不能选择早于当前时间的日期,也不能选择早于开始领取时间的日期
  */
 const disabledEndDate = (time: Date) => {
   const today = new Date();
@@ -391,7 +393,7 @@ const disabledEndDate = (time: Date) => {
   if (couponModel.value.beginGetDate) {
     const startDate = new Date(couponModel.value.beginGetDate);
     startDate.setHours(0, 0, 0, 0);
-    return time.getTime() <= startDate.getTime();
+    return time.getTime() < startDate.getTime();
   }
   return false;
 };