From 5db503b2a15c818a90fa9514d4ae6b641be6d644 Mon Sep 17 00:00:00 2001 From: treadpit Date: Fri, 16 Oct 2020 17:43:33 +0800 Subject: [PATCH 1/2] feat: support festival of holiday plugin --- docs/v2/api.md | 11 -- docs/v2/guide.md | 3 +- src/app.json | 13 +- src/component/v2/index.wxml | 2 +- .../v2/plugins/holidays/holidays-map.js | 163 ++++++++++++++++-- src/component/v2/plugins/holidays/index.js | 107 ++++++++---- src/component/v2/theme/theme-default.wxss | 4 + src/component/v2/theme/theme-elegant.wxss | 4 + src/pages/calendarV2/index.js | 2 +- 9 files changed, 241 insertions(+), 68 deletions(-) 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..3d1138d 100644 --- a/docs/v2/guide.md +++ b/docs/v2/guide.md @@ -105,12 +105,13 @@ const conf = { takeoverTap: 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/index.wxml b/src/component/v2/index.wxml index f47ac36..ac8d35a 100644 --- a/src/component/v2/index.wxml +++ b/src/component/v2/index.wxml @@ -34,7 +34,7 @@ - {{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/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/pages/calendarV2/index.js b/src/pages/calendarV2/index.js index c03dc46..7d0d832 100644 --- a/src/pages/calendarV2/index.js +++ b/src/pages/calendarV2/index.js @@ -19,7 +19,7 @@ const conf = { calendarConfig: { // theme: 'elegant', // showHolidays: true, - // chooseAreaMode: true + chooseAreaMode: true // defaultDate: '2020-9-8', // autoChoosedWhenJump: true }, From f9ad3e31bbde35c688ec4aae59bdb0794af33dcc Mon Sep 17 00:00:00 2001 From: treadpit Date: Fri, 16 Oct 2020 17:55:57 +0800 Subject: [PATCH 2/2] feat: support config of emphasisWeek --- docs/v2/guide.md | 1 + src/component/v2/core.js | 4 ++-- src/component/v2/index.wxml | 2 +- src/component/v2/plugins/week.js | 4 ++-- src/component/v2/utils/index.js | 2 +- src/pages/calendarV2/index.js | 1 + 6 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/v2/guide.md b/docs/v2/guide.md index 3d1138d..c642cc9 100644 --- a/docs/v2/guide.md +++ b/docs/v2/guide.md @@ -103,6 +103,7 @@ const conf = { inverse: true, // 单选模式下是否支持取消选中, markToday: '今', // 当天日期展示不使用默认数字,用特殊文字标记 takeoverTap: true, // 是否完全接管日期点击事件(日期不会选中) + emphasisWeek: true, // 是否高亮显示周末日期 chooseAreaMode: true, // 开启日期范围选择模式,该模式下只可选择时间段 showHolidays: true, // 显示法定节假日班/休情况,需引入holidays插件 showFestival: true, // 显示节日信息(如教师节等),需引入holidays插件 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 ac8d35a..4d15a87 100644 --- a/src/component/v2/index.wxml +++ b/src/component/v2/index.wxml @@ -28,7 +28,7 @@ - + {{config.markToday && item.isToday ? config.markToday : item.date}}