vue日历组件vue-calendar-component的使用介绍

vue-calendar-component的GitHub介绍
使用效果:根据开始时间和结束时间,查询出当前时间前6个月的签到详情,日历控件中只能切换6个月的日历情况
效果图:
在这里插入图片描述
核心代码:

<template>
   <div class="calendar">
     <Calendar ref="Calendar" :markDate="markDate" @choseDay="clickDay" :agoDayHide="today" @changeMonth="changeMonth"></Calendar>
   </div>
</template>
<script>
import Calendar from '@/components/calendar/calendar.vue'
  export default {
    data() {
      return {
        markDate: [],
        signinList: [], // 签到日期列表
        today: Date.parse(new Date()).toString(),
        isSign: false,
      }
    },
    components: {
      Calendar
    },
    created() {
      this.queryIsSignIn();
      this.getSignIn()
    },
    methods: {
      getSignIn() { // 签到日历查询
        var that = this;
        var year = new Date().getFullYear()
        // var month = (new Date().getMonth() + 1) > 10 ? new Date().getMonth() + 1 : '0' + (new Date().getMonth() + 1)
        var month = new Date().getMonth() + 1
        if (month < 6) {
          month = (month + 7) > 10 ? (month + 7) : '0' + (month + 7)
          year = year - 1
        } else {
          month = (month - 5) > 10 ? (month - 5) : '0' + (month - 5)
        }
        var params = {
          studentid: that.$utils.CONFIG.user.data.student.id,
          starttime: year + '-' + month + '-01',
          endtime: that.$utils.moment(new Date()).format('YYYY-MM-DD'),
        }
        that.$utils.getJson(that.$utils.CONFIG.api.getSignIn, function (res) {
          if (res.succflag === 0) {
            that.signinList = res.data
            that.signinList.forEach(item => {
              that.markDate.push(that.$utils.moment(item.time).format('YYYY/MM/DD'))
            })
          }
        }, function () {}, params, false, {token: that.$utils.CONFIG.user.token});
      },
      clickDay (date) {
        console.log(date)
      },
      changeMonth (date) { // 已签到时日历
        var month = parseInt(date.split('/')[1])
        var year = new Date().getFullYear()
        var currentMoth = (new Date()).getMonth() + 1
        if (month === (currentMoth - 6) && currentMoth < 6) {
          currentMoth = (currentMoth + 7) > 10 ? (currentMoth + 7) : '0' + (currentMoth + 7)
          year = year - 1
          this.$refs.Calendar.ChoseMonth((year + '-' + currentMoth + '-01'), false)
        } else if (month === (currentMoth - 6) && currentMoth >= 6) {
          currentMoth = (currentMoth - 5) > 10 ? (currentMoth - 5) : '0' + (currentMoth - 5)
          this.$refs.Calendar.ChoseMonth((year + '-' + currentMoth + '-01'), false)
        } else if (month > currentMoth) {
          this.$refs.Calendar.ChoseMonth(this.$utils.moment(new Date()).format('YYYY-MM-DD'), false)
        }
      },
    }
  }
</script>
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值