diff --git a/docs/v2/api.md b/docs/v2/api.md index c1288c8..3bb9909 100644 --- a/docs/v2/api.md +++ b/docs/v2/api.md @@ -288,17 +288,6 @@ calendar.chooseDateArea(['2020-10-20', '2020-10-30']) ## 节假日 -### 显示法定节假日班/休情况 - -配置日历config: - -```js {2} -calendarConfig: { - showHolidays: true, - ... // 更多配置待接入 -} -``` - ### 获取日历面板当前年份节假日信息 ```js diff --git a/docs/v2/guide.md b/docs/v2/guide.md index e1f9d9f..c642cc9 100644 --- a/docs/v2/guide.md +++ b/docs/v2/guide.md @@ -103,14 +103,16 @@ const conf = { inverse: true, // 单选模式下是否支持取消选中, markToday: '今', // 当天日期展示不使用默认数字,用特殊文字标记 takeoverTap: true, // 是否完全接管日期点击事件(日期不会选中) + emphasisWeek: true, // 是否高亮显示周末日期 chooseAreaMode: true, // 开启日期范围选择模式,该模式下只可选择时间段 showHolidays: true, // 显示法定节假日班/休情况,需引入holidays插件 + showFestival: true, // 显示节日信息(如教师节等),需引入holidays插件 highlightToday: true, // 是否高亮显示当天,区别于选中样式(初始化时当天高亮并不代表已选中当天) defaultDate: '2018-3-6', // 默认选中指定某天,如需选中需配置 autoChoosedWhenJump: true preventSwipe: true, // 是否禁用日历滑动切换月份 firstDayOfWeek: 'Mon', // 每周第一天为周一还是周日,默认按周日开始 onlyShowCurrentMonth: true, // 日历面板是否只显示本月日期 - autoChoosedWhenJump: true, // 跳转到指定日期后是否需要自动选中 + autoChoosedWhenJump: true, // 设置默认日期及跳转到指定日期后是否需要自动选中 disableMode: { // 禁用某一天之前/之后的所有日期 type: 'after', // [‘before’, 'after'] diff --git a/src/app.json b/src/app.json index ae9f3d6..047ea65 100644 --- a/src/app.json +++ b/src/app.json @@ -1,5 +1,5 @@ { - "pages":[ + "pages": [ "pages/index/index", "pages/calendar/index", "pages/calendarV2/index", @@ -8,10 +8,11 @@ "pages/calendarMoreComponent/index", "pages/datepickerTemplate/index" ], - "window":{ - "backgroundTextStyle":"light", + "window": { + "backgroundTextStyle": "light", "navigationBarBackgroundColor": "#fff", "navigationBarTitleText": "小程序日历", - "navigationBarTextStyle":"black" - } -} + "navigationBarTextStyle": "black" + }, + "sitemapLocation": "sitemap.json" +} \ No newline at end of file diff --git a/src/component/v2/core.js b/src/component/v2/core.js index 7bbf5eb..dd40ae0 100644 --- a/src/component/v2/core.js +++ b/src/component/v2/core.js @@ -42,7 +42,7 @@ function calculatePrevMonthGrids(year, month, config) { empytGrids.push({ ...YMInfo, date: i, - day: week || 7 + week }) } } @@ -112,7 +112,7 @@ function calculateNextMonthGrids(year, month, config) { id: i - 1, ...YMInfo, date: i, - day: week || 7 + week: week || 7 }) } } diff --git a/src/component/v2/index.wxml b/src/component/v2/index.wxml index f47ac36..4d15a87 100644 --- a/src/component/v2/index.wxml +++ b/src/component/v2/index.wxml @@ -28,13 +28,13 @@ - + {{config.markToday && item.isToday ? config.markToday : item.date}} - {{item.label || item.lunar.Term || item.lunar.IDayCn}} + {{item.label || item.lunar.Term || item.lunar.IDayCn}} { return { name: 'holidays', - beforeRender(calendarData = {}, calendarConfig = {}) { + beforeRender(calendarData = {}, calendarConfig = {}, component) { let { dates = [] } = calendarData - if (calendarConfig.showHolidays) { + if (calendarConfig.showHolidays || calendarConfig.showFestival) { dates = dates.map(d => { let item = { ...d } const { year, month, date } = item - const hasHolidaysOfThisMonth = holidays[year] && holidays[year][month] - if (hasHolidaysOfThisMonth) { - const holidayDate = hasHolidaysOfThisMonth[date] - if (holidayDate) { - item.label = holidayDate.text - } else { - const holidayKeys = Object.keys( - hasHolidaysOfThisMonth - ).filter(item => item.includes('-')) - let target = '' - for (let v of holidayKeys) { - const [start, end] = v.split('-') - if (+d.date >= +start && +d.date <= +end) { - target = v - break - } + const hasHolidaysOfThisMonth = + (holidays[year] && holidays[year][month]) || {} + const holidayDate = hasHolidaysOfThisMonth[date] + if (holidayDate) { + item = { + ...item, + ...holidayDate + } + } else { + const holidayKeys = Object.keys( + hasHolidaysOfThisMonth + ).filter(item => item.includes('-')) + let target = '' + for (let v of holidayKeys) { + const [start, end] = v.split('-') + if (+d.date >= +start && +d.date <= +end) { + target = v + break + } + } + const [start, end] = target.split('-') + const isInHolidays = inHolidays( + { + year, + month + }, + { + start, + end, + current: date + } + ) + if (isInHolidays) { + item = { + ...item, + ...hasHolidaysOfThisMonth[target] } - const [start, end] = target.split('-') - const isInHolidays = inHolidays( - { - year, - month - }, - { - start, - end, - current: date + } else if (calendarConfig.showFestival) { + const festivalDate = hasFestivalDate(item, component) + if (festivalDate) { + item = { + ...item, + ...festivalDate } - ) - if (isInHolidays) { - item.label = hasHolidaysOfThisMonth[target].text } } } diff --git a/src/component/v2/plugins/week.js b/src/component/v2/plugins/week.js index 49f8e36..c6fec17 100644 --- a/src/component/v2/plugins/week.js +++ b/src/component/v2/plugins/week.js @@ -77,7 +77,7 @@ function getDatesWhenTargetInFirstWeek(target, firstWeekDates) { year: prevMonthInfo.year, month: prevMonthInfo.month, date: lastMonthDatsCount, - day: week + week }) lastMonthDatsCount -= 1 } @@ -95,7 +95,7 @@ function getDatesWhenTargetInLastWeek(target, lastWeekDates) { year: prevMonthInfo.year, month: prevMonthInfo.month, date: i + 1, - day: week + week }) } return dates diff --git a/src/component/v2/theme/theme-default.wxss b/src/component/v2/theme/theme-default.wxss index 6162385..08de663 100644 --- a/src/component/v2/theme/theme-default.wxss +++ b/src/component/v2/theme/theme-default.wxss @@ -55,3 +55,7 @@ .default_date-desc-disable { color: #e2e2e2; } + +.default_festival { + color: #c2c2c2; +} diff --git a/src/component/v2/theme/theme-elegant.wxss b/src/component/v2/theme/theme-elegant.wxss index d1993e8..aa1be92 100644 --- a/src/component/v2/theme/theme-elegant.wxss +++ b/src/component/v2/theme/theme-elegant.wxss @@ -52,3 +52,7 @@ .elegant_date-desc-disable { color: #e2e2e2; } + +.elegant_festival { + color: #c2c2c2; +} diff --git a/src/component/v2/utils/index.js b/src/component/v2/utils/index.js index f304be4..395e4ef 100644 --- a/src/component/v2/utils/index.js +++ b/src/component/v2/utils/index.js @@ -197,7 +197,7 @@ class DateUtil { id: i - 1, month: +month, date: i, - day: week || 7, + week, isToday: +today.year === +year && +today.month === +month && i === +today.date } diff --git a/src/pages/calendarV2/index.js b/src/pages/calendarV2/index.js index c03dc46..9fd0869 100644 --- a/src/pages/calendarV2/index.js +++ b/src/pages/calendarV2/index.js @@ -19,7 +19,8 @@ const conf = { calendarConfig: { // theme: 'elegant', // showHolidays: true, - // chooseAreaMode: true + // emphasisWeek: true, + chooseAreaMode: true // defaultDate: '2020-9-8', // autoChoosedWhenJump: true },