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
    };
   }
相关推荐
行走的陀螺仪1 小时前
uni-app + Vue3编辑页/新增页面给列表页传参
前端·vue.js·uni-app
摘星编程2 小时前
React Native + OpenHarmony:Spinner旋转加载器
javascript·react native·react.js
We་ct2 小时前
LeetCode 205. 同构字符串:解题思路+代码优化全解析
前端·算法·leetcode·typescript
2301_812731413 小时前
CSS3笔记
前端·笔记·css3
ziblog3 小时前
CSS3白云飘动动画特效
前端·css·css3
越努力越幸运5083 小时前
CSS3学习之网格布局grid
前端·学习·css3
半斤鸡胗3 小时前
css3基础
前端·css
ziblog3 小时前
CSS3创意精美页面过渡动画效果
前端·css·css3
akangznl3 小时前
第四章 初识css3
前端·css·css3·html5
会豪3 小时前
深入理解 CSS3 滤镜(filter):从基础到实战进阶
前端·css·css3