Skip to content

Commit

Permalink
fix(date-picker): 修复 hour-minute 类型下选项刷新问题 (#2784)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robin-Wubin authored Jan 5, 2024
1 parent e8cb423 commit 48b1aa5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/packages/__VUE/datepicker/index.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export default create({
selectedValue: (string | number)[];
selectedOptions: PickerOption[];
}) => {
if (['date', 'datetime', 'datehour', 'month-day', 'year-month'].includes(props.type)) {
if (['date', 'datetime', 'datehour', 'month-day', 'year-month', 'hour-minute'].includes(props.type)) {
let formatDate: (number | string)[] = [];
selectedValue.forEach((item) => {
formatDate.push(item);
Expand All @@ -243,6 +243,12 @@ export default create({
date = new Date(year, month, day, Number(formatDate[3]), Number(formatDate[4]));
} else if (props.type === 'datehour') {
date = new Date(year, month, day, Number(formatDate[3]));
} else if (props.type === 'hour-minute') {
date = new Date(state.currentDate);
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate();
date = new Date(year, month, day, Number(formatDate[0]), Number(formatDate[1]));
}
state.currentDate = formatValue(date as Date);
}
Expand Down
8 changes: 7 additions & 1 deletion src/packages/__VUE/datepicker/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export default create({
selectedValue: (string | number)[];
selectedOptions: PickerOption[];
}) => {
if (['date', 'datetime', 'datehour', 'month-day', 'year-month'].includes(props.type)) {
if (['date', 'datetime', 'datehour', 'month-day', 'year-month', 'hour-minute'].includes(props.type)) {
let formatDate: (number | string)[] = [];
selectedValue.forEach((item) => {
formatDate.push(item);
Expand All @@ -243,6 +243,12 @@ export default create({
date = new Date(year, month, day, Number(formatDate[3]), Number(formatDate[4]));
} else if (props.type === 'datehour') {
date = new Date(year, month, day, Number(formatDate[3]));
} else if (props.type === 'hour-minute') {
date = new Date(state.currentDate);
const year = date.getFullYear();
const month = date.getMonth();
const day = date.getDate();
date = new Date(year, month, day, Number(formatDate[0]), Number(formatDate[1]));
}
state.currentDate = formatValue(date as Date);
}
Expand Down

0 comments on commit 48b1aa5

Please sign in to comment.