70 lines
2.3 KiB
JavaScript
70 lines
2.3 KiB
JavaScript
import Mock from "mockjs"
|
|
|
|
const student = Mock.mock({
|
|
"list|100": [
|
|
{
|
|
"Id|+1": 1,
|
|
"name": "@cname",
|
|
"gender":`@pick(['男', '女'])`,
|
|
"studentId": "@integer(1000000000,9999999999)",
|
|
"department":`@pick(['机电工程系', '护理分院','建筑系','材料科学与工程系','环境科学与工程系'])`,
|
|
"major":`@pick(['机械制造与自动化', '材料科学与工程', '环境科学与工程', '建筑工程', '护理学'])`,
|
|
"classes":`@pick(['机制1班', '材料1班', '环境1班', '建筑1班','护理1班'])`,
|
|
"status":`@pick(['休学', '退学', '复学'])`,
|
|
},
|
|
],
|
|
});
|
|
|
|
export default [
|
|
{
|
|
url:'/api-list',
|
|
method:'get',
|
|
response: () => {
|
|
return {
|
|
code: 200,
|
|
data: student
|
|
}
|
|
}
|
|
},
|
|
{
|
|
url: '/api-student',
|
|
method: 'post',
|
|
response: (req) => {
|
|
if (req.body.name !== '') {
|
|
return student.list.filter(item => item.name.includes(req.body.name))
|
|
}
|
|
else if (req.body.studentId !== '') {
|
|
const studentId = Number(req.body.studentId)
|
|
if (!isNaN(studentId)) {
|
|
return student.list.filter(item => item.studentId === studentId)
|
|
} else {
|
|
return {
|
|
code: 400,
|
|
message: 'Invalid student number format'
|
|
}
|
|
}
|
|
}
|
|
else if (req.body.name !== '') {
|
|
return student.list.filter(item => item.name.includes(req.body.name))
|
|
}
|
|
else if (req.body.gender !== '') {
|
|
return student.list.filter(item => item.gender.includes(req.body.gender))
|
|
}
|
|
else if (req.body.department !== '') {
|
|
return student.list.filter(item => item.grade.includes(req.body.department))
|
|
}
|
|
else if (req.body.major !== '') {
|
|
return student.list.filter(item => item.major.includes(req.body.major))
|
|
}
|
|
else if (req.body.classes !== '') {
|
|
return student.list.filter(item => item.classes.includes(req.body.classes))
|
|
}
|
|
else if (req.body.status !== '') {
|
|
return student.list.filter(item => item.major.includes(req.body.status))
|
|
}
|
|
return {
|
|
code: 200,
|
|
}
|
|
}
|
|
}
|
|
] |