This commit is contained in:
吕才卓 2024-04-08 18:13:54 +08:00
parent 61ea10ecf3
commit fecbc1d096
4 changed files with 220 additions and 94 deletions

View File

@ -1,6 +1,8 @@
import sdy from './modules/sdy' import sdy from './modules/sdy'
import ycy from './modules/ycy' import ycy from './modules/ycy'
import lcz from './modules/lcz'
export default [ export default [
...sdy, ...sdy,
...ycy ...ycy,
...lcz,
] ]

40
mock/modules/lcz.js Normal file
View File

@ -0,0 +1,40 @@
import Mock from "mockjs";
function randomGender() {
return ['男', '女'][Math.floor(Math.random() * 2)];
}
const student = Mock.mock({
"list|100": [
{
id: '@id',
name: '@cname',
gender: randomGender(),
studentId: '@id',
department: function () {
return ['计算机科学系', '数学系', '物理系', '化学系'][this.random(0, 3)];
},
major: function () {
return ['计算机科学与技术', '数学', '物理学', '化学', '生物学', '经济学'][this.random(0, 5)];
},
classes: function () {
return ['一班', '二班', '三班', '四班', '五班'][this.random(0, 4)];
},
status: function () {
return ['休学', '退学', '复学'][this.random(0, 2)];
}
}
]
})
export default [
{
url: '/api/student',
method: 'post',
response: (config) => {
return {
code: 200,
data: student.list
};
}
}
];

View File

@ -1,7 +1,5 @@
import request from "@/utils/request"; import request from "@/utils/request";
// 统一管理接口
const API = {
STUDENT_URL: "/api/student",
};
export const reqStudent = () => request.post(API.STUDENT_URL); export function APIStudent(data) {
return request.post('/api/student', data)
}

View File

