Selaa lähdekoodia

feat:修改点击today

AmandaG 8 kuukautta sitten
vanhempi
commit
ba87069534
1 muutettua tiedostoa jossa 20 lisäystä ja 11 poistoa
  1. 20 11
      src/components/DateRange/src/components/CalendarDate.vue

+ 20 - 11
src/components/DateRange/src/components/CalendarDate.vue

@@ -1,8 +1,10 @@
 <script lang="ts" setup>
 import dayjs, { Dayjs } from 'dayjs'
 import { ref, watch } from 'vue'
-import moment from 'moment'
+import { useUserStore } from '@/stores/modules/user'
 
+const userStore = useUserStore()
+const valueFormatDate = 'MM/DD/YYYY'
 // type RangeValue = [Dayjs, Dayjs]
 // const ETDDate = ref<RangeValue>()
 const props = defineProps({
@@ -21,13 +23,20 @@ const props = defineProps({
     default: false
   }
 })
-const ETDDate = ref(props.Date)
+const ETDDate = ref([])
 watch(
   () => props.Date,
-  (current) => {
-    ETDDate.value = current
-  }
+  (current: any) => {
+    if (current?.length == 2) {
+      ETDDate.value = [
+        current[0] ? dayjs(current[0]).format(valueFormatDate) : '',
+        current[1] ? dayjs(current[1]).format(valueFormatDate) : ''
+      ]
+    }
+  },
+  { immediate: true, deep: true }
 )
+
 const emit = defineEmits(['DateRangeChange', 'DateChange'])
 const open = ref(false)
 const Disabled = ref([false, false])
@@ -48,12 +57,12 @@ const ChangeToday = (val: any) => {
   if (val == 'Earliest') {
     // ETDDate.value = [dayjs(), dayjs()]
     ETDDate.value[0] = dayjs()
-    const date1 = moment(String(ETDDate.value[0])).format('MM/DD/YYYY')
+    const date1 = dayjs(String(ETDDate.value[0])).format(valueFormatDate)
     DateList.value[0] = date1
     daterange(DateList.value[1])
   } else {
     ETDDate.value[1] = dayjs()
-    const date1 = moment(String(ETDDate.value[1])).format('MM/DD/YYYY')
+    const date1 = dayjs(String(ETDDate.value[1])).format(valueFormatDate)
     DateList.value[1] = date1
     daterange(DateList.value[0])
   }
@@ -69,13 +78,13 @@ const handleCalendarOpen = (date: any) => {
 }
 const Earliest = () => {
   ETDDate.value[0] = dayjs('Oct-05-2009')
-  const date1 = moment(String(ETDDate.value[0])).format('MM/DD/YYYY')
+  const date1 = dayjs(String(ETDDate.value[0])).format(valueFormatDate)
   DateList.value[0] = date1
   daterange(DateList.value[1])
 }
 const Latest = () => {
   ETDDate.value[1] = dayjs()
-  const date1 = moment(String(ETDDate.value[1])).format('MM/DD/YYYY')
+  const date1 = dayjs(String(ETDDate.value[1])).format(valueFormatDate)
   DateList.value[1] = date1
   daterange(DateList.value[0])
 }
@@ -116,7 +125,7 @@ const isTwoDate = (date: any) => {
       :disabled="Disabled"
       @change="changeRangeData"
       :placeholder="['Start Time', 'End Time']"
-      format="MMM-DD-YYYY"
+      :format="userStore.dateFormat"
       valueFormat="MM/DD/YYYY"
       @openChange="handleCalendarOpen(ETDDate)"
       @panelChange="handlePanelChange"
@@ -182,4 +191,4 @@ const isTwoDate = (date: any) => {
 .icon_suffix {
   fill: var(--color-neutral-1);
 }
-</style>
+</style>