render.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import plugins from './plugins/index'
  2. import { getCalendarConfig } from './utils/index'
  3. /**
  4. * 渲染日历
  5. */
  6. export function renderCalendar(calendarData, calendarConfig) {
  7. return new Promise(resolve => {
  8. const Component = this
  9. if (Component.firstRender === void 0) {
  10. Component.firstRender = true
  11. } else {
  12. Component.firstRender = false
  13. }
  14. const exitData = Component.data.calendar || {}
  15. for (let plugin of plugins.installed) {
  16. const [, p] = plugin
  17. if (typeof p.beforeRender === 'function') {
  18. const {
  19. calendarData: newData,
  20. calendarConfig: newConfig
  21. } = p.beforeRender(
  22. { ...exitData, ...calendarData },
  23. calendarConfig || getCalendarConfig(Component),
  24. Component
  25. )
  26. calendarData = newData
  27. calendarConfig = newConfig
  28. }
  29. }
  30. Component.setData(
  31. {
  32. config: calendarConfig,
  33. calendar: calendarData
  34. },
  35. () => {
  36. const rst = {
  37. calendar: calendarData,
  38. config: calendarConfig,
  39. firstRender: Component.firstRender
  40. }
  41. resolve(rst)
  42. if (Component.firstRender) {
  43. Component.triggerEvent('afterCalendarRender', rst)
  44. Component.firstRender = false
  45. }
  46. }
  47. )
  48. })
  49. }