calendar.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <template>
  2. <div class="demo-app">
  3. <FullCalendar
  4. ref="fullCalendar"
  5. locale="zh-cn"
  6. firstDay="1"
  7. :editable="false"
  8. :droppable="false"
  9. :eventLimit="true"
  10. :defaultDate="defaultDate"
  11. weekNumberCalculation="ISO"
  12. :customButtons="btn"
  13. :header="headers"
  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: null, default: `${new Date().getFullYear()}` }, //当前日历的年份
  40. events: { type: Array, default: () => [] },
  41. useDraft: { type: Boolean, default: true },
  42. useEvent: { type: Boolean, default: true },
  43. selfBtn: { type: Object, default: () => {} },
  44. },
  45. components: {
  46. FullCalendar, // make the <FullCalendar> tag available
  47. },
  48. data: function() {
  49. return {
  50. form: { isAllDay: true },
  51. dialog: false,
  52. calendarPlugins: [
  53. // plugins must be defined in the JS
  54. dayGridPlugin,
  55. // timeGridPlugin,
  56. interactionPlugin, // needed for dateClick
  57. ],
  58. planList: [],
  59. addTitle: '',
  60. headers: {
  61. left: 'prev',
  62. center: 'title',
  63. right: 'today ,next',
  64. },
  65. btn: {},
  66. };
  67. },
  68. methods: {
  69. handleDateClick(arg) {
  70. this.$emit('click', arg);
  71. },
  72. drawSelect(arg) {
  73. this.$emit('draft', arg);
  74. },
  75. clickEvent(arg) {
  76. if (this.useEvent) this.$emit('eventClick', arg);
  77. },
  78. setBtn() {
  79. let selfBtn = _.cloneDeep(this.selfBtn);
  80. let keys = Object.keys(selfBtn);
  81. for (const key of keys) {
  82. let { position, ...info } = selfBtn[key];
  83. selfBtn[key] = { ...info };
  84. if (position === 'left') this.headers.left = `${this.headers.left}, ${key}`;
  85. else this.headers.right = `${this.headers.right}, ${key}`;
  86. }
  87. this.$set(this, `btn`, selfBtn);
  88. },
  89. },
  90. computed: {
  91. defaultDate() {
  92. return `${this.year}-01-01`;
  93. },
  94. rangeStart() {
  95. return `${this.year}-01-01`;
  96. },
  97. rangeEnd() {
  98. return `${this.year}-12-31`;
  99. },
  100. },
  101. watch: {
  102. selfBtn: {
  103. immediate: true,
  104. handler(val) {
  105. if (val) this.setBtn();
  106. },
  107. },
  108. },
  109. };
  110. </script>
  111. <style lang="less">
  112. @import '~@fullcalendar/core/main.css';
  113. @import '~@fullcalendar/daygrid/main.css';
  114. </style>