|
|
|
@ -7,11 +7,17 @@ import { exchangeStudentDemoSession } from "@/api/studentDemo";
|
|
|
|
import { saveStudentDemoSession } from "@/utils/studentDemo";
|
|
|
|
import { saveStudentDemoSession } from "@/utils/studentDemo";
|
|
|
|
|
|
|
|
|
|
|
|
const message = ref("正在连接教师演示会话…");
|
|
|
|
const message = ref("正在连接教师演示会话…");
|
|
|
|
|
|
|
|
let readyTimer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function notifyReady() {
|
|
|
|
|
|
|
|
if (window.opener) window.opener.postMessage({ type: "STUDENT_DEMO_READY" }, window.location.origin);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function receiveTicket(event) {
|
|
|
|
function receiveTicket(event) {
|
|
|
|
if (event.origin !== window.location.origin || event.source !== window.opener || event.data?.type !== "STUDENT_DEMO_TICKET") return;
|
|
|
|
if (event.origin !== window.location.origin || event.source !== window.opener || event.data?.type !== "STUDENT_DEMO_TICKET") return;
|
|
|
|
exchangeStudentDemoSession(event.data.ticket).then((res) => {
|
|
|
|
exchangeStudentDemoSession(event.data.ticket).then((res) => {
|
|
|
|
saveStudentDemoSession(res.data);
|
|
|
|
saveStudentDemoSession(res.data);
|
|
|
|
|
|
|
|
window.clearInterval(readyTimer);
|
|
|
|
window.removeEventListener("message", receiveTicket);
|
|
|
|
window.removeEventListener("message", receiveTicket);
|
|
|
|
window.location.replace("/index");
|
|
|
|
window.location.replace("/index");
|
|
|
|
}).catch(() => { message.value = "演示链接已失效,请返回教师端重新打开。"; });
|
|
|
|
}).catch(() => { message.value = "演示链接已失效,请返回教师端重新打开。"; });
|
|
|
|
@ -20,9 +26,13 @@ function receiveTicket(event) {
|
|
|
|
onMounted(() => {
|
|
|
|
onMounted(() => {
|
|
|
|
if (!window.opener) { message.value = "演示链接已失效,请返回教师端重新打开。"; return; }
|
|
|
|
if (!window.opener) { message.value = "演示链接已失效,请返回教师端重新打开。"; return; }
|
|
|
|
window.addEventListener("message", receiveTicket);
|
|
|
|
window.addEventListener("message", receiveTicket);
|
|
|
|
window.opener.postMessage({ type: "STUDENT_DEMO_READY" }, window.location.origin);
|
|
|
|
notifyReady();
|
|
|
|
|
|
|
|
readyTimer = window.setInterval(notifyReady, 500);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
onBeforeUnmount(() => {
|
|
|
|
|
|
|
|
window.clearInterval(readyTimer);
|
|
|
|
|
|
|
|
window.removeEventListener("message", receiveTicket);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
onBeforeUnmount(() => window.removeEventListener("message", receiveTicket));
|
|
|
|
|
|
|
|
</script>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>.student-demo-entry{display:grid;min-height:100vh;place-items:center;background:#06111d;color:#dff7ff;font-size:18px}</style>
|
|
|
|
<style scoped>.student-demo-entry{display:grid;min-height:100vh;place-items:center;background:#06111d;color:#dff7ff;font-size:18px}</style>
|
|
|
|
|