123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <template>
- <div class="demo-app">
- <FullCalendar
- ref="fullCalendar"
- locale="zh-cn"
- firstDay="1"
- :editable="false"
- :droppable="false"
- :eventLimit="eventLimit"
- :defaultDate="defaultDate"
- weekNumberCalculation="ISO"
- :customButtons="btn"
- :header="headers"
- :button-text="{
- today: '今天',
- dayGridMonth: '月视图',
- dayGridWeek: '周视图',
- listMonth: '月列表',
- }"
- :valid-range="{
- start: rangeStart,
- end: rangeEnd,
- }"
- :slot-event-overlap="false"
- :defaultView="view"
- :plugins="calendarPlugins"
- :selectable="useDraft"
- :events="event"
- @select="drawSelect"
- :eventOrder="`start`"
- @eventClick="clickEvent"
- :views="views"
- :displayEventEnd="true"
- :displayEventTime="true"
- />
- </div>
- </template>
- <script>
- import FullCalendar from '@fullcalendar/vue';
- import dayGridPlugin from '@fullcalendar/daygrid';
- import listPlugin from '@fullcalendar/list';
- import timeGridPlugin from '@fullcalendar/timegrid';
- import interactionPlugin from '@fullcalendar/interaction';
- var moment = require('moment');
- import _ from 'lodash';
- export default {
- props: {
- year: { type: null, default: `${new Date().getFullYear()}` }, //当前日历的年份
- events: { type: Array, default: () => [] },
- useDraft: { type: Boolean, default: true },
- useEvent: { type: Boolean, default: true },
- selfBtn: { type: Object, default: () => {} },
- eventLimit: { type: null, default: false },
- vacation: { type: Array, default: () => [] },
- },
- components: {
- FullCalendar, // make the <FullCalendar> tag available
- },
- data: function() {
- var that = this;
- return {
- view: 'dayGridMonth',
- form: { isAllDay: true },
- dialog: false,
- calendarPlugins: [
- // plugins must be defined in the JS
- dayGridPlugin,
- listPlugin,
- timeGridPlugin,
- interactionPlugin, // needed for dateClick
- ],
- planList: [],
- addTitle: '',
- headers: {
- left: 'prev',
- center: 'title',
- right: 'dayGridMonth,dayGridWeek, today ,next',
- },
- btn: {},
- views: {
- dayGridMonth: {
- eventLimit: _.clone(this.eventLimit),
- },
- dayGridWeek: {
- duration: { day: 7 },
- },
- listMonth: {
- eventLimit: _.clone(this.eventLimit),
- },
- },
- };
- },
- methods: {
- handleDateClick(arg) {
- this.$emit('click', arg);
- },
- drawSelect(arg) {
- arg.endStr = moment(arg.endStr)
- .subtract(1, 'days')
- .format('YYYY-MM-DD');
- // let is_possbile = this.$checkDate({ ...arg, vacation: this.vacation });
- let is_possbile = this.$checkDate(arg.startStr, arg.endStr, this.vacation);
- if (is_possbile == true) this.$emit('draft', arg);
- else this.$message.error('您选择的时间段与假期重合,请您重新选择');
- },
- clickEvent(arg) {
- if (this.useEvent) this.$emit('eventClick', arg);
- },
- setBtn() {
- let selfBtn = _.cloneDeep(this.selfBtn);
- let keys = Object.keys(selfBtn);
- for (const key of keys) {
- let { position, ...info } = selfBtn[key];
- selfBtn[key] = { ...info };
- if (position === 'left') this.headers.left = `${this.headers.left}, ${key}`;
- else this.headers.right = `${key}, ${this.headers.right} `;
- }
- this.$set(this, `btn`, selfBtn);
- },
- },
- computed: {
- defaultDate() {
- return `${this.year}-01-01`;
- },
- rangeStart() {
- return `${this.year}-01-01`;
- },
- rangeEnd() {
- return `${this.year}-12-31`;
- },
- event() {
- let nv = this.vacation.map(i => {
- let object = JSON.parse(JSON.stringify(i));
- object.end = moment(i.end)
- .add(1, 'days')
- .format('YYYY-MM-DD');
- return object;
- });
- let ne = this.events.map(i => {
- let object = JSON.parse(JSON.stringify(i));
- object.end = moment(i.end)
- .add(1, 'days')
- .format('YYYY-MM-DD');
- return object;
- });
- return nv.concat(ne);
- },
- },
- watch: {
- selfBtn: {
- immediate: true,
- handler(val) {
- if (val) this.setBtn();
- },
- },
- },
- };
- </script>
- <style lang="less">
- @import '~@fullcalendar/core/main.css';
- @import '~@fullcalendar/daygrid/main.css';
- </style>
|