From 3730730f1ed9c938adf5d8de358f486e52eaac26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=95=E6=89=8D=E5=8D=93?= <2284808383@qq.com> Date: Wed, 10 Apr 2024 09:14:35 +0800 Subject: [PATCH] stu --- mock/modules/lcz.js | 169 ++++++++------ src/api/students.js | 4 + src/pages/students/student.vue | 394 ++++++++++++++++++++++++--------- 3 files changed, 396 insertions(+), 171 deletions(-) diff --git a/mock/modules/lcz.js b/mock/modules/lcz.js index 19e4c97..f981a3a 100644 --- a/mock/modules/lcz.js +++ b/mock/modules/lcz.js @@ -1,70 +1,111 @@ 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 [ +const student = Mock.mock({ + "list|100": [ { - url:'/api-list', - method:'get', - response: () => { - return { - code: 200, - data: student - } - } + "Id|+1": 1, + "name": "@cname", + "gender": `@pick(['男', '女'])`, + "studentId": "@integer(1000000000,9999999999)", + "department": `@pick(['机电工程系', '护理分院','建筑系','材料科学与工程系','环境科学与工程系'])`, + "major": `@pick(['机械制造与自动化', '材料科学与工程', '环境科学与工程', '建筑工程', '护理学'])`, + "classes": `@pick(['机制1班', '材料1班', '环境1班', '建筑1班','护理1班'])`, + "status": `@pick(['休学', '退学', '复学'])`, }, - { - 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, - } + ], +}); + +export default [ + { + url: '/api-list', + method: 'get', + response: () => { + return { + code: 200, + data: student } } - ] \ No newline at end of file + }, + { + url: '/api-updateStudent', + 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, + } + } + }, + { + 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, + } + } + } +] \ No newline at end of file diff --git a/src/api/students.js b/src/api/students.js index 0bc246a..10f9583 100644 --- a/src/api/students.js +++ b/src/api/students.js @@ -5,4 +5,8 @@ export function getList() { } export function getStudents(studentData) { return request.post('/api-student', studentData) +} + +export function updateStudent(updateStudent) { + return request.post('/api-updateStudent', updateStudent) } \ No newline at end of file diff --git a/src/pages/students/student.vue b/src/pages/students/student.vue index af3d510..d428936 100644 --- a/src/pages/students/student.vue +++ b/src/pages/students/student.vue @@ -2,56 +2,69 @@