calendar.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. :customButtons="btn"
  10. :header="headers"
  11. :button-text="{
  12. today: '今天',
  13. }"
  14. :valid-range="{
  15. start: rangeStart,
  16. end: rangeEnd,
  17. }"
  18. :slot-event-overlap="false"
  19. defaultView="dayGridMonth"
  20. :plugins="calendarPlugins"
  21. :selectable="useDraft"
  22. :events="events"
  23. @select="drawSelect"
  24. :eventOrder="`start`"
  25. @eventClick="clickEvent"
  26. />
  27. </div>
  28. </template>
  29. <script>
  30. import FullCalendar from '@fullcalendar/vue';
  31. import dayGridPlugin from '@fullcalendar/daygrid';
  32. import interactionPlugin from '@fullcalendar/interaction';
  33. import _ from 'lodash';
  34. export default {
  35. props: {
  36. year: { type: null, default: `${new Date().getFullYear()}` }, //当前日历的年份
  37. events: { type: Array, default: () => [] },
  38. useDraft: { type: Boolean, default: true },
  39. useEvent: { type: Boolean, default: true },
  40. selfBtn: { type: Object, default: () => {} },
  41. },
  42. components: {
  43. FullCalendar, // make the <FullCalendar> tag available
  44. },
  45. data: function() {
  46. return {
  47. form: { isAllDay: true },
  48. dialog: false,
  49. calendarPlugins: [
  50. // plugins must be defined in the JS
  51. dayGridPlugin,
  52. // timeGridPlugin,
  53. interactionPlugin, // needed for dateClick
  54. ],
  55. // calendarEvents: [],
  56. planList: [],
  57. addTitle: '',
  58. headers: {
  59. left: 'prev',
  60. center: 'title',
  61. right: 'today ,next',
  62. },
  63. btn: {},
  64. };
  65. },
  66. methods: {
  67. handleDateClick(arg) {
  68. this.$emit('click', arg);
  69. },
  70. drawSelect(arg) {
  71. this.$emit('draft', arg);
  72. },
  73. clickEvent(arg) {
  74. if (this.useEvent) this.$emit('eventClick', arg);
  75. },
  76. setBtn() {
  77. let selfBtn = _.cloneDeep(this.selfBtn);
  78. let keys = Object.keys(selfBtn);
  79. for (const key of keys) {
  80. let { position, ...info } = selfBtn[key];
  81. selfBtn[key] = { ...info };
  82. if (position === 'left') this.headers.left = `${this.headers.left}, ${key}`;
  83. else this.headers.right = `${this.headers.right}, ${key}`;
  84. }
  85. this.$set(this, `btn`, selfBtn);
  86. },
  87. },
  88. computed: {
  89. defaultDate() {
  90. return `${this.year}-01-01`;
  91. },
  92. rangeStart() {
  93. return `${this.year}-01-01`;
  94. },
  95. rangeEnd() {
  96. return `${this.year}-12-31`;
  97. },
  98. },
  99. watch: {
  100. selfBtn: {
  101. immediate: true,
  102. handler(val) {
  103. if (val) this.setBtn();
  104. },
  105. },
  106. },
  107. };
  108. </script>
  109. <style lang="less">
  110. @import '~@fullcalendar/core/main.css';
  111. @import '~@fullcalendar/daygrid/main.css';
  112. </style>