elementui el-calendar日历组件使用示例

 更新时间:2023年12月01日 14:18:27   作者:瑞瑞_  
这篇文章主要为大家介绍了elementui el-calendar日历组件使用示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

需求

需要在日历基础上展示每天排班记录及排班详情、当天是否有异常情况。完成效果:

elementui自带切换月份按钮与设计图不符,所以我隐藏了插件自带的按钮,自己加了个左右切换图标,代码如下:

// 隐藏组件自带切换月份按钮
::v-deep.el-calendar .el-calendar__button-group{
   display: none;
}

在html中新增
<!-- 日历两侧年月切换 -->
<img class="month-cut-img month-cut-left" @click="dateCut(1)" src="../../../../assets/img/scheduling/calendar-month-left.png" />
<img class="month-cut-img month-cut-right" @click="dateCut(2)" src="../../../../assets/img/scheduling/calendar-month-right.png" />
<img class="month-cut-img year-cut-left" @click="dateCut(3)" src="../../../../assets/img/scheduling/calendar-year-left.png" />
<img class="month-cut-img year-cut-right" @click="dateCut(4)" src="../../../../assets/img/scheduling/calendar-year-right.png" />

具体代码实现

html

<!-- 日历两侧年月切换 -->
<img class="month-cut-img month-cut-left" @click="dateCut(1)" src="../../../../assets/img/scheduling/calendar-month-left.png" />
<img class="month-cut-img month-cut-right" @click="dateCut(2)" src="../../../../assets/img/scheduling/calendar-month-right.png" />
<img class="month-cut-img year-cut-left" @click="dateCut(3)" src="../../../../assets/img/scheduling/calendar-year-left.png" />
<img class="month-cut-img year-cut-right" @click="dateCut(4)" src="../../../../assets/img/scheduling/calendar-year-right.png" />
<!-- 日历 -->
<el-calendar v-model="calendarVal">
  <template slot="dateCell" slot-scope="{date, data}">
    <div @click="viewDetail(data.day)">
      <div class="date">{{ data.day.slice(8) }}</div>
      <div v-for="item in schedulingData.schedulingHandle">
        <div v-if="item.date == data.day">
          <!-- 是否异常 -->
          <div class="abnormal-state" v-if="item.hasException === true"></div>
          <!-- 排版情况 === memberAmount:根据是否有值班成员判断是否排班;isPast:日期是否已过;isToday:是否是今天  -->
          <div class="scheduling-state scheduling-state-notset" v-if="item.memberAmount === 0">
            <img src="../../../../assets/img/scheduling/scheduling-state1.png">
            <span class="f14">未排</span>
          </div>
          <div class="scheduling-state scheduling-state-ordering1" v-if="item.memberAmount > 0 && item.isPast === true && item.isToday === false">
            <img src="../../../../assets/img/scheduling/scheduling-state2.png">
            <span class="f14">已排</span>
          </div>
          <div class="scheduling-state scheduling-state-ordering2" v-if="item.memberAmount > 0 && item.isToday === true">
            <img src="../../../../assets/img/scheduling/scheduling-state3.png">
            <span class="f14">已排</span>
          </div>
          <div class="scheduling-state scheduling-state-ordering3" v-if="item.memberAmount > 0 && item.isPast === false && item.isToday === false">
            <img src="../../../../assets/img/scheduling/scheduling-state4.png">
             <span class="f14">已排</span>
          </div>
          <!-- 当日排班情况弹窗 -->
          <div class="today-scheduling-detail" v-if="item.showTodayScheduling">
            <div class="today-scheduling-title">当日排班</div>
            <div class="today-scheduling-center">
              <div class="today-scheduling-item" v-for="item1 in item.todayDetail">
                <div class="name1">{{ item1.shiftName }}</div>
                <div class="name2">{{ item1.crewName }}</div>
              </div>
            </div>
            <div class="today-scheduling-footer">
              <div class="edit"><span class="el-icon-edit"></span>编辑</div>
              <div class="view"><span class="el-icon-view"></span>查看</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </template>
</el-calendar>
<div class="back-to-today" @click="dateCut(5)">回到今天</div>

js 

dateCut(type) {
  // type:1 月份左侧按钮,2 月份右侧按钮,3 年份左侧按钮,4 年份右侧按钮,5 回到今天
  if (type === 1) {
    this.calendarVal = new Date(this.calendarVal).getMonth() > 0 ?
      new Date(this.calendarVal).getFullYear() + '-' + new Date(this.calendarVal).getMonth() + '-01' :
      new Date(this.calendarVal).getFullYear() - 1 + '-12' + '-01'
  } else if (type === 2) {
    this.calendarVal = new Date(this.calendarVal).getMonth() < 11 ?
      new Date(this.calendarVal).getFullYear() + '-' + (Number(new Date(this.calendarVal).getMonth()) + 2) + '-01' :
      new Date(this.calendarVal).getFullYear() + 1 + '-01' + '-01'
  } else if (type === 3) {
    this.calendarVal = new Date(this.calendarVal).getFullYear() - 1 + '-' + (Number(new Date(this.calendarVal).getMonth()) + 1) + '-01'
  } else if (type === 4) {
     this.calendarVal = new Date(this.calendarVal).getFullYear() + 1 + '-' + (Number(new Date(this.calendarVal).getMonth()) + 1) + '-01'
  } else if (type === 5) {
     this.calendarVal = this.getDate(new Date()).fullDate
  }
  this.getData() // 调接口数据
},

