index.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <full-calendar
  3. ref="fullCalendar"
  4. :options="fullCalendarOptions"
  5. />
  6. </template>
  7. <script>
  8. import FullCalendar from '@fullcalendar/vue'
  9. import dayGridPlugin from '@fullcalendar/daygrid'
  10. import timeGridPlugin from '@fullcalendar/timegrid'
  11. import listPlugin from '@fullcalendar/list'
  12. // 依赖引入不生效,需要手动引入对应依赖的js文件
  13. import interactionPlugin from './interaction'
  14. import bootstrapPlugin from '@fullcalendar/bootstrap'
  15. import lang from '@/locales/fullcalendar'
  16. import I18n from '@/utils/i18n'
  17. import '@fullcalendar/bootstrap/main.css'
  18. import '@fullcalendar/common/main.css'
  19. import '@fullcalendar/daygrid/main.css'
  20. export default {
  21. components: {
  22. FullCalendar
  23. },
  24. props: {
  25. options: {
  26. type: Object,
  27. default: () => ({})
  28. },
  29. // 新增配置项:是否隐藏其他月份日期
  30. hideOtherMonthDays: {
  31. type: Boolean,
  32. default: false
  33. }
  34. },
  35. data () {
  36. return {
  37. calendarOptions: {
  38. plugins: [dayGridPlugin, timeGridPlugin, listPlugin, bootstrapPlugin, interactionPlugin],
  39. initialView: 'dayGridMonth',
  40. fixedWeekCount: false,
  41. views: {
  42. dayGridMonth: {
  43. showNonCurrentDates: !this.hideOtherMonthDays // 是否隐藏非当前月日期
  44. }
  45. }
  46. }
  47. }
  48. },
  49. computed: {
  50. fullCalendarOptions () {
  51. const options = Object.assign({
  52. // locales: lang.locales,
  53. // locale: this.locale
  54. }, this.calendarOptions, this.options)
  55. return options
  56. },
  57. locale () {
  58. return lang.localeMap[I18n.getLanguage()]
  59. }
  60. },
  61. watch: {
  62. hideOtherMonthDays: {
  63. handler (newVal) {
  64. const calendarApi = this.$refs.fullCalendar?.getApi()
  65. if (calendarApi) {
  66. calendarApi.setOption('views', {
  67. dayGridMonth: {
  68. showNonCurrentDates: !this.hideOtherMonthDays // 根据 prop 反转逻辑
  69. }
  70. })
  71. calendarApi.render() // 强制重新渲染
  72. }
  73. },
  74. immediate: true
  75. }
  76. }
  77. }
  78. </script>