欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

设置节假日

程序员文章站 2022-05-16 18:36:41
...
   formatter(day) {
	      // console.log('day', day)
	      const year = day.date.getFullYear()
	      const month = day.date.getMonth() + 1
	      const date = day.date.getDate()
	      let week = day.date.getDay()
	      if (week === 0) week = 7
	      const holiday = [
	        {
	          year: 2020,
	          monthDate: [
	            {
	              month: 1,
	              date: [
	                { day: 1, text: '元旦', holidayColor: true },
	                { day: 24, text: '除夕', holidayColor: true },
	                { day: 25, text: '春节', holidayColor: true },
	              ]
	            },
	            {
	              month: 2,
	              date: [
	                { day: 14, text: '情人节', holidayColor: true },
	                { day: 8, text: '元宵节', holidayColor: true }
	              ]
	            },
	            {
	              month: 4,
	              date: [
	                { day: 1, text: '愚人节', holidayColor: true },
	                { day: 4, text: '清明节', holidayColor: true }
	              ]
	            },
	            {
	              month: 5,
	              date: [
	                { day: 1, text: '劳动节', holidayColor: true }
	              ]
	            },
	            {
	              month: 6,
	              date: [
	                { day: 1, text: '儿童节', holidayColor: true },
	                { day: 25, text: '端午节', holidayColor: true }
	              ]
	            },
	            {
	              month: 8,
	              date: [
	                { day: 25, text: '七夕节', holidayColor: true }
	              ]
	            },
	            {
	              month: 9,
	              date: [
	                { day: 10, text: '教师节', holidayColor: true }
	              ]
	            },
	            {
	              month: 10,
	              date: [
	                { day: 1, text: '国庆节', holidayColor: true },
	                { day: 1, text: '中秋节', holidayColor: true }
	              ]
	            },
	            {
	              month: 11,
	              date: [
	                { day: 11, text: '光棍节', holidayColor: true }
	              ]
	            },
	            {
	              month: 12,
	              date: [
	                { day: 24, text: '平安夜', holidayColor: true },
	                { day: 25, text: '圣诞节', holidayColor: true }
	              ]
	            },
	          ]
	        },
	        {
	          year: 2021,
	          monthDate: [
	            {
	              month: 1,
	              date: [
	                { day: 1, text: '元旦', holidayColor: true }
	              ]
	            },
	            {
	              month: 2,
	              date: [
	                { day: 14, text: '情人节', holidayColor: true },
	                { day: 11, text: '除夕', holidayColor: true },
	                { day: 12, text: '春节', holidayColor: true },
	                { day: 26, text: '元宵节', holidayColor: true }
	              ]
	            },
	            {
	              month: 4,
	              date: [
	                { day: 1, text: '愚人节', holidayColor: true },
	                { day: 4, text: '清明节', holidayColor: true }
	              ]
	            },
	            {
	              month: 5,
	              date: [
	                { day: 1, text: '劳动节', holidayColor: true }
	              ]
	            },
	            {
	              month: 6,
	              date: [
	                { day: 1, text: '儿童节', holidayColor: true },
	                { day: 14, text: '端午节', holidayColor: true }
	              ]
	            },
	            {
	              month: 8,
	              date: [
	                { day: 14, text: '七夕节', holidayColor: true }
	              ]
	            },
	            {
	              month: 9,
	              date: [
	                { day: 10, text: '教师节', holidayColor: true },
	                { day: 21, text: '中秋节', holidayColor: true }
	              ]
	            },
	            {
	              month: 10,
	              date: [
	                { day: 1, text: '国庆节', holidayColor: true }
	              ]
	            },
	            {
	              month: 11,
	              date: [
	                { day: 11, text: '光棍节', holidayColor: true }
	              ]
	            },
	            {
	              month: 12,
	              date: [
	                { day: 24, text: '平安夜', holidayColor: true },
	                { day: 25, text: '圣诞节', holidayColor: true }
	              ]
	            },
	          ]
	        },
	        {
	          year: 2022,
	          monthDate: [
	            {
	              month: 1,
	              date: [
	                { day: 1, text: '元旦', holidayColor: true },
	                { day: 31, text: '除夕', holidayColor: true },
	              ]
	            },
	            {
	              month: 2,
	              date: [
	                { day: 14, text: '情人节', holidayColor: true },
	                { day: 1, text: '春节', holidayColor: true },
	                { day: 25, text: '元宵节', holidayColor: true }
	              ]
	            },
	            {
	              month: 4,
	              date: [
	                { day: 1, text: '愚人节', holidayColor: true },
	                { day: 5, text: '清明节', holidayColor: true }
	              ]
	            },
	            {
	              month: 5,
	              date: [
	                { day: 1, text: '劳动节', holidayColor: true }
	              ]
	            },
	            {
	              month: 6,
	              date: [
	                { day: 1, text: '儿童节', holidayColor: true },
	                { day: 3, text: '端午节', holidayColor: true }
	              ]
	            },
	            {
	              month: 8,
	              date: [
	                { day: 4, text: '七夕节', holidayColor: true }
	              ]
	            },
	            {
	              month: 9,
	              date: [
	                { day: 10, text: '教师节', holidayColor: true },
	                { day: 10, text: '中秋节', holidayColor: true }
	              ]
	            },
	            {
	              month: 10,
	              date: [
	                { day: 1, text: '国庆节', holidayColor: true }
	              ]
	            },
	            {
	              month: 11,
	              date: [
	                { day: 11, text: '光棍节', holidayColor: true }
	              ]
	            },
	            {
	              month: 12,
	              date: [
	                { day: 24, text: '平安夜', holidayColor: true },
	                { day: 25, text: '圣诞节', holidayColor: true }
	              ]
	            },
	          ]
	        },
	      ]
	      if (week === 6 || week === 7) day.weekendColor = true
	      const yearObj = holiday.filter(item => item.year === year)[0]
	      if (!yearObj) return day
	      const monthObj = yearObj.monthDate.filter(item => item.month === month)[0]
	      if (!monthObj) return day
	      monthObj.date.forEach(item => {
	        if (item.day === date) {
	          day.text = item.text
	          day.holidayColor = item.holidayColor
	        }
	      })
	      return day;
	    },

相关标签: 小程序