-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #386 from treadpit/develop
feat: add plugin of holidays
- Loading branch information
Showing
6 changed files
with
248 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* * | ||
@Author: drfu* | ||
@Description: 数据来源于国务院办公厅关于2020年部分节假日安排的通知(国办发明电〔2019〕16号)_政府信息公开专栏,http://www.gov.cn/zhengce/content/2019-11/21/content_5454164.htm | ||
@Date: 2020-10-12 14:29:45* | ||
* @Last Modified by: drfu | ||
* @Last Modified time: 2020-10-12 14:30:31 | ||
*/ | ||
|
||
export default { | ||
2020: { | ||
1: { | ||
1: { | ||
type: 'holiday', | ||
name: '元旦', | ||
text: '休' | ||
}, | ||
19: { | ||
type: 'work', | ||
name: '调班', | ||
text: '班' | ||
}, | ||
'24-30': { | ||
type: 'holiday', | ||
name: '春节', | ||
text: '休' | ||
} | ||
}, | ||
2: { | ||
1: { | ||
type: 'work', | ||
name: '调班', | ||
text: '班' | ||
} | ||
}, | ||
4: { | ||
'4-6': { | ||
type: 'holiday', | ||
name: '清明节', | ||
text: '休' | ||
}, | ||
26: { | ||
type: 'work', | ||
name: '调班', | ||
text: '班' | ||
} | ||
}, | ||
5: { | ||
'1-5': { | ||
type: 'holiday', | ||
name: '劳动节', | ||
text: '休' | ||
}, | ||
9: { | ||
type: 'work', | ||
name: '调班', | ||
text: '班' | ||
} | ||
}, | ||
6: { | ||
'25-27': { | ||
type: 'holiday', | ||
name: '端午节', | ||
text: '休' | ||
}, | ||
28: { | ||
type: 'work', | ||
name: '调班', | ||
text: '班' | ||
} | ||
}, | ||
9: { | ||
27: { | ||
type: 'work', | ||
name: '调班', | ||
text: '班' | ||
} | ||
}, | ||
10: { | ||
'1-8': { | ||
type: 'holiday', | ||
name: '国庆节/中秋节', | ||
text: '休' | ||
}, | ||
10: { | ||
type: 'work', | ||
name: '调班', | ||
text: '班' | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
/* * | ||
@Author: drfu* | ||
@Description: 显示法定节假日班/休情况 | ||
@Date: 2020-10-12 14:29:45* | ||
* @Last Modified by: drfu | ||
* @Last Modified time: 2020-10-12 14:30:51 | ||
*/ | ||
|
||
import holidays from './holidays-map' | ||
import { dateUtil, getCalendarData, logger } from '../../utils/index' | ||
|
||
function inHolidays({ year, month }, { start, end, current }) { | ||
const getTimeStamp = dateUtil.getTimeStamp | ||
const startTimestamp = getTimeStamp({ | ||
year, | ||
month, | ||
date: start | ||
}) | ||
const endTimestamp = getTimeStamp({ | ||
year, | ||
month, | ||
date: end | ||
}) | ||
const currentDateTimestamp = getTimeStamp({ | ||
year, | ||
month, | ||
date: current | ||
}) | ||
if ( | ||
currentDateTimestamp >= startTimestamp && | ||
currentDateTimestamp <= endTimestamp | ||
) { | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
export default () => { | ||
return { | ||
name: 'holidays', | ||
beforeRender(calendarData = {}, calendarConfig = {}) { | ||
let { dates = [] } = calendarData | ||
if (calendarConfig.showHolidays) { | ||
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 [start, end] = target.split('-') | ||
const isInHolidays = inHolidays( | ||
{ | ||
year, | ||
month | ||
}, | ||
{ | ||
start, | ||
end, | ||
current: date | ||
} | ||
) | ||
if (isInHolidays) { | ||
item.label = hasHolidaysOfThisMonth[target].text | ||
} | ||
} | ||
} | ||
return item | ||
}) | ||
} | ||
return { | ||
calendarData: { | ||
...calendarData, | ||
dates: dates | ||
}, | ||
calendarConfig | ||
} | ||
}, | ||
methods(component) { | ||
return { | ||
getHolidaysOfCurrentYear() { | ||
const calendar = getCalendarData('calendar', component) | ||
const { curYear } = calendar | ||
return this.methods(component).getHolidaysOfYear(curYear) | ||
}, | ||
getHolidaysOfYear(year) { | ||
if (!year) return logger.warn('getHolidaysOfCurrentYear() 入参错误') | ||
if (!holidays[year]) { | ||
logger.warn('未匹配到当前年份节假日信息,请自行补充') | ||
return { | ||
err: 'not match' | ||
} | ||
} | ||
return holidays[year] | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters