写陀螺匠日历配置,需要根据动态年份和月份获取当前月份的周六周天日期,具体方法在下面,有需要的可以看一下
// 获取本月的休息时间(传入年和月)
getWeeks(year, month) {
let is_days = new Date(year, month, 0).getDate() // 当前月份多少天
const date = new Date()
const currentYear = year
let currentMonth = month
if (currentMonth < 10) currentMonth = '0' + currentMonth
const firstDate = new Date(`${currentYear}-${currentMonth}-01`)
const day = parseInt(firstDate.getDay() == 0 ? 7 : firstDate.getDay())
const days = new Date(currentYear, currentMonth, 0).getDate()
// 计算当月周数
let weeks
const temp = days % 7
if (7 - day >= temp) {
weeks = parseInt(days / 7) + 1
} else {
weeks = parseInt(days / 7) + 2
}
const lastDay = new Date(`${currentYear}-${currentMonth}-${days}`).getDay()
if (lastDay === 0) {
weeks--
}
// 提取本月的周六和周末
let freeDays = []
if (day <= 7) {
freeDays.push(7 - day)
freeDays.push(1 + (7 - day))
}
for (let i = 1, j = weeks; i < j; i++) {
const last = freeDays[freeDays.length - 1]
if (last + 6 <= is_days) {
freeDays.push(last + 6)
}
if (last + 7 <= is_days) {
freeDays.push(last + 7)
}
}
if (freeDays[0] == 0) {
freeDays.splice(0, 1)
}
let result = []
freeDays.forEach((m) => {
result.push(`${currentYear}-${currentMonth}-${m < 10 ? '0' + m : m}`)
})
return result
}