289 lines
8.6 KiB
TypeScript
289 lines
8.6 KiB
TypeScript
![]() |
// 考试题库相关API接口
|
||
|
import { ApiRequest } from '../request'
|
||
|
import type {
|
||
|
ApiResponse,
|
||
|
Repo,
|
||
|
Question,
|
||
|
CreateRepoRequest,
|
||
|
UpdateRepoRequest,
|
||
|
CreateQuestionRequest,
|
||
|
UpdateQuestionRequest,
|
||
|
CreateQuestionOptionRequest,
|
||
|
UpdateQuestionOptionRequest,
|
||
|
CreateQuestionAnswerRequest,
|
||
|
UpdateQuestionAnswerRequest,
|
||
|
CreateQuestionRepoRequest,
|
||
|
UpdateQuestionRepoRequest,
|
||
|
} from '../types'
|
||
|
|
||
|
/**
|
||
|
* 考试题库API模块
|
||
|
*/
|
||
|
export class ExamApi {
|
||
|
|
||
|
// ========== 题库管理 ==========
|
||
|
|
||
|
/**
|
||
|
* 课程新建题库
|
||
|
*/
|
||
|
static async createCourseRepo(data: CreateRepoRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 创建课程题库:', data)
|
||
|
const response = await ApiRequest.post<string>('/biz/repo/courseAdd', data)
|
||
|
console.log('✅ 创建课程题库成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取课程题库
|
||
|
*/
|
||
|
static async getCourseRepoList(): Promise<ApiResponse<Repo[]>> {
|
||
|
const response = await ApiRequest.get<Repo[]>(`/biz/repo/repoList`)
|
||
|
console.log('✅ 获取课程题库列表成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除题库
|
||
|
*/
|
||
|
static async deleteRepo(id: string): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 删除题库:', { id })
|
||
|
const response = await ApiRequest.delete<string>('/gen/repo/repo/delete', {
|
||
|
params: { id }
|
||
|
})
|
||
|
console.log('✅ 删除题库成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 编辑题库
|
||
|
*/
|
||
|
static async updateRepo(data: UpdateRepoRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 编辑题库:', data)
|
||
|
const response = await ApiRequest.put<string>('/gen/repo/repo/edit', data)
|
||
|
console.log('✅ 编辑题库成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
// ========== 题目管理 ==========
|
||
|
|
||
|
/**
|
||
|
* 查询题库下题目
|
||
|
*/
|
||
|
static async getQuestionsByRepo(repoId: string): Promise<ApiResponse<Question[]>> {
|
||
|
console.log('🚀 查询题库下题目:', { repoId })
|
||
|
const response = await ApiRequest.get<Question[]>(`/biz/repo/questionList/${repoId}`)
|
||
|
console.log('✅ 查询题库下题目成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 查询题目详情
|
||
|
*/
|
||
|
static async getQuestionDetail(questionId: string): Promise<ApiResponse<Question>> {
|
||
|
console.log('🚀 查询题目详情:', { questionId })
|
||
|
const response = await ApiRequest.get<Question>(`/biz/repo/repoList/${questionId}`)
|
||
|
console.log('✅ 查询题目详情成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 添加题目
|
||
|
*/
|
||
|
static async createQuestion(data: CreateQuestionRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 添加题目:', data)
|
||
|
const response = await ApiRequest.post<string>('/gen/question/question/add', data)
|
||
|
console.log('✅ 添加题目成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 编辑题目
|
||
|
*/
|
||
|
static async updateQuestion(data: UpdateQuestionRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 编辑题目:', data)
|
||
|
const response = await ApiRequest.put<string>('/gen/question/question/edit', data)
|
||
|
console.log('✅ 编辑题目成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除题目
|
||
|
*/
|
||
|
static async deleteQuestion(id: string): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 删除题目:', { id })
|
||
|
const response = await ApiRequest.delete<string>('/gen/question/question/delete', {
|
||
|
params: { id }
|
||
|
})
|
||
|
console.log('✅ 删除题目成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
// ========== 题目选项管理 ==========
|
||
|
|
||
|
/**
|
||
|
* 添加题目选项
|
||
|
*/
|
||
|
static async createQuestionOption(data: CreateQuestionOptionRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 添加题目选项:', data)
|
||
|
const response = await ApiRequest.post<string>('/gen/questionoption/questionOption/add', data)
|
||
|
console.log('✅ 添加题目选项成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 编辑题目选项
|
||
|
*/
|
||
|
static async updateQuestionOption(data: UpdateQuestionOptionRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 编辑题目选项:', data)
|
||
|
const response = await ApiRequest.put<string>('/gen/questionoption/questionOption/edit', data)
|
||
|
console.log('✅ 编辑题目选项成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除题目选项
|
||
|
*/
|
||
|
static async deleteQuestionOption(id: string): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 删除题目选项:', { id })
|
||
|
const response = await ApiRequest.delete<string>('/gen/questionoption/questionOption/delete', {
|
||
|
params: { id }
|
||
|
})
|
||
|
console.log('✅ 删除题目选项成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
// ========== 题目答案管理 ==========
|
||
|
|
||
|
/**
|
||
|
* 添加题目答案
|
||
|
*/
|
||
|
static async createQuestionAnswer(data: CreateQuestionAnswerRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 添加题目答案:', data)
|
||
|
const response = await ApiRequest.post<string>('/gen/questionanswer/questionAnswer/add', data)
|
||
|
console.log('✅ 添加题目答案成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 编辑题目答案
|
||
|
*/
|
||
|
static async updateQuestionAnswer(data: UpdateQuestionAnswerRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 编辑题目答案:', data)
|
||
|
const response = await ApiRequest.put<string>('/gen/questionanswer/questionAnswer/edit', data)
|
||
|
console.log('✅ 编辑题目答案成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除题目答案
|
||
|
*/
|
||
|
static async deleteQuestionAnswer(id: string): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 删除题目答案:', { id })
|
||
|
const response = await ApiRequest.delete<string>('/gen/questionanswer/questionAnswer/delete', {
|
||
|
params: { id }
|
||
|
})
|
||
|
console.log('✅ 删除题目答案成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
// ========== 题库题目关联管理 ==========
|
||
|
|
||
|
/**
|
||
|
* 添加题库题目关联
|
||
|
*/
|
||
|
static async createQuestionRepo(data: CreateQuestionRepoRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 添加题库题目关联:', data)
|
||
|
const response = await ApiRequest.post<string>('/gen/questionrepo/questionRepo/add', data)
|
||
|
console.log('✅ 添加题库题目关联成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 编辑题库题目关联
|
||
|
*/
|
||
|
static async updateQuestionRepo(data: UpdateQuestionRepoRequest): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 编辑题库题目关联:', data)
|
||
|
const response = await ApiRequest.put<string>('/gen/questionrepo/questionRepo/edit', data)
|
||
|
console.log('✅ 编辑题库题目关联成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 删除题库题目关联
|
||
|
*/
|
||
|
static async deleteQuestionRepo(id: string): Promise<ApiResponse<string>> {
|
||
|
console.log('🚀 删除题库题目关联:', { id })
|
||
|
const response = await ApiRequest.delete<string>('/gen/questionrepo/questionRepo/delete', {
|
||
|
params: { id }
|
||
|
})
|
||
|
console.log('✅ 删除题库题目关联成功:', response)
|
||
|
return response
|
||
|
}
|
||
|
|
||
|
// ========== 常用工具方法 ==========
|
||
|
|
||
|
/**
|
||
|
* 题目类型映射
|
||
|
*/
|
||
|
static getQuestionTypeText(type: number): string {
|
||
|
const typeMap: Record<number, string> = {
|
||
|
0: '单选题',
|
||
|
1: '多选题',
|
||
|
2: '判断题',
|
||
|
3: '填空题',
|
||
|
4: '简答题',
|
||
|
5: '复合题'
|
||
|
}
|
||
|
return typeMap[type] || '未知类型'
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 难度等级映射
|
||
|
*/
|
||
|
static getDifficultyText(difficulty: number): string {
|
||
|
const difficultyMap: Record<number, string> = {
|
||
|
1: '简单',
|
||
|
2: '中等',
|
||
|
3: '困难'
|
||
|
}
|
||
|
return difficultyMap[difficulty] || '未知难度'
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 批量添加题目选项
|
||
|
*/
|
||
|
static async batchCreateQuestionOptions(
|
||
|
questionId: string,
|
||
|
options: Omit<CreateQuestionOptionRequest, 'questionId'>[]
|
||
|
): Promise<ApiResponse<string>[]> {
|
||
|
console.log('🚀 批量添加题目选项:', { questionId, options })
|
||
|
|
||
|
const promises = options.map(option =>
|
||
|
this.createQuestionOption({ ...option, questionId })
|
||
|
)
|
||
|
|
||
|
const responses = await Promise.all(promises)
|
||
|
console.log('✅ 批量添加题目选项成功:', responses)
|
||
|
return responses
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 批量添加题目答案
|
||
|
*/
|
||
|
static async batchCreateQuestionAnswers(
|
||
|
questionId: string,
|
||
|
answers: Omit<CreateQuestionAnswerRequest, 'questionId'>[]
|
||
|
): Promise<ApiResponse<string>[]> {
|
||
|
console.log('🚀 批量添加题目答案:', { questionId, answers })
|
||
|
|
||
|
const promises = answers.map(answer =>
|
||
|
this.createQuestionAnswer({ ...answer, questionId })
|
||
|
)
|
||
|
|
||
|
const responses = await Promise.all(promises)
|
||
|
console.log('✅ 批量添加题目答案成功:', responses)
|
||
|
return responses
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default ExamApi
|