diff --git a/src/api/calendar/Calendar.ts b/src/api/calendar/Calendar.ts index 38be445c2..553a0baae 100644 --- a/src/api/calendar/Calendar.ts +++ b/src/api/calendar/Calendar.ts @@ -2,11 +2,13 @@ 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; title: number; isHolidays: boolean; + isWorks: boolean; date: string; lunars: string; lunarsChina: string; @@ -42,7 +44,7 @@ class Calendar { title() { const title: string[] = []; for (let i = 0; i <= 6; i++) { - title.push(constValue.nStr1[i % 7]); + title.push(constValue.nStr5[i % 7]); } return title; } @@ -81,7 +83,7 @@ class Calendar { const y = date[1] === 1 ? date[0] - 1 : date[0]; const m = date[1] === 1 ? 12 : date[1] - 1; let w = DateClass.solarMonth(y, m); - + console.log("获取当月前面需补齐的数组-->",y,m,w,last) const arr: dateBase[] = []; for (let i = 0; i < last; i++) { const lun = DateClass.getLunars(y, m, w - i); @@ -90,6 +92,7 @@ class Calendar { title: w - i, isCurrent: false, isHolidays: DateClass.getHolidays([y, m, w - i]), + isWorks: DateClass.getWorks([y, m, w - i]), date: `${y}-${clockFactory(m)}-${clockFactory(w - i)}`, lunars: lun, lunarsChinese: @@ -100,7 +103,8 @@ class Calendar { lunarDay: DateClass.getlunarDay(Number(l[0]), Number(l[1]), Number(l[2])), animal: DateClass.getAnimal(Number(l[0])), astro: DateClass.toAstro(y, m, w - i), - term: getTerm(Number(l[0]), m, w - i) + term: getTerm(Number(l[0]), m, w - i), + }); } return arr; @@ -112,7 +116,6 @@ class Calendar { const arr: dateBase[] = []; const y = date[1] === 12 ? date[0] + 1 : date[0]; const m = date[1] === 12 ? 1 : date[1] + 1; - for (let i = 1; i < 42 - day.length + 1; i++) { const lun = DateClass.getLunars(y, m, i); const l = lun.split('-'); @@ -120,6 +123,7 @@ class Calendar { title: i, isCurrent: false, isHolidays: DateClass.getHolidays([y, m, i]), + isWorks: DateClass.getWorks([y, m, i]), date: `${y}-${clockFactory(m)}-${clockFactory(i)}`, lunars: lun, lunarsChinese: @@ -145,6 +149,7 @@ class Calendar { title: i, isCurrent: true, isHolidays: DateClass.getHolidays([date[0], date[1], i]), + isWorks: DateClass.getWorks([date[0], date[1], i]), date: `${date[0]}-${clockFactory(date[1])}-${clockFactory(i)}`, lunars: lun, lunarsChinese: @@ -167,13 +172,17 @@ class Calendar { const result = this.validateDate(date); const currentDay = DateClass.solarWeeks(result[0], result[1]); - + console.log("获取当月的完整数据",currentDay,result) // 获取当月的完整数据 const beforDays = this.beforDays(date, currentDay).reverse(); const m = this.getDay(date, beforDays); + + console.log("获取当月的完整数据--->",m,date) + const afterDays = this.afterDays(m, date); + // 转化成参数 const params = this.getDateParams(afterDays, date); @@ -183,8 +192,138 @@ class Calendar { for (let row = 0; row < 6; row++) { dateArray.push(params.splice(0, 7)); } + // 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; // 要转换的日期字符串 + let now = new Date(dateStr); + let nowTime = now.getTime(); + let second = nowTime % 86400000; + let day = (now.getDay() + 6) % 7; + let endTime = nowTime - second + new Date().getTimezoneOffset() * 60000 - day * 86400000; + // var dataAry = new Array + // for(let i = 0; i <7; i++) { + let nextWeekFirstDatysss = new Date(endTime ); + // let y: any = nextWeekFirstDaty.getFullYear(); + // let m: any = nextWeekFirstDaty.getMonth() + 1; + // let d: any = nextWeekFirstDaty.getDate(); + // dataAry.push([y,m,d]) + // } + + console.log("获得一周的所有日期---------------->",dateStr,now.getDay(),day,nextWeekFirstDatysss,endTime) + + + let currentTime = DateClass.getCurrent() + const dateArray: dateBase[] = []; + for(let i = 0; i <7; i++) { + let nextWeekFirstDaty = new Date(endTime + 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('-'); + console.log("获得一周的所有日期",i,d,endTime + 86400000*(i+1)) + dateArray.push({ + title: d, + isCurrent: true, + isHolidays: DateClass.getHolidays([y, m, d + i]), + isWorks: DateClass.getWorks([y, m, d - i]), + date: `${y}-${clockFactory(m)}-${clockFactory(d + i)}`, + 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 + i), + term: getTerm(Number(l[0]), m, d + i), + + }); + } + return dateArray + + } } export default new Calendar(); diff --git a/src/api/calendar/DateClass.ts b/src/api/calendar/DateClass.ts index 9d0714507..847ad0521 100644 --- a/src/api/calendar/DateClass.ts +++ b/src/api/calendar/DateClass.ts @@ -1,7 +1,8 @@ import constValue from '@/api/calendar/const'; import { clockFactory } from '@/api/calendar/utils'; import config from '@/api/calendar/config'; -export const dayArr = ['日', '一', '二', '三', '四', '五', '六']; +export const dayArr = [ '一', '二', '三', '四', '五', '六','日']; +// export const dayArr = ['日', '一', '二', '三', '四', '五', '六']; /** * 日期信息的操作类 @@ -32,6 +33,18 @@ class DateClass { config.Holidays.indexOf(`${date[0]}${clockFactory(date[1])}${clockFactory(date[2])}`) > -1 ); + } + getWorks(date: number[]) { + // console.log("日清杀杀杀",`${date[0]}${clockFactory(date[1])}${clockFactory(date[2])}`) + // console.log("日清杀杀杀--》",config.Works.indexOf(`${date[0]}${clockFactory(date[1])}${clockFactory(date[2])}`)) + // console.log("日清杀杀杀--》",( + // config.Works.indexOf(`${date[0]}${clockFactory(date[1])}${clockFactory(date[2])}`) > + // -1 + // )) + return ( + config.Works.indexOf(`${date[0]}${clockFactory(date[1])}${clockFactory(date[2])}`) > + -1 + ); } /** * 获取公历月份天数 @@ -61,7 +74,11 @@ class DateClass { */ solarWeek(y: number, m: number, d: number) { let date = new Date(y, m - 1, d); - let week = date.getDay(); + let week = date.getDay()-1; + if(week < 0){ + week = 6 + } + // console.log("获取公历某一天是星期几",y, m ,date,week,week < 0) return week; } /** @@ -81,7 +98,10 @@ class DateClass { * @returns {string} 返回农历日期通俗表示法:‘初一’ */ toChinaDay(d: number) { + let str = d == 10 ? constValue.nStr2[0] : constValue.nStr2[Math.floor(d / 10)]; + + // console.log('返回农历日期通俗表示法',d,str) return str + (d % 10 ? constValue.nStr1[d % 10] : constValue.nStr1[10]); } /** @@ -298,37 +318,73 @@ class DateClass { } /** @ 作者: 秦东 - @ 时间: 2024-07-12 11:50:37 - @ 功能: 处理年月日回退数据 + @ 时间: 2024-07-15 09:00:20 + @ 功能: 前进时间 @ 1: 月;2:周;3:天 */ - gobackTime(y: number, m: number, d: number,t?:number){ - console.log("计算时间--0--》",y,m,d,t) + moveTime(y: number, m: number, d: number,t?:number){ switch(t){ case 2: - let startWeek = this.getMonday(y,m,d,'s',0) - let endWeek = this.getMonday(y,m,d,'e',0) + let startWeek = this.getMonday(y,m,d,'s',1) + let endWeek = this.getMonday(y,m,d,'e',1) return { start:startWeek, end:endWeek } 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) - } + 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 + if(month > 12){ + y = y + 1; + m = 1 + d = this.solarMonth(y,m) }else{ - d = day + m = month + let day = this.solarMonth(y,month) + if(d > day){ + d = day + } + } return [y,m,d] + } + } + /** + @ 作者: 秦东 + @ 时间: 2024-07-12 11:50:37 + @ 功能: 处理年月日回退数据 + @ 1: 月;2:周;3:天 + */ + gobackTime(y: number, m: number, d: number,t?:number, dt?:number){ + // console.log("计算时间--0--》",y,m,d,t) + switch(t){ + case 2: + let startWeek = this.getMonday(y,m,d,'s',dt?dt:0) + let endWeek = this.getMonday(y,m,d,'e',dt?dt:0) + return { + start:startWeek, + end:endWeek + } + 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 @@ -336,7 +392,7 @@ class DateClass { y = y -1; m = 12 d = this.solarMonth(y,m) - console.log("计算时间--1--》",y,m,d) + // console.log("计算时间--1--》",y,m,d) }else{ m = month let day = this.solarMonth(y,month) @@ -354,7 +410,7 @@ class DateClass { /** @ 作者: 秦东 @ 时间: 2024-07-12 13:48:55 - @ 功能: 获取周 + @ 功能: 任意日期获取周 */ getMonday = (year: number, month: number, taday: number,type: any, dates: any) => { // let now = new Date(); @@ -373,11 +429,7 @@ class DateClass { - console.log("now--->",now) - console.log("nowTime--->",nowTime) - console.log("day--->",day) - console.log("longTime--->",longTime) - console.log("n--->",n) + @@ -393,9 +445,19 @@ class DateClass { let d: any = date.getDate(); // m = m < 10 ? "0" + m : m; // d = d < 10 ? "0" + d : d; + + + // console.log("now--->",date) + // console.log("nowTime--->",nowTime) + // console.log("day--->",day) + // console.log("longTime--->",longTime) + // console.log("n--->",n) + let days = y + "-" + m + "-" + d; return [y, m, d]; } + + } export default new DateClass(); diff --git a/src/api/calendar/config.ts b/src/api/calendar/config.ts index 911138f2e..eacc07ee3 100644 --- a/src/api/calendar/config.ts +++ b/src/api/calendar/config.ts @@ -132,6 +132,38 @@ export default { '20230125', '20230126', '20230127', + '20231230', + '20240101', + '20240210', + '20240210', + '20240211', + '20240212', + '20240213', + '20240214', + '20240215', + '20240216', + '20240217', + '20240404', + '20240405', + '20240406', + '20240501', + '20240502', + '20240503', + '20240504', + '20240505', + '20240608', + '20240609', + '20240610', + '20240915', + '20240916', + '20240917', + '20241001', + '20241002', + '20241003', + '20241004', + '20241005', + '20241006', + '20241007', ], /** * 补休日期 @@ -165,5 +197,13 @@ export default { '20220507', '20221008', '20221009', + '20240204', + '20240218', + '20240407', + '20240428', + '20240511', + '20240914', + '20240929', + '20241012', ], }; diff --git a/src/api/calendar/const.ts b/src/api/calendar/const.ts index fcff549ab..3618f192b 100644 --- a/src/api/calendar/const.ts +++ b/src/api/calendar/const.ts @@ -303,6 +303,19 @@ export default { '\u516b', '\u4e5d', '\u5341' + ], + nStr5: [ + '\u4e00', + '\u4e8c', + '\u4e09', + '\u56db', + '\u4e94', + '\u516d', + '\u65e5', + '\u4e03', + '\u516b', + '\u4e5d', + '\u5341' ], /** * 日期转农历称呼速查表 diff --git a/src/components/DesignForm/app/calendar/calendar1/calendarItem.vue b/src/components/DesignForm/app/calendar/calendar1/calendarItem.vue new file mode 100644 index 000000000..545a67743 --- /dev/null +++ b/src/components/DesignForm/app/calendar/calendar1/calendarItem.vue @@ -0,0 +1,222 @@ + + + + + + diff --git a/src/components/DesignForm/app/calendar/calendar1/calendarPage.vue b/src/components/DesignForm/app/calendar/calendar1/calendarPage.vue index 1e8d12e56..ca6230990 100644 --- a/src/components/DesignForm/app/calendar/calendar1/calendarPage.vue +++ b/src/components/DesignForm/app/calendar/calendar1/calendarPage.vue @@ -5,6 +5,14 @@ --> @@ -102,7 +212,7 @@ const forwardTime = () =>{ } } .weekNumber{ - + } } diff --git a/src/components/DesignForm/app/calendar/calendar1/dayPage.vue b/src/components/DesignForm/app/calendar/calendar1/dayPage.vue new file mode 100644 index 000000000..a78938cd0 --- /dev/null +++ b/src/components/DesignForm/app/calendar/calendar1/dayPage.vue @@ -0,0 +1,153 @@ + + + + diff --git a/src/components/DesignForm/app/calendar/calendar1/monthPage.vue b/src/components/DesignForm/app/calendar/calendar1/monthPage.vue new file mode 100644 index 000000000..15ba9e647 --- /dev/null +++ b/src/components/DesignForm/app/calendar/calendar1/monthPage.vue @@ -0,0 +1,129 @@ + + + + diff --git a/src/components/DesignForm/app/calendar/calendar1/weekPage.vue b/src/components/DesignForm/app/calendar/calendar1/weekPage.vue new file mode 100644 index 000000000..1ab3b7b71 --- /dev/null +++ b/src/components/DesignForm/app/calendar/calendar1/weekPage.vue @@ -0,0 +1,110 @@ + + + + diff --git a/src/components/DesignForm/app/calendarPage.vue b/src/components/DesignForm/app/calendarPage.vue index ab14dd546..2de7a0c0f 100644 --- a/src/components/DesignForm/app/calendarPage.vue +++ b/src/components/DesignForm/app/calendarPage.vue @@ -25,7 +25,7 @@ let timek = new Date()