AnCao/web/src/api/question.ts
yanlongqi b30647d81b 重构题目练习模式,优化用户体验
主要变更:
- 移除独立的随机题目 API 和快速开始卡片
- 添加应用图标 (icon.svg) 和品牌标识
- 优化首页布局,添加 logo 和"安全保密考试题库"标语
- 将随机模式改为答题页面内的可选开关(默认关闭)
- 改进错题练习逻辑,单独处理随机错题功能
- 同步更新 README.md 文档

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-07 22:45:44 +08:00

98 lines
2.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { request } from '../utils/request'
import type { Question, SubmitAnswer, AnswerResult, Statistics, ApiResponse, WrongQuestion, WrongQuestionStats } from '../types/question'
// 获取题目列表
export const getQuestions = (params?: { type?: string; search?: string }) => {
return request.get<ApiResponse<Question[]>>('/practice/questions', { params })
}
// 获取指定题目
export const getQuestionById = (id: number) => {
return request.get<ApiResponse<Question>>(`/practice/questions/${id}`)
}
// 提交答案
export const submitAnswer = (data: SubmitAnswer) => {
return request.post<ApiResponse<AnswerResult>>('/practice/submit', data)
}
// 获取统计数据
export const getStatistics = () => {
return request.get<ApiResponse<Statistics>>('/practice/statistics')
}
// 重置进度 (暂时返回模拟数据,后续实现)
export const resetProgress = async () => {
// TODO: 实现真实的重置接口
return {
success: true,
data: null
}
}
// ========== 错题本相关 API ==========
// 获取错题列表
export const getWrongQuestions = (params?: { is_mastered?: boolean; type?: string }) => {
return request.get<ApiResponse<WrongQuestion[]>>('/wrong-questions', { params })
}
// 获取错题统计
export const getWrongQuestionStats = () => {
return request.get<ApiResponse<WrongQuestionStats>>('/wrong-questions/stats')
}
// 获取随机错题
export const getRandomWrongQuestion = () => {
return request.get<ApiResponse<Question>>('/wrong-questions/random')
}
// 标记错题为已掌握
export const markWrongQuestionMastered = (id: number) => {
return request.put<ApiResponse<null>>(`/wrong-questions/${id}/mastered`)
}
// 删除单个错题
export const deleteWrongQuestion = (id: number) => {
return request.delete<ApiResponse<null>>(`/wrong-questions/${id}`)
}
// 清空错题本
export const clearWrongQuestions = () => {
return request.delete<ApiResponse<null>>('/wrong-questions')
}
// ========== 题库管理相关 API ==========
// 创建题目
export const createQuestion = (data: {
type: string
type_name?: string
question: string
answer: any
options?: Record<string, string>
}) => {
return request.post<ApiResponse<Question>>('/practice/questions', data)
}
// 更新题目
export const updateQuestion = (id: number, data: {
type?: string
type_name?: string
question?: string
answer?: any
options?: Record<string, string>
}) => {
return request.put<ApiResponse<Question>>(`/practice/questions/${id}`, data)
}
// 删除题目
export const deleteQuestion = (id: number) => {
return request.delete<ApiResponse<null>>(`/practice/questions/${id}`)
}
// 获取题目解析AI
export const explainQuestion = (questionId: number) => {
return request.post<ApiResponse<{ explanation: string }>>('/practice/explain', { question_id: questionId })
}