0
点赞
收藏
分享

微信扫一扫

react+antdesign实现,日、周、月、季度的禁止选择某个日期、其他的都可以选择。

react+antdesign实现,日、周、月、季度的禁止选择某个日期、其他的都可以选择。_前端

代码:// 禁止选中日期的函数

  const disabledDate = (current) => {

    const monthEnd = dayjs().subtract(2, "day").endOf("month"); // 截止日期

    return (

      dayDisable.some((item) => {

        const currentDate = dayjs(current).format("YYYY-MM-DD");

        return dayjs(item).isSame(currentDate);

      }) || current >= monthEnd

    );

  };

  // 禁止选择的周日期

  const weekdisabledDate = (current) => {

    return dayDisable.some((item) => {

      return current >= dayjs(item) && current <= dayjs(item).endOf("week");

    });

  };

  // 禁止选择的月日期

  const monthdisabledDate = (current) => {

    return dayDisable.some((item) => {

      return current >= dayjs(item) && current <= dayjs(item).endOf("month");

    });

  };

  // 禁止选择的季度日期

  const quarterdisabledDate = (current) => {

    return dayDisable.some((item) => {

      return current >= dayjs(item) && current <= dayjs(item).endOf("quarter");

    });

  };

最终效果

react+antdesign实现,日、周、月、季度的禁止选择某个日期、其他的都可以选择。_antdesign_02


其他周、月、季度 只需要后端返回起始的日期就行,通过dayjs(‘2024-04-01’).endOf("month");来获取截至日期

react+antdesign实现,日、周、月、季度的禁止选择某个日期、其他的都可以选择。_react_03

举报

相关推荐

0 条评论