From a87707e85fda43d7e09f984074ec408ca32a52b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=B2=85?= <907037276@qq.com> Date: Sat, 5 Sep 2026 14:39:58 +0800 Subject: [PATCH] fix: open student demo through hash route --- src/views/studentDemo/index.vue | 2 +- src/views/teacherEnd/trainingTask/index.vue | 2 +- tests/student-demo-hash-routing.test.mjs | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 tests/student-demo-hash-routing.test.mjs diff --git a/src/views/studentDemo/index.vue b/src/views/studentDemo/index.vue index 3f4da12..b0d015b 100644 --- a/src/views/studentDemo/index.vue +++ b/src/views/studentDemo/index.vue @@ -19,7 +19,7 @@ function receiveTicket(event) { saveStudentDemoSession(res.data); window.clearInterval(readyTimer); window.removeEventListener("message", receiveTicket); - window.location.replace("/index"); + window.location.replace("/#/index"); }).catch(() => { message.value = "演示链接已失效,请返回教师端重新打开。"; }); } diff --git a/src/views/teacherEnd/trainingTask/index.vue b/src/views/teacherEnd/trainingTask/index.vue index 75239c8..ce22ed1 100644 --- a/src/views/teacherEnd/trainingTask/index.vue +++ b/src/views/teacherEnd/trainingTask/index.vue @@ -578,7 +578,7 @@ async function restoreAllTasksDefaults() { async function openStudentDemo() { if (!selectedTeachingClass.value) return; - const child = window.open("/student-demo", "_blank"); + const child = window.open("/#/student-demo", "_blank"); if (!child) { proxy?.$modal?.msgError?.("浏览器拦截了演示窗口,请允许弹窗后重试"); return; } let ticket = ""; let childReady = false; diff --git a/tests/student-demo-hash-routing.test.mjs b/tests/student-demo-hash-routing.test.mjs new file mode 100644 index 0000000..434eaaa --- /dev/null +++ b/tests/student-demo-hash-routing.test.mjs @@ -0,0 +1,12 @@ +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { resolve } from "node:path"; + +const root = resolve(import.meta.dirname, ".."); +const teacherTaskPage = readFileSync(resolve(root, "src/views/teacherEnd/trainingTask/index.vue"), "utf8"); +const studentDemoPage = readFileSync(resolve(root, "src/views/studentDemo/index.vue"), "utf8"); + +assert.match(teacherTaskPage, /window\.open\("\/#\/student-demo", "_blank"\)/, "学生端讲解必须通过 Hash 路由打开演示入口"); +assert.match(studentDemoPage, /window\.location\.replace\("\/#\/index"\)/, "兑换演示学生会话后必须通过 Hash 路由进入学生首页"); + +console.log("student demo uses hash routes instead of falling back to the teacher homepage");