Эх сурвалжийг харах

feat: 移动端时间选择组件支持选择未来时间

cuiyalong 8 сар өмнө
parent
commit
e8e8927513

+ 19 - 6
apps/mobile/src/components/selector/date-time-group/index.vue

@@ -107,6 +107,11 @@ export default {
     PopupLayout
   },
   props: {
+    // 最大时间是否可以选择一个未来的时间,默认最大时间为当天
+    endTimeFeature: {
+      type: Boolean,
+      default: false
+    },
     /**
      * 是否高亮
      */
@@ -137,8 +142,16 @@ export default {
     }
   },
   data() {
+    const now = dayjs()
+    const threeYearLater = now.add(3, 'year');
+    const endMaxDate = this.endTimeFeature ? threeYearLater.toDate() : now.toDate()
+    const startMinDate = new Date(2015, 0, 1)
     return {
       debug: import.meta.env.DEV,
+      conf: {
+        startMinDate: startMinDate,
+        endMaxDate: endMaxDate
+      },
       picker: {
         type: 'date',
         showToolBar: false,
@@ -153,16 +166,16 @@ export default {
         valueStamp: '',
         placeholder: '开始时间',
         currentDate: new Date(),
-        minDate: new Date(2010, 0, 1),
-        maxDate: new Date()
+        minDate: startMinDate,
+        maxDate: endMaxDate
       },
       end: {
         value: '',
         valueStamp: '',
         placeholder: '结束时间',
         currentDate: new Date(),
-        minDate: new Date(2010, 0, 1),
-        maxDate: new Date()
+        minDate: startMinDate,
+        maxDate: endMaxDate
       },
       popupShow: {
         start: false,
@@ -227,9 +240,9 @@ export default {
       }
       // 重置最大值和最小值
       if (type === 'start') {
-        this.end.minDate = new Date(2015, 0, 1)
+        this.end.minDate = this.conf.startMinDate
       } else if (type === 'end') {
-        this.start.maxDate = new Date()
+        this.start.maxDate = this.conf.endMaxDate
       }
       if (type === 'start') {
         this[type].currentDate = this.startTimeRemap

+ 5 - 0
apps/mobile/src/components/selector/date-time-list/index.vue

@@ -14,6 +14,7 @@
       :highlight="dateTimeGroupActive"
       :startPlaceholder="startPlaceholder"
       :endPlaceholder="endPlaceholder"
+      :endTimeFeature="endTimeFeature"
       @change="onChange"
       ref="dateTimeGroup"
     />
@@ -43,6 +44,10 @@ export default {
         return []
       }
     },
+    endTimeFeature: {
+      type: Boolean,
+      default: false
+    },
     options: {
       type: Array,
       default() {