Procházet zdrojové kódy

♻️ refactor(classroom): 使用UserType枚举统一角色定义

- 将Classroom组件中的Role枚举值从硬编码改为引用UserType枚举
- 优化角色判断逻辑,提高代码一致性和可维护性

♻️ refactor(stock): 优化课堂导航角色参数传递

- 使用UserType枚举替代硬编码的角色字符串
- 简化角色判断条件,使代码更清晰易懂
yourname před 7 měsíci
rodič
revize
de46a9e07f

+ 3 - 2
src/client/mobile/components/Classroom/useClassroom.ts

@@ -7,9 +7,10 @@ import AliRtcEngine, { AliRtcSubscribeState, AliRtcVideoTrack } from 'aliyun-rtc
 import { toast } from 'react-toastify';
 import { User } from '../../hooks/AuthProvider';
 import { aliyunClient } from '@/client/api';
+import { UserType } from '@/server/modules/users/user.enum';
 export enum Role {
-  Teacher = 'admin',
-  Student = 'student'
+  Teacher = UserType.TEACHER,
+  Student = UserType.STUDENT
 }
 
 // 从SDK中提取需要的类型和枚举

+ 4 - 4
src/client/mobile/pages/StockHomePage.tsx

@@ -1,16 +1,16 @@
-import React from "react";
 import { useNavigate } from "react-router";
 import { useAuth } from "@/client/mobile/hooks/AuthProvider";
+import { UserType } from "@/server/modules/users/user.enum";
 
 export default function StockHomePage() {
   const { user } = useAuth();
   const navigate = useNavigate();
 
   const handleClassroomClick = () => {
-    if (user?.roles?.some(role => role.name === 'admin')) {
-      navigate('/mobile/classroom?role=admin');
+    if (user?.userType === UserType.TEACHER) {
+      navigate('/mobile/classroom?role=' + UserType.TEACHER);
     } else {
-      navigate('/mobile/classroom?role=student');
+      navigate('/mobile/classroom?role=' + UserType.STUDENT);
     }
   };