Browse Source

日历组件

chenc 3 years ago
parent
commit
8a52b23a43

+ 91 - 2
src/views/dashboard/MyToDo.vue

@@ -35,7 +35,8 @@
           <a-col :xs="24" :sm="24" :md="24" :lg="10">
             <a-card title="日历" :bordered="false">
               <div>
-                <a-calendar :fullscreen="false" />
+                <!-- <a-calendar :fullscreen="false" /> -->
+                <FullCalendar :options="calendarOptions" class="eventDeal-wrap" />
               </div>
             </a-card>
           </a-col>
@@ -276,10 +277,88 @@
 <script>
 import { mapGetters } from 'vuex'
 import { getAction } from '@/api/manage'
+import FullCalendar from '@fullcalendar/vue'
+import dayGridPlugin from '@fullcalendar/daygrid'
+import interactionPlugin from '@fullcalendar/interaction'
+import timeGridPlugin from '@fullcalendar/timegrid'
+// import '@fullcalendar/core/main.css'
+import '@fullcalendar/daygrid/main.css'
 export default {
   name: 'Home',
+  components: {
+    FullCalendar
+  },
   data() {
     return {
+      //日历组件参数-----------------------
+      calendarOptions: {
+        // 引入的插件
+        plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
+        // 日历头部按钮位置
+        headerToolbar: {
+          left: 'prev,next',
+          center: 'title',
+          right: 'dayGridMonth'
+        },
+        // 日历头部按钮中文转换
+        buttonText: {
+          month: '月'
+        },
+        initialView: 'dayGridMonth', // 指定默认显示视图
+        locale: 'zh-ch', // 切换语言,当前为中文
+        firstDay: '1', // 设置一周中显示的第一天是周几,周日是0,周一是1,以此类推
+        weekNumberCalculation: 'ISO', // 与firstDay配套使用
+        eventCOlor: '#3d8eec', // 全部日历日程背景色
+        timeGridEventMinHeight: '20', // 设置事件的最小高度
+        aspectRatio: '1.5', // 设置日历单元格宽高比
+        displayEventTime: false, // 是否显示事件时间
+        allDaySlot: false, // 周、日视图时,all-day不显示
+        eventLimit: true, // 设置月日程,与all-day slot 的最大显示数量,超过的通过弹窗展示
+        eventTimeFormat: {
+          hour: 'numeric',
+          minute: '2-digit',
+          hour12: false
+        },
+        slotLabelFormat: {
+          hour: '2-digit',
+          minute: '2-digit',
+          meridiem: false,
+          hour12: false // 设置时间为24小时制
+        },
+        events: [
+          {
+            title: 'Meeting',
+            start: '2021-10-13T14:30:00',
+            extendedProps: {
+              status: 'done'
+            }
+          },
+          {
+          title: 'Birthday Party',
+          start: '2021-10-14T07:00:00',
+          backgroundColor: 'green',
+          borderColor: 'green'
+        }
+        ], // 日程数组
+        // 事件
+        editable: true, // 是否可以进行(拖动、缩放)修改
+        eventStartEditable: true, // Event日程开始时间可以改变,默认为true,若为false,则表示开始结束时间范围不能拉伸,只能拖拽
+        eventDurationEditable: true, // Event日程的开始结束时间距离是否可以改变,默认为true,若为false,则表示开始结束时间范围不能拉伸,只能拖拽
+        selectable: true, // 是否可以选中日历格
+        selectMirror: true,
+        selectMinDistance: 0, // 选中日历格的最小距离
+        weekends: true,
+        navLinks: false, // 天链接
+        selectHelper: false,
+        selectEventOverlap: false, // 相同时间段的多个日程视觉上是否允许重叠,默认为true,允许
+        dayMaxEvents: true,
+        dateClick: this.handleDateClick, // 日期点击
+        eventsSet: this.handleEvents, // 事件点击
+        eventClick: this.handleEventClick, // 日程点击信息展示
+        eventDrop: this.handleEventDrop, // 日程拖动事件
+        eventResize: this.eventResize // 日程缩放事件
+      },
+      ////日历组件参数结尾----------------------
       userInfo: this.$store.getters.userInfo,
       todoList: [],
       activeKeyAll: [],
@@ -343,7 +422,17 @@ export default {
   mounted() {
     this.loadData()
   },
-  methods: {
+  methods: {// 日程保存
+    // 日期点击
+    handleDateClick(selectInfo) {
+      // if (confirm('您是否要在【' + selectInfo.dateStr + '】添加一个新的事件?')) {
+      //   // 父组件直接调用子组件方法
+      //   this.$refs['eventDialogue'].openDialog('add')
+      //   // 父组件直接修改子组件变量
+      //   // this.$refs['eventDialogue'].dialogVisible = true
+      // }
+      this.$router.push('/oa/my-plan/schedulePlan')
+    },
     loadData() {
       try {
         // 获取系统消息

+ 134 - 0
src/views/oa/my-plan/add/savePlan.vue

@@ -0,0 +1,134 @@
+<template>
+  <div>
+    <a-form :form="form" @submit="handleSubmit">
+      <a-row :gutter="24">
+        <a-col :span="12">
+          <a-form-item label="日程标题">
+            <a-input
+                v-model="note"
+              v-decorator="['note', { rules: [{ required: true, message: '请输入日程标题!' }] },]"
+              placeholder="请输入日程标题"
+            />
+          </a-form-item>
+        </a-col>
+        <a-col :span="12">
+          <a-form-item label="日程类型">
+            <a-select
+              v-decorator="[
+          'gender1',
+          { rules: [{ required: false, message: 'Please select your gender!' }] }
+        ]"
+              placeholder="请选择日程类型"
+            >
+              <a-select-option value="日常记录">日常记录</a-select-option>
+              <a-select-option value="本周工作">本周工作</a-select-option>
+              <a-select-option value="下周计划">下周计划</a-select-option>
+            </a-select>
+          </a-form-item>
+        </a-col>
+      </a-row>
+      <a-row :gutter="24">
+        <a-col :span="12">
+          <a-form-item label="提醒类型">
+            <a-select
+              v-decorator="[
+          'gender2',
+          { rules: [{ required: true, message: 'Please select your gender!' }] }
+        ]"
+              placeholder="请选择提醒类型"
+            >
+              <a-select-option value="邮件">邮件</a-select-option>
+              <a-select-option value="短信">短信</a-select-option>
+              <a-select-option value="系统消息">系统消息</a-select-option>
+            </a-select>
+          </a-form-item>
+        </a-col>
+        <a-col :span="12">
+          <a-form-item label="紧急程度">
+            <a-select
+              v-decorator="[
+          'gender3',
+          { rules: [{ required: false, message: 'Please select your gender!' }] }
+        ]"
+              placeholder="请选择紧急程度"
+            >
+              <a-select-option value="一般">一般</a-select-option>
+              <a-select-option value="重要">重要</a-select-option>
+              <a-select-option value="紧机">紧机</a-select-option>
+            </a-select>
+          </a-form-item>
+        </a-col>
+      </a-row>
+      <a-row :gutter="24">
+        <a-col :span="12">
+          <a-form-item label="提醒时间">
+            <a-select
+              v-decorator="[
+          'gender4',
+          { rules: [{ required: true, message: 'Please select your gender!' }] }
+        ]"
+              placeholder="请选择提醒时间"
+            >
+              <a-select-option value="不提醒">不提醒</a-select-option>
+              <a-select-option value="开始时">开始时</a-select-option>
+              <a-select-option value="提前5分钟">提前5分钟</a-select-option>
+              <a-select-option value="提前10分钟">提前10分钟</a-select-option>
+              <a-select-option value="提前15分钟">提前15分钟</a-select-option>
+            </a-select>
+          </a-form-item>
+        </a-col>
+        <a-col :span="12">
+          <a-form-item label="重复提醒">
+            <a-select
+              v-decorator="[
+          'gender5',
+          { rules: [{ required: true, message: 'Please select your gender!' }] },
+        ]"
+              placeholder="请选择重复提醒"
+            >
+              <a-select-option value="一般">不重复</a-select-option>
+              <a-select-option value="每天">每天</a-select-option>
+              <a-select-option value="每周">每周</a-select-option>
+              <a-select-option value="每月">每月</a-select-option>
+              <a-select-option value="每年">每年</a-select-option>
+            </a-select>
+          </a-form-item>
+        </a-col>
+      </a-row>
+      <a-row :gutter="24">
+        <a-col :span="24">
+          <a-form-item label="备注">
+            <a-textarea
+              v-model="value"
+              placeholder="备注"
+              :auto-size="{ minRows: 3, maxRows: 5 }"
+            />
+          </a-form-item>
+        </a-col>
+      </a-row>
+    </a-form>
+  </div>
+</template>
+
+<script>
+import { mapGetters } from 'vuex'
+import { getAction } from '@/api/manage'
+export default {
+  name: 'SavePlan',
+  data() {
+    return {
+      formLayout: 'horizontal',
+      form: this.$form.createForm(this, { name: 'coordinated' }),
+      note:""
+    }
+  },
+  created() {},
+  computed: {},
+  mounted() {},
+  methods: {
+    handleSubmit() {}
+  }
+}
+</script>
+<style lang="less" scoped>
+</style>

+ 213 - 0
src/views/oa/my-plan/schedulePlan.vue

@@ -0,0 +1,213 @@
+<template>
+  <div id="home">
+    <FullCalendar :options="calendarOptions" class="eventDeal-wrap" />
+    <a-modal
+      v-model="savePlanModalVisible"
+      title="新增日程计划"
+      @ok="handleOk"
+      @cancel="handleCancel"
+      width="80%"
+    >
+      <save-plan ref="savePlan"></save-plan>
+    </a-modal>
+  </div>
+</template>
+
+<script>
+import { mapGetters } from 'vuex'
+import { getAction } from '@/api/manage'
+import FullCalendar from '@fullcalendar/vue'
+import dayGridPlugin from '@fullcalendar/daygrid'
+import interactionPlugin from '@fullcalendar/interaction'
+import timeGridPlugin from '@fullcalendar/timegrid'
+// import '@fullcalendar/core/main.css'
+import '@fullcalendar/daygrid/main.css'
+import SavePlan from './add/savePlan'
+export default {
+  name: 'SchedulePlan',
+  components: {
+    FullCalendar,
+    SavePlan
+  },
+  data() {
+    return {
+        savePlanModalVisible:false,
+        ///////////////////日历参数
+      calendarOptions: {
+        // 引入的插件
+        plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
+        // 日历头部按钮位置
+        headerToolbar: {
+          left: 'prev,next today',
+          center: 'title',
+          right: 'dayGridMonth, timeGridWeek, timeGridDay'
+        },
+        // 日历头部按钮中文转换
+        buttonText: {
+          today: '今天',
+          month: '月',
+          week: '周',
+          day: '天'
+        },
+        initialView: 'dayGridMonth', // 指定默认显示视图
+        locale: 'zh-ch', // 切换语言,当前为中文
+        firstDay: '1', // 设置一周中显示的第一天是周几,周日是0,周一是1,以此类推
+        weekNumberCalculation: 'ISO', // 与firstDay配套使用
+        eventCOlor: '#3d8eec', // 全部日历日程背景色
+        timeGridEventMinHeight: '20', // 设置事件的最小高度
+        aspectRatio: '1.5', // 设置日历单元格宽高比
+        displayEventTime: false, // 是否显示事件时间
+        allDaySlot: false, // 周、日视图时,all-day不显示
+        eventLimit: true, // 设置月日程,与all-day slot 的最大显示数量,超过的通过弹窗展示
+        eventTimeFormat: {
+          hour: 'numeric',
+          minute: '2-digit',
+          hour12: false
+        },
+        slotLabelFormat: {
+          hour: '2-digit',
+          minute: '2-digit',
+          meridiem: false,
+          hour12: false // 设置时间为24小时制
+        },
+        events: [
+          {
+            title: 'Meeting',
+            start: '2021-10-13T14:30:00',
+            extendedProps: {
+              status: 'done'
+            }
+          },
+          {
+          title: 'Birthday Party',
+          start: '2021-10-14T07:00:00',
+          backgroundColor: 'green',
+          borderColor: 'green'
+        }
+        ], // 日程数组
+        // 事件
+        editable: true, // 是否可以进行(拖动、缩放)修改
+        eventStartEditable: true, // Event日程开始时间可以改变,默认为true,若为false,则表示开始结束时间范围不能拉伸,只能拖拽
+        eventDurationEditable: true, // Event日程的开始结束时间距离是否可以改变,默认为true,若为false,则表示开始结束时间范围不能拉伸,只能拖拽
+        selectable: true, // 是否可以选中日历格
+        selectMirror: true,
+        selectMinDistance: 0, // 选中日历格的最小距离
+        weekends: true,
+        navLinks: true, // 天链接
+        selectHelper: false,
+        selectEventOverlap: false, // 相同时间段的多个日程视觉上是否允许重叠,默认为true,允许
+        dayMaxEvents: true,
+        dateClick: this.handleDateClick, // 日期点击
+        eventsSet: this.handleEvents, // 事件点击
+        eventClick: this.handleEventClick, // 日程点击信息展示
+        eventDrop: this.handleEventDrop, // 日程拖动事件
+        eventResize: this.eventResize // 日程缩放事件
+      }
+      ,selectInfo:{}//选择的日期
+      /////////////////////////////////日历参数结尾
+    }
+  },
+  created() {
+  },
+  computed: {
+  },
+  mounted() {
+  },
+  methods: {
+    // 日程保存
+    saveEvent(val) {
+      let eventsArr = this.calendarOptions.events
+      try {
+        if (eventsArr.length === 0) {
+          eventsArr.push(val)
+        } else {
+          eventsArr.forEach((item, index, eventsArr) => {
+            // 若为修改日程
+            if (item.eventID === val.eventID) {
+              throw new Error(index)
+            }
+          })
+          // 若为新增日程
+          eventsArr.push(val)
+        }
+      } catch (e) {
+        // 若为修改日程
+        eventsArr.splice(e.message, 1, val)
+      }
+    },
+    // 日程删除
+    deleteEvent(val) {
+      let eventsArr = this.calendarOptions.events
+      try {
+        eventsArr.forEach((item, index, eventsArr) => {
+          if (item.eventID === val) {
+            throw new Error(index)
+          }
+        })
+      } catch (e) {
+        // 删除指定日程
+        eventsArr.splice(parseInt(e.message), 1)
+      }
+    },
+    // 日程事件点击
+    handleEvents(info) {
+      console.log('handleEvents.info:', info)
+      // this.currentEvents = events
+      
+    },
+    handleWeekendsToggle() {
+      console.log('handleWeekendsToggle')
+      this.calendarOptions.weekends = !this.calendarOptions.weekends
+    },
+    // 日期点击
+    handleDateClick(selectInfo) {
+    //   if (confirm('您是否要在【' + selectInfo.dateStr + '】添加一个新的事件?')) {
+    //     // 父组件直接调用子组件方法
+    //     this.$refs['eventDialogue'].openDialog('add')
+    //     // 父组件直接修改子组件变量
+    //     // this.$refs['eventDialogue'].dialogVisible = true
+    //   }
+    console.log(selectInfo)
+    this.selectInfo=selectInfo;
+    this.savePlanModalVisible=true;
+    },
+    // 日程点击信息展示
+    handleEventClick(info) {
+      console.log('handleEventClick.info:', info)
+      info.el.style.borderColor = 'red'
+      this.$refs['eventDialogue'].openDialog('view', info)
+    },
+    // 日程事件触发
+    eventClick(info) {
+      console.log('eventClick.info:', info)
+      info.el.style.borderColor = 'red'
+    },
+    // 日程拖动事件
+    handleEventDrop(info) {
+      this.$refs['eventDialogue'].eventFormModel.start = info.event.start
+      this.$refs['eventDialogue'].eventFormModel.end = info.event.end
+    },
+    // 日程缩放事件
+    eventResize(info) {
+      this.$refs['eventDialogue'].eventFormModel.start = info.event.start
+      this.$refs['eventDialogue'].eventFormModel.end = info.event.end
+    },
+    handleOk(){
+        var selectObject={
+            title: this.$refs.savePlan.note,
+            start: this.selectInfo.dateStr,
+            extendedProps: {
+              status: 'done'
+            }
+        }
+        this.calendarOptions.events.push(selectObject)
+        this.savePlanModalVisible=false;
+    },
+    handleCancel(){
+
+    }
+  }
+}
+</script>
+<style lang="less" scoped>
+</style>