index.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <script>
  2. import { getSchedule } from '@/api/calendar'
  3. import { getSchedule as getScheduleCache } from '@/utils/cache'
  4. import { ScheduleType } from '@/constant'
  5. import ScheduleCalendar from './ScheduleCalendar'
  6. import ScheduleSwiper from './ScheduleSwiper'
  7. export default {
  8. name: 'ScheduleComponent',
  9. components: {
  10. ScheduleCalendar,
  11. ScheduleSwiper
  12. },
  13. props: {
  14. schedule: {
  15. type: String,
  16. default: null
  17. }
  18. },
  19. data () {
  20. return {
  21. options: null
  22. }
  23. },
  24. watch: {
  25. schedule: {
  26. handler () {
  27. this.getSchedule()
  28. },
  29. immediate: true
  30. }
  31. },
  32. methods: {
  33. getApi () {
  34. return this.$attrs.editable ? getSchedule : getScheduleCache
  35. },
  36. getSchedule () {
  37. const options = {
  38. loading: true,
  39. error: false,
  40. detail: null
  41. }
  42. this.options = options
  43. this.getApi()(this.schedule).then(
  44. schedule => {
  45. options.detail = schedule
  46. },
  47. () => {
  48. options.error = true
  49. }
  50. ).finally(() => {
  51. options.loading = false
  52. })
  53. }
  54. },
  55. render (h) {
  56. if (this.options.loading) {
  57. return h('div', {
  58. class: 'c-schedule',
  59. directives: [
  60. {
  61. name: 'loading',
  62. value: true
  63. }
  64. ]
  65. })
  66. }
  67. if (this.options.error) {
  68. return h('StatusWrapper', {
  69. props: {
  70. error: true
  71. },
  72. on: {
  73. retry: this.getSchedule
  74. }
  75. })
  76. }
  77. const { detail } = this.options
  78. return h(detail.type === ScheduleType.RECUR ? 'ScheduleSwiper' : 'ScheduleCalendar', {
  79. props: {
  80. detail,
  81. ...this.$attrs
  82. },
  83. on: this.$listeners
  84. })
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. .c-schedule {
  90. min-height: 300px;
  91. }
  92. </style>