使用FullCalendar做日程安排

2023-10-27

自定义实现了加载,删除,样式的定义,鼠标悬停的显示,如图

 

 单击弹出编辑框

 其中日周天的选择器都是作为插件引入的,这个组件还是蛮庞杂的,功能也强大,需要时间去研究

<template>
  <div style="width:100%;height:100%">
    <FullCalendar
      ref="FullCalendar"
      :options="calendarOptions"
      class="eventDeal-wrap"
    >
      <template #eventContent="arg">
        <el-tooltip placement="top" effect="light">
          <div slot="content">【开始时间】: {{ momentFormat(arg.event.start) }}<br/>【结束时间】: {{ momentFormat(arg.event.end) }}<br/>【备注】: {{arg.event.extendedProps.remark}}</div>
          <div style="text-align:left;">
            <el-button type="danger" class='el-buttons' style="background-color:#F56C6C;width:20px;height:20px;padding:2px" @click.stop="deleteEvent(arg.event)" icon="el-icon-delete" size="mini" circle></el-button>
            {{arg.event.title}}
          </div>
        </el-tooltip>
      </template>
    </FullCalendar>
    <el-dialog
      :visible.sync="dialogShow"
      :destroy-on-close="true"
      :close-on-press-escape="false"
      :close-on-click-modal="false"
      width="600px"
      :title="dialogTitle"
      height="500px"
      @close="close"
    >
      <el-form
        :model="BusinessModel"
        label-width="140px"
        ref="ruleForm"
        size="medium"
        :rules="rules"
      >
        <el-row :gutter="20">
          <el-col :offset="0">
            <el-form-item label="标题:" prop="title" class="is-required">
              <el-input v-model="BusinessModel.title"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :offset="0">
            <el-form-item label="涉及工段:" prop="task_type" class="is-required">
              <el-select
                v-model="BusinessModel.task_type"
                placeholder="选择工段"
                filterable
              >
                <el-option
                  v-for="(key, val) in productTaskType"
                  :key="key"
                  :label="val"
                  :value="key"
                >
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :offset="0">
            <el-form-item label="时间范围:" prop="times" class="is-required">
              <el-date-picker
                size="medium"
                v-model="BusinessModel.times"
                type="datetimerange"
                align="right"
                start-placeholder="起始时间"
                end-placeholder="结束时间"
                :default-time="['00:00:00', '23:59:59']"
                @change="dateChange($event, BusinessModel)"
              >
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :offset="0">
            <el-form-item label="备注" prop="remark">
              <el-input type="textarea" :rows="15" v-model="BusinessModel.remark"> </el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <div style="float: left; color: blue">注意:带*选项表示必填项</div>
        <el-button v-on:click="dialogShow = false">取 消</el-button>
        <el-button type="primary" v-on:click="onSave()">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import FullCalendar from "@fullcalendar/vue";
