jd-opensource / jd-opensource/taro-ui

日历多选设置currentDate,初始日期相同不会二次跳转

Open
#1,149 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.7k
Forks
740
PR merge metrics
No merged PRs in 30d

Description

**问题描述**
二次跳转currentDate,初始日期相同时不生效

**复现步骤**
日历设置多选true,选择25号到26号区间,,然后设置currentDate跳转到25号。第一次可以成功,重复第二次以上会导致失败。

```js
// 选择日期
selectCalendar(isMultiSelect, e) {
const { dispatchSelectDate, dispatchSetStateData, bookDay } = this.props.skuOptions;
if (isMultiSelect) { // 多选
const status = this.computeDateLong(e.value)
if (status.isMoreThanBookDay) { // 选择的日期大于起订晚数
this.selectMultipleDate(e)
} else {
if (e.value.end) {
Taro.showToast({
title: `该酒店${bookDay}晚起订,请重新选择`,
icon: 'none'
})
dispatchSetStateData({
selectedDate: { start: e.value.start, end: e.value.start }, // currentDate跳转至初始日期
chooseDates: 0
})
}
}
} else {
dispatchSelectDate(e)
}
}
```

**期望行为**
多次选择范围区间,初始日期相同时依旧可以正确跳转currentDate

**报错信息**

**系统信息**

Taro v1.2.26

Taro CLI 1.2.26 environment info:
System:
OS: Windows 10
Binaries:
Node: 10.15.3 - C:\Program Files\nodejs\node.EXE
Yarn: 1.16.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD

**补充信息**
taro-ui 中对相同日期进行了处理,导致不更新
```
componentWillReceiveProps (nextProps: Props) {
const { currentDate, isMultiSelect } = nextProps
if (!currentDate || currentDate === this.props.currentDate) return

if (isMultiSelect && this.props.isMultiSelect) {
const { start, end } = currentDate as Calendar.SelectedDate
const { start: preStart, end: preEnd } = this.props
.currentDate as Calendar.SelectedDate

if (start === preStart && preEnd === end) {
return
}
}

const stateValue: State = this.getInitializeState(
currentDate,
isMultiSelect
)

this.setState(stateValue)
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.