<template>
<div class="work-day-manage">
<h3>工作日管理</h3>
<div class="calendar-wrap">
<FullCalendar defaultView="dayGridMonth"
ref="fullCalendar"
:header="{
left: 'dayGridMonth,timeGridWeek, timeGridDay',
center: 'title',
right: 'today prev,next,'
}"
:events="events"
:eventColor="'#378006'"
:eventBackgroundColor="'#378006'"
:eventResizableFromStart="true"
@eventClick="handleEventClick"
:editable="true"
:droppable="true"
:selectMirror="true"
:selectAllow="selectAllow"
:unselectAuto="false"
:weekends="true"
:selectable="true"
:locale="zhLocale"
@viewSkeletonRender="viewSkeletonRender"
@dateClick="handleDateClick"
@select="handleDateSelect"
:plugins="calendarPlugins"/>
</div>
</div>
</template>
<script>
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import interactionPlugin from '@fullcalendar/interaction'
import timeGridPlugin from '@fullcalendar/timegrid'
import zhLocale from '@fullcalendar/core/locales/zh-cn'
import { formatDate } from '@/utils/common'
export default {
data() {
return {
defaultView: 'dayGridMonth',
calendarPlugins: [dayGridPlugin, interactionPlugin, timeGridPlugin],
zhLocale,
events: [
// event data...
{
title: 'Event1',
start: '2019-08-26 15:00:23',
end: '2019-08-26 19:00:00',
startTime: '2019-08-26 15:00:23',
endTime: '2019-08-26 19:00:00',
allDay: false,
},
{
title: 'Event2',
start: '2019-08-21',
end: '2019-08-25',
allDay: false,
user: 'abc',
backgroundColor: 'orange',
className: 'event-bar',
startTime: '2019-08-21',
},
{
title: 'Event3',
start: '2019-08-21',
end: '2019-08-25',
allDay: false,
user: 'abc',
backgroundColor: 'orange',
className: 'event-bar',
startTime: '2019-08-21',
}
],
}
},
components: {
FullCalendar,
},
mounted() {
console.log(formatDate(new Date(), 'YYYY-MM-DD HH:mm:ss'))
},
methods: {
viewSkeletonRender(info) {
this.defaultView = info.view.type
},
selectAllow() {
if (this.defaultView === 'dayGridMonth') {
return false
}
return true
},
handleDateClick(arg) {
console.log(arg)
// arg.dayEl.style.backgroundColor = 'red'
// arg.dayEl.style.backgroundColor = 'red'
console.log(this.$refs.fullCalendar.getApi().getEvents())
},
handleDateSelect(arg) {
console.log(arg)
},
handleEventClick(eventInfo) {
console.log(eventInfo.event)
},
}
}
</script>
<style lang="less">
@import '~@fullcalendar/core/main.css';
@import '~@fullcalendar/daygrid/main.css';
@import '~@fullcalendar/timegrid/main.css';
.work-day-manage {
padding: 0 20px;
.calendar-wrap {
width: 1000px;
height: 2000px;
.fc {
}
}
}
</style>