fix: load matrix data on view switch, align matrix week to Mon-Sun
- Call triggerMatrixSearch() when switching from calendar to matrix view - Add datesSet early-return in matrix mode to prevent state overwrite - Add initial mount check for matrix mode - Align matrix week start to Monday (was Sunday) to match calendar view The matrix view was not loading data because triggerMatrixSearch was not called in setViewMode, and FullCalendar's datesSet callback was overwriting the state date range when switching views. Also the week started on Sunday vs the calendar's Monday, causing the two views to display different weeks. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -363,6 +363,10 @@ export default defineComponent({
|
||||
if (cachedViewMode === 'matrix' || cachedViewMode === 'calendar') {
|
||||
viewMode.value = cachedViewMode;
|
||||
}
|
||||
// 如果初始视图是矩阵,在组件挂载后加载矩阵视图数据
|
||||
if (viewMode.value === 'matrix') {
|
||||
nextTick(() => triggerMatrixSearch());
|
||||
}
|
||||
|
||||
const isLandscape = ref(false);
|
||||
|
||||
@@ -407,13 +411,15 @@ export default defineComponent({
|
||||
const matrixWeekStart = computed(() => {
|
||||
const d = new Date(matrixWeekCursor.value);
|
||||
const day = d.getDay();
|
||||
d.setDate(d.getDate() - day);
|
||||
const diff = day === 0 ? 6 : day - 1; // Monday as first day of week
|
||||
d.setDate(d.getDate() - diff);
|
||||
return formatDate(d, DateFormatter.Date);
|
||||
});
|
||||
const matrixWeekEnd = computed(() => {
|
||||
const d = new Date(matrixWeekCursor.value);
|
||||
const day = d.getDay();
|
||||
d.setDate(d.getDate() + (6 - day));
|
||||
const diff = day === 0 ? 6 : day - 1; // Monday as first day of week
|
||||
d.setDate(d.getDate() + (6 - diff));
|
||||
return formatDate(d, DateFormatter.Date);
|
||||
});
|
||||
const matrixWeekRange = computed(() => `${matrixWeekStart.value} ~ ${matrixWeekEnd.value}`);
|
||||
@@ -468,6 +474,9 @@ export default defineComponent({
|
||||
isLandscape.value = false;
|
||||
}
|
||||
setKey('clazz_view_mode', mode);
|
||||
if (mode === 'matrix') {
|
||||
triggerMatrixSearch();
|
||||
}
|
||||
updateCalendarSize();
|
||||
};
|
||||
|
||||
@@ -797,6 +806,8 @@ export default defineComponent({
|
||||
view(event.id)
|
||||
},
|
||||
datesSet: function({start, end}) {
|
||||
// 矩阵视图有自己的日期范围和数据加载逻辑
|
||||
if (viewMode.value === 'matrix') return;
|
||||
if (store.hanging) {
|
||||
store.hanging = false;
|
||||
let {state: cachedState} = getKey('clazz_state');
|
||||
|
||||
Reference in New Issue
Block a user