Merge branch 'dev' of https://gitea.dykj.co/sundongyu/dykj-college-back-office-management-system into dev
This commit is contained in:
commit
3a3e268f69
|
@ -29,41 +29,29 @@ export default [
|
|||
{
|
||||
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,
|
||||
response(req) {
|
||||
// 假设req.body的结构是{Id: '唯一标识', ...其他字段}
|
||||
const requestBody = req.body;
|
||||
const studentId = requestBody.Id;
|
||||
|
||||
// 模拟检查数据库中是否存在该id
|
||||
// 在真实环境中,这一步应当由后端服务完成
|
||||
const students = getMockStudents(); // 假设这是存储模拟学生数据的地方
|
||||
const existingStudent = students.find(student => student.id === studentId);
|
||||
|
||||
if (existingStudent) {
|
||||
// 更新数据库中的学生信息(在模拟中,我们直接修改内存中的数据)
|
||||
Object.assign(existingStudent, requestBody);
|
||||
return {
|
||||
code: 200,
|
||||
message: '更新成功',
|
||||
data: existingStudent
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
code: 404,
|
||||
message: '未找到具有该ID的学生'
|
||||
};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -4,5 +4,5 @@ const API = {
|
|||
LOGIN_URL: "/api/login",
|
||||
};
|
||||
|
||||
export const reqUser = () => request.post(API.LOGIN_URL);
|
||||
export const reqUser = (data) => request.post(API.LOGIN_URL,data);
|
||||
// export const reqUserone = (data) => request.post(API.LOGIN_URL, data);
|
|
@ -10,3 +10,9 @@ export function getStudents(studentData) {
|
|||
export function updateStudent(updateStudent) {
|
||||
return request.post('/api-updateStudent', updateStudent)
|
||||
}
|
||||
|
||||
// const API = {
|
||||
// STUDENT_URL: "/api/user",
|
||||
// };
|
||||
|
||||
// export const reqStudent = () => request.get(API.STUDENT_URL);
|
|
@ -59,7 +59,7 @@
|
|||
</div>
|
||||
<t-form-item style="margin-right: 1rem">
|
||||
<t-button theme="primary" type="submit">查询</t-button>
|
||||
<t-button theme="primary" type="reset">重置</t-button>
|
||||
<t-button theme="default" type="reset">重置</t-button>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-header>
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
</div>
|
||||
<t-form-item style="margin-right: 1rem">
|
||||
<t-button theme="primary" type="submit">查询</t-button>
|
||||
<t-button theme="primary" type="reset">重置</t-button>
|
||||
<t-button theme="default" type="reset">重置</t-button>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-header>
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
</div>
|
||||
<t-form-item style="margin-right: 1rem">
|
||||
<t-button theme="primary" type="submit">查询</t-button>
|
||||
<t-button theme="primary" type="reset">重置</t-button>
|
||||
<t-button theme="default" type="reset">重置</t-button>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-header>
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
</div>
|
||||
<t-form-item style="margin-right: 1rem">
|
||||
<t-button theme="primary" type="submit">查询</t-button>
|
||||
<t-button theme="primary" type="reset">重置</t-button>
|
||||
<t-button theme="default" type="reset">重置</t-button>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-header>
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
</div>
|
||||
<t-form-item style="margin-right: 1rem">
|
||||
<t-button theme="primary" type="submit">查询</t-button>
|
||||
<t-button theme="primary" type="reset">重置</t-button>
|
||||
<t-button theme="default" type="reset">重置</t-button>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-header>
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
</div>
|
||||
<t-form-item style="margin-right: 1rem">
|
||||
<t-button theme="primary" type="submit">查询</t-button>
|
||||
<t-button theme="primary" type="reset">重置</t-button>
|
||||
<t-button theme="default" type="reset">重置</t-button>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-header>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
</div>
|
||||
<t-form-item style="margin-right: 1rem">
|
||||
<t-button theme="primary" type="submit">查询</t-button>
|
||||
<t-button theme="primary" type="reset">重置</t-button>
|
||||
<t-button theme="default" type="reset">重置</t-button>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-header>
|
||||
|
|
|
@ -82,45 +82,53 @@ const rules = reactive({
|
|||
},
|
||||
],
|
||||
password: [
|
||||
{
|
||||
required: true,
|
||||
message: "密码必填",
|
||||
},
|
||||
{
|
||||
len: 8,
|
||||
message: "请输入 8 位密码",
|
||||
},
|
||||
{
|
||||
pattern: /^(?=.*[A-Z])(?=.*\d)[A-Za-z\d]{8,}$/u,
|
||||
message: "密码必须包含至少一个大写字母,并由字母和数字组成",
|
||||
},
|
||||
// {
|
||||
// required: false,
|
||||
// message: "密码必填",
|
||||
// },
|
||||
// {
|
||||
// len: 8,
|
||||
// message: "请输入 8 位密码",
|
||||
// },
|
||||
// {
|
||||
// message: "密码必须包含至少一个大写字母,并由字母和数字组成",
|
||||
// },
|
||||
],
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
reqUser();
|
||||
});
|
||||
|
||||
const onSubmit = async () => {
|
||||
try {
|
||||
if (!form || !form.value) {
|
||||
console.warn("form 或 form.value 不存在,无法进行表单验证");
|
||||
return;
|
||||
}
|
||||
const validateResult = await form.value?.validate();
|
||||
if (validateResult?.result) {
|
||||
await reqUser(formData.account, formData.password);
|
||||
MessagePlugin.success("提交成功");
|
||||
await router.push("/");
|
||||
} else {
|
||||
const firstError = validateResult?.errors[0]?.message || "未知错误";
|
||||
console.log("Errors: ", validateResult.errors);
|
||||
MessagePlugin.warning(firstError);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("请求失败:", error);
|
||||
MessagePlugin.error("提交失败");
|
||||
const data1 = {
|
||||
username: formData.account,
|
||||
password: formData.password,
|
||||
};
|
||||
const { data } = await reqUser(data1);
|
||||
|
||||
if (data === true) {
|
||||
MessagePlugin.success("登录成功");
|
||||
router.push("/");
|
||||
} else {
|
||||
MessagePlugin.error("登录失败");
|
||||
}
|
||||
|
||||
// try {
|
||||
// if (!form || !form.value) {
|
||||
// console.warn("form 或 form.value 不存在,无法进行表单验证");
|
||||
// return;
|
||||
// }
|
||||
// const validateResult = await form.value?.validate();
|
||||
// if (validateResult?.result) {
|
||||
|
||||
// MessagePlugin.success("提交成功");
|
||||
// await router.push("/");
|
||||
// } else {
|
||||
// const firstError = validateResult?.errors[0]?.message || "未知错误";
|
||||
// console.log("Errors: ", validateResult.errors);
|
||||
// MessagePlugin.warning(firstError);
|
||||
// }
|
||||
// } catch (error) {
|
||||
// console.error("请求失败:", error);
|
||||
// MessagePlugin.error("提交失败");
|
||||
// }
|
||||
};
|
||||
|
||||
function handleForgotPasswordClick() {
|
||||
|
|
|
@ -153,7 +153,7 @@ const onValidate = ({ validateResult, firstError }) => {
|
|||
justify-content: center;
|
||||
align-items: center;
|
||||
height: 100vh;
|
||||
background-image: url(../../assets/bg1.jpg);
|
||||
background-image: url(../../assets/bg.jpg);
|
||||
background-size: cover;
|
||||
padding: 2rem;
|
||||
}
|
||||
|
|
|
@ -5,24 +5,26 @@
|
|||
<t-form
|
||||
ref="form"
|
||||
:data="studentData"
|
||||
reset-type="initial"
|
||||
label-width="calc(2em + 40px)"
|
||||
layout="inline"
|
||||
class="scarch-from"
|
||||
colon
|
||||
@reset="onReset"
|
||||
@submit="onSubmit"
|
||||
>
|
||||
<t-row class="scarch-from">
|
||||
<t-col :span="3">
|
||||
<div style="margin-left: 0.5rem">
|
||||
|
||||
<t-form-item label="姓名" name="name">
|
||||
<t-input v-model="studentData.name"></t-input>
|
||||
</t-form-item>
|
||||
</t-col>
|
||||
<t-col :span="3">
|
||||
|
||||
<t-form-item label="学号" name="studentId">
|
||||
<t-input v-model="studentData.studentId"></t-input>
|
||||
</t-form-item>
|
||||
</t-col>
|
||||
<t-col :push="2" :span="4">
|
||||
<t-button theme="primary" type="submit">查询</t-button>
|
||||
</div>
|
||||
<t-form-item style="margin-right: 1rem">
|
||||
|
||||
<t-button theme="primary" type="submit">查询</t-button>
|
||||
<t-button
|
||||
theme="default"
|
||||
variant="base"
|
||||
|
@ -30,8 +32,7 @@
|
|||
style="margin-left: 1rem"
|
||||
>重置</t-button
|
||||
>
|
||||
</t-col>
|
||||
</t-row>
|
||||
</t-form-item>
|
||||
</t-form>
|
||||
</t-header>
|
||||
<t-content class="table-box">
|
||||
|
@ -40,29 +41,32 @@
|
|||
<h4 style="font-size: 110%">学生列表</h4>
|
||||
</div>
|
||||
<div>
|
||||
<t-button theme="primary" size="small" style="margin-right:2.5rem" @click="onAddSubmit">
|
||||
<t-button theme="primary" size="small" style="margin-right:0rem" @click="onAddSubmit">
|
||||
<template #icon><add-icon /></template>
|
||||
增加学员信息
|
||||
</t-button>
|
||||
<t-button
|
||||
shape="circle"
|
||||
theme="primary"
|
||||
@click="refresh"
|
||||
style="margin-left: 0.8rem"
|
||||
>
|
||||
<template #icon><load-icon /></template>
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
<t-table
|
||||
<t-base-table
|
||||
rowKey="Id"
|
||||
:data="studentList"
|
||||
:columns="studentColumns"
|
||||
:stripe="stripe"
|
||||
: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"
|
||||
max-height="550"
|
||||
>
|
||||
<template #operation="{ row }">
|
||||
<t-button
|
||||
|
@ -78,13 +82,13 @@
|
|||
>
|
||||
</t-popconfirm>
|
||||
</template>
|
||||
</t-table>
|
||||
</t-base-table>
|
||||
</t-content>
|
||||
</t-layout>
|
||||
|
||||
<t-space>
|
||||
<t-dialog
|
||||
v-model="visible"
|
||||
v-model:visible="visible"
|
||||
header="学生变动处理"
|
||||
width="40%"
|
||||
:confirm-on-enter="true"
|
||||
|
@ -147,85 +151,21 @@
|
|||
</t-space>
|
||||
</t-dialog>
|
||||
</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>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, computed, onMounted } from "vue";
|
||||
import { ref, computed, onMounted } from "vue";
|
||||
import { getList, getStudents, updateStudent } from "@/api/students";
|
||||
// import {reqStudent} from "@/api/students";
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
import { useRouter } from "vue-router";
|
||||
import { AddIcon, LoadIcon } from "tdesign-icons-vue-next";
|
||||
// import { reqStudent } from "@/api/students";
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const studentData = reactive({
|
||||
const studentData = ref({
|
||||
Id: "",
|
||||
name: "",
|
||||
gender: "",
|
||||
|
@ -247,16 +187,6 @@ const dialogData = ref({
|
|||
status: "",
|
||||
});
|
||||
|
||||
// const AddDialogData = ref({
|
||||
// name: "",
|
||||
// gender: "",
|
||||
// studentId: "",
|
||||
// department: "",
|
||||
// major: "",
|
||||
// classes: "",
|
||||
// status: "",
|
||||
// });
|
||||
|
||||
const visible = ref(false);
|
||||
const studentList = ref([]);
|
||||
|
||||
|
@ -264,43 +194,60 @@ const studentColumns = ref([
|
|||
{
|
||||
colKey: "Id",
|
||||
title: "序号",
|
||||
width: "100",
|
||||
},
|
||||
{
|
||||
colKey: "name",
|
||||
title: "姓名",
|
||||
align: "center",
|
||||
width: "100",
|
||||
|
||||
},
|
||||
{
|
||||
colKey: "gender",
|
||||
title: "性别",
|
||||
align: "center",
|
||||
width: "100",
|
||||
},
|
||||
{
|
||||
colKey: "studentId",
|
||||
title: "学号",
|
||||
align: "center",
|
||||
width: "150",
|
||||
},
|
||||
{
|
||||
colKey: "department",
|
||||
title: "系院",
|
||||
align: "center",
|
||||
width: "150",
|
||||
},
|
||||
{
|
||||
colKey: "major",
|
||||
title: "专业",
|
||||
align: "center",
|
||||
width: "150",
|
||||
},
|
||||
{
|
||||
colKey: "classes",
|
||||
title: "班级",
|
||||
align: "center",
|
||||
width: "150",
|
||||
},
|
||||
{
|
||||
colKey: "status",
|
||||
title: "状态",
|
||||
align: "center",
|
||||
width: "150",
|
||||
},
|
||||
{
|
||||
colKey: "operation",
|
||||
title: "操作",
|
||||
align: "center",
|
||||
width: "150",
|
||||
},
|
||||
]);
|
||||
|
||||
const pagination = reactive({
|
||||
const pagination = ref({
|
||||
defaultCurrent: 1,
|
||||
defaultPageSize: 10,
|
||||
total: 0,
|
||||
|
@ -343,7 +290,7 @@ const TableData = async () => {
|
|||
const res = await getList();
|
||||
// console.log(res);
|
||||
studentList.value = res.data.list;
|
||||
pagination.total = res.data.list.length;
|
||||
pagination.value.total = res.data.list.length;
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
|
@ -355,47 +302,64 @@ const Modify = (row) => {
|
|||
console.log("点击了确认按钮,弹出弹窗", row);
|
||||
visible.value = true;
|
||||
dialogData.value = {
|
||||
name: row.name,
|
||||
gender: row.gender,
|
||||
studentId: row.studentId,
|
||||
department: row.department,
|
||||
major: row.major,
|
||||
classes: row.classes,
|
||||
status: row.status,
|
||||
...row
|
||||
};
|
||||
};
|
||||
|
||||
const onAddSubmit = async ({ validateResult, firstError }) => {
|
||||
if (validateResult === true) {
|
||||
await TableData.addStockList(dialogData.value);
|
||||
getNewTable();
|
||||
MessagePlugin.success("提交成功");
|
||||
visible.value = false;
|
||||
} else {
|
||||
console.log("Validate Errors: ", firstError, validateResult);
|
||||
}
|
||||
};
|
||||
// const onConfirmAnother = async () => {
|
||||
// console.log("点击了确认按钮", );
|
||||
// visible.value = false;
|
||||
// await updateStudent(dialogData.value)
|
||||
|
||||
// };
|
||||
const onConfirmAnother = async () => {
|
||||
console.log("点击了确认按钮");
|
||||
// 准备要更新的数据
|
||||
const studentId = dialogData.value.studentId;
|
||||
// 调用更新学生信息的接口
|
||||
try {
|
||||
const response = await updateStudent({ ...dialogData.value, studentId });
|
||||
// 检查接口返回结果是否成功
|
||||
if (response.success) {
|
||||
// 同步更新表格数据(这部分逻辑已在之前的解答中给出)
|
||||
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) {
|
||||
console.error("更新学生信息时发生错误", error);
|
||||
MessagePlugin.error("学生信息更新失败");
|
||||
}
|
||||
const onConfirmAnother = async () => {
|
||||
// const index = studentList.value.findIndex((item)=> item.Id === .Id)
|
||||
// await aaa(dialogData.value)
|
||||
// TableData()
|
||||
// if (index !== -1) {
|
||||
// studentList.value.splice(index,dialogData.value)
|
||||
|
||||
// }else{
|
||||
// console.log(11111);
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
// console.log("点击了确认按钮" ,studentId);
|
||||
// // 准备要更新的数据
|
||||
// const studentId = dialogData.value.studentId;
|
||||
// // 调用更新学生信息的接口
|
||||
// try {
|
||||
// const response = await updateStudent({ ...dialogData.value, studentId });
|
||||
// // 检查接口返回结果是否成功
|
||||
// if (response) {
|
||||
// // 同步更新表格数据(这部分逻辑已在之前的解答中给出)
|
||||
// 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) {
|
||||
// console.error("更新学生信息时发生错误", error);
|
||||
// MessagePlugin.error("学生信息更新失败");
|
||||
// }
|
||||
// 关闭对话框
|
||||
visible.value = false;
|
||||
};
|
||||
|
@ -426,10 +390,6 @@ const Delete = async (row) => {
|
|||
}
|
||||
};
|
||||
|
||||
const onAddSubmit = () =>{
|
||||
console.log("点击新增");
|
||||
visible.value = true;
|
||||
}
|
||||
const close = (context) => {
|
||||
console.log("关闭弹窗,点击关闭按钮、按下ESC、点击蒙层等触发", context);
|
||||
};
|
||||
|
@ -453,7 +413,7 @@ const onOverlayClick = (context) => {
|
|||
background-color: @base-white-color;
|
||||
margin-bottom: 2rem;
|
||||
.scarch-from {
|
||||
height: 3.75rem;
|
||||
height: 60px;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
|
@ -472,4 +432,7 @@ const onOverlayClick = (context) => {
|
|||
align-items: center;
|
||||
}
|
||||
}
|
||||
:deep(.t-form__controls-content) {
|
||||
justify-content: space-between;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -11,7 +11,7 @@ export default defineConfig({
|
|||
server: {
|
||||
proxy: {
|
||||
"/api": {
|
||||
target: "http://192.168.1.10:8080",
|
||||
target: "http://192.168.1.2:8080",
|
||||
changeOrigin: true,
|
||||
},
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue
Block a user