vue antdesign 时间选择限制到此刻以及此刻之后

455 阅读1分钟
              <a-date-picker
                format="YYYY-MM-DD HH:mm:ss"
                :disabled-date="disabledDate"
                :disabled-time="disabledDateTime"
                :show-time="{ defaultValue: moment('00:00:00', 'HH:mm:ss') }"
                v-model="tsOrder.appDate"
                placeholder="请输入申请日期"
              />
  //==============================================
  disabledDate(current) {
        const strSelect = current.format('YYYY-MM-DD') + ' 00:00:00',
          strThis = moment().format('YYYY-MM-DD') + ' 00:00:00';
        return moment(strSelect).valueOf() < moment(strThis).valueOf()
      },
      //此刻以及此刻之后可选
      disabledDateTime(current) {
        if (current) {
          let today = moment().date();
          if (today == current.date()) {
            const thisHour = Number(moment().hour()),
              thisMinute = Number(moment().minutes()),
              thisSecond = Number(moment().seconds()),
              selectHour = Number(current.hour()),
              selectMinute = Number(current.minutes()),
              selectSecond = Number(current.seconds());
            let endHour = 0,
              endMinute = 0,
              endSecond = 0;
            console.log('当前时间', thisHour, thisMinute, thisSecond)
            console.log('选中时间', selectHour, selectMinute, selectSecond)
            endHour = thisHour;
            endMinute = thisMinute;
            endSecond = thisSecond;
            if ((selectHour - thisHour) > 0) {
              endMinute = 0;
              endSecond = 0;
            }
            if ((selectMinute - thisMinute) > 0) {
              endSecond = 0;
            }
            console.log('最终准备数据', endHour, endMinute, endSecond)
            return {
              disabledHours: () => this.range(0, endHour),
              disabledMinutes: () => this.range(0, endMinute),
              disabledSeconds: () => this.range(0, endSecond)
            }
          } else {
            return {
              disabledHours: () => [],
              disabledMinutes: () => [],
              disabledSeconds: () => []
            }
          }
        }
      },
      range(start, end) {
        const result = [];
        for (let i = start; i < end; i++) {
          result.push(i);
        }
        return result;
      },