From c06d003c38611766296da02189fde05d661c5144 Mon Sep 17 00:00:00 2001 From: words Date: Thu, 23 Jul 2026 22:05:18 +0800 Subject: [PATCH] =?utf8?q?fix:=20=E5=A4=8D=E4=B9=A0=E6=A8=A1=E5=BC=8F?= =?utf8?q?=E8=BF=9B=E5=BA=A6=E8=AE=B0=E5=BD=95=20bug=EF=BC=88WEB=20?= =?utf8?q?=E7=89=88=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - Home.js: 点击复习时通过 ?type=review1/2/3 传递活动类型 - TestMode.js: 读取 URL 的 type 参数,finishTest 按类型写入 op_type 修复前 op_type 写死为 'test',导致复习完成不被记录; 必须再点一次复习才能记录(与线下版本行为不一致) - 重建前端 build --- frontend/src/components/Home.js | 8 ++++---- frontend/src/components/TestMode.js | 11 +++++++---- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/Home.js b/frontend/src/components/Home.js index 2ea0518..2f00eb6 100644 --- a/frontend/src/components/Home.js +++ b/frontend/src/components/Home.js @@ -50,16 +50,16 @@ function Home() { navigate(`/study/${groupId}`); } if (type === 'test' && item.test && item.test.includes('请开始测试')) { - navigate(`/test/${groupId}`); + navigate(`/test/${groupId}?type=test`); } if (type === 'review1' && item.review1 && (item.review1.includes('请开始复习') || item.review1.includes('请尽快复习'))) { - navigate(`/test/${groupId}`); + navigate(`/test/${groupId}?type=review1`); } if (type === 'review2' && item.review2 && (item.review2.includes('请开始复习') || item.review2.includes('请尽快复习'))) { - navigate(`/test/${groupId}`); + navigate(`/test/${groupId}?type=review2`); } if (type === 'review3' && item.review3 && (item.review3.includes('请开始复习') || item.review3.includes('请尽快复习'))) { - navigate(`/test/${groupId}`); + navigate(`/test/${groupId}?type=review3`); } }; diff --git a/frontend/src/components/TestMode.js b/frontend/src/components/TestMode.js index 0184174..c45b4f8 100644 --- a/frontend/src/components/TestMode.js +++ b/frontend/src/components/TestMode.js @@ -1,5 +1,5 @@ import React, { useState, useEffect, useCallback, useRef } from 'react'; -import { useParams, useNavigate } from 'react-router-dom'; +import { useParams, useNavigate, useSearchParams } from 'react-router-dom'; import axios from 'axios'; import './TestMode.css'; @@ -8,6 +8,9 @@ const API_BASE = "http://124.222.157.124:1060"; function TestMode() { const { groupId } = useParams(); const navigate = useNavigate(); + const [searchParams] = useSearchParams(); + // 活动类型:test / review1 / review2 / review3(首页点击复习时通过 ?type= 传入;缺省为 test) + const activityType = searchParams.get('type') || 'test'; const [words, setWords] = useState([]); const [queue, setQueue] = useState([]); // 当前测试队列 const [wrongQueue, setWrongQueue] = useState([]); // 错词重考队列 @@ -119,14 +122,14 @@ function TestMode() { setIsRetesting(true); }, [wrongQueue]); - // 完成测试,记录进度 + // 完成测试,记录进度(op_type 依据活动类型:test / review1 / review2 / review3) const finishTest = useCallback(async () => { await axios.post(`${API_BASE}/api/progress/update`, { group_id: groupId, - op_type: 'test' + op_type: activityType }); navigate('/'); - }, [groupId, navigate]); + }, [groupId, navigate, activityType]); // 键盘事件 const handleKeyDown = useCallback((e) => { -- 2.43.0