calendar.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <div class="hello">
  3. <el-date-picker size='small' v-model="selectDate" type="month"
  4. placeholder="选择月" value-format="yyyy-MM">
  5. </el-date-picker>
  6. <el-button size='small' @click='changeDate'>确定</el-button>
  7. <full-calendar
  8. :config="config"
  9. :events="events"
  10. ref="calendar"
  11. @event-selected='eventClick'
  12. @day-click="dayClick">
  13. </full-calendar>
  14. <add-schedule v-if="isAdd" :isAdd='isAdd' :editItem='editItem' @add='addItem' @close='isAdd = false'></add-schedule>
  15. </div>
  16. </template>
  17. <script>
  18. import { FullCalendar } from 'vue-full-calendar'
  19. import 'fullcalendar/dist/fullcalendar.css'
  20. import addSchedule from '@/components/calendar/add.vue'
  21. export default {
  22. data () {
  23. return {
  24. isAdd:false,
  25. selectDate:'',//日期选择器选中的月份
  26. config: {
  27. firstDay:'0',//以周日为每周的第一天
  28. // weekends: true,//是否在日历中显示周末
  29. locale: 'zh-cn',//语言
  30. defaultView: 'month',//默认按月显示
  31. height: 'auto',//高度
  32. fixedWeekCount:false,//是否固定显示六周
  33. // weekMode:"liquid",//周数不定,每周的高度可变,整个日历高度不变
  34. allDaySlot:false,
  35. // allDay:true,
  36. header: {//表头信息
  37. left: 'prev, next, today',
  38. center: 'title',
  39. right: 'hide, custom'
  40. },
  41. },
  42. events: [{
  43. id:1,
  44. title:'出差',
  45. start:'2019-04-03',
  46. end:'2019-04-05'
  47. }, {
  48. id:2,
  49. title:'春游',
  50. start:'2019-04-12',
  51. }],
  52. newItem:{},
  53. editItem:{}
  54. }
  55. },
  56. components : { FullCalendar, addSchedule },
  57. methods:{
  58. changeDate(){
  59. // this.$refs.calendar.fireMethod('gotoDate', this.selectDate)
  60. this.$refs.calendar.fireMethod('prev');
  61. },
  62. eventClick(event){ //events的点击事件
  63. this.editItem = event
  64. this.isAdd = true
  65. },
  66. dayClick(date, jsEvent, view){ //日期的点击事件
  67. this.editItem = {}
  68. this.isAdd = true
  69. },
  70. addItem(detail){
  71. this.newItem = JSON.parse(detail)
  72. if(this.editItem.id){//如果是编辑,就删掉该条
  73. this.events.forEach( (el,ind)=>{
  74. if(el.id == this.editItem.id){
  75. this.events.splice(ind,1)
  76. }
  77. })
  78. }
  79. this.events.push({
  80. id : this.editItem.id?this.editItem.id:this.setUuid(),
  81. title : this.newItem.title,
  82. start : this.newItem.period[0],
  83. end : this.newItem.period[1],
  84. })
  85. },
  86. setUuid(){
  87. var s = [];
  88. var hexDigits = "0123456789abcdef";
  89. for(var i = 0; i < 36; i++){ s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1); }
  90. s[14] = "4";
  91. s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1);
  92. s[8] = s[13] = s[18] = s[23];
  93. var uuid = s.join("");
  94. return uuid;
  95. },
  96. },
  97. }
  98. </script>
  99. <!-- Add "scoped" attribute to limit CSS to this component only -->
  100. <style scoped>
  101. </style>