index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { dateUtil } from '../../utils/index'
  2. import convertSolarLunar from './convertSolarLunar'
  3. export default () => {
  4. return {
  5. name: 'convertSolarLunar',
  6. beforeRender(calendarData = {}, calendarConfig = {}) {
  7. let { dates = [], selectedDates = [] } = calendarData
  8. if (calendarConfig.showLunar) {
  9. dates = dates.map(dataInfo => {
  10. const { year, month, date } = dataInfo
  11. return {
  12. ...dataInfo,
  13. lunar: convertSolarLunar.solar2lunar(year, month, date)
  14. }
  15. })
  16. selectedDates = selectedDates.map(dataInfo => {
  17. const { year, month, date } = dataInfo
  18. return {
  19. ...dataInfo,
  20. lunar: convertSolarLunar.solar2lunar(year, month, date)
  21. }
  22. })
  23. }
  24. return {
  25. calendarData: {
  26. ...calendarData,
  27. dates: dates,
  28. selectedDates: selectedDates
  29. },
  30. calendarConfig
  31. }
  32. },
  33. methods() {
  34. return {
  35. convertSolarLunar: dateInfo => {
  36. if (!dateInfo) return dateInfo
  37. if (typeof dateInfo === 'string' && dateInfo.includes('-')) {
  38. dateInfo = dateUtil.transformDateRow2Dict(dateInfo)
  39. }
  40. const { year, month, date } = dateInfo
  41. return convertSolarLunar.solar2lunar(year, month, date)
  42. }
  43. }
  44. }
  45. }
  46. }