get-calendar-data.js
2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
* @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) || {}
}
}
}
}
}
}