hookehuyr

fix(检查页面): 修复日期选择和加载逻辑问题

修复初始化时日期选择逻辑错误,优化日期参数传递方式
添加状态变量跟踪用户是否主动选择日期
确保页面刷新和导航时正确加载数据
<!--
* @Date: 2025-05-29 15:34:17
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2026-01-18 22:09:36
* @LastEditTime: 2026-01-21 15:30:00
* @FilePath: /mlaj/src/views/checkin/IndexCheckInPage.vue
* @Description: 文件描述
-->
......@@ -332,12 +332,22 @@ const formatter = (day) => {
// 添加一个响应式变量来存储当前选中的日期
const selectedDate = ref(new Date());
const hasUserSelectedDate = ref(!!route.query.date)
const isInitializing = ref(true)
const onSelectDay = (day) => {
const currentSelectedDate = dayjs(day).format('YYYY-MM-DD');
if (isInitializing.value && !hasUserSelectedDate.value) {
selectedDate.value = currentSelectedDate;
return;
}
getTaskDetail(dayjs(day).format('YYYY-MM'));
// 更新当前选中的日期
const currentSelectedDate = dayjs(day).format('YYYY-MM-DD');
selectedDate.value = currentSelectedDate;
hasUserSelectedDate.value = true;
// 修改浏览器地址把当前的date加入地址栏, 页面不刷新
// 使用replace替代push,避免在浏览器历史记录中添加多个条目
......@@ -353,7 +363,7 @@ const onSelectDay = (day) => {
checkinDataList.value = []
finished.value = false
// 重新加载数据
onLoad(currentSelectedDate)
onLoad(currentSelectedDate, true)
}
const onClickSubtitle = (evt) => {
......@@ -384,7 +394,7 @@ const onSelectCourse = (course) => {
checkinDataList.value = []
finished.value = false
// 重新加载数据
onLoad(dayjs(selectedDate.value).format('YYYY-MM-DD'))
onLoad(route.query.date, hasUserSelectedDate.value)
}
/**
......@@ -597,17 +607,21 @@ const finished = ref(false)
const limit = ref(3)
const page = ref(0)
const onLoad = async (date) => {
const onLoad = async (date, isUserInitiated) => {
const nextPage = page.value;
const current_date = date || route.query.date || dayjs().format('YYYY-MM-DD');
//
const res = await getUploadTaskListAPI({
const current_date = date || route.query.date;
const shouldPassDate = typeof isUserInitiated === 'boolean' ? isUserInitiated : hasUserSelectedDate.value
const params = {
limit: limit.value,
page: nextPage,
task_id: route.query.id,
subtask_id: selectedSubtaskId.value,
date: current_date
});
};
if (current_date && shouldPassDate) {
params.date = current_date;
}
const res = await getUploadTaskListAPI(params);
if (res.code === 1) {
// 整理数据结构
const newItems = formatData(res.data);
......@@ -635,6 +649,7 @@ const initPage = async (date) => {
selectedSubtaskId.value = '';
const current_date = date || route.query.date;
hasUserSelectedDate.value = !!current_date;
if (current_date) {
selectedDate.value = new Date(current_date);
await getTaskDetail(dayjs(current_date).format('YYYY-MM'));
......@@ -642,7 +657,7 @@ const initPage = async (date) => {
nextTick(() => {
calendarRef.value?.reset(new Date(current_date));
})
onLoad(current_date);
onLoad(current_date, true);
} else {
selectedDate.value = new Date();
await getTaskDetail(dayjs().format('YYYY-MM'));
......@@ -650,7 +665,7 @@ const initPage = async (date) => {
nextTick(() => {
calendarRef.value?.reset(new Date());
})
onLoad(dayjs().format('YYYY-MM-DD'));
onLoad(null, false);
}
}
......@@ -658,6 +673,9 @@ onMounted(async () => {
// 记录当前的taskId
lastTaskId.value = route.query.id;
await initPage(route.query.date);
nextTick(() => {
isInitializing.value = false;
})
// 获取作品类型数据
try {
......@@ -753,13 +771,13 @@ onDeactivated(() => {
})
const refresh_checkin_list = async () => {
const current_date = route.query.date || dayjs().format('YYYY-MM-DD')
const current_date = route.query.date
checkinDataList.value = []
page.value = 0
finished.value = false
loading.value = true
await getTaskDetail(dayjs(current_date).format('YYYY-MM'))
await onLoad(current_date)
await getTaskDetail(dayjs(current_date || dayjs()).format('YYYY-MM'))
await onLoad(current_date, hasUserSelectedDate.value)
}
onActivated(async () => {
......