From 0faf0b3b9ac4c2523f85d4815decd71d3cca09be Mon Sep 17 00:00:00 2001 From: herenshan112 Date: Tue, 16 Jul 2024 15:14:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=8E=86=E8=A7=86=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/calendar/Calendar.ts | 78 +++++++++++ src/api/calendar/DateClass.ts | 31 +++-- .../app/calendar/calendar1/calendarItem.vue | 105 ++++++++++---- .../app/calendar/calendar1/calendarPage.vue | 36 ++++- .../app/calendar/calendar1/dayPage.vue | 131 +++++++++++++++++- .../app/calendar/calendar1/monthPage.vue | 3 +- .../app/calendar/calendar1/weekPage.vue | 27 +++- src/components/DesignForm/app/index.vue | 28 ++-- src/components/DesignForm/app/timeAxis.vue | 17 ++- 9 files changed, 385 insertions(+), 71 deletions(-) diff --git a/src/api/calendar/Calendar.ts b/src/api/calendar/Calendar.ts index d9515c08a..553a0baae 100644 --- a/src/api/calendar/Calendar.ts +++ b/src/api/calendar/Calendar.ts @@ -2,6 +2,7 @@ import constValue from '@/api/calendar/const'; import constVal from '@/api/calendar/const'; import DateClass from '@/api/calendar/DateClass'; import { clockFactory } from '@/api/calendar/utils'; +import { formToJSON } from 'axios'; export interface dateBase { isCurrent: boolean; @@ -194,6 +195,83 @@ class Calendar { // console.log("日历数据",dateArray) return dateArray; } + //获取单一日期格式 + gainOneDay(y: number, m: number, d: number){ + let dateStr = y + "-" + m + "-" + d; // 要转换的日期字符串 + let now = new Date(dateStr); //当前日期字符串转换成Date对象 + const lun = DateClass.getLunars(y, m, d); + const l = lun.split('-'); + let currentTime = DateClass.getCurrent() + return { + title: d, + isCurrent: true, + isHolidays: DateClass.getHolidays([y, m, d]), + isWorks: DateClass.getWorks([y, m, d]), + date: `${y}-${clockFactory(m)}-${clockFactory(d)}`, + lunars: lun, + lunarsChinese: + DateClass.toChinaMonth(Number(l[1])) + DateClass.toChinaDay(Number(l[2])), + lunarsChina: DateClass.toChinaDay(Number(l[2])), + isNow: currentTime[2] === d ? true : false, + solarDay: DateClass.getSolarDay(m, d ), + lunarDay: DateClass.getlunarDay(Number(l[0]), Number(l[1]), Number(l[2])), + animal: DateClass.getAnimal(Number(l[0])), + astro: DateClass.toAstro(y, m, d), + term: getTerm(Number(l[0]), m, d), + + } + } + + //获取指定日期所在周的时间 + gainDayOfWeek(year: number, month: number, taday: number){ + let dateStr = year + "-" + month + "-" + taday; // 要转换的日期字符串 + let now = new Date(dateStr); //当前日期字符串转换成Date对象 + let nowTime = now.getTime(); + let nowDayOfWeek = now.getDay()==0?7:now.getDay(); //今天本周的第几天 + let taDay = now.getDate() + let firstTime = now.setDate(taDay - nowDayOfWeek + 1) + let currentTime = DateClass.getCurrent() + const dateArray: dateBase[] = []; + for(let i=1; i<=7;i++){ + let nextWeekFirstDaty = new Date(firstTime + 86400000 * (i - 1)) + let y: any = nextWeekFirstDaty.getFullYear(); + let m: any = nextWeekFirstDaty.getMonth() + 1; + let d: any = nextWeekFirstDaty.getDate(); + const lun = DateClass.getLunars(y, m, d); + const l = lun.split('-'); + dateArray.push({ + title: d, + isCurrent: true, + isHolidays: DateClass.getHolidays([y, m, d]), + isWorks: DateClass.getWorks([y, m, d - i]), + date: `${y}-${clockFactory(m)}-${clockFactory(d)}`, + lunars: lun, + lunarsChinese: + DateClass.toChinaMonth(Number(l[1])) + DateClass.toChinaDay(Number(l[2])), + lunarsChina: DateClass.toChinaDay(Number(l[2])), + isNow: currentTime[2] === d ? true : false, + solarDay: DateClass.getSolarDay(m, d + i), + lunarDay: DateClass.getlunarDay(Number(l[0]), Number(l[1]), Number(l[2])), + animal: DateClass.getAnimal(Number(l[0])), + astro: DateClass.toAstro(y, m, d), + term: getTerm(Number(l[0]), m, d), + + }); + } + + + // console.log("dateStr=========>",dateStr) + // console.log("now=========>",now) + // console.log("nowTime=========>",nowTime) + // console.log("nowDayOfWeek=========>",nowDayOfWeek) + // console.log("taDay=========>",taDay) + // console.log("kjsd=========>",firstTime) + // console.log("dateArray=========>",dateArray) + + return dateArray + } + + //获得一周的所有日期 getWeekNumber(year: number, month: number, taday: number) { let dateStr = year + "-" + month + "-" + taday; // 要转换的日期字符串 diff --git a/src/api/calendar/DateClass.ts b/src/api/calendar/DateClass.ts index e48cbafc9..847ad0521 100644 --- a/src/api/calendar/DateClass.ts +++ b/src/api/calendar/DateClass.ts @@ -333,6 +333,14 @@ class DateClass { } break; case 3: + let dateStr = y + "-" + m + "-" + d; // 要转换的日期字符串 + let now = new Date(dateStr); //当前日期字符串转换成Date对象 + let nowTime = now.getTime(); + let nextWeekFirstDaty = new Date(nowTime + 86400000) + let yy: any = nextWeekFirstDaty.getFullYear(); + let mm: any = nextWeekFirstDaty.getMonth() + 1; + let dd: any = nextWeekFirstDaty.getDate(); + return [yy,mm,dd] break; default: let month = m + 1 @@ -369,21 +377,14 @@ class DateClass { } break; case 3: - let day = d-1 - if(day <= 0){ - let month = m - 1 - if(month <= 0){ - y = y -1; - m = 12 - d = this.solarMonth(y,m) - }else{ - m = month - d = this.solarMonth(y,month) - } - }else{ - d = day - } - return [y,m,d] + let dateStr = y + "-" + m + "-" + d; // 要转换的日期字符串 + let now = new Date(dateStr); //当前日期字符串转换成Date对象 + let nowTime = now.getTime(); + let nextWeekFirstDaty = new Date(nowTime - 86400000) + let yy: any = nextWeekFirstDaty.getFullYear(); + let mm: any = nextWeekFirstDaty.getMonth() + 1; + let dd: any = nextWeekFirstDaty.getDate(); + return [yy,mm,dd] break; default: let month = m - 1 diff --git a/src/components/DesignForm/app/calendar/calendar1/calendarItem.vue b/src/components/DesignForm/app/calendar/calendar1/calendarItem.vue index 3a42ccfc5..545a67743 100644 --- a/src/components/DesignForm/app/calendar/calendar1/calendarItem.vue +++ b/src/components/DesignForm/app/calendar/calendar1/calendarItem.vue @@ -1,28 +1,3 @@ - - + + + diff --git a/src/components/DesignForm/app/calendar/calendar1/monthPage.vue b/src/components/DesignForm/app/calendar/calendar1/monthPage.vue index 251bbce31..15ba9e647 100644 --- a/src/components/DesignForm/app/calendar/calendar1/monthPage.vue +++ b/src/components/DesignForm/app/calendar/calendar1/monthPage.vue @@ -30,7 +30,7 @@ onMounted(()=>{ const selectedTime = ref(props.taDay[0] + "-" + clockFactory(props.taDay[1]) + "-" + clockFactory(props.taDay[2])) const emit = defineEmits(['getDate']); -function changeDate(time: dateBase) { +const changeDate = (time: dateBase) => { selectedTime.value = time.date; emit('getDate', time); } @@ -115,6 +115,7 @@ const TBody = computed(() => padding: 2px; font-size: 16px; transition: all 0.2s; + width: calc(100%/7); } .t-calendar-col:last-child { border-right: 1px solid #ebeef5; diff --git a/src/components/DesignForm/app/calendar/calendar1/weekPage.vue b/src/components/DesignForm/app/calendar/calendar1/weekPage.vue index 2ce942b54..1ab3b7b71 100644 --- a/src/components/DesignForm/app/calendar/calendar1/weekPage.vue +++ b/src/components/DesignForm/app/calendar/calendar1/weekPage.vue @@ -26,11 +26,24 @@ const drawingBoardHeight = computed(()=>{ //周期 const THeader = Calendar.title(); const WeekBody = computed(()=>{ - - console.log("画板高度--->",props.taDay.start[0]); - return Calendar.getWeekNumber(props.taDay.start[0],props.taDay.start[1],props.taDay.start[2]); + Calendar.gainDayOfWeek(props.taDay.start[0],props.taDay.start[1],props.taDay.start[2]); + console.log("画板高度--->",props.taDay.start[0]); + return Calendar.gainDayOfWeek(props.taDay.start[0],props.taDay.start[1],props.taDay.start[2]); }); + +onMounted(()=>{ + nextTick(()=>{ + let ddTime = DateClass.getCurrent() + selectedTime.value = ddTime[0] + "-" + clockFactory(ddTime[1]) + "-" + clockFactory(ddTime[2]) + }) +}) +const selectedTime = ref(props.taDay[0] + "-" + clockFactory(props.taDay[1]) + "-" + clockFactory(props.taDay[2])) +const emit = defineEmits(['getDate']); +const changeDate = (time: dateBase) => { + selectedTime.value = time.date; + emit('getDate', time); +}