Repository: youzan/vant (TypeScript)

Issue:
[Bug Report] Title van-calendar 日历控件切换问题
### Reproduction Link

https://vant-ui.github.io/vant/#/zh-CN/calendar

### Vant Version

4.9.1

### Describe the Bug

平铺模式下，switch-mode=“month” 的情况下，当设置了min-date 时，切换月份的时候，无法切回当前月份。

### Reproduce Steps

设置min-date为7月5日， 把月份切换到8月份，控件则无法切回7月份

### Device / Browser

_No response_


Discussion:
Hello @Romio-L. Please provide an online reproduction demo by [codesandbox](https://codesandbox.io/p/devbox/vant-4-issue-template-8fuq5o) or a minimal GitHub repository. Issues marked with `need reproduce` will be closed if there is no activity within 3 days. For background, please refer to [Why reproductions are required](https://antfu.me/posts/why-reproductions-are-required).

你好 @Romio-L, 我们需要你提供一个在线的重现示例，以便于我们帮你排查问题。你可以通过点击 [codesandbox](https://codesandbox.io/p/devbox/vant-4-issue-template-8fuq5o) 创建，或者提供一个最小化的 GitHub 仓库。如果 3 天内未跟进，此 issue 将会被自动关闭。背景请参考 [为什么需要最小重现](https://antfu.me/posts/why-reproductions-are-required-zh)。
As the issue was labeled with `need reproduce`, but no response in 3 days. This issue will be closed. Feel free to comment and reopen it if you have any further questions. For background, please refer to [Why reproductions are required](https://antfu.me/posts/why-reproductions-are-required).

由于该 issue 被标记为 "需要重现"，但在 3 天内没有回应，因此该 issue 将被关闭。如果你有任何进一步的问题，请随时发表评论并重新打开该 issue。背景请参考 [为什么需要最小重现](https://antfu.me/posts/why-reproductions-are-required-zh)。
https://github.com/Romio-L/vant-calendar-demo

这是一个Vant Calendar 月份切换 BUG 的演示代码工程
> https://github.com/Romio-L/vant-calendar-demo
> 
> 这是一个Vant Calendar 月份切换 BUG 的演示代码工程

嗯，感谢反馈，后续会修复这个问题
设置max-date后，当选择day 大于max-date设置的day时，也会出现无法切换回max-date的月份

**重现链接**
https://codesandbox.io/p/devbox/vant-4-issue-template-forked-ct5z3c?file=%2Fsrc%2FApp.vue%3A23%2C21&workspaceId=6205d4c6-c28c-490e-b9e1-d04f0ad54b58

**描述**
max-date设置的（2024,6,20）
![20240716171227_rec_](https://github.com/user-attachments/assets/492fac1b-0c4b-4427-9e12-6199b7a83a40)

**步骤**
1.选择某月大于20号的日期
2.重新打开日历，发现无法再切换到7月
> 设置max-date后，当选择day 大于max-date设置的day时，也会出现无法切换回max-date的月份
> 
> **重现链接** https://codesandbox.io/p/devbox/vant-4-issue-template-forked-ct5z3c?file=%2Fsrc%2FApp.vue%3A23%2C21&workspaceId=6205d4c6-c28c-490e-b9e1-d04f0ad54b58
> 
> **描述** max-date设置的（2024,6,20） ![20240716171227_rec_](https://private-user-images.githubusercontent.com/87625509/349020438-492fac1b-0c4b-4427-9e12-6199b7a83a40.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjExMjg1MzYsIm5iZiI6MTcyMTEyODIzNiwicGF0aCI6Ii84NzYyNTUwOS8zNDkwMjA0MzgtNDkyZmFjMWItMGM0Yi00NDI3LTllMTItNjE5OWI3YTgzYTQwLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE2VDExMTAzNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFkOTEwMzM3MjUwZGUxNzZmMWJkMjc2NzU0NDFiMmYyYmQ2MjU5YzIzODMyNGI2OWUyNGQ1ODQ2YjI2MTI4ZTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.SH6E677RMJgpWMiLsr78mvGYqblLcYIwY06iBRZHOg4) [ ![20240716171227_rec_](https://private-user-images.githubusercontent.com/87625509/349020438-492fac1b-0c4b-4427-9e12-6199b7a83a40.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjExMjg1MzYsIm5iZiI6MTcyMTEyODIzNiwicGF0aCI6Ii84NzYyNTUwOS8zNDkwMjA0MzgtNDkyZmFjMWItMGM0Yi00NDI3LTllMTItNjE5OWI3YTgzYTQwLmdpZj9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA3MTYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwNzE2VDExMTAzNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFkOTEwMzM3MjUwZGUxNzZmMWJkMjc2NzU0NDFiMmYyYmQ2MjU5YzIzODMyNGI2OWUyNGQ1ODQ2YjI2MTI4ZTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.SH6E677RMJgpWMiLsr78mvGYqblLcYIwY06iBRZHOg4) ](https://private-user-images.githubusercontent.com/87625509/349020438-492fac1b-0c4b-4427-9e12-6199b7a83a40.gif?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjExMjg1MzYsIm5iZiI6MTcyMTEyODIzNiwicGF0aCI6Ii84NzYyNTUwOS8zNDkwMjA0MzgtNDkyZmFjMWItMGM0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c2NzU0NDFiMmYyYmQ2MjU5YzIzODMyNGI2OWUyNGQ1ODQ2YjI2MTI4ZTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.SH6E677RMJgpWMiLsr78mvGYqblLcYIwY06iBRZHOg4)
> 
> **步骤** 1.选择某月大于20号的日期 2.重新打开日历，发现无法再切换到7月

嗯，同一个原因导致的
请问修复了吗



Patch:
diff --git a/packages/vant/src/calendar/CalendarHeader.tsx b/packages/vant/src/calendar/CalendarHeader.tsx
index 7f536398647..6adae946f39 100644
--- a/packages/vant/src/calendar/CalendarHeader.tsx
+++ b/packages/vant/src/calendar/CalendarHeader.tsx
@@ -5,6 +5,7 @@ import { createNamespace, HAPTICS_FEEDBACK, makeStringProp } from '../utils';
 import {
   t,
   bem,
+  compareMonth,
   getPrevMonth,
   getPrevYear,
   getNextMonth,
@@ -39,22 +40,22 @@ export default defineComponent({
   setup(props, { slots, emit }) {
     const prevMonthDisabled = computed(() => {
       const prevMonth = getPrevMonth(props.date!);
-      return props.minDate && prevMonth < props.minDate;
+      return props.minDate && compareMonth(prevMonth, props.minDate) < 0;
     });
 
     const prevYearDisabled = computed(() => {
       const prevYear = getPrevYear(props.date!);
-      return props.minDate && prevYear < props.minDate;
+      return props.minDate && compareMonth(prevYear, props.minDate) < 0;
     });
 
     const nextMonthDisabled = computed(() => {
       const nextMonth = getNextMonth(props.date!);
-      return props.maxDate && nextMonth > props.maxDate;
+      return props.maxDate && compareMonth(nextMonth, props.maxDate) > 0;
     });
 
     const nextYearDisabled = computed(() => {
       const nextYear = getNextYear(props.date!);
-      return props.maxDate && nextYear > props.maxDate;
+      return props.maxDate && compareMonth(nextYear, props.maxDate) > 0;
     });
 
     const renderTitle = () => {


Test patch:
diff --git a/packages/vant/src/calendar/test/switch-mode.spec.ts b/packages/vant/src/calendar/test/switch-mode.spec.ts
index a3267971aa1..8241e1b301d 100644
--- a/packages/vant/src/calendar/test/switch-mode.spec.ts
+++ b/packages/vant/src/calendar/test/switch-mode.spec.ts
@@ -62,6 +62,29 @@ test('disable previous and next month buttons', async () => {
   expect(nextMonth.classes()).not.toContain(disabledActionClass);
 });
 
+test('disable the previous month button correctly when the minDate is the current time', async () => {
+  const wrapper = mount(Calendar, {
+    props: {
+      minDate: new Date(),
+      poppable: false,
+      switchMode: 'month',
+    },
+  });
+
+  await later();
+  const [prevMonth, nextMonth] = wrapper.findAll(
+    '.van-calendar__header-action',
+  );
+
+  expect(prevMonth.classes()).toContain(disabledActionClass);
+
+  await nextMonth.trigger('click');
+  expect(prevMonth.classes()).not.toContain(disabledActionClass);
+
+  await prevMonth.trigger('click');
+  expect(prevMonth.classes()).toContain(disabledActionClass);
+});
+
 test('disable previous and next year buttons', async () => {
   const maxDate = getNextYear(minDate);
   const wrapper = mount(Calendar, {