NG-ZORRO / ng-zorro-antd

Angular UI Component Library based on Ant Design
https://ng.ant.design
MIT License
8.86k stars 3.91k forks source link

使用nz-datepicker 组合成 range,使用nzDisabledDate,显示可以点击,但点击无效 #6709

Closed yy7054wyq5 closed 3 years ago

yy7054wyq5 commented 3 years ago

Reproduction link

https://stackblitz.com/edit/angular-jqekil?file=src/app/app.component.ts

Steps to reproduce

  1. 点击链接里的选择"按周",
  2. 选中一个开始日期
  3. 在结束日期的datepicker中,无法选中未禁用的最后一天。 截屏2021-05-21 上午10 28 13

What is expected?

选中未禁用的最后一天。

What is actually happening?

无法选中未禁用的最后一天。

Environment Info
ng-zorro-antd 11.4.1
Browser 版本 90.0.4430.212(正式版本) (x86_64),mac
wenqi73 commented 3 years ago
yy7054wyq5 commented 3 years ago
  • 升到 11.4.2
  • 在日期面板中用来判断是否可点击的时间是当天的00:00:00点;而点击后时间则变为当前时间,如16:10:00,这时候用 getTime() 会不准。你的例子中应该剔除掉 time 仅用 date 来判断
 disabledEndDate = (endValue: Date): boolean => {
    if (!endValue || !this.startValue) {
      return false;
    }
    let range = Infinity;
    switch (this.range) {
      case 'week':
        const ymd = format(addWeeks(this.startValue, 1), 'yyyy-MM-dd');
        range = new Date(ymd + ' 23:59:59').getTime();
        break;
      default:
        break;
    }
    return (
      endValue.getTime() <= this.startValue.getTime() ||
      endValue.getTime() > range
    );
  };

我采用的是这种方式,也是可行的。感谢。

galaxynova1999 commented 3 years ago

要进行比较的两个时间使用moment(date).endOf('days')处理一下也是可以的