From 2b2edec9df3b417ad580e3f44a196a4cd004b142 Mon Sep 17 00:00:00 2001 From: DarkPhoenix2704 Date: Tue, 20 Feb 2024 07:16:14 +0000 Subject: [PATCH] fix(nc-gui): refactor remove Dates & use dayjs --- .../nc-gui/components/nc/DateWeekSelector.vue | 52 ++++++------ .../components/nc/MonthYearSelector.vue | 42 +++++----- .../calendar/DayView/DateTimeField.vue | 9 ++- .../smartsheet/calendar/MonthView.vue | 25 +++--- .../smartsheet/calendar/VRecordCard.vue | 1 - .../calendar/WeekView/DateTimeField.vue | 16 ++-- .../smartsheet/calendar/YearView.vue | 2 +- .../composables/useCalendarViewStore.ts | 80 +++++++++---------- 8 files changed, 111 insertions(+), 116 deletions(-) diff --git a/packages/nc-gui/components/nc/DateWeekSelector.vue b/packages/nc-gui/components/nc/DateWeekSelector.vue index 4810e284c9..e28e966788 100644 --- a/packages/nc-gui/components/nc/DateWeekSelector.vue +++ b/packages/nc-gui/components/nc/DateWeekSelector.vue @@ -1,16 +1,16 @@ @@ -161,20 +161,22 @@ const paginate = (action: 'next' | 'prev') => {
- {{ day }} + {{ + day + }}
(), { selectedDate: null, isDisabled: false, - pageDate: new Date(), + pageDate: dayjs(), yearPicker: false, }) const emit = defineEmits(['update:selectedDate', 'update:pageDate']) -const pageDate = useVModel(props, 'pageDate', emit) -const selectedDate = useVModel(props, 'selectedDate', emit) +const pageDate = useVModel(props, 'pageDate', emit) +const selectedDate = useVModel(props, 'selectedDate', emit) const years = computed(() => { - const date = dayjs(pageDate.value) + const date = pageDate.value const startOfYear = date.startOf('year') const years: dayjs.Dayjs[] = [] for (let i = 0; i < 12; i++) { @@ -28,16 +28,10 @@ const years = computed(() => { return years }) -const currentYear = computed(() => { - return pageDate.value.getFullYear() -}) - const months = computed(() => { - const date = dayjs(pageDate.value) - const months: dayjs.Dayjs[] = [] for (let i = 0; i < 12; i++) { - months.push(date.set('month', i)) + months.push(pageDate.value.set('month', i)) } return months }) @@ -48,19 +42,19 @@ const compareDates = (date1: dayjs.Dayjs, date2: dayjs.Dayjs) => { } const isMonthSelected = (date: dayjs.Dayjs) => { - if (!selectedDate.value) return false - return compareDates(date, dayjs(selectedDate.value)) + if (!dayjs(selectedDate.value).isValid()) return false + return compareDates(date, selectedDate.value) } const paginateMonth = (action: 'next' | 'prev') => { - let date = dayjs(pageDate.value) + let date = pageDate.value if (action === 'next') { date = date.add(1, 'year') } else { date = date.subtract(1, 'year') } - pageDate.value = date.toDate() - emit('update:pageDate', date.toDate()) + pageDate.value = date + emit('update:pageDate', date) } const paginateYear = (action: 'next' | 'prev') => { @@ -70,8 +64,8 @@ const paginateYear = (action: 'next' | 'prev') => { } else { date = date.subtract(12, 'year').clone() } - pageDate.value = date.toDate() - emit('update:pageDate', date.toDate()) + pageDate.value = date + emit('update:pageDate', date) } const paginate = (action: 'next' | 'prev') => { @@ -99,7 +93,7 @@ const compareYear = (date1: dayjs.Dayjs, date2: dayjs.Dayjs) => { {{ $t('labels.previousYear') }} - {{ yearPicker ? 'Select Year' : currentYear }} + {{ yearPicker ? 'Select Year' : pageDate.year() }} @@ -119,7 +113,7 @@ const compareYear = (date1: dayjs.Dayjs, date2: dayjs.Dayjs) => { '!bg-brand-50 !border-2 !border-brand-500': isMonthSelected(month), }" class="h-9 rounded-lg flex font-medium items-center justify-center hover:(border-1 border-gray-200 bg-gray-100) text-gray-500 cursor-pointer" - @click="selectedDate = month.toDate()" + @click="selectedDate = month" > {{ month.format('MMM') }} @@ -129,10 +123,10 @@ const compareYear = (date1: dayjs.Dayjs, date2: dayjs.Dayjs) => { v-for="(year, id) in years" :key="id" :class="{ - '!bg-brand-50 !border-2 !border-brand-500': compareYear(year, dayjs(selectedDate)), + '!bg-brand-50 !border-2 !border-brand-500': compareYear(year, selectedDate), }" class="h-9 rounded-lg flex font-medium items-center justify-center hover:(border-1 border-gray-200 bg-gray-100) text-gray-500 cursor-pointer" - @click="selectedDate = year.toDate()" + @click="selectedDate = year" > {{ year.format('YYYY') }} diff --git a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue index 57f2112d98..4d6ab72978 100644 --- a/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue +++ b/packages/nc-gui/components/smartsheet/calendar/DayView/DateTimeField.vue @@ -17,6 +17,8 @@ const { selectedDate, selectedTime, formattedData, calendarRange, formattedSideB const hours = computed(() => { const hours: Array = [] + const _selectedDate = dayjs(selectedDate.value) + for (let i = 0; i < 24; i++) { hours.push( dayjs() @@ -24,9 +26,9 @@ const hours = computed(() => { .minute(0) .second(0) .millisecond(0) - .year(selectedDate.value.getFullYear() || dayjs().year()) - .month(selectedDate.value.getMonth() || dayjs().month()) - .date(selectedDate.value.getDate() || dayjs().date()), + .year(_selectedDate.year()) + .month(_selectedDate.month()) + .date(_selectedDate.date()), ) } return hours @@ -639,7 +641,6 @@ const dragStart = (event: MouseEvent, record: Row) => { :record="record" :resize="!!record.rowMeta.range?.fk_to_col && isUIAllowed('dataEdit')" color="blue" - size="auto" @resize-start="onResizeStart" /> diff --git a/packages/nc-gui/components/smartsheet/calendar/MonthView.vue b/packages/nc-gui/components/smartsheet/calendar/MonthView.vue index f2c6ab4c0e..39638c3708 100644 --- a/packages/nc-gui/components/smartsheet/calendar/MonthView.vue +++ b/packages/nc-gui/components/smartsheet/calendar/MonthView.vue @@ -1,6 +1,5 @@