ant design vue 日期选择器设置日期范围限制(时间限制范围 开始时间~结束时间不能超过一个月,且禁选超过当前日期时间)


computed: {
    getStartDate () {
      let resultDate, year, month, date
      let currDate = new Date()
      year = currDate.getFullYear()
      month = currDate.getMonth() + 1
      date = currDate.getDate()
      switch (month) {
        case 1:
          month += 11
          year--
          break
        default:
          month -= 1
          break
      }
      month = (month < 10) ? ('0' + month) : month
      date = (date < 10) ? ('0' + date) : date
      resultDate = `${year}-${month}-${date} 00:00:00`
      return resultDate
    },
    getEndDate () {
      let resultDate, year, month, date
      let currDate = new Date()
      year = currDate.getFullYear()
      month = currDate.getMonth() + 1
      date = currDate.getDate()
      month = (month < 10) ? ('0' + month) : month
      date = (date < 10) ? ('0' + date) : date
      resultDate = `${year}-${month}-${date} 00:00:00`
      return resultDate
    }
  },
moment,
    /**
    * 清空禁用时间段的设置
    */
    onOpenChange (status) {
      // 清空禁用时间段的设置
      this.disabledCurrent = null
    },
    /**
    * 获取手动选择的时间段起始值
    */
    onCalendarChange (dates) {
      // 获取手动选择的时间段起始值
      this.disabledCurrent = dates[0]
    },
    onChangeTimer (value, data) {
      this.dataList.forEach((item, i) => {
        if (item.name === data) {
          item.value = value
        }
      })
    },
    /**
    * 1、时间限制范围 开始时间~结束时间不能超过一个月,且禁选超过当前日期时间
    */
    disabledDate (current) {
      if (!this.disabledCurrent) return current > moment()
      return (current && current < moment(this.disabledCurrent).subtract(1, 'M').startOf('day')) || current > moment(this.disabledCurrent).add(1, 'M').endOf('day') || current > moment()
    },

你可能感兴趣的:(ant design vue 日期选择器设置日期范围限制(时间限制范围 开始时间~结束时间不能超过一个月,且禁选超过当前日期时间))