vue calendar list implementation

 page implementation

<template>
  <div class="trip-manager">
    <div class="options">
      <el-form :model="formData" :inline="true">
        <el-form-item >
        <el-select v-model="formData.name" placeholder="选择用户">
          <el-option v-for="i in options" :label="i.name" :value="i.id" :key="i.id"></el-option>
        </el-select>
        </el-form-item>
        <el-form-item >
          <el-date-picker
            v-model="formData.month"
            type="month"
            value-format="yyyy-MM"
            placeholder="选择月"
            @change="changeDate">
          </el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="container">
     <div class="day">
       <div class="day-box" v-for="i in dayOFweek" :key="i">{
   
   {i}}</div>
     </div>
      <div class="date">
        <template v-for="(i,index) in dayData.countDay">
          <div class="date-box" v-if="i===0" :key="index"></div>
          <div class="date-box"  :key="index" v-if="i<16 && i !==0">
            <p>{
   
   {formatte(i)}}</p>
            <p title="hhhhhh">上午:{
   
   {'哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈'}}</p>
            <p>下午:{
   
   {'哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈'}}</p>
          </div>
          <div class="date-box" :key="index" v-if="i>=16" :class="{light:dayData.today==i}">
            <p>{
   
   {formatte(i)}}</p>
            <i class="el-icon-circle-plus"></i>
          </div>
        </template>
      </div>
    </div>
  </div>
</template>

style

<style scoped lang="less">
.trip-manager{
  height: 100%;
  background: #ffffff;
  border-radius: 4px;
  position: relative;
  .options{
    padding: 20px 20px;
  }
  .container{
    width: 97%;
    margin: 0 20px;
   .day{
     display: flex;
     flex-direction: row;
     text-align: right;
     font-weight: 800;
     .day-box{
       height: 80px;
       margin: 0 5px 20px 0;
       border-bottom: 1px solid #efefef;
       width: calc((100% - 60px)/7);
       min-width: calc((100% - 60px)/7);
       max-width: calc((100% - 60px)/7);
       &:nth-child(7n){
         margin-right: 0;
       }
     }
   }
    .date{
      display: flex;
      justify-content: flex-start;
      align-content: center;
      flex-wrap: wrap;
      .date-box{
        position: relative;
        flex-shrink: 0;
        margin: 0 5px 20px 0;
        background: #efefef;
        height: 150px;
        border-bottom: 3px solid #B3C0D1;
        width: calc(100% - 60px)/7;
        min-width: calc((100% - 60px)/7);
        max-width: calc((100% - 60px)/7);
        &:nth-child(7n){
          margin-right: 0;
        }
        p:nth-child(1){
          text-align: right;
        }
        p{
          padding: 0 20px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }
        i{
          width: 20%;
          height: 20%;
          font-size: 50px;
          color: #606266;
          position: absolute;
          top: 0;
          left: 0;
          bottom: 0;
          right: 0;
          margin: auto;
        }
      }
      .light{
        border-bottom: 3px solid #7CB0FF !important;
      }
    }

  }
}
</style>

method implementation

<script>
export default {
  name: 'tripManager',
  data () {
    return {
      formData: {
        name: '',
        month: ''
      },
      options: [{ name: '张三', id: 1 }, { name: '李四', id: 2 }],
      dayOFweek: ['日', '一', '二', '三', '四', '五', '六'],
      dayData: {
        countDay: [], // 当月天数
        today: new Date().getDate(), // 当天
        firstDay: '' // 一周中的第几天
      }

    }
  },
  computed: {
    formatte () {
      return function (data) {
        if (data === 0) return
        if (data < 10) {
          data = '0' + data
        }
        return data
      }
    }
  },
  created () {
    this.getDayList(new Date())
  },
  methods: {
    // 获取日历列表相关信息
    getDayList (now) {
      const month = now.getMonth() + 1 // 当前月
      const year = now.getFullYear() // 当前年
      const data = new Date(year + '-' + month + '-' + 1) // 当月第一天日期
      this.dayData.firstDay = this.dayOFweek[data.getDay()] // 当月第一天是星期几
      const days = new Date(year, month, 0).getDate() // 当月总天数
      this.formData.month = year + '-' + month // 设置日期选择默认年-月
      const times = this.dayOFweek.indexOf(this.dayData.firstDay) // 当月第一天是星期几下标
      // 当月天数转存为数组
      for (let i = 1; i <= days; i++) {
        this.dayData.countDay.push(i)
      }
      for (let j = 0; j < times; j++) {
        this.dayData.countDay.unshift(0)
      }
      // console.log('data', this.dayData.countDay, times, this.dayData.firstDay)
    },
    changeDate (val) {
      this.dayData.countDay = []
      this.getDayList(new Date(val))
    }

  }
}
</script>

rendering effect

Guess you like

Origin blog.csdn.net/weixin_42835381/article/details/129797723