forked from hqwlkj/umi-dva-antd-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathh5.js
80 lines (73 loc) · 1.91 KB
/
h5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import mockjs from 'mockjs';
/**
* 生成章节数据
* @param parentId
* @returns {any[]}
*/
function fakeChapterList() {
return mockjs.mock({
'list|50': [{ label: '@ctitle', 'parentId|1-2': 1, 'value|+1': 3 }],
});
}
/**
* 生成试题
* @param count 试题数量
*/
function fakeQuestions() {
return mockjs.mock({
'list|100': [{
id: '@integer(0,100)',
description: '@ctitle(40)',
'options': ['@ctitle(10)', '@ctitle(20)', '@ctitle(13)', '@ctitle(18)'],
'answers': ['@pick(0,1,2,3)'],
'chapterID|1-2': 1,
'sectionID|+1': 3,
}],
});
}
function getFakeChapterList(req, res) {
const params = req.query;
const parentId = params.pid || 1;
const result = fakeChapterList();
return res.json(result.list.filter(x => x.parentId === parentId));
}
function getQuestions(req, res) {
// const params = req.query;
// const chapterID = params.chapterID || 1;
// const sectionID = params.sectionID || 3;
const questions = fakeQuestions();
// const chapterQuestions = questions.list.filter(x => x.chapterID === chapterID);
// const data = chapterQuestions.filter(x => x.sectionID === sectionID);
return res.json(questions.list);
}
function getTestPaper(req, res) {
const questions = fakeQuestions();
const paper = {
...mockjs.mock({
id: '@integer(1,100)',
}),
questionTotal: questions.list.length || 0,
};
return res.json({
paper,
questions: questions.list,
});
}
function postTestResult(req, res) {
const result = mockjs.mock({
'result': {
'paperId': '@integer(1,100)',
'score': '@integer(1,100)',
'wrongTotal': '@integer(0,80)',
'time': '9:28',
'isPass': '@pick(true,false)',
},
});
return res.json(result);
}
export default {
'GET /api/chapter': getFakeChapterList,
'GET /api/questions': getQuestions,
'GET /api/test/paper': getTestPaper,
'POST /api/test/result': postTestResult,
};