@ -1,129 +1,193 @@
<template> <template>
<t-space direction="vertical"> <div class="back-color">
<t-form ref="searchForm" @reset="onReset"> <t-layout style="height: 90%; background-color: #f5f7fb">
<t-form-item label="姓名" name="name"> <t-header class="scarch-box">
<t-input v-model="searchCriteria.name" placeholder="请输入姓名"></t-input> <t-modal
</t-form-item> v-model="isModalVisible"
<t-form-item label="学号" name="studentId"> @confirm="onSave"
<t-input v-model="searchCriteria.studentId" placeholder="请输入学号"></t-input> @cancel="onModalCancel"
</t-form-item> title="修改学生信息"
<t-form-item> >
<t-space size="10px"> <t-form ref="searchForm" @reset="onReset" class="scarch-from">
<t-button theme="primary" type="submit" @click="onSearch">查询</t-button> <div style="margin-left: 1rem">
<t-button theme="default" variant="base" type="reset">重置</t-button> <t-form-item label="姓名" name="name">
</t-space> <t-input
</t-form-item> v-model="searchCriteria.name"
</t-form> placeholder="请输入姓名"
></t-input>
<t-space> </t-form-item>
<t-checkbox v-model="stripe">显示斑马纹</t-checkbox> </div>
<t-checkbox v-model="bordered">显示表格边框</t-checkbox> <div style="margin-left: 1rem">
<t-checkbox v-model="hover">显示悬浮效果</t-checkbox> <t-form-item label="学号" name="studentId">
<t-checkbox v-model="tableLayout">宽度自适应</t-checkbox> <t-input
<t-checkbox v-model="showHeader">显示表头</t-checkbox> v-model="searchCriteria.studentId"
</t-space> placeholder="请输入学号"
></t-input>
<t-table </t-form-item>
rowKey="studentId" </div>
:data="studentList" <t-form-item style="margin-right: 1rem">
:columns="studentColumns" <t-space size="10px">
:stripe="stripe" <t-button theme="primary" type="submit" @click="onSearch"
:bordered="bordered" >查询</t-button
:hover="hover" >
:size="size" <t-button theme="default" variant="base" type="reset"
:table-layout="tableLayout ? 'auto' : 'fixed'" >重置</t-button
:pagination="pagination" >
:showHeader="showHeader" </t-space>
cellEmptyContent="-" </t-form-item>
resizable </t-form>
></t-table> </t-modal>
</t-space> </t-header>
<!-- 动态操作列 --> <t-content class="table-box">
<!-- <t-table-column label="操作"> <t-table
<template #default="{ row }"> rowKey="studentId"
<t-button-group> :data="studentList"
<t-button @click="handleLeave(row)">休学</t-button> :columns="studentColumns"
<t-button @click="handleWithdraw(row)">退学</t-button> :stripe="stripe"
<t-button @click="handleReturn(row)">复学</t-button> :bordered="bordered"
</t-button-group> :hover="hover"
</template> :size="size"
</t-table-column> --> :table-layout="tableLayout ? 'auto' : 'fixed'"
:pagination="pagination"
:showHeader="showHeader"
cellEmptyContent="-"
resizable
>
<template #operation="slotProps">
<t-button
theme="default"
variant="text"
size="small"
@click="showEditModal(slotProps)"
>修改</t-button
>
</template>
</t-table>
</t-content>
</t-layout>
</div>
</template> </template>
<script setup> <script setup>
import { ref, reactive, computed } from 'vue'; import { ref, reactive, computed } from "vue";
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";
import { APIStudent } from "@/api/students";
const isModalVisible = ref(false);
const editStudent = ref({});
//
const showEditModal = (student) => {
isModalVisible.value = true;
editStudent.value = Object.assign({}, student);
};
//
const onSave = () => {
// API updateStudent
updateStudent(editStudent.value).then(() => {
//
isModalVisible.value = false;
// studentList
});
};
//
const onModalCancel = () => {
isModalVisible.value = false;
editStudent.value = {};
};
const router = useRouter(); const router = useRouter();
const searchForm = ref(null); const searchForm = ref(null);
const initialStudentData = []; const initialStudentData = [];
const total = 28; const total = 28;
for (let i = 0; i < total; i++) { for (let i = 0; i < total; i++) {
let statusValue = ["休学", "退学", "复学"][i % 3];
initialStudentData.push({ initialStudentData.push({
studentId: `${'S'}${i + 1}`, Id: `${i + 1}`,
name: ['贾明', '张三', '王芳'][i % 3], name: ["贾明", "张三", "王芳"][i % 3],
gender: ['男', '女'][i % 2], gender: ["男", "女"][i % 2],
departmentCode: 'D' + (i % 4 + 1), studentId: i + 1000000000,
department: ['计算机科学系', '数学系', '物理系', '化学系'][i % 4], department: ["计算机科学系", "数学系", "物理系", "化学系"][i % 4],
className: 'C' + (i % 5 + 1), major: ["计算机科学与技术", "数学", "物理学", "化学", "生物学", "经济学"][
majorCode: 'M' + (i % 6 + 1), i % 6
major: ['计算机科学与技术', '数学', '物理学', '化学', '生物学', '经济学'][i % 6], ],
classCode: 'C' + (i % 5 + 1), classes: ["一班", "二班", "三班", "四班", "五班"][i % 5],
classes: ['一班', '二班', '三班', '四班', '五班'][i % 5], status: statusValue,
}); });
} }
// //
const searchCriteria = reactive({ name: '', studentId: '' }); const searchCriteria = reactive({ name: "", studentId: "" });
// //
const studentList = computed(() => { const studentList = computed(() => {
return initialStudentData.filter(student => return initialStudentData.filter(
(!searchCriteria.name || student.name.includes(searchCriteria.name)) && (student) =>
(!searchCriteria.studentId || student.studentId === searchCriteria.studentId) (!searchCriteria.name || student.name.includes(searchCriteria.name)) &&
(!searchCriteria.studentId ||
student.studentId === searchCriteria.studentId)
); );
}); });
// //
const studentColumns = ref([ const studentColumns = ref([
{ {
colKey: 'studentId', colKey: "Id",
title: '学号', title: "序号",
}, },
{ {
colKey: 'name', colKey: "name",
title: '姓名', title: "姓名",
}, },
{ {
colKey: 'gender', colKey: "gender",
title: '性别', title: "性别",
}, },
{ {
colKey: 'department', colKey: "studentId",
title: '系院', title: "学号",
}, },
{ {
colKey: 'major', colKey: "department",
title: '专业', title: "系院",
}, },
{ {
colKey: 'classes', colKey: "major",
title: '班级', title: "专业",
},
{
colKey: "classes",
title: "班级",
},
{
colKey: "status",
title: "状态",
formatter: (value) => {
switch (value) {
case "休学":
return "休学";
case "退学":
return "退学";
case "复学":
return "复学";
default:
return "-";
}
},
},
{
colKey: "operation",
title: "操作",
}, },
]); ]);
const size = ref('medium');
const tableLayout = ref(false);
const stripe = ref(false);
const bordered = ref(false);
const hover = ref(true);
const showHeader = ref(true);
const pagination = reactive({ const pagination = reactive({
defaultCurrent: 1, defaultCurrent: 1,
defaultPageSize: 5, defaultPageSize: 10,
total: initialStudentData.length, total: initialStudentData.length,
}); });
@ -133,14 +197,36 @@ const onSearch = () => {
}; };
const onReset = () => { const onReset = () => {
searchCriteria.name = ''; searchCriteria.name = "";
searchCriteria.studentId = ''; searchCriteria.studentId = "";
pagination.defaultCurrent = 1; pagination.defaultCurrent = 1;
MessagePlugin.success("重置成功"); MessagePlugin.success("重置成功");
}; };
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>
.scarch-box {
width: 100%;
background-color: @base-white-color;
margin-bottom: 2rem;
.scarch-from {
height: 3.75rem;
display: flex;
justify-content: space-between;
align-items: center;
}
}
.table-box {
height: 42rem;
background-color: @base-white-color;
padding: 1rem;
padding-top: 0;
.table-header {
height: 3rem;
display: flex;
justify-content: space-between;
align-items: center;
}
}
</style> </style>