Skip to content

[calendar] 日历组件带有switchMode时不能正确加载日历视图 #3455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ITsPro-CN opened this issue Jan 15, 2025 · 5 comments · Fixed by #3457
Closed

[calendar] 日历组件带有switchMode时不能正确加载日历视图 #3455

ITsPro-CN opened this issue Jan 15, 2025 · 5 comments · Fixed by #3457
Labels
bug Something isn't working

Comments

@ITsPro-CN
Copy link

tdesign-miniprogram 版本

1.8.4

重现链接

No response

重现步骤

简单DEMO

<t-calendar switch-mode="month" minDate="{{minDate}}" maxDate="{{maxDate}}">

在页面加载完成后修改minDate或maxDate,且当天不在区间范围内。

由于calendar.js line 197 calcCurrentMonth方法中,在newValue为null时会使用this.getCurrentDate()作为当前的日期值,该方法默认值为当天,此时如果正好设置了minDate或maxDate,且当天不在区间范围内,line 204设置的currentMonth会是一个空数组,会导致日期试图无法正常加载:

Image

这个问题解决方法比较多,所以发个issue你们评估一下。一个可行的方法是在line 202后面判断一下是否空数组,如果是空数组的话用minDate刷新视图。

if (currentMonth.length === 0) {
	this.calcCurrentMonth(this.data.minDate)
	return
}

当然也可以修改getCurrentDate方法,增加一个判断value是否在minDate和maxDate之间的步骤,并对非法的value进行处理。就是不知道会不会对不设置switch-mode的时候产生影响。

期望结果

No response

实际结果

No response

基础库版本

No response

补充说明

No response

Copy link
Contributor

👋 @prprprPro,感谢给 TDesign 提出了 issue。
请根据 issue 模版确保背景信息的完善,我们将调查并尽快回复你。

@ITsPro-CN
Copy link
Author

上面这个代码会导致没设置minDate时死循环,修改一下:

if (!newValue && currentMonth.length === 0) return this.calcCurrentMonth(this.data.minDate || Date.now())

@anlyyao
Copy link
Collaborator

anlyyao commented Jan 16, 2025

@prprprPro 请问是什么场景才会出现 “在页面加载完成后修改 minDate 或 maxDate,且value不在区间范围内”?

@anlyyao
Copy link
Collaborator

anlyyao commented Jan 16, 2025

@prprprPro 我大概懂你的点了,就是 value 不在 [minDate, maxDate] 区间范围时,期望日历仍能正常显示。我处理一下吧、

@anlyyao anlyyao added the enhancement New feature or request label Jan 16, 2025
@anlyyao anlyyao added bug Something isn't working and removed enhancement New feature or request labels Jan 16, 2025
@ITsPro-CN
Copy link
Author

@prprprPro 我大概懂你的点了,就是 value 不在 [minDate, maxDate] 区间范围时,期望日历仍能正常显示。我处理一下吧、

对的,因为默认value是当天,不在[minDate, maxDate]区间的情况很常见。那几个方法看的我有点头大...不提PR了还是交给你吧哈哈哈

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants