antd vue a-range-picker如何设置不能选择当前和之后的时间,包含时分秒

html 复制代码
<a-range-picker
              v-model:value="formState.reqTime"
              show-time
              format="YYYY-MM-DD HH:mm:ss"
              :disabledDate="disabledDate"
              :disabledTime="disabledTime"
              :placeholder="['开始时间', '结束时间']"
              style="width: 382px"
              separator="-"
            >
            </a-range-picker>
javascript 复制代码
import dayjs from 'dayjs';
setup() {
 const disabledDate = current => {
      return current && current > dayjs().endOf('day');
    };
    const range = (start, end) => {
      const result = [];
      for (let i = start; i < end; i++) {
        result.push(i);
      }
      return result;
    };
    function disabledTime(dates, partial) {
      const hours = dayjs().hour();
      const minutes = dayjs().minute();
      const seconds = dayjs().second();
      if (!dates) {
        dates = dayjs();
      }
      if (partial == 'start') {
        if (dates[0] && dayjs(dates[0]).date() === dayjs().date()) {
          if (dayjs(dates[0]).hour() === dayjs().hour()) {
            return {
              disabledHours: () => range(hours + 1, 24),
              disabledMinutes: () => range(minutes + 1, 60),
              disabledSeconds: () => range(seconds + 1, 60)
            };
          } else {
            return {
              disabledHours: () => range(hours, 24),
              disabledMinutes: () => [],
              disabledSeconds: () => []
            };
          }
        } else {
          return {
            disabledHours: () => [],
            disabledMinutes: () => [],
            disabledSeconds: () => []
          };
        }
      } else if (partial == 'end') {
        if (dates[1] && dayjs(dates[1]).date() === dayjs().date()) {
          if (dayjs(dates[1]).hour() === dayjs().hour()) {
            return {
              disabledHours: () => range(hours + 1, 24),
              disabledMinutes: () => range(minutes + 1, 60),
              disabledSeconds: () => range(seconds + 1, 60)
            };
          } else {
            return {
              disabledHours: () => range(hours, 24),
              disabledMinutes: () => [],
              disabledSeconds: () => []
            };
          }
        } else {
          return {
            disabledHours: () => [],
            disabledMinutes: () => [],
            disabledSeconds: () => []
          };
        }
      }
    }
    return {
      disabledDate,
      disabledTime
    };
   }
相关推荐
中微子42 分钟前
React状态管理最佳实践
前端
烛阴1 小时前
void 0 的奥秘:解锁 JavaScript 中 undefined 的正确打开方式
前端·javascript
中微子1 小时前
JavaScript 事件与 React 合成事件完全指南:从入门到精通
前端
Hexene...1 小时前
【前端Vue】如何实现echarts图表根据父元素宽度自适应大小
前端·vue.js·echarts
初遇你时动了情1 小时前
腾讯地图 vue3 使用 封装 地图组件
javascript·vue.js·腾讯地图
dssxyz1 小时前
uniapp打包微信小程序主包过大问题_uniapp 微信小程序时主包太大和vendor.js过大
javascript·微信小程序·uni-app
华子w9089258591 小时前
基于 SpringBoot+VueJS 的农产品研究报告管理系统设计与实现
vue.js·spring boot·后端
天天扭码2 小时前
《很全面的前端面试题》——HTML篇
前端·面试·html
xw52 小时前
我犯了错,我于是为我的uni-app项目引入环境标志
前端·uni-app
!win !2 小时前
被老板怼后,我为uni-app项目引入环境标志
前端·小程序·uni-app