css代码

// 日历组件样式修改
  .is-selected {
    color: #1989FA;
  }
  ::v-deep.el-calendar{
    height: calc(100% - 35px);
  }
  ::v-deep.el-calendar .el-calendar__body{
    padding-bottom: 16px;
    height: calc(100% - 80px);
  }
  ::v-deep.el-calendar .el-calendar-table{
    height: 100%;
  }
  .el-backtop, ::v-deep.el-calendar .el-calendar-table td.is-today .date{
    //background: #5E97F9;
    //box-shadow: 0px 4px 7px 0px rgba(113,208,255,0.5);
    //color: #fff;
    background: #DCE9FF;
    color: rgba(0,0,0,0.45);
  }
  .el-backtop, ::v-deep.el-calendar .el-calendar-table .date:hover{
    background: #DCE9FF;
    color: rgba(0,0,0,0.45);
  }
  ::v-deep.el-calendar .el-calendar-table .el-calendar-day:hover{
    background: none;
  }
  ::v-deep.el-calendar .el-calendar-table td.is-selected{
    background: none;
  }
  ::v-deep.el-calendar .el-calendar-table td.is-selected .date{
    background: #5E97F9;
    box-shadow: 0px 4px 7px 0px rgba(113,208,255,0.5);
    color: #fff;
  }
  ::v-deep.el-calendar .el-calendar__button-group{
    display: none;
  }
  ::v-deep.el-calendar .el-calendar__title{
    margin: 0 auto;
  }
  ::v-deep.el-calendar .el-calendar-table .el-calendar-day{
    position: relative;
  }

日历组件就完成了,有任何问题欢迎大家留言!

以上就是elementui el-calendar日历组件使用示例的详细内容,更多关于elementui el-calendar日历组件的资料请关注脚本之家其它相关文章!

相关文章

  • vue-element-admin开发教程(v4.0.0之前)

    vue-element-admin开发教程(v4.0.0之前)

    本文主要介绍了vue-element-admin开发教程(v4.0.0之前),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-04-04
  • Vue打包后静态资源图片失效彻底解决的终极指南

    Vue打包后静态资源图片失效彻底解决的终极指南

    文章详细分析了Vue项目中静态资源路径失效的问题,包括开发、构建、部署等阶段的常见原因,并提供了多种解决方案,旨在帮助开发者系统性地解决静态资源路径问题,构建稳定可靠的前端应用,需要的朋友可以参考下
    2025-03-03
  • vue项目debugger调试看不到源码的问题及解决

    vue项目debugger调试看不到源码的问题及解决

    这篇文章主要介绍了vue项目debugger调试看不到源码的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-06-06
  • Vue项目实现token无感刷新的示例代码

    Vue项目实现token无感刷新的示例代码

    最近在使用系统的过程中,业务人员反馈刚登录一会就提示token过期需要重新登录,所以本文为大家分享一个无感刷新的实现代码,需要的可以参考下
    2023-07-07
  • 从零开始封装自己的自定义Vue组件

    从零开始封装自己的自定义Vue组件

    如何封装自己的Vue组件,如何把自己的Vue代码封装成公共组件,今天为大家简单介绍一下如何封装自己的Vue组件
    2018-10-10
  • 去除Element-Plus下拉菜单边框的实现步骤

    去除Element-Plus下拉菜单边框的实现步骤

    Element-Plus 是 Element UI 的 Vue 3 版本,它提供了一套完整的组件库,在使用 Element-Plus 进行开发时,我们可能会遇到需要自定义组件样式的情况,本文将介绍如何使用 CSS 来去除 Element-Plus 下拉框的边框,需要的朋友可以参考下
    2024-03-03
  • vue+tsc+noEmit导致打包报TS类型错误问题及解决方法

    vue+tsc+noEmit导致打包报TS类型错误问题及解决方法

    当我们新建vue3项目,package.json文件会自动给我添加一些配置选项,这写选项基本没有问题,但是在实际操作过程中,当项目越来越复杂就会出现问题,本文给大家分享vue+tsc+noEmit导致打包报TS类型错误问题及解决方法,感兴趣的朋友一起看看吧
    2023-10-10
  • element el-table实现多级表头的代码

    element el-table实现多级表头的代码

    多级表头的作用与优势,多级表头能够清晰地展示数据的层次结构,帮助我们更好地理解数据之间的关系,下面通过本文给大家介绍element el-table实现多级表头的代码,感兴趣的朋友跟随小编一起看看吧
    2024-04-04
  • vue-awesome-swiper 基于vue实现h5滑动翻页效果【推荐】

    vue-awesome-swiper 基于vue实现h5滑动翻页效果【推荐】

    说到h5的翻页,很定第一时间想到的是swiper。但是我当时想到的却是,vue里边怎么用swiper。这篇文章主要介绍了vue-awesome-swiper - 基于vue实现h5滑动翻页效果 ,需要的朋友可以参考下
    2018-11-11
  • Vue中关于异步请求数据未更新的解决

    Vue中关于异步请求数据未更新的解决

    本文将探讨Vue中异步请求数据未更新的常见原因,并提供解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2025-03-03

最新评论