fix: prevent cached task loading mask from sticking

bugfix/ai-assessment-evidence-rescore
陈沅 1 month ago
parent 3dfb390f22
commit 3f0493452b

@ -79,6 +79,8 @@ export function getTrainingTaskByKey(taskKey) {
return Promise.resolve({ code: 200, data: preview.taskConfig }); return Promise.resolve({ code: 200, data: preview.taskConfig });
} }
if (pendingTaskRequests.has(normalizedTaskKey)) { if (pendingTaskRequests.has(normalizedTaskKey)) {
// 页面切回时可能复用仍在进行的请求;重新通知当前路由显示加载状态。
notifyStudentTaskConfigLoading(normalizedTaskKey, true);
return pendingTaskRequests.get(normalizedTaskKey); return pendingTaskRequests.get(normalizedTaskKey);
} }
notifyStudentTaskConfigLoading(normalizedTaskKey, true); notifyStudentTaskConfigLoading(normalizedTaskKey, true);

@ -63,7 +63,9 @@ function handleStudentTaskConfigLoading(event) {
studentTaskLoading.value = Boolean(detail.loading); studentTaskLoading.value = Boolean(detail.loading);
} }
watch(currentStudentTaskKey, (taskKey) => { watch(currentStudentTaskKey, (taskKey) => {
studentTaskLoading.value = Boolean(taskKey); // 已缓存的实训页重新激活时不会再次执行 onMounted 请求,不能仅因路由
// 切换而保留遮罩;真实请求会通过 student-task-config-loading 事件重新打开。
studentTaskLoading.value = false;
}, { immediate: true }); }, { immediate: true });
onMounted(() => window.addEventListener("student-task-config-loading", handleStudentTaskConfigLoading)); onMounted(() => window.addEventListener("student-task-config-loading", handleStudentTaskConfigLoading));
onBeforeUnmount(() => window.removeEventListener("student-task-config-loading", handleStudentTaskConfigLoading)); onBeforeUnmount(() => window.removeEventListener("student-task-config-loading", handleStudentTaskConfigLoading));

@ -0,0 +1,23 @@
const assert = require("assert");
const fs = require("fs");
const path = require("path");
const root = path.join(__dirname, "..");
const appMain = fs.readFileSync(path.join(root, "src", "layout", "components", "AppMain.vue"), "utf8");
const trainingTaskApi = fs.readFileSync(path.join(root, "src", "api", "trainingTask.js"), "utf8");
assert(
appMain.includes("studentTaskLoading.value = false;"),
"切回已缓存的学生实训页时,旧加载遮罩必须先清除"
);
assert(
!appMain.includes("studentTaskLoading.value = Boolean(taskKey);"),
"路由切换不能在没有真实请求时强制显示实训加载遮罩"
);
assert.match(
trainingTaskApi,
/if \(pendingTaskRequests\.has\(normalizedTaskKey\)\) \{[\s\S]*?notifyStudentTaskConfigLoading\(normalizedTaskKey, true\);[\s\S]*?return pendingTaskRequests\.get\(normalizedTaskKey\);/,
"复用进行中的任务配置请求时,必须重新广播加载状态"
);
console.log("student task loading lifecycle static checks passed");
Loading…
Cancel
Save