|
|
@@ -9,15 +9,16 @@ import { ClassroomStatus } from '../../../share/types_stock.ts';
|
|
|
import type { ExamSocketRoomMessage } from './types.ts';
|
|
|
import type { AnswerRecord, Answer } from './types.ts';
|
|
|
import type { ClassroomData } from '../../../share/types_stock.ts';
|
|
|
+import { useAuth } from "../../hooks.tsx";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 答题卡页面
|
|
|
export default function ExamCard() {
|
|
|
+ const { user } = useAuth();
|
|
|
const [searchParams] = useSearchParams();
|
|
|
const classroom = searchParams.get('classroom');
|
|
|
- const nickname = searchParams.get('nickname');
|
|
|
const {
|
|
|
socketRoom: { joinRoom, leaveRoom },
|
|
|
answerManagement,
|
|
|
@@ -47,7 +48,7 @@ export default function ExamCard() {
|
|
|
});
|
|
|
|
|
|
useEffect(() => {
|
|
|
- if (!classroom || !nickname) {
|
|
|
+ if (!classroom || !user?.username) {
|
|
|
globalThis.location.href = '/exam';
|
|
|
return;
|
|
|
}
|
|
|
@@ -56,7 +57,7 @@ export default function ExamCard() {
|
|
|
globalThis.location.href = '/exam';
|
|
|
return;
|
|
|
}
|
|
|
- }, [classroom, nickname, classroomData]);
|
|
|
+ }, [classroom, user, classroomData]);
|
|
|
|
|
|
// 加入/离开房间
|
|
|
useEffect(() => {
|
|
|
@@ -105,12 +106,12 @@ export default function ExamCard() {
|
|
|
setHoldingStock('1');
|
|
|
setHoldingCash('0');
|
|
|
|
|
|
- if (classroom && nickname) {
|
|
|
+ if (classroom && user?.username) {
|
|
|
const answer = {
|
|
|
date: currentDate,
|
|
|
holdingStock: '1',
|
|
|
holdingCash: '0',
|
|
|
- userId: nickname,
|
|
|
+ userId: String(user.id),
|
|
|
price: currentPrice
|
|
|
};
|
|
|
|
|
|
@@ -118,7 +119,7 @@ export default function ExamCard() {
|
|
|
await answerManagement.storeAnswer(
|
|
|
classroom as string,
|
|
|
currentQuestion?.id || '',
|
|
|
- nickname,
|
|
|
+ user.username,
|
|
|
answer,
|
|
|
(success) => {
|
|
|
if (success) {
|
|
|
@@ -132,18 +133,18 @@ export default function ExamCard() {
|
|
|
message.error('提交答案失败');
|
|
|
}
|
|
|
}
|
|
|
- }, [classroom, nickname, currentDate, currentPrice, answerManagement, currentQuestion]);
|
|
|
+ }, [classroom, user, currentDate, currentPrice, answerManagement, currentQuestion]);
|
|
|
|
|
|
const handleChooseB = useCallback(async () => {
|
|
|
setHoldingStock('0');
|
|
|
setHoldingCash('1');
|
|
|
|
|
|
- if (classroom && nickname) {
|
|
|
+ if (classroom && user?.username) {
|
|
|
const answer = {
|
|
|
date: currentDate,
|
|
|
holdingStock: '0',
|
|
|
holdingCash: '1',
|
|
|
- userId: nickname,
|
|
|
+ userId: String(user.id),
|
|
|
price: currentPrice
|
|
|
};
|
|
|
|
|
|
@@ -151,7 +152,7 @@ export default function ExamCard() {
|
|
|
await answerManagement.storeAnswer(
|
|
|
classroom as string,
|
|
|
currentQuestion?.id || '',
|
|
|
- nickname,
|
|
|
+ user.username,
|
|
|
answer,
|
|
|
(success) => {
|
|
|
if (success) {
|
|
|
@@ -165,7 +166,7 @@ export default function ExamCard() {
|
|
|
message.error('提交答案失败');
|
|
|
}
|
|
|
}
|
|
|
- }, [classroom, nickname, currentDate, currentPrice, answerManagement, currentQuestion]);
|
|
|
+ }, [classroom, user, currentDate, currentPrice, answerManagement, currentQuestion]);
|
|
|
|
|
|
// 初始化用户的答题记录
|
|
|
useEffect(() => {
|
|
|
@@ -252,7 +253,7 @@ export default function ExamCard() {
|
|
|
{/* 信息显示 */}
|
|
|
<div className="bg-white p-6 rounded-lg shadow-md">
|
|
|
<div className="grid grid-cols-2 gap-4 mb-4">
|
|
|
- <div className="text-gray-600">昵称: {nickname}</div>
|
|
|
+ <div className="text-gray-600">昵称: {user?.username || '未知用户'}</div>
|
|
|
<div className="text-gray-600">代码: {classroomData.code}</div>
|
|
|
</div>
|
|
|
|