import dayGridPlugin from "@fullcalendar/daygrid";
import interactionPlugin from "@fullcalendar/interaction";
import timeGridPlugin from "@fullcalendar/timegrid";
import {loadEnums,ProductTaskType} from '../../uitility/enmu'
import qs from 'qs'
export default {
  name: "DEMO",
  components: {
    FullCalendar,
  },
  data() {
    return {
      calendarOptions: {
        // 引入的插件
        plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
        // 日历头部按钮位置
        headerToolbar: {
          left: "prev,next today",
          center: "title",
          right: "dayGridMonth, timeGridWeek, timeGridDay",
        },
        // 日历头部按钮中文转换
        buttonText: {
          today: "今天",
          month: "月",
          week: "周",
          day: "天",
        },
        customButtons: {
          prev: {
            text: "上个月",
            click: () => {
              this.prev();
            },
          },
          next: {
            text: "下个月",
            click: () => {
              this.next();
            },
          },
          today: {
            text: "今天",
            click: () => {
              this.today();
            },
          },
        },
        locale: "zh-ch", // 切换语言,当前为中文
        firstDay: "1", // 设置一周中显示的第一天是周几,周日是0,周一是1,以此类推
        weekNumbers: true,
        weekNumberCalculation: "ISO", // 与firstDay配套使用
        weekNumberContent: this.weekNumberContent,
        eventColor: "#3d8eec", // 全部日历日程背景色
        timeGridEventMinHeight: "20", // 设置事件的最小高度
        aspectRatio: "1.5", // 设置日历单元格宽高比
        displayEventTime: true, // 是否显示事件时间
        allDaySlot: false, // 周、日视图时,all-day不显示
        allDayDefault: false,
        editable: true, //是否允许修改事件
        selectable: true,
        eventLimit: true, // 设置月日程,与all-day slot 的最大显示数量,超过的通过弹窗展示
        eventTimeFormat: {
          hour: "2-digit",
          minute: "2-digit",
          second: "2-digit",
          hour12: false,
        },
        slotLabelFormat: {
          hour: "2-digit",
          minute: "2-digit",
          second: "2-digit",
          meridiem: false,
          hour12: false, // 设置时间为24小时制
        },
        events: [], // 日程数组
        // 事件
        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, // 日程缩放事件
      },
      condition: [],
      dialogShow: false,
      rules: {
        title: { required: true, message: "请填写标题", trigger: "blur" },
        times: [
          { required: true, message: "请选择起始结束时间", trigger: "blur" },
        ],
        task_type: { required: true, message: "请选择工段", trigger: "blur" },
      },
      BusinessModel: {
        id: null,
        title: null,
        start_time: null,
        end_time: null,
        remark: null,
        times: [],
        task_type: null
      },
      dialogTitle : null,
      productTaskType: {},
    };
  },
  mounted() {
    this.$nextTick(() => {
      loadEnums(ProductTaskType,(data) => { this.productTaskType = data })
      this.queryEvent()
    });
  },
  created() {},
  methods: {
    momentFormat(val) {
      return this.$moment(val).format("YYYY-MM-DD HH:mm:ss")
    },
    weekNumberContent: ({num, text, date }) => {
      return { html: `<div style='font-family:'Microsoft YaHei',font-size:18px>${num}周</div>` }
    },
    close() {
      this.dialogShow = false;
    },
    // 日程删除
    deleteEvent(info) {
      this.$confirm("您是否要删除【" + info.title + "】报备?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          //ProductionEvent/DeleteById
          console.log(info)
          this.axios
            .post("ProductionEvent/DeleteById?"+ qs.stringify({id: info.id}))
            .then((response) => {
              if(response.data.Data) {
                info.remove()
              }
            })
            .catch((error) => {
              this.$message({
                message: error,
                type: "warning",
              });
            })
        })
        .catch((error) => {
          this.$message({
            message: '已取消操作',
            type: 'info'
          })
        })
    },
    // 日程事件点击
    handleEvents(info) {
      console.log("handleEvents.info:", info)
    },
    handleWeekendsToggle() {
      this.calendarOptions.weekends = !this.calendarOptions.weekends;
    },
    // 日期点击
    handleDateClick(selectInfo) {
      this.$confirm("您是否要在【" + selectInfo.dateStr + "】添加一个新的报备?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.dialogTitle = '创建新的报备'
          Object.keys(this.BusinessModel).forEach((key) => {
            this.BusinessModel[key] = null
          })
          this.BusinessModel.times = [
            this.$moment(selectInfo.date),
            this.$moment(selectInfo.date).add(1, "days"),
          ];
          this.dialogShow = true;
        })
        .catch((error) => {
          this.$message({
            message: '已取消操作',
            type: 'info'
          })
        })
    },
    // 日程点击信息展示
    handleEventClick(info) {
      this.dialogTitle = `编辑报备【${ info.event.title }】`
      info.el.style.borderColor = "red";
      this.BusinessModel.id = info.event.id
      this.BusinessModel.title = info.event.title
      // remark 属于扩展字段 extendedProps
      this.BusinessModel.remark = info.event.extendedProps.remark
      this.BusinessModel.times = [this.$moment(info.event.start).format("YYYY-MM-DD HH:mm:ss"),
                                  this.$moment(info.event.end).format("YYYY-MM-DD HH:mm:ss")]
      // task_type 属于扩展字段 extendedProps
      this.BusinessModel.task_type = info.event.extendedProps.task_type
      this.dialogShow = true
    },
    // 日程事件触发
    eventClick(info) {
      info.el.style.borderColor = "red";
    },
    saveEvent(info) {
      this.BusinessModel.id = info.event.id
      this.BusinessModel.title = info.event.title
      // remark 属于扩展字段 extendedProps
      this.BusinessModel.remark = info.event.extendedProps.remark
      this.BusinessModel.times = [this.$moment(info.event.start).format("YYYY-MM-DD HH:mm:ss"),
                                  this.$moment(info.event.end).format("YYYY-MM-DD HH:mm:ss")]
      this.BusinessModel.start_time = this.$moment(this.BusinessModel.times[0]).format("YYYY-MM-DD HH:mm:ss")
      this.BusinessModel.end_time = this.$moment(this.BusinessModel.times[1]).format("YYYY-MM-DD HH:mm:ss")
      this.dialogShow = false
      this.axios.post('ProductionEvent/AddOrUpdate', this.BusinessModel)
        .then((response) => {
          if(response.data.Data) {
            this.$message.success('操作成功!')
            this.queryEvent()
            this.dialogShow = false
          }
        })
        .catch((error) => {
          this.$message({
            message: error,
            type: 'warning'
          })
        })
    },
    // 日程拖动事件
    handleEventDrop(info) {
      this.saveEvent(info)
    },
    // 日程缩放事件
    eventResize(info) {
      this.saveEvent(info)
    },
    prev() {
      this.$refs.FullCalendar.getApi().prev()
      this.queryEvent()
    },
    next() {
      this.$refs.FullCalendar.getApi().next()
      this.queryEvent()
    },
    today() {
      this.$refs.FullCalendar.getApi().today()
      this.queryEvent()
    },
    // 去数据库检索报备信息
    queryEvent() {
      let start = this.$moment(
        this.$refs.FullCalendar.getApi().view.activeStart
      ).format("YYYY-MM-DD HH:mm:ss");
      let end = this.$moment(
        this.$refs.FullCalendar.getApi().view.activeEnd
      ).format("YYYY-MM-DD HH:mm:ss");
      this.condition = [];
      this.condition.push({
        FieldName: "start_time",
        ConditionalType: "3",
        FieldValue: start,
      });
      this.condition.push({
        FieldName: "end_time",
        ConditionalType: "5",
        FieldValue: end,
      });
      this.axios
        .post("ProductionEvent/QueryCondition", this.condition)
        .then((response) => {
          if(response.data.Data && Array.isArray(response.data.Data) && response.data.Data.length > 0) {
            // 清除所有报备
            this.$refs.FullCalendar.getApi()
              .view.calendar.getEvents()
              .forEach((eventSource) => {
                eventSource.remove();
              });
            // 检索报备并显示报备
            for(let i = 0; i < response.data.Data.length; i++) {
              let entity = response.data.Data[i]
              // 向日历中添加事项
              this.$refs.FullCalendar.getApi().view.calendar.addEvent({
                id: entity.id,
                title: entity.title,
                start: this.$moment(entity.start_time).format("YYYY-MM-DD HH:mm:ss"),
                end: this.$moment(entity.end_time).format("YYYY-MM-DD HH:mm:ss"),
                remark: entity.remark,
                task_type: entity.task_type,
                // 修改背景颜色
                backgroundColor:'#409EFF',
                // 修改边框颜色
                borderColor:'#DDDDDD',
              })
            }
          }
        })
        .catch((error) => {
          this.$message({
            message: error,
            type: "warning",
          });
        })
    },
    dateChange(times, row) {
      // row.StartDate = this.$moment(times[0]).format("YYYY-MM-DD HH:mm:ss")
      // row.EndDate = this.$moment(times[1]).format("YYYY-MM-DD HH:mm:ss")
    },
    // 添加或保存报备
    onSave() {
      this.$refs["ruleForm"].validate((valid) => {
        if (valid) {
          this.BusinessModel.start_time = this.$moment(this.BusinessModel.times[0]).format("YYYY-MM-DD HH:mm:ss")
          this.BusinessModel.end_time = this.$moment(this.BusinessModel.times[1]).format("YYYY-MM-DD HH:mm:ss")
          this.dialogShow = false
          this.axios.post('ProductionEvent/AddOrUpdate', this.BusinessModel)
            .then((response) => {
              if(response.data.Data) {
                this.$message.success('操作成功!')
                this.queryEvent()
                this.dialogShow = false
              }
            })
            .catch((error) => {
              this.$message({
                message: error,
                type: 'warning'
              })
            })
        }
      });
    },
    taskChange(value) {
      console.log(value)
    }
  },
};
</script>
<style lang="less" scoped>
.eventDeal-wrap {
  height: 97% !important;
}
/deep/ .fc-header-toolbar {
  margin-top: 15px;
  margin-left: 15px;
  margin-right: 15px;
}
/deep/ .fc-prev-button,
/deep/ .fc-next-button {
  font-size: 16px;
  background-color: #409eff !important;
  border: 1px solid #dcdfe6;
}
/deep/ .fc-today-button {
  font-size: 16px;
  background-color: #67c23a !important;
  border: 1px solid #dcdfe6;
}
/deep/ .fc--button.fc-button.fc-button-primary {
  display: none;
}
/deep/ .fc-dayGridMonth-button.fc-button.fc-button-primary,
/deep/ .fc-timeGridWeek-button.fc-button.fc-button-primary,
/deep/ .fc-timeGridDay-button.fc-button.fc-button-primary {
  border-radius: 0.25em;
  font-size: 16px;
  background-color: #409eff !important;
}
/deep/ .fc-daygrid-dot-event .fc-event-title {
  text-overflow: ellipsis; //字符溢出隐藏
}
/deep/ .el-tooltip {
  width: 100%;
}
//  日历自定义样式
/deep/ .fc-state-default {
  background-color: initial;
  background-image: initial;
  border: none;
  // box-shadow: 0 0 0 1px #409EFF;
}
/deep/ .fc-toolbar .fc-left {
  font-size: 12px;
  margin-left: 2px;
}
/deep/ .fc-ltr .fc-basic-view .fc-day-top .fc-day-number {
  float: left;
}
/deep/.fc-ltr .fc-basic-view .fc-day-top .fc-day-cnTerm,
/deep/.fc-ltr .fc-basic-view .fc-day-top .fc-day-cnDate {
  float: right;
}
/deep/.fc-ltr .fc-basic-view .fc-day-top .fc-day-cnTerm {
  color: #f08f00;
}
// 每日任务自定义样式
/deep/ .fc-event,
.fc-event-dot {
  color: #FFFFFF;
  background-color: #409EFF;
  border-color:'#DDDDDD';
  cursor: pointer;
  font-size: 12px;
  padding: 2px 5px;
}
// /deep/ .fc-event {
//   border: none;
// }
// /deep/ .fc-row .fc-content-skeleton {
//   height: 100%;
// }
// // 去除滚动条
// /deep/ .fc-view-container *,
// .fc-view-container ::after,
// .fc-view-container ::before {
//   box-sizing: border-box;
// }
// /deep/ .fc-row .fc-content-skeleton td,
// /deep/ .fc-row .fc-helper-skeleton td {
//   color: #666;
// }
</style>

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

