element-plus日历(Calendar)动态渲染,页面为何不显示获取到的值?



<template>
  <el-calendar ref="calendar">
    <template #header="{ date }">
      <span style="font-size: 18px;color:#0a519b;font-weight: bold">工时填报备忘录</span>
      <span style="font-size: 25px;color:#0a519b;font-weight: bold">{{ date }}</span>
      <el-button-group >
        <div style="margin-top: 10px;">
          <el-button size="small" @click="selectDate('prev-month')" style="font-size: 15px">
            上个月
          </el-button>
          <el-button size="small" @click="selectDate('today')" style="font-size: 15px">今天</el-button>
          <el-button size="small" @click="selectDate('next-month')" style="font-size: 15px">
            下个月
          </el-button>
        </div>
      </el-button-group>
    </template>
    <template #date-cell="{ data }">
      <el-row :class="data.isSelected ? 'is-selected' : 'sds'">
        {{ data.day.split('-').slice(1).join('-') }}
        {{ data.isSelected ? '✔️' : '' }}
      </el-row>
      <div v-for="(item,index) in textContent(data.day)" :key="index" style="padding-top: 15px">
        <e-row>
          <el-col class="center">
            <el-tag type="warning" class="tag">
              <el-row v-if="item.reportType === ''" >
                <el-col :span="17" class="tag">
                  <span>出勤状态</span>
                </el-col>
                <el-col :span="1"></el-col>
                <el-col :span="6" class="tag2">
                  <span>{{item.reportType}}</span>
                </el-col>
              </el-row>
              <el-row v-else>
                <el-col :span="17" class="tag">
                  <span>出勤状态</span>
                </el-col>
                <el-col :span="1"></el-col>
                <el-col :span="6" class="tag2">
                  <span>{{item.reportType}}</span>
                </el-col>
              </el-row>
            </el-tag>
          </el-col>
        </e-row>
        <el-row
          style="margin-top: 10px"
          class="hours"
          v-if="item.workingHours && item.overtimeWorkingHours === 0"
        >
          <el-col :span="11" class="center">
            <span style="font-size: 12px">正常工时</span><span class="center2" style="">0</span></el-col>
          <el-col :span="2" class="center">|</el-col>
          <el-col :span="11" class="center">
            <span style="font-size: 12px">加班工时</span><span class="center2">0</span></el-col>
        </el-row>
        <el-row v-else style="margin-top: 10px" class="hours" >
          <el-col :span="11" class="center">
            <span style="font-size: 12px">正常工时</span><span class="center2" style="">{{item.workingHours }}</span></el-col>
          <el-col :span="2" class="center">|</el-col>
          <el-col :span="11" class="center">
            <span style="font-size: 12px">加班工时</span><span class="center2">{{ item.overtimeWorkingHours }}</span></el-col>
        </el-row>
      </div>

    </template>


  </el-calendar>
</template>

<script lang="ts" setup>
import {ref} from 'vue'
import type { CalendarDateType, CalendarInstance } from 'element-plus'
import {getHoursData} from "@/api/hours/hoursCalendar";



const calendar = ref<CalendarInstance>()
const selectDate = (val: CalendarDateType) => {
  if (!calendar.value) return
  calendar.value?.selectDate(val)
}

//处理日期获取后台数据动态渲染上去
const textContent = (date) => {

  //当前date是拿到上面日历组件当前的日期值 根据该值去筛选测试数据找到对应各个日期下对应的数据return出去
  return getHoursData().then(res=>{
    return res.list.filter((item)=>{
      if(date == item.reportDate){
        console.log("这是获取到的相同日期1"+item.reportDate);
        console.log("这是获取到的相同日期2"+date);
        console.log("这是查到的相同的值"+JSON.stringify(item))
        return date === item.reportDate;
      }else {
        console.log("这是获取到的不日期1"+item.reportDate);
        console.log("这是获取到的不日期2"+date);
        console.log("这是查到的不相同的值"+JSON.stringify(item))
      }

    })
  })
};

</script>

<style scoped >
:deep .el-calendar-table thead th {
  color: #0c63be;
  font-weight: bold;
  font-size: 15px;
}
:deep .el-calendar-table .el-calendar-day:hover {
  background-color: #3c89da;
  font-size: 20px;
  color: white;
}
:deep .el-calendar-table .el-calendar-day{
  height: 150px;
  font-size: 16px;
  font-weight: 600;
}
.aaa .is-selected .dataStyle {
  color: #ffab11;
}
.aaa .prev .dataStyle {
  color: #c4c5c8;
}
.aaa .next .dataStyle {
  color: #c4c5c8;
}
:deep .el-calendar {
  --el-calendar-cell-width: 130px;
}
.center {
  display: flex;
  justify-content: center;
  align-items: center;
}
.center2 {
  display: flex;
  justify-content: center;
  align-items: center;
  color: #ffab11;
  margin-left: 5px;
  font-size: 15px;
}
</style>

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值