vue中集成 <el-calendar>日历控件,显示数据的状况
vue中集成 <el-calendar>日历控件,显示数据的状况。每个日期上显示颜色方框。
在 <el-calendar> 控件的 <template> 中处理具体的颜色显示,使用 v-if 函数调用处理参数,其中添加 slot-scope="{date, data}" 可获取日期和数据。
效果图:
参考链接:https://blog.csdn.net/weixin_56718509/article/details/131699291
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | <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> |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
2019-06-04 java yyyyMMddHHmmss格式字符串转换为yyyy-MM-dd HH:mm:ss格式字符串