calendar.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <div class="demo-app">
  3. <FullCalendar
  4. ref="fullCalendar"
  5. locale="zh-cn"
  6. firstDay="1"
  7. :defaultDate="defaultDate"
  8. weekNumberCalculation="ISO"
  9. :header="{
  10. left: 'prev',
  11. center: 'title',
  12. right: 'today ,next',
  13. }"
  14. :button-text="{
  15. today: '今天',
  16. }"
  17. :valid-range="{
  18. start: rangeStart,
  19. end: rangeEnd,
  20. }"
  21. :slot-event-overlap="false"
  22. defaultView="dayGridMonth"
  23. :plugins="calendarPlugins"
  24. :selectable="useDraft"
  25. :events="events"
  26. @select="drawSelect"
  27. :eventOrder="`start`"
  28. @eventClick="clickEvent"
  29. />
  30. </div>
  31. </template>
  32. <script>
  33. import FullCalendar from '@fullcalendar/vue';
  34. import dayGridPlugin from '@fullcalendar/daygrid';
  35. import interactionPlugin from '@fullcalendar/interaction';
  36. import _ from 'lodash';
  37. export default {
  38. props: {
  39. year: { type: String, default: `${new Date().getFullYear()}` }, //当前日历的年份
  40. events: { type: Array, default: () => [] },
  41. useDraft: { type: Boolean, default: true },
  42. useEvent: { type: Boolean, default: true },
  43. },
  44. components: {
  45. FullCalendar, // make the <FullCalendar> tag available
  46. },
  47. data: function() {
  48. return {
  49. form: { isAllDay: true },
  50. dialog: false,
  51. calendarPlugins: [
  52. // plugins must be defined in the JS
  53. dayGridPlugin,
  54. // timeGridPlugin,
  55. interactionPlugin, // needed for dateClick
  56. ],
  57. // calendarEvents: [],
  58. planList: [],
  59. addTitle: '',
  60. };
  61. },
  62. methods: {
  63. handleDateClick(arg) {
  64. this.$emit('click', arg);
  65. },
  66. drawSelect(arg) {
  67. this.$emit('draft', arg);
  68. },
  69. clickEvent(arg) {
  70. if (this.useEvent) this.$emit('eventClick', arg);
  71. },
  72. },
  73. computed: {
  74. defaultDate() {
  75. return `${this.year}-01-01`;
  76. },
  77. rangeStart() {
  78. return `${this.year}-01-01`;
  79. },
  80. rangeEnd() {
  81. return `${this.year}-12-31`;
  82. },
  83. },
  84. };
  85. </script>
  86. <style lang="less">
  87. @import '~@fullcalendar/core/main.css';
  88. @import '~@fullcalendar/daygrid/main.css';
  89. </style>