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(datepicker): "hour-minute"类型下,修改小时不刷新分钟列的选择范围 #2784

Merged
merged 6 commits into from
Jan 5, 2024
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 @@
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 @@
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]));

Check warning on line 251 in src/packages/__VUE/datepicker/index.vue

View check run for this annotation

Codecov / codecov/patch

src/packages/__VUE/datepicker/index.vue#L246-L251

Added lines #L246 - L251 were not covered by tests
}
state.currentDate = formatValue(date as Date);
}
Expand Down