首页 > 其他分享 >vue中集成 <el-calendar>日历控件,显示数据的状况

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

时间:2024-06-04 13:56:25浏览次数:9  
标签:控件 00 vue 日历 date data day showList

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

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

效果图:

 

 

参考链接:https://blog.csdn.net/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>

  

标签:控件,00,vue,日历,date,data,day,showList
From: https://www.cnblogs.com/webttt/p/18230604

相关文章

  • 基于Java+Vue的园区智能化管理系统:综合管控,推进数字化转型(源代码分享)
       前言:智慧园区管理平台是一个集成了多种功能的综合性系统,旨在通过信息化、智能化手段提升园区的管理效率和服务质量。以下是针对系统的各个功能模块的简要描述:一、楼栋管理会务管理:管理园区内的会议预约、会议室使用等。园区信息:展示园区的基本信息,如位置、面积、规划......
  • Vue实现动态组件
    使用场景:同一个区域因状态不同或者tab页,展示给用户不同模版样式逻辑的组件动态组件实现,是通过使用 is attribute来切换不同的组件<componentv-bind:is="currentTabComponent"></component> 一、公共动态组件父组件(可以通过keep-alive缓存)<!--公共动态组件isComp......
  • Vue3-组件通信详解
    文章目录组件通信的含义Vue3组件通信和Vue2的区别组件通信的具体实现props(父子组件通信)自定义事件(子传父)mitt(任意组件间通信)v-model$attrs(非props的父子组件通信)r......
  • JavaFX 常见UI控件使用
    UI控件介绍JavaFX提供了一套丰富的用户界面控件,这些控件可以用来创建现代的、交互式的图形用户界面(GUI)。JavaFX控件是JavaFX库中预定义的组件,它们封装了创建用户界面元素的复杂性,使得开发者可以快速地构建应用程序界面。以下是一些常见的JavaFX控件:控件名说明L......
  • vue2.0和vue3.0同时使用
    背景:原先电脑上安装了vue2.0和node14.17.6版本,后面新项目使用的是vue3.0和node 16.6.1。通过nvm安装node 16.6.1的时候,不小心把原来的2.0环境给搞坏了。目的:本文将通过文字描述(都是cmd命令,截图感觉没啥意义)的方式,讲述卸载和安装多版本node的vue环境前言:步骤中所有的命令都......
  • pinia之Vue 的存储库,案例:允许跨组件/页面共享状态--传值
    pinia之Vue的存储库,案例:允许跨组件/页面共享状态--传值第⼀步:npminstallpinia第⼆步:操作src/main.tsimport{createApp}from'vue'importAppfrom'./App.vue'/*引⼊createPinia,⽤于创建pinia*/import{createPinia}from'pinia'/*创建pinia*/con......
  • Django + Vue 使用Nginx + uWsgi部署
    1.settings.py配置STATIC_ROOT=os.path.join(BASE_DIR,'static/dist')#导入前后端静态资源后更改即可DEBUG=True#为True不容易暴露项目信息,当然也不显示BUG信息ALLOWED_HOSTS=['*']STATIC_URL='/static/' 2.django端打包静态资源#会在static下生成[root@dsc1m......
  • 界面控件DevExpress WinForms的流程图组件 - 可完美复制Visio功能(二)
    DevExpressWinForms的Diagram(流程图)组件允许您复制MicrosoftVisio中的许多功能,并能在下一个WindowsForms项目中引入信息丰富的图表、流程图和组织图。P.S:DevExpressWinForms拥有180+组件和UI库,能为WindowsForms平台创建具有影响力的业务解决方案。DevExpressWinForms能完美......
  • vue3中ref绑定自定义组件没有获取到dom?
    问题<template><my-compref="test"/></template><scriptlang="ts"setup>consttest=ref()onMounted(()=>{console.log(test.value)})</script>打印出来的是一个proxy对象解决办法1.如果ref绑定的是一个普通的d......
  • 第十九节:带你梳理Vue2: 父组件向子组件传参(props传参)
    1.组件嵌套1.1组件的嵌套使用之前有说过,Vue组件跟Vue实例是一样的,因此在Vue中一个组件中也可以定义并使用自己的局部组件,这就是组件的嵌套使用例如:示例代码如下:<divid="app"><!--3.使用组件--><my-component></my-component></div><script>......