Skip to content
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

fix(Calendar): set current date is inital #4339

Merged
merged 2 commits into from
Jul 16, 2021

Conversation

nemo-shen
Copy link
Collaborator

#4288

和vant getInitialDate 相同逻辑

maxDate: number | null = null
) {
minDate = minDate || (this.data.minDate as number);
maxDate = maxDate || (this.data.maxDate as number);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我看 props 里 minDate 是 Date 类型,而这里是 number 类型,中间有转换吗

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

小程序不支持在props中定义 Date 类型,原先的方式也是 number 类型,改动后也是在最后通过 getTime 后获取时间戳处理,可以看下最开始的两个初始化方法

  • 这里以前的考虑应该是采用了 number 类型
  • 这里在 props 中 type = null 的考虑猜测可能为了后续支持 Date 类型方便(如果微信官方增加这个新特性的话)
  • 实际上内部都是通过 number 处理
  • 这里的类型还关联到 fix: 修改min-date和max-date的传值校验 problem #4258 #4333 这个PR,他在解决用户可能传入一个 空字符串 进来的问题
  • (min|max)Date其实按照现在的做法来看是有可能超出预期的,但是在这里没做过多的兜底,因为 (min|max)Date已经有默认值了,所以这里直接 as number
  • 在vant里面就比较方便,因为不需要定义类型为 null 所以类型很明确成了 Date

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

soga~ 了解了

@chenjiahan chenjiahan merged commit 82811d4 into youzan:dev Jul 16, 2021
@chenjiahan
Copy link
Member

👏👏

@nemo-shen nemo-shen deleted the hotfix/calendar_default-date_0714 branch July 16, 2021 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants