|
|
@@ -1,6 +1,6 @@
|
|
|
import React,{ useState, useCallback, useEffect } from 'react';
|
|
|
import { useQuery } from '@tanstack/react-query';
|
|
|
-import { useSearchParams } from "react-router";
|
|
|
+import { useSearchParams, useNavigate } from "react-router";
|
|
|
import dayjs from 'dayjs';
|
|
|
import { message } from 'antd';
|
|
|
import { useSocketClient } from './hooks/useSocketClient.ts';
|
|
|
@@ -17,6 +17,7 @@ import { useAuth } from "../../hooks.tsx";
|
|
|
// 答题卡页面
|
|
|
export default function ExamCard() {
|
|
|
const { user } = useAuth();
|
|
|
+ const navigate = useNavigate();
|
|
|
const [searchParams] = useSearchParams();
|
|
|
const classroom = searchParams.get('classroom');
|
|
|
const {
|
|
|
@@ -51,13 +52,15 @@ export default function ExamCard() {
|
|
|
// 初始化答题卡数据
|
|
|
const initExamCard = useCallback(async () => {
|
|
|
if (!classroom || !user?.username) {
|
|
|
- globalThis.location.href = '/exam';
|
|
|
+ // globalThis.location.href = '/exam';
|
|
|
+ navigate('/mobile')
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
if (classroomData && classroomData.status !== ClassroomStatus.OPEN) {
|
|
|
message.error('该教室已关闭');
|
|
|
- globalThis.location.href = '/exam';
|
|
|
+ // globalThis.location.href = '/exam';
|
|
|
+ navigate('/mobile')
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -191,7 +194,7 @@ export default function ExamCard() {
|
|
|
await answerManagement.storeAnswer(
|
|
|
classroom as string,
|
|
|
currentQuestion?.id || '',
|
|
|
- user.username,
|
|
|
+ String(user.id),
|
|
|
answer,
|
|
|
(success) => {
|
|
|
if (success) {
|
|
|
@@ -207,36 +210,36 @@ export default function ExamCard() {
|
|
|
}
|
|
|
}, [classroom, user, currentDate, currentPrice, answerManagement, currentQuestion]);
|
|
|
|
|
|
- // 监听socket消息更新答题记录
|
|
|
- useEffect(() => {
|
|
|
- if (!lastMessage?.message) return;
|
|
|
+ // // 监听socket消息更新答题记录
|
|
|
+ // useEffect(() => {
|
|
|
+ // if (!lastMessage?.message) return;
|
|
|
|
|
|
- const { type } = lastMessage.message;
|
|
|
- if (type === 'answer' || type === 'question' || type === 'restart') {
|
|
|
- if (classroom && user?.id) {
|
|
|
- answerManagement.getUserAnswers(classroom, String(user.id))
|
|
|
- .then(answers => {
|
|
|
- if (answers && answers.length > 0) {
|
|
|
- const lastAnswer = answers[answers.length - 1];
|
|
|
- setHoldingStock(lastAnswer.holdingStock);
|
|
|
- setHoldingCash(lastAnswer.holdingCash);
|
|
|
+ // const { type } = lastMessage.message;
|
|
|
+ // if (type === 'answer' || type === 'question' || type === 'restart') {
|
|
|
+ // if (classroom && user?.id) {
|
|
|
+ // answerManagement.getUserAnswers(classroom, String(user.id))
|
|
|
+ // .then(answers => {
|
|
|
+ // if (answers && answers.length > 0) {
|
|
|
+ // const lastAnswer = answers[answers.length - 1];
|
|
|
+ // setHoldingStock(lastAnswer.holdingStock);
|
|
|
+ // setHoldingCash(lastAnswer.holdingCash);
|
|
|
|
|
|
- const records = answers.map((answer: Answer, index: number): AnswerRecord => ({
|
|
|
- date: answer.date,
|
|
|
- price: String(answer.price || '0'),
|
|
|
- holdingStock: answer.holdingStock,
|
|
|
- holdingCash: answer.holdingCash,
|
|
|
- profitAmount: answer.profitAmount || 0,
|
|
|
- profitPercent: answer.profitPercent || 0,
|
|
|
- index: index + 1
|
|
|
- }));
|
|
|
+ // const records = answers.map((answer: Answer, index: number): AnswerRecord => ({
|
|
|
+ // date: answer.date,
|
|
|
+ // price: String(answer.price || '0'),
|
|
|
+ // holdingStock: answer.holdingStock,
|
|
|
+ // holdingCash: answer.holdingCash,
|
|
|
+ // profitAmount: answer.profitAmount || 0,
|
|
|
+ // profitPercent: answer.profitPercent || 0,
|
|
|
+ // index: index + 1
|
|
|
+ // }));
|
|
|
|
|
|
- setAnswerRecords(records);
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }, [lastMessage, classroom, user, answerManagement]);
|
|
|
+ // setAnswerRecords(records);
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }, [lastMessage, classroom, user, answerManagement]);
|
|
|
|
|
|
if (isLoading || !classroomData) {
|
|
|
return <div className="flex items-center justify-center min-h-screen">加载中...</div>;
|