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
    };
   }
相关推荐
Net蚂蚁代码1 小时前
Angular入门的环境准备步骤工作
前端·javascript·angular.js
小阮的学习笔记2 小时前
electron实现加载页(启动页)
vue.js·electron
小着3 小时前
vue项目页面最底部出现乱码
前端·javascript·vue.js·前端框架
lichenyang4536 小时前
React ajax中的跨域以及代理服务器
前端·react.js·ajax
呆呆的小草6 小时前
Cesium距离测量、角度测量、面积测量
开发语言·前端·javascript
WHOAMI_老猫6 小时前
xss注入遇到转义,html编码绕过了解一哈
javascript·web安全·渗透测试·xss·漏洞原理
一 乐7 小时前
民宿|基于java的民宿推荐系统(源码+数据库+文档)
java·前端·数据库·vue.js·论文·源码
testleaf8 小时前
前端面经整理【1】
前端·面试
BillKu8 小时前
Vue3 + TypeScript + Element Plus 表格行按钮不触发 row-click 事件、不触发勾选行,只执行按钮的 click 事件
vue.js·elementui·typescript
好了来看下一题8 小时前
使用 React+Vite+Electron 搭建桌面应用
前端·react.js·electron