fix: 修复课程运行时初始化与拖拽测试

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
zhongyidianandClaude Opus 4.8 committed 2026-08-27 10:35:17 +08:00
1 parent d77281ff0d
commit 1e02c7835e
6 files changed
+173 -154

No files matched your search

+41 -4
View File
@@ -40,6 +40,45 @@ function warnVideoAjaxUnavailable(description: string) {
});
}
/**
* 从 URL 参数初始化易班会话状态
* 在 React 渲染前调用,确保页面首次读取进度时 courseId / userId 已写入 store
*/
export function initializeYibanSession() {
const params = new URLSearchParams(window.location.search);
const courseId = params.get("courseId") ?? params.get("courseid");
const uid = params.get("uid");
const forceYiban = params.get("yiban") === "1";
const hasYibanParams = !!(courseId || uid);
const hasVideoAjax = isVideoAjaxAvailable();
const isYibanEnv = import.meta.env.DEV
? hasYibanParams && forceYiban
: hasYibanParams;
const storageMode = isYibanEnv && hasVideoAjax ? "yiban" : "session";
const userStore = useUserStore.getState();
userStore.setYibanConnectionStatus(
storageMode === "yiban" ? "connected" : "disconnected",
);
if (courseId) userStore.setCourseId(courseId);
if (uid) userStore.setUserInfo({ userId: uid });
console.info(
storageMode === "yiban"
? "[yiban] initialized"
: "[yiban] use session storage fallback",
{
courseId,
uid,
isDev: import.meta.env.DEV,
forceYiban,
hasYibanParams,
hasVideoAjax,
storageMode,
},
);
}
/**
* 获取 VideoAjax 实例
*/
@@ -228,10 +267,7 @@ export async function getUserStorage(
if (backend === "session") {
const itemValue = sessionStorage.getItem(getStorageKey(lessonId, key));
return itemValue === undefined ||
itemValue === null ||
itemValue === "null" ||
itemValue === ""
return itemValue === null || itemValue === "null" || itemValue === ""
? { status: "empty", content: "" }
: { status: "success", content: itemValue };
}
@@ -466,6 +502,7 @@ export async function saveUserAnswer(params: {
return false;
}
// 易班 API 以 getUserAnswer 写入答题记录,方法名与「保存」语义相反,属平台既有命名
const result = await yibanStatusRequest<unknown>({
method: (callback) =>
getVideoAjax().getUserAnswer(