使用FullCalendar做日程安排 的相关文章

随机推荐

  • java代码比较数据_比对两个数据库的差异:Java篇

    人类之所以进步 在于会使用工具 我们知道 有代码比对工具 有版本控制控制工具比对同一个文件不同人修改的地方 还有eclipse工具提供的Compare History 工具 我同事比较 同情 我每次发布产品版本都要手动比对本地和在线数据库的
  • 解决Navicat远程服务器2013-Lost connection to MYSQL server at 'reading for initial communication packet'

    问题所在 使用Navicat远程服务器mysql数据库时报错误 2013 Lost connection to MYSQL server at reading for initial communication packet system
  • 工具类Util中的@Value注解注入为空

    1 原因分析 在后端开发当中我们可能会使用到工具类 而一般的工具类中的方法都是静态方法 而 Value注解只能给普通变量注入值 不能直接给静态变量赋值 2 延伸 静态变量 即类变量 是一个类的属性 而不是对象的属性 spring依赖注入是基
  • 【Java基础知识 4】秒懂数组拷贝,感知新境界

    目录 一 前言 二 为什么数组的起始索引是0而不是1 三 起别名 四 System arraycopy与Arrays copyOf 浅拷贝
  • socat工具

    socat socat 是一个功能强大的网络工具 它允许在两个连接的数据流之间建立双向通信 该工具可以用于创建虚拟串口 转发网络流量 调试和测试网络应用程序等 以下是 socat 的一些主要特点和用途 连接不同类型的套接字 socat 可以
  • Asymmetric Gained Deep Image Compression With Continuous Rate Adaptation文献复现

    前言 相关论文阅读自行解决 这里主要是记录代码的学习与实验的复现 github地址 此代码非官方部署代码 而是私人实现的 本博客仅做学习记录 1 代码学习 1 1 主要框架部分 这里的主编解码器与高斯建模的方式 采用的是同joint上下联合
  • 推荐系统与深度学习-学习笔记六

    仅供学习 第六章 基于深度学习的推荐模型 6 1 基于DNN的推荐算法 wide deep 6 2 基于DeepFM的推荐算法 6 3 基于矩阵分解和图像特征的推荐算法 6 4 基于循环网络的推荐算法 6 5 基于生成对抗网络的推荐算法 第
  • 发布镜像【DockerHub或阿里云】

    发布镜像到DockerHub 登录DockerHub root us4ci6jaxom1jjz2 docker login u windrose0318 Password WARNING Your password will be stor
  • vs2013中静态库lib文件的生成与使用

    一 静态库lib文件的生成 1 文件 新建项目 Visual C win32项目 输入项目名称 例如 CMath 2 项目右键 添加 新建项 CMath h class CMath public CMath CMath void setX
  • 【iOS】UserDefaults使用的一些“坑”

    UserDefaults使用的一些 坑 项目场景 问题1 初始化程序组对应UserDefaults失败 原因分析 问题2 没有记录数据的时候 读取值为0 or false 导致配置使用时错误 原因分析 问题3 extension进程中监听需
  • google lab 深度学习_Google 深度学习笔记 - 深度神经网络实践

    优化 Regularization 在前面实现的RELU连接的两层神经网络中 加Regularization进行约束 采用加l2 norm的方法 进行负反馈 代码实现上 只需要对tf sgd relu nn中train loss做修改即可
  • 用gdb调试运行中的程序

    今天一早到了公司 策划就和我说 前几天出过问题的那台服务器 玩家又登陆不上游戏了 上去一看 又是CPU使用100 这问题最近经常出现 又不好查 就干脆让运维先别重启了 直接上线调试 一开始以为是lua脚本的死循环 后来才发现原来是底层的定时
  • WebSocket心跳机制/服务器端开连接(JS前端)

    情景 前端使用 WebSocket 的时候 后端长时间没有推送数据 导致 WebSocket 连接经常断开 后端也会报错 解决方法 通过 心跳机制 让前端和后端始终保持连接 代码 WebSocket心跳检测 var ws heartChec
  • Altium Designer 原理图编译屏蔽/Compile Mask

    Place Directives Compile Mask 这个功能并不只提供给你要将某区域不做ERC 检查显示而已 只要的是它可以将原理图工作领域中的仿真源掩盖起来
  • Android TV开发总结【焦点】

    一 焦点获取 首先 TV端的开发和我们手机端开发最大的区别就在于TV端存在焦点的概念 如下图 可想而知 手机端我们直接通过点击 长按某个区域处理响应事件处 但是TV端只能通过遥控器的上下左右来操控焦点 从而选中特定的区域处理相应事件 在TV
  • Dialog、Drawer 点击浏览器回退、前进,遮罩层不消失问题

    文章目录 问题 一 modal append to body 二 解决方案 方案1 给组件添加 modal append to body false 属性 方案2 全局 推荐此方法 问题 Vue 项目中使用 element ui Dialo
  • 《计算机网络》速成

    课时1 计算机网络体系结构 考点 重要程度 占分 题型 计算机网络的组成和功能 选择题 计算机网络的分类 选择题 性能指标 选择题 计算题 体系结构与参考模型 选择题 1 1计算机网络概述 计算机网络的组成 从组成部分看 一个完整的计算机网
  • 解析Python爬虫常见异常及处理方法

    作为专业爬虫程序猿长期混迹于爬虫ip解决方案中 我们经常会遇到各种各样的异常情况 在爬虫开发过程中 处理这些异常是不可或缺的一部分 本文将为大家总结常见的Python爬虫异常 并分享相应的处理方法 帮助你避免绊倒在爬虫之路上 一 网络连接异
  • mysql 存储过程 多行_MySQL结果由存储过程中的多行组成

    我正在处理的存储过程有时会出错 我得到的结果包含多个行错误 但仅限于某些JOB ID INPUT值 我明白是什么导致了这个错误 所以我试着非常小心地确保我的返回值在它们应该是标量时 很难看到存储过程 所以我不确定可以在哪里生成错误 由于错误
  • 使用FullCalendar做日程安排

    自定义实现了加载 删除 样式的定义 鼠标悬停的显示 如图 单击弹出编辑框 其中日周天的选择器都是作为插件引入的 这个组件还是蛮庞杂的 功能也强大 需要时间去研究