This commit is contained in:
sundongyu 2024-04-10 11:46:46 +08:00
commit 923bebedf1
3 changed files with 396 additions and 171 deletions

View File

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

View File

@ -6,3 +6,7 @@ export function getList() {
export function getStudents(studentData) { export function getStudents(studentData) {
return request.post('/api-student', studentData) return request.post('/api-student', studentData)
} }
export function updateStudent(updateStudent) {
return request.post('/api-updateStudent', updateStudent)
}

View File

@ -2,56 +2,69 @@
<div class="back-color"> <div class="back-color">
<t-layout style="height: 90%; background-color: #f5f7fb"> <t-layout style="height: 90%; background-color: #f5f7fb">
<t-header class="scarch-box"> <t-header class="scarch-box">
<t-form <t-form
ref="form" ref="form"
:data="studentData" :data="studentData"
reset-type="initial" reset-type="initial"
colon colon
@reset="onReset" @reset="onReset"
@submit="onSubmit" @submit="onSubmit"
> >
<t-row class="scarch-from"> <t-row class="scarch-from">
<t-col :span="3"> <t-col :span="3">
<t-form-item label="姓名" name="name"> <t-form-item label="姓名" name="name">
<t-input v-model="studentData.name"></t-input> <t-input v-model="studentData.name"></t-input>
</t-form-item> </t-form-item>
</t-col> </t-col>
<t-col :span="3"> <t-col :span="3">
<t-form-item label="学号" name="studentId"> <t-form-item label="学号" name="studentId">
<t-input v-model="studentData.studentId"></t-input> <t-input v-model="studentData.studentId"></t-input>
</t-form-item> </t-form-item>
</t-col> </t-col>
<t-col :push="2" :span="4"> <t-col :push="2" :span="4">
<t-button theme="primary" type="submit" <t-button theme="primary" type="submit">查询</t-button>
>查询</t-button <t-button
> theme="default"
<t-button theme="default" variant="base" type="reset" variant="base"
style="margin-left: 1rem;">重置</t-button type="reset"
> style="margin-left: 1rem"
</t-col> >重置</t-button
</t-row> >
</t-form> </t-col>
</t-header> </t-row>
<t-content class="table-box"> </t-form>
<t-table </t-header>
rowKey="Id" <t-content class="table-box">
:data="studentList" <div class="table-header">
:columns="studentColumns" <div>
:stripe="stripe" <h4 style="font-size: 110%">学生列表</h4>
:bordered="bordered" </div>
:hover="true" <div>
:size="size" <t-button theme="primary" size="small" style="margin-right:2.5rem" @click="onAddSubmit">
:table-layout="tableLayout ? 'auto' : 'fixed'" <template #icon><add-icon /></template>
:pagination="pagination" 增加学员信息
:showHeader="true" </t-button>
cellEmptyContent="-" </div>
resizable </div>
lazy-load <t-table
@row-click="handleRowClick" rowKey="Id"
@page-change="onPageChange" :data="studentList"
:loading="loading" :columns="studentColumns"
> :stripe="stripe"
<template #operation="{ row }"> :bordered="bordered"
:hover="true"
:size="size"
:table-layout="tableLayout ? 'auto' : 'fixed'"
:pagination="pagination"
:showHeader="true"
cellEmptyContent="-"
resizable
lazy-load
@row-click="handleRowClick"
@page-change="onPageChange"
:loading="loading"
>
<template #operation="{ row }">
<t-button <t-button
theme="default" theme="default"
variant="text" variant="text"
@ -59,71 +72,153 @@
@click="Modify(row)" @click="Modify(row)"
>修改</t-button >修改</t-button
> >
<t-popconfirm <t-popconfirm content="确认删除吗" @confirm="Delete(row)">
content="确认删除吗"
@confirm="Delete(row)"
>
<t-button theme="default" variant="text" size="small" <t-button theme="default" variant="text" size="small"
>删除</t-button >删除</t-button
> >
</t-popconfirm> </t-popconfirm>
</template> </template>
</t-table> </t-table>
</t-content> </t-content>
</t-layout> </t-layout>
<t-space> <t-space>
<t-dialog <t-dialog
ref="postForm"
v-model="visible" v-model="visible"
header="学生变动处理" header="学生变动处理"
width="40%" width="40%"
:confirm-on-enter="true"
:on-cancel="onCancel" :on-cancel="onCancel"
:on-esc-keydown="onEscKeydown"
:on-close-btn-click="onCloseBtnClick" :on-close-btn-click="onCloseBtnClick"
:on-overlay-click="onOverlayClick"
:on-close="close"
:on-confirm="onConfirmAnother" :on-confirm="onConfirmAnother"
:close-on-overlay-click="false" ref="postForm"
> >
<t-space direction="vertical" style="width: 100%"> <t-space direction="vertical" style="width: 100%">
<div> <div>
<t-form <t-form
ref="form" ref="form"
:data="formData" :data="dialogData"
reset-type="initial" reset-type="initial"
colon colon
@reset="onReset" @reset="onReset"
> >
<t-form-item label="姓名" name="name"> <t-form-item label="姓名" name="name">
<t-input v-model="formData.name"></t-input> <t-input v-model="dialogData.name"></t-input>
</t-form-item> </t-form-item>
<t-form-item label="性别" name="gender"> <t-form-item label="性别" name="gender">
<t-input v-model="formData.gender"></t-input> <t-input v-model="dialogData.gender"></t-input>
</t-form-item> </t-form-item>
<t-form-item label="学号" name="studentId"> <t-form-item label="学号" name="studentId">
<t-input v-model="formData.studentId"></t-input> <t-input v-model="dialogData.studentId"></t-input>
</t-form-item> </t-form-item>
<t-form-item label="系院" name="department"> <t-form-item label="系院" name="department">
<t-input v-model="formData.department"></t-input> <t-input v-model="dialogData.department"></t-input>
</t-form-item> </t-form-item>
<t-form-item label="专业" name="major"> <t-form-item label="专业" name="major">
<t-input v-model="formData.major"></t-input> <t-input v-model="dialogData.major"></t-input>
</t-form-item> </t-form-item>
<t-form-item label="班级" name="classes"> <t-form-item label="班级" name="classes">
<t-input v-model="formData.classes"></t-input> <t-input v-model="dialogData.classes"></t-input>
</t-form-item> </t-form-item>
<t-form-item label="状态" name="status"> <t-form-item
<t-input v-model="formData.status"></t-input> label="状态"
</t-form-item> name="status"
:span="12"
style="width: 16rem; margin-bottom: 0.5rem"
>
<t-select
v-model="dialogData.status"
clearable
placeholder="请选择状态"
>
<t-option
v-for="item in status"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</t-select>
</t-form-item>
</t-form> </t-form>
</div> </div>
</t-space> </t-space>
</t-dialog> </t-dialog>
</t-space> </t-space>
<!-- <t-space>
<t-dialog
v-model:visible="visible"
header="新增学生信息"
width="40%"
:confirm-on-enter="true"
:on-cancel="onCancel"
:on-esc-keydown="onEscKeydown"
:on-close-btn-click="onCloseBtnClick"
:on-overlay-click="onOverlayClick"
:on-close="close"
:on-confirm="onConfirmAnother"
ref="postForm"
>
<t-space direction="vertical" style="width: 100%">
<div>
<t-form
ref="form"
:data="AddDialogData"
reset-type="initial"
colon
@reset="onReset"
>
<t-form-item label="姓名" name="name">
<t-input v-model="AddDialogData.name"></t-input>
</t-form-item>
<t-form-item label="性别" name="gender">
<t-input v-model="AddDialogData.gender"></t-input>
</t-form-item>
<t-form-item label="学号" name="studentId">
<t-input v-model="AddDialogData.studentId"></t-input>
</t-form-item>
<t-form-item label="系院" name="department">
<t-input v-model="AddDialogData.department"></t-input>
</t-form-item>
<t-form-item label="专业" name="major">
<t-input v-model="AddDialogData.major"></t-input>
</t-form-item>
<t-form-item label="班级" name="classes">
<t-input v-model="AddDialogData.classes"></t-input>
</t-form-item>
<t-form-item
label="状态"
name="status"
:span="12"
style="width: 16rem; margin-bottom: 0.5rem"
>
<t-select
v-model="AddDialogData.status"
clearable
placeholder="请选择状态"
>
<t-option
v-for="item in status"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</t-select>
</t-form-item>
</t-form>
</div>
</t-space>
</t-dialog>
</t-space> -->
</div> </div>
</template> </template>
<script setup> <script setup>
import { ref, reactive, computed, onMounted } from "vue"; import { ref, reactive, computed, onMounted } from "vue";
import {getList, getStudents } from "@/api/students"; import { getList, getStudents, updateStudent } from "@/api/students";
import { MessagePlugin } from "tdesign-vue-next"; import { MessagePlugin } from "tdesign-vue-next";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
// import { reqStudent } from "@/api/students"; // import { reqStudent } from "@/api/students";
@ -131,7 +226,7 @@ import { useRouter } from "vue-router";
const router = useRouter(); const router = useRouter();
const studentData = reactive({ const studentData = reactive({
Id:"", Id: "",
name: "", name: "",
gender: "", gender: "",
studentId: "", studentId: "",
@ -142,7 +237,7 @@ const studentData = reactive({
}); });
// //
const formData = ref({ const dialogData = ref({
name: "", name: "",
gender: "", gender: "",
studentId: "", studentId: "",
@ -150,8 +245,19 @@ const formData = ref({
major: "", major: "",
classes: "", classes: "",
status: "", status: "",
}) });
const visible = ref(true)
// const AddDialogData = ref({
// name: "",
// gender: "",
// studentId: "",
// department: "",
// major: "",
// classes: "",
// status: "",
// });
const visible = ref(false);
const studentList = ref([]); const studentList = ref([]);
const studentColumns = ref([ const studentColumns = ref([
@ -190,7 +296,7 @@ const studentColumns = ref([
{ {
colKey: "operation", colKey: "operation",
title: "操作", title: "操作",
align: "center" align: "center",
}, },
]); ]);
@ -223,27 +329,32 @@ const onSubmit = async () => {
// //
const onReset = () => { const onReset = () => {
TableData() TableData();
} };
const status = ref([
{ label: "休学", value: 0 },
{ label: "退学", value: 1 },
{ label: "复学", value: 2 },
]);
// //
const TableData = async () => { const TableData = async () => {
const res = await getList() const res = await getList();
// console.log(res); // console.log(res);
studentList.value = res.data.list studentList.value = res.data.list;
pagination.total = res.data.list.length pagination.total = res.data.list.length;
} };
console.log(TableData.name);
onMounted(() => { onMounted(() => {
TableData() TableData();
}) });
// //
const Modify = row => { const Modify = (row) => {
conlose.log(1) console.log("点击了确认按钮,弹出弹窗", row);
visible.value = true; visible.value = true;
formData.value = { dialogData.value = {
name: row.name, name: row.name,
gender: row.gender, gender: row.gender,
studentId: row.studentId, studentId: row.studentId,
@ -254,16 +365,85 @@ const Modify = row => {
}; };
}; };
// const onConfirmAnother = async () => {
// console.log("", );
// visible.value = false;
// await updateStudent(dialogData.value)
// };
const onConfirmAnother = async () => { const onConfirmAnother = async () => {
console.log("点击了确认按钮");
//
const studentId = dialogData.value.studentId;
//
try { try {
// APIupdateStudent const response = await updateStudent({ ...dialogData.value, studentId });
await updateStudent(formData.value); //
// if (response.success) {
visible.value = false; //
TableData(); const index = studentList.value.findIndex(
(stu) => stu.studentId === studentId
);
if (index !== -1) {
studentList.value.splice(index, 1, dialogData.value);
}
MessagePlugin.success("学生信息更新成功");
} else {
MessagePlugin.error(response.message || "学生信息更新失败");
}
} catch (error) { } catch (error) {
console.error('更新学生信息失败:', error); console.error("更新学生信息时发生错误", error);
MessagePlugin.error("学生信息更新失败");
} }
//
visible.value = false;
};
const Delete = async (row) => {
try {
// APIdeleteStudentID
const response = await deleteStudent(row.studentId);
if (response.success) {
//
const index = studentList.value.findIndex((stu) => stu.studentId === row.studentId);
if (index !== -1) {
studentList.value.splice(index, 1);
}
pagination.total -= 1;
//
MessagePlugin.success('学生信息删除成功');
} else {
//
MessagePlugin.error(response.message || '学生信息删除失败');
}
} catch (error) {
console.error('删除学生信息时发生错误', error);
MessagePlugin.error('学生信息删除失败');
}
};
const onAddSubmit = () =>{
console.log("点击新增");
visible.value = true;
}
const close = (context) => {
console.log("关闭弹窗点击关闭按钮、按下ESC、点击蒙层等触发", context);
};
const onCancel = (context) => {
console.log("点击了取消按钮", context);
};
const onEscKeydown = (context) => {
console.log("按下了ESC", context);
};
const onCloseBtnClick = (context) => {
console.log("点击了关闭按钮", context);
};
const onOverlayClick = (context) => {
console.log("点击了蒙层", context);
}; };
</script> </script>