298 lines
7.3 KiB
TypeScript
298 lines
7.3 KiB
TypeScript
import { defineMock } from '@alova/mock';
|
|
|
|
// 模拟题目数据
|
|
const mockQuestions = [
|
|
{
|
|
id: '1',
|
|
title: '朱熹的生卒年份',
|
|
content: '朱熹(朱子)生于哪一年,卒于哪一年?',
|
|
type: 'single',
|
|
options: [
|
|
{ key: 'A', value: '1130-1200', isCorrect: true },
|
|
{ key: 'B', value: '1120-1190' },
|
|
{ key: 'C', value: '1140-1210' },
|
|
{ key: 'D', value: '1125-1195' }
|
|
],
|
|
correctAnswer: ['A'],
|
|
score: 10,
|
|
difficulty: 'easy',
|
|
category: '朱子生平',
|
|
tags: ['朱熹', '生平', '基础知识'],
|
|
createTime: '2024-01-01 10:00:00',
|
|
updateTime: '2024-01-01 10:00:00'
|
|
},
|
|
{
|
|
id: '2',
|
|
title: '朱子理学的核心思想',
|
|
content: '朱子理学的核心思想包括哪些?(多选)',
|
|
type: 'multiple',
|
|
options: [
|
|
{ key: 'A', value: '理气论', isCorrect: true },
|
|
{ key: 'B', value: '心性论', isCorrect: true },
|
|
{ key: 'C', value: '格物致知', isCorrect: true },
|
|
{ key: 'D', value: '王道思想' }
|
|
],
|
|
correctAnswer: ['A', 'B', 'C'],
|
|
score: 15,
|
|
difficulty: 'medium',
|
|
category: '朱子思想',
|
|
tags: ['理学', '哲学', '思想'],
|
|
createTime: '2024-01-01 11:00:00',
|
|
updateTime: '2024-01-01 11:00:00'
|
|
},
|
|
{
|
|
id: '3',
|
|
title: '朱子的著作',
|
|
content: '《四书章句集注》是朱子的代表作品吗?',
|
|
type: 'single',
|
|
options: [
|
|
{ key: 'A', value: '是', isCorrect: true },
|
|
{ key: 'B', value: '不是' }
|
|
],
|
|
correctAnswer: ['A'],
|
|
score: 8,
|
|
difficulty: 'easy',
|
|
category: '朱子著作',
|
|
tags: ['著作', '四书'],
|
|
createTime: '2024-01-01 12:00:00',
|
|
updateTime: '2024-01-01 12:00:00'
|
|
},
|
|
{
|
|
id: '4',
|
|
title: '朱子的家乡',
|
|
content: '朱熹的出生地是哪里?',
|
|
type: 'single',
|
|
options: [
|
|
{ key: 'A', value: '江西婺源' },
|
|
{ key: 'B', value: '福建尤溪', isCorrect: true },
|
|
{ key: 'C', value: '福建建阳' },
|
|
{ key: 'D', value: '浙江金华' }
|
|
],
|
|
correctAnswer: ['B'],
|
|
score: 12,
|
|
difficulty: 'medium',
|
|
category: '朱子生平',
|
|
tags: ['家乡', '生平'],
|
|
createTime: '2024-01-01 13:00:00',
|
|
updateTime: '2024-01-01 13:00:00'
|
|
},
|
|
{
|
|
id: '5',
|
|
title: '朱子教育思想',
|
|
content: '朱子在教育方面提出了哪些重要观点?(多选)',
|
|
type: 'multiple',
|
|
options: [
|
|
{ key: 'A', value: '因材施教', isCorrect: true },
|
|
{ key: 'B', value: '学思并重', isCorrect: true },
|
|
{ key: 'C', value: '博学笃行', isCorrect: true },
|
|
{ key: 'D', value: '死记硬背' }
|
|
],
|
|
correctAnswer: ['A', 'B', 'C'],
|
|
score: 20,
|
|
difficulty: 'hard',
|
|
category: '朱子教育',
|
|
tags: ['教育', '思想', '方法'],
|
|
createTime: '2024-01-01 14:00:00',
|
|
updateTime: '2024-01-01 14:00:00'
|
|
}
|
|
];
|
|
|
|
// 题目分类
|
|
const mockCategories = [
|
|
{ name: '朱子生平', count: 2 },
|
|
{ name: '朱子思想', count: 1 },
|
|
{ name: '朱子著作', count: 1 },
|
|
{ name: '朱子教育', count: 1 }
|
|
];
|
|
|
|
// 题库管理接口的mock数据
|
|
export default defineMock({
|
|
// 获取题目列表
|
|
'[GET]/admin/questions': ({ query }) => {
|
|
let filteredQuestions = [...mockQuestions];
|
|
|
|
// 关键词搜索
|
|
if (query.keyword) {
|
|
filteredQuestions = filteredQuestions.filter(q =>
|
|
q.title.includes(query.keyword!) ||
|
|
q.content.includes(query.keyword!) ||
|
|
q.category.includes(query.keyword!)
|
|
);
|
|
}
|
|
|
|
// 题型筛选
|
|
if (query.type) {
|
|
filteredQuestions = filteredQuestions.filter(q => q.type === query.type);
|
|
}
|
|
|
|
// 难度筛选
|
|
if (query.difficulty) {
|
|
filteredQuestions = filteredQuestions.filter(q => q.difficulty === query.difficulty);
|
|
}
|
|
|
|
// 分类筛选
|
|
if (query.category) {
|
|
filteredQuestions = filteredQuestions.filter(q => q.category === query.category);
|
|
}
|
|
|
|
// 分页
|
|
const page = parseInt(query.page) || 1;
|
|
const pageSize = parseInt(query.pageSize) || 10;
|
|
const total = filteredQuestions.length;
|
|
const start = (page - 1) * pageSize;
|
|
const end = start + pageSize;
|
|
|
|
return {
|
|
code: 200,
|
|
message: 'success',
|
|
data: {
|
|
list: filteredQuestions.slice(start, end),
|
|
total,
|
|
page,
|
|
pageSize
|
|
}
|
|
};
|
|
},
|
|
|
|
// 获取题目详情
|
|
'[GET]/admin/questions/{id}': ({ params }) => {
|
|
const question = mockQuestions.find(q => q.id === params.id);
|
|
if (!question) {
|
|
return {
|
|
status: 404,
|
|
body: {
|
|
code: 404,
|
|
message: '题目不存在',
|
|
data: null
|
|
}
|
|
};
|
|
}
|
|
|
|
return {
|
|
code: 200,
|
|
message: 'success',
|
|
data: question
|
|
};
|
|
},
|
|
|
|
// 创建题目
|
|
'[POST]/admin/questions': ({ data }) => {
|
|
const newQuestion = {
|
|
...data,
|
|
id: (mockQuestions.length + 1).toString(),
|
|
createTime: new Date().toLocaleString('zh-CN'),
|
|
updateTime: new Date().toLocaleString('zh-CN')
|
|
};
|
|
|
|
mockQuestions.push(newQuestion);
|
|
|
|
return {
|
|
code: 200,
|
|
message: 'success',
|
|
data: {
|
|
message: '创建成功',
|
|
id: newQuestion.id
|
|
}
|
|
};
|
|
},
|
|
|
|
// 更新题目
|
|
'[PUT]/admin/questions/{id}': ({ params, data }) => {
|
|
const index = mockQuestions.findIndex(q => q.id === params.id);
|
|
if (index === -1) {
|
|
return {
|
|
status: 404,
|
|
body: {
|
|
code: 404,
|
|
message: '题目不存在',
|
|
data: null
|
|
}
|
|
};
|
|
}
|
|
|
|
mockQuestions[index] = {
|
|
...data,
|
|
id: params.id,
|
|
createTime: mockQuestions[index].createTime,
|
|
updateTime: new Date().toLocaleString('zh-CN')
|
|
};
|
|
|
|
return {
|
|
code: 200,
|
|
message: 'success',
|
|
data: { message: '更新成功' }
|
|
};
|
|
},
|
|
|
|
// 删除题目
|
|
'[DELETE]/admin/questions/{id}': ({ params }) => {
|
|
const index = mockQuestions.findIndex(q => q.id === params.id);
|
|
if (index === -1) {
|
|
return {
|
|
status: 404,
|
|
body: {
|
|
code: 404,
|
|
message: '题目不存在',
|
|
data: null
|
|
}
|
|
};
|
|
}
|
|
|
|
mockQuestions.splice(index, 1);
|
|
|
|
return {
|
|
code: 200,
|
|
message: 'success',
|
|
data: { message: '删除成功' }
|
|
};
|
|
},
|
|
|
|
// 批量删除题目
|
|
'[DELETE]/admin/questions/batch': ({ data }) => {
|
|
let deletedCount = 0;
|
|
data.ids.forEach(id => {
|
|
const index = mockQuestions.findIndex(q => q.id === id);
|
|
if (index !== -1) {
|
|
mockQuestions.splice(index, 1);
|
|
deletedCount++;
|
|
}
|
|
});
|
|
|
|
return {
|
|
code: 200,
|
|
message: 'success',
|
|
data: {
|
|
message: `成功删除${deletedCount}个题目`
|
|
}
|
|
};
|
|
},
|
|
|
|
// 获取题目分类列表
|
|
'[GET]/admin/questions/categories': () => {
|
|
return {
|
|
code: 200,
|
|
message: 'success',
|
|
data: mockCategories
|
|
};
|
|
},
|
|
|
|
// 导出题目模板
|
|
'[GET]/admin/questions/template': () => {
|
|
const blob = new Blob(['模板内容'], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
|
|
return blob;
|
|
},
|
|
|
|
// 批量导入题目
|
|
'[POST]/admin/questions/import': () => {
|
|
return {
|
|
code: 200,
|
|
message: 'success',
|
|
data: {
|
|
message: '导入成功',
|
|
successCount: 5,
|
|
failCount: 0
|
|
}
|
|
};
|
|
}
|
|
}, true);
|