vue中集成 <el-calendar>日历控件,显示数据的状况

vue中集成 <el-calendar>日历控件,显示数据的状况。每个日期上显示颜色方框。

在  <el-calendar> 控件的 <template> 中处理具体的颜色显示,使用 v-if 函数调用处理参数,其中添加 slot-scope="{date, data}" 可获取日期和数据。

效果图:

参考链接:https://blog.youkuaiyun.com/weixin_56718509/article/details/131699291

<template><!--数据日历-->

  <div>

    <el-calendar v-model="value" @input="handleCalendarChange">

      <template

        slot="dateCell"

        slot-scope="{date, data}">

        <div v-if="data.type != 'current-month'"><!--非当前月日期仅显示数字-->

          <div  style="width: 45px;height: 25px;margin-top: 5px;text-align: center;color: #d4cfcf;padding-top: 2px;">

            {{ data.day.split('-').slice(2).join('-') }}</div>

        </div>

        <div v-if="data.type == 'current-month' && handelData(data)">

          <div :class="(data.overCss == null?'grey':data.overCss)" style="width: 45px;height: 25px;border-radius: 10px;margin-top: 5px;text-align: center;color: white;padding-top: 2px;">

            {{ data.day.split('-').slice(2).join('-') }}</div>

        </div>

      </template>

    </el-calendar>



    <el-row :gutter="20">

      <el-col :span="8"><div class="tip-foot"><el-row><el-col :span="12">正常</el-col><el-col :span="12" class="green tip-color"></el-col></el-row></div></el-col>

      <el-col :span="8"><div class="tip-foot"><el-row><el-col :span="12">超标</el-col><el-col :span="12" class="red tip-color"></el-col></el-row></div></el-col>

      <el-col :span="8"><div class="tip-foot"><el-row><el-col :span="12">无数据</el-col><el-col :span="12" class="grey tip-color"></el-col></el-row></div></el-col>

    </el-row>



  </div>

</template>



<script>



    export default {

      name: "dataCalendar",

      data() {

        return {

          value: new Date(),

          showList:[],

          monitorTime:new Date()

        }

      },

      created() {

          getDataList();

      },

      methods: {

        //查询

        getDataList(){

          //查询数据赋值给 this.showList

          //本例中格式 this.showList=[{monitorTime:'2024-06-04 00:00:00',dataFlag:'1',data:5}]

           

        },

        //日期更改

        handleCalendarChange(value){

          this.monitorTime = this.formatDateString(value);

          this.getDataList();

        },

        formatDateString(date) {

          const year = date.getFullYear();

          const month = String(date.getMonth() + 1).padStart(2, '0');

          const day = String(date.getDate()).padStart(2, '0');

          return `${year}-${month}-${day} 00:00:00`;

        },

        //处理数据

        handelData(e) {

          for (let i = 0; i < this.showList.length; i++) {

            if (this.showList[i].monitorTime.substring(0, 10) == e.day + '') {

              if(this.showList[i].data == null){//如果没有数据则不填充样式,css中处理成灰色

                  continue;

                }else if (this.showList[i].dataFlag == '1') {

                  e.overCss = 'red';

                } else if (this.showList[i].dataFlag == '0') {

                  e.overCss = 'green';

                }

            }

          }

          return true;

        },

         



      }

    }

</script>



<style lang="scss" scoped>

  .green{

    background-color: green;

  }

  .red{

    background-color: #b81e1e;

  }

  .grey{

    background-color: darkgrey;

  }

  .tip-foot{

    width: 60%;

    text-align: center;

    margin-left: 20%;

  }



  .tip-color{

    width: 30px;

    height: 20px;

    border-radius: 5px;

  }



</style>





<style type="text/css">



</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值