You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.1 KiB
70 lines
2.1 KiB
2 months ago
|
/**
|
||
|
* @Author: drfu*
|
||
|
* @Description: 获取日历数据
|
||
|
* @Date: 2020-10-08 21:22:09*
|
||
|
* @Last Modified by: drfu
|
||
|
* @Last Modified time: 2020-10-11 13:42:37
|
||
|
* */
|
||
|
|
||
|
import { getCalendarData, logger, getCalendarConfig } from '../../utils/index'
|
||
|
|
||
|
function wrapDateWithLunar(dates = [], convertFn) {
|
||
|
const datesWithLunar = JSON.parse(JSON.stringify(dates)).map(date => ({
|
||
|
...date,
|
||
|
lunar: convertFn(date)
|
||
|
}))
|
||
|
return datesWithLunar
|
||
|
}
|
||
|
|
||
|
export default () => {
|
||
|
return {
|
||
|
name: 'getData',
|
||
|
methods(component) {
|
||
|
return {
|
||
|
getCurrentYM: () => {
|
||
|
const { curYear, curMonth } = getCalendarData('calendar', component)
|
||
|
return {
|
||
|
year: curYear,
|
||
|
month: curMonth
|
||
|
}
|
||
|
},
|
||
|
getSelectedDates: (options = {}) => {
|
||
|
const dates =
|
||
|
getCalendarData('calendar.selectedDates', component) || []
|
||
|
const config = getCalendarConfig(component) || {}
|
||
|
if (options.lunar && !config.showLunar) {
|
||
|
const injectedFns = component.calendar || {}
|
||
|
if (typeof injectedFns.convertSolarLunar === 'function') {
|
||
|
return wrapDateWithLunar(dates, injectedFns.convertSolarLunar)
|
||
|
} else {
|
||
|
logger.warn('获取农历信息需引入农历插件')
|
||
|
}
|
||
|
} else {
|
||
|
return dates
|
||
|
}
|
||
|
},
|
||
|
getCalendarDates: (options = {}) => {
|
||
|
const config = getCalendarConfig(component) || {}
|
||
|
const dates = getCalendarData('calendar.dates', component)
|
||
|
if (options.lunar && !config.showLunar) {
|
||
|
const injectedFns = component.calendar || {}
|
||
|
if (typeof injectedFns.convertSolarLunar === 'function') {
|
||
|
return wrapDateWithLunar(dates, injectedFns.convertSolarLunar)
|
||
|
} else {
|
||
|
logger.warn('获取农历信息需引入农历插件')
|
||
|
}
|
||
|
} else {
|
||
|
return dates
|
||
|
}
|
||
|
},
|
||
|
getCalendarAllData: () => {
|
||
|
return {
|
||
|
data: getCalendarData('calendar', component) || {},
|
||
|
config: getCalendarConfig(component) || {}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|