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): optimize date range picker panel initial render result #4879

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/date-picker/DateRangePickerPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { defineComponent, computed, ref } from 'vue';
import { defineComponent, computed, ref, onMounted } from 'vue';
import dayjs from 'dayjs';
import isFunction from 'lodash/isFunction';
import isArray from 'lodash/isArray';
Expand Down Expand Up @@ -56,6 +56,22 @@ export default defineComponent({
const hoverValue = ref([]);
const activeIndex = computed(() => (isFirstValueSelected.value ? 1 : 0));

onMounted(() => {
if (value.value.length === 2 && !props.enableTimePicker) {
// 确保右侧面板月份比左侧大 避免两侧面板月份一致
const nextMonth = value.value.map((v: string) => parseToDayjs(v, formatRef.value.format).month());
year.value = value.value.map((v: string) => parseToDayjs(v, formatRef.value.valueType).year());
if (year.value[0] === year.value[1] && nextMonth[0] === nextMonth[1]) {
nextMonth[0] === 11 ? (nextMonth[0] -= 1) : (nextMonth[1] += 1);
}
month.value = nextMonth;
// 月份季度选择时需要确保右侧面板年份比左侧大
if (['month', 'quarter'].includes(props.mode) && year.value[0] === year.value[1]) {
year.value = [year.value[0], year.value[0] + 1];
}
}
});

// 日期 hover
function onCellMouseEnter(date: Date) {
isHoverCell.value = true;
Expand Down
Loading