|
|
@@ -1,6 +1,6 @@
|
|
|
import React, { useState, useEffect } from 'react';
|
|
|
import { useAuth } from './hooks.tsx';
|
|
|
-import { useNavigate } from 'react-router';
|
|
|
+import { useNavigate, useSearchParams } from 'react-router';
|
|
|
import { Role, ClassStatus } from './components/Classroom/useClassroom.ts';
|
|
|
// import { TeacherView } from './components/Classroom/TeacherView.tsx';
|
|
|
// import { StudentView } from './components/Classroom/StudentView.tsx';
|
|
|
@@ -112,7 +112,18 @@ const CreateClassSection = () => {
|
|
|
|
|
|
const Classroom = () => {
|
|
|
const context = useClassroomContext();
|
|
|
- const { role, classStatus, isLoggedIn, login, classId, joinClass } = context;
|
|
|
+ const { role, classStatus, isLoggedIn, login, classId, joinClass, setRole } = context;
|
|
|
+ const [searchParams] = useSearchParams();
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ // 处理URL中的role参数
|
|
|
+ const urlRole = searchParams.get('role');
|
|
|
+ if (urlRole && !role) {
|
|
|
+ const roleValue = urlRole === 'admin' ? Role.Teacher : Role.Student;
|
|
|
+ setRole(roleValue);
|
|
|
+ login(roleValue);
|
|
|
+ }
|
|
|
+ }, [searchParams]);
|
|
|
|
|
|
useEffect(() => {
|
|
|
|