添加首页每日一练快捷入口并修复API调用问题

主要改动:
1. 修复每日一练排行榜API调用bug(request.get替代request)
2. 在首页快速开始区域添加每日一练快捷入口卡片
3. 实现点击卡片直接跳转到今日每日一练答题页面
4. 添加每日一练状态检测和错误提示

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
燕陇琪 2025-12-02 00:52:40 +08:00
parent 2be5f49528
commit 0074e5978f
2 changed files with 47 additions and 1 deletions

View File

@ -97,7 +97,7 @@ export const submitExam = (examId: number, data: SubmitExamRequest) => {
// 获取每日一练排行榜
export const getDailyExamRanking = () => {
return request<{
return request.get<{
success: boolean
data: {
exam_id: number

View File

@ -604,6 +604,52 @@ const Home: React.FC = () => {
<RocketOutlined />
</Title>
<Row gutter={[12, 12]}>
{/* 每日一练快捷入口 */}
<Col xs={24} sm={24} md={12} lg={8}>
<Card
hoverable
className={styles.quickCard}
onClick={async () => {
// 检查今日每日一练是否存在
if (dailyExamRanking.exam_id) {
try {
// 调用开始考试API创建考试记录
const res = await examApi.startExam(dailyExamRanking.exam_id)
if (res.success && res.data) {
// 跳转到考试答题页面(注意路由是 /taking 不是 /take
navigate(`/exam/${dailyExamRanking.exam_id}/taking/${res.data.record_id}`)
} else {
message.error(res.message || '开始考试失败')
}
} catch (error) {
console.error('开始每日一练失败:', error)
message.error('开始考试失败,请稍后再试')
}
} else {
message.warning('今日每日一练尚未生成,请稍后再试')
}
}}
>
<Space align="center" size="middle" style={{ width: '100%' }}>
<div
className={styles.quickIconWrapper}
style={{
background: 'linear-gradient(135deg, #fff7e6 0%, #ffe7ba 100%)',
borderColor: '#ffd591'
}}
>
<CrownOutlined className={styles.quickIcon} style={{ color: '#fa8c16' }} />
</div>
<div style={{ flex: 1 }}>
<Title level={5} style={{ margin: 0 }}></Title>
<Paragraph type="secondary" style={{ margin: 0, fontSize: '13px' }}>
{dailyExamRanking.exam_title ? dailyExamRanking.exam_title : '今日练习,冲刺高分'}
</Paragraph>
</div>
</Space>
</Card>
</Col>
<Col xs={24} sm={24} md={12} lg={8}>
<Card
hoverable