提交代码,在sys_user表中新增了account_type字段来区分学生和老师
This commit is contained in:
1 parent
b215f7b9b3
commit
0c6d70cc4c
26 files changed
+5917
-3
No files matched your search
@@ -0,0 +1,65 @@
|
||||
import request from '@/utils/request';
|
||||
|
||||
// 获取管理员列表
|
||||
export function getAdminList(params?: any) {
|
||||
// 根据不同类型构造不同参数
|
||||
return request({
|
||||
url: '/studentMsg/admin/list',
|
||||
method: 'get',
|
||||
params
|
||||
});
|
||||
}
|
||||
|
||||
// 新增管理员
|
||||
export function addAdmin(data: any) {
|
||||
return request({
|
||||
url: '/studentMsg/admin',
|
||||
method: 'post',
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
// 更新管理员
|
||||
export function updateAdmin(data: any) {
|
||||
return request({
|
||||
url: '/studentMsg/admin',
|
||||
method: 'put',
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
// 删除管理员
|
||||
export function deleteAdmin(id: number | string) {
|
||||
return request({
|
||||
url: `/studentMsg/admin/${id}`,
|
||||
method: 'delete'
|
||||
});
|
||||
}
|
||||
|
||||
// 分配范围
|
||||
export function assignScope(params: any, data: any) {
|
||||
return request({
|
||||
url: '/studentMsg/admin/assignScope',
|
||||
method: 'post',
|
||||
params,
|
||||
data
|
||||
});
|
||||
}
|
||||
|
||||
// 获取范围名称
|
||||
export function getScopeNames(params: any) {
|
||||
return request({
|
||||
url: '/studentMsg/admin/getScopeNames',
|
||||
method: 'get',
|
||||
params
|
||||
});
|
||||
}
|
||||
|
||||
// 获取可分配的范围
|
||||
export function getScopeOptions(type: string) {
|
||||
return request({
|
||||
url: '/studentMsg/admin/getScopeOptions',
|
||||
method: 'get',
|
||||
params: { type }
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,424 @@
|
||||
import request from '@/utils/request';
|
||||
import { AxiosPromise } from 'axios';
|
||||
import { StudentQuery, StudentVO, StudentForm, XgDeptTreeVO, R, TableDataInfo } from './types';
|
||||
|
||||
|
||||
/**
|
||||
* 查询部门下拉树结构
|
||||
* @param deptId 部门ID
|
||||
*/
|
||||
export const XgDeptTreeSelect = (belongDeptId?: number): AxiosPromise<XgDeptTreeVO[]> => {
|
||||
// 实际项目中连接后端接口
|
||||
return request({
|
||||
url: '/system/user/deptTree',
|
||||
method: 'get',
|
||||
params: {
|
||||
belongDeptId
|
||||
}
|
||||
});
|
||||
|
||||
// // 模拟数据,直接返回与页面组件期望格式一致的数据
|
||||
// return Promise.resolve({
|
||||
// data: mockDeptTree,
|
||||
// status: 200,
|
||||
// statusText: 'OK',
|
||||
// headers: {},
|
||||
// config: {} as any
|
||||
// }) as any;
|
||||
};
|
||||
|
||||
|
||||
// 查询学生列表
|
||||
export function listStudent(query?: StudentQuery): AxiosPromise<R<TableDataInfo<StudentVO[]>>> {
|
||||
// 实际使用时连接后端接口
|
||||
// return request({
|
||||
// url: '/studentMsg/student/list',
|
||||
// method: 'get',
|
||||
// params: query
|
||||
// });
|
||||
|
||||
// 模拟数据
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
code: 200,
|
||||
msg: 'success',
|
||||
data: {
|
||||
total: mockStudentData.length,
|
||||
rows: mockStudentData
|
||||
}
|
||||
}
|
||||
} as any);
|
||||
}
|
||||
|
||||
// 查询学生详细
|
||||
export function getStudent(studentId?: string | number): AxiosPromise<R<{
|
||||
student: StudentVO;
|
||||
majors: any[];
|
||||
classes: any[];
|
||||
}>> {
|
||||
if (studentId) {
|
||||
// 实际使用时连接后端接口
|
||||
// return request({
|
||||
// url: '/studentMsg/student/' + studentId,
|
||||
// method: 'get'
|
||||
// });
|
||||
|
||||
// 模拟数据
|
||||
const student = mockStudentData.find(item => item.studentId === studentId);
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
code: 200,
|
||||
msg: 'success',
|
||||
data: {
|
||||
student: student || {},
|
||||
majors: mockMajors,
|
||||
classes: mockClasses
|
||||
}
|
||||
}
|
||||
} as any);
|
||||
} else {
|
||||
// 新增时返回初始空对象和选项数据
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
code: 200,
|
||||
msg: 'success',
|
||||
data: {
|
||||
student: {},
|
||||
majors: mockMajors,
|
||||
classes: mockClasses
|
||||
}
|
||||
}
|
||||
} as any);
|
||||
}
|
||||
}
|
||||
|
||||
// 新增学生
|
||||
export function addStudent(data: StudentForm): AxiosPromise<R<any>> {
|
||||
// 实际使用时连接后端接口
|
||||
// return request({
|
||||
// url: '/studentMsg/student',
|
||||
// method: 'post',
|
||||
// data: data
|
||||
// });
|
||||
|
||||
// 模拟数据
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
code: 200,
|
||||
msg: '添加成功'
|
||||
}
|
||||
} as any);
|
||||
}
|
||||
|
||||
// 修改学生
|
||||
export function updateStudent(data: StudentForm): AxiosPromise<R<any>> {
|
||||
// 实际使用时连接后端接口
|
||||
// return request({
|
||||
// url: '/studentMsg/student',
|
||||
// method: 'put',
|
||||
// data: data
|
||||
// });
|
||||
|
||||
// 模拟数据
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
code: 200,
|
||||
msg: '修改成功'
|
||||
}
|
||||
} as any);
|
||||
}
|
||||
|
||||
// 删除学生
|
||||
export function delStudent(studentId: string | number | Array<string | number>): AxiosPromise<R<any>> {
|
||||
// 实际使用时连接后端接口
|
||||
// return request({
|
||||
// url: '/studentMsg/student/' + studentId,
|
||||
// method: 'delete'
|
||||
// });
|
||||
|
||||
// 模拟数据
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
code: 200,
|
||||
msg: '删除成功'
|
||||
}
|
||||
} as any);
|
||||
}
|
||||
|
||||
// 查询院系树结构
|
||||
export function deptTreeSelect(): AxiosPromise<R<any>> {
|
||||
// 实际使用时连接后端接口
|
||||
// return request({
|
||||
// url: '/studentMsg/dept/treeselect',
|
||||
// method: 'get'
|
||||
// });
|
||||
|
||||
// 模拟数据
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
code: 200,
|
||||
msg: 'success',
|
||||
data: mockDeptTree
|
||||
}
|
||||
} as any);
|
||||
}
|
||||
|
||||
// 导出学生
|
||||
export function exportStudent(query?: StudentQuery): AxiosPromise<any> {
|
||||
// 实际使用时连接后端接口
|
||||
// return request({
|
||||
// url: '/studentMsg/student/export',
|
||||
// method: 'get',
|
||||
// params: query
|
||||
// });
|
||||
|
||||
// 模拟数据
|
||||
return Promise.resolve({
|
||||
data: mockStudentData,
|
||||
status: 200,
|
||||
statusText: 'OK',
|
||||
headers: {},
|
||||
config: {} as any
|
||||
}) as any;
|
||||
}
|
||||
|
||||
// 学生状态修改
|
||||
export function changeStudentStatus(studentId: string | number, status: string): AxiosPromise<R<any>> {
|
||||
// 实际使用时连接后端接口
|
||||
// return request({
|
||||
// url: '/studentMsg/student/changeStatus',
|
||||
// method: 'put',
|
||||
// data: {
|
||||
// studentId,
|
||||
// status
|
||||
// }
|
||||
// });
|
||||
|
||||
// 模拟数据
|
||||
return Promise.resolve({
|
||||
data: {
|
||||
code: 200,
|
||||
msg: '状态修改成功'
|
||||
}
|
||||
} as any);
|
||||
}
|
||||
|
||||
// 模拟数据 - 学生列表
|
||||
const mockStudentData: StudentVO[] = [
|
||||
{
|
||||
studentId: 1,
|
||||
studentNo: '202001001',
|
||||
studentName: '张三',
|
||||
nickName: '小张',
|
||||
sex: '0',
|
||||
age: 20,
|
||||
phonenumber: '13800138001',
|
||||
email: 'zhangsan@example.com',
|
||||
idCard: '110101200101011234',
|
||||
deptId: 105,
|
||||
deptName: '计算机科学与技术系',
|
||||
majorId: 1,
|
||||
majorName: '计算机科学与技术',
|
||||
classId: 101,
|
||||
className: '计算机2001班',
|
||||
address: '北京市海淀区',
|
||||
status: '0',
|
||||
createTime: '2023-01-01 10:00:00',
|
||||
remark: ''
|
||||
},
|
||||
{
|
||||
studentId: 2,
|
||||
studentNo: '202001002',
|
||||
studentName: '李四',
|
||||
nickName: '小李',
|
||||
sex: '0',
|
||||
age: 21,
|
||||
phonenumber: '13800138002',
|
||||
email: 'lisi@example.com',
|
||||
idCard: '110101200001011235',
|
||||
deptId: 105,
|
||||
deptName: '计算机科学与技术系',
|
||||
majorId: 1,
|
||||
majorName: '计算机科学与技术',
|
||||
classId: 101,
|
||||
className: '计算机2001班',
|
||||
address: '上海市浦东新区',
|
||||
status: '0',
|
||||
createTime: '2023-01-01 10:10:00',
|
||||
remark: ''
|
||||
},
|
||||
{
|
||||
studentId: 3,
|
||||
studentNo: '202001003',
|
||||
studentName: '王五',
|
||||
nickName: '小王',
|
||||
sex: '0',
|
||||
age: 19,
|
||||
phonenumber: '13800138003',
|
||||
email: 'wangwu@example.com',
|
||||
idCard: '110101200201011236',
|
||||
deptId: 106,
|
||||
deptName: '软件工程系',
|
||||
majorId: 2,
|
||||
majorName: '软件工程',
|
||||
classId: 201,
|
||||
className: '软工2001班',
|
||||
address: '广州市天河区',
|
||||
status: '0',
|
||||
createTime: '2023-01-02 09:00:00',
|
||||
remark: ''
|
||||
},
|
||||
{
|
||||
studentId: 4,
|
||||
studentNo: '202001004',
|
||||
studentName: '赵六',
|
||||
nickName: '小赵',
|
||||
sex: '1',
|
||||
age: 20,
|
||||
phonenumber: '13800138004',
|
||||
email: 'zhaoliu@example.com',
|
||||
idCard: '110101200101011237',
|
||||
deptId: 106,
|
||||
deptName: '软件工程系',
|
||||
majorId: 2,
|
||||
majorName: '软件工程',
|
||||
classId: 201,
|
||||
className: '软工2001班',
|
||||
address: '深圳市南山区',
|
||||
status: '0',
|
||||
createTime: '2023-01-02 10:30:00',
|
||||
remark: ''
|
||||
},
|
||||
{
|
||||
studentId: 5,
|
||||
studentNo: '202001005',
|
||||
studentName: '钱七',
|
||||
nickName: '小钱',
|
||||
sex: '1',
|
||||
age: 21,
|
||||
phonenumber: '13800138005',
|
||||
email: 'qianqi@example.com',
|
||||
idCard: '110101200001011238',
|
||||
deptId: 107,
|
||||
deptName: '人工智能系',
|
||||
majorId: 3,
|
||||
majorName: '人工智能',
|
||||
classId: 301,
|
||||
className: '人工智能2001班',
|
||||
address: '杭州市西湖区',
|
||||
status: '1', // 停用状态
|
||||
createTime: '2023-01-03 11:20:00',
|
||||
remark: '休学中'
|
||||
}
|
||||
];
|
||||
|
||||
// 模拟数据 - 院系树
|
||||
const mockDeptTree = [
|
||||
{
|
||||
id: 100,
|
||||
label: '信息学院',
|
||||
children: [
|
||||
{
|
||||
id: 105,
|
||||
label: '计算机科学与技术系',
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 106,
|
||||
label: '软件工程系',
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 107,
|
||||
label: '人工智能系',
|
||||
children: []
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
id: 200,
|
||||
label: '经济管理学院',
|
||||
children: [
|
||||
{
|
||||
id: 205,
|
||||
label: '市场营销系',
|
||||
children: []
|
||||
},
|
||||
{
|
||||
id: 206,
|
||||
label: '财务管理系',
|
||||
children: []
|
||||
}
|
||||
]
|
||||
}
|
||||
];
|
||||
|
||||
// 模拟数据 - 专业
|
||||
const mockMajors = [
|
||||
{
|
||||
majorId: 1,
|
||||
majorName: '计算机科学与技术',
|
||||
deptId: 105
|
||||
},
|
||||
{
|
||||
majorId: 2,
|
||||
majorName: '软件工程',
|
||||
deptId: 106
|
||||
},
|
||||
{
|
||||
majorId: 3,
|
||||
majorName: '人工智能',
|
||||
deptId: 107
|
||||
},
|
||||
{
|
||||
majorId: 4,
|
||||
majorName: '市场营销',
|
||||
deptId: 205
|
||||
},
|
||||
{
|
||||
majorId: 5,
|
||||
majorName: '财务管理',
|
||||
deptId: 206
|
||||
}
|
||||
];
|
||||
|
||||
// 模拟数据 - 班级
|
||||
const mockClasses = [
|
||||
{
|
||||
classId: 101,
|
||||
className: '计算机2001班',
|
||||
majorId: 1
|
||||
},
|
||||
{
|
||||
classId: 102,
|
||||
className: '计算机2002班',
|
||||
majorId: 1
|
||||
},
|
||||
{
|
||||
classId: 201,
|
||||
className: '软工2001班',
|
||||
majorId: 2
|
||||
},
|
||||
{
|
||||
classId: 202,
|
||||
className: '软工2002班',
|
||||
majorId: 2
|
||||
},
|
||||
{
|
||||
classId: 301,
|
||||
className: '人工智能2001班',
|
||||
majorId: 3
|
||||
},
|
||||
{
|
||||
classId: 401,
|
||||
className: '市场营销2001班',
|
||||
majorId: 4
|
||||
},
|
||||
{
|
||||
classId: 501,
|
||||
className: '财务管理2001班',
|
||||
majorId: 5
|
||||
}
|
||||
];
|
||||
|
||||
export default { listStudent, getStudent, addStudent, updateStudent, delStudent, deptTreeSelect, exportStudent, changeStudentStatus, XgDeptTreeSelect };
|
||||
@@ -0,0 +1,63 @@
|
||||
import request from '@/utils/request';
|
||||
import { AxiosPromise } from 'axios';
|
||||
import { StudentMsgVO, StudentMsgForm, StudentMsgQuery } from '@/api/studentMsg/studentMsg/types';
|
||||
|
||||
/**
|
||||
* 查询学生信息列表
|
||||
* @param query
|
||||
* @returns {*}
|
||||
*/
|
||||
|
||||
export const listStudentMsg = (query?: StudentMsgQuery): AxiosPromise<StudentMsgVO[]> => {
|
||||
return request({
|
||||
url: '/studentMsg/studentMsg/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 查询学生信息详细
|
||||
* @param id
|
||||
*/
|
||||
export const getStudentMsg = (id: string | number): AxiosPromise<StudentMsgVO> => {
|
||||
return request({
|
||||
url: '/studentMsg/studentMsg/' + id,
|
||||
method: 'get'
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 新增学生信息
|
||||
* @param data
|
||||
*/
|
||||
export const addStudentMsg = (data: StudentMsgForm) => {
|
||||
return request({
|
||||
url: '/studentMsg/studentMsg',
|
||||
method: 'post',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 修改学生信息
|
||||
* @param data
|
||||
*/
|
||||
export const updateStudentMsg = (data: StudentMsgForm) => {
|
||||
return request({
|
||||
url: '/studentMsg/studentMsg',
|
||||
method: 'put',
|
||||
data: data
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 删除学生信息
|
||||
* @param id
|
||||
*/
|
||||
export const delStudentMsg = (id: string | number | Array<string | number>) => {
|
||||
return request({
|
||||
url: '/studentMsg/studentMsg/' + id,
|
||||
method: 'delete'
|
||||
});
|
||||
};
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* 部门树结构
|
||||
*/
|
||||
export interface XgDeptTreeVO extends BaseEntity {
|
||||
id: number | string;
|
||||
label: string;
|
||||
parentId: number | string;
|
||||
weight: number;
|
||||
children: XgDeptTreeVO[];
|
||||
disabled: boolean;
|
||||
}
|
||||
|
||||
// 学生查询参数
|
||||
export interface StudentQuery {
|
||||
pageNum: number;
|
||||
pageSize: number;
|
||||
studentName?: string;
|
||||
studentNo?: string;
|
||||
phonenumber?: string;
|
||||
status?: string;
|
||||
deptId?: number;
|
||||
}
|
||||
|
||||
// 学生视图对象
|
||||
export interface StudentVO {
|
||||
studentId: number | string;
|
||||
studentNo: string;
|
||||
studentName: string;
|
||||
nickName?: string;
|
||||
sex?: string;
|
||||
age?: number;
|
||||
phonenumber?: string;
|
||||
email?: string;
|
||||
idCard?: string;
|
||||
deptId?: number;
|
||||
deptName?: string;
|
||||
majorId?: number;
|
||||
majorName?: string;
|
||||
classId?: number;
|
||||
className?: string;
|
||||
address?: string;
|
||||
status?: string;
|
||||
createBy?: number;
|
||||
createTime?: string;
|
||||
updateBy?: number;
|
||||
updateTime?: string;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
// 学生表单对象
|
||||
export interface StudentForm {
|
||||
studentId?: number | string;
|
||||
deptId?: number;
|
||||
studentNo: string;
|
||||
studentName: string;
|
||||
nickName?: string;
|
||||
password?: string;
|
||||
phonenumber?: string;
|
||||
email?: string;
|
||||
idCard?: string;
|
||||
sex?: string;
|
||||
status?: string;
|
||||
majorId?: number;
|
||||
classId?: number;
|
||||
address?: string;
|
||||
remark?: string;
|
||||
}
|
||||
|
||||
// 统一响应类型
|
||||
export interface R<T> {
|
||||
code: number;
|
||||
msg: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
// 表格数据信息类型
|
||||
export interface TableDataInfo<T> {
|
||||
total: number;
|
||||
rows: T;
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:title="mode === 'add' ? '新增' + getTypeLabel(type) : '编辑' + getTypeLabel(type)"
|
||||
v-model="visible"
|
||||
width="500px"
|
||||
append-to-body
|
||||
destroy-on-close
|
||||
>
|
||||
<el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
|
||||
<el-form-item label="姓名" prop="name">
|
||||
<el-input v-model="form.name" placeholder="请输入姓名" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号码" prop="phone">
|
||||
<el-input v-model="form.phone" placeholder="请输入手机号码" />
|
||||
</el-form-item>
|
||||
<el-form-item label="性别" prop="sex">
|
||||
<el-radio-group v-model="form.sex">
|
||||
<el-radio :label="0">男</el-radio>
|
||||
<el-radio :label="1">女</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入备注" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, watchEffect, computed } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
mode: {
|
||||
type: String,
|
||||
default: 'add'
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'school'
|
||||
},
|
||||
admin: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'submit']);
|
||||
|
||||
// 计算属性:对话框可见性
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
});
|
||||
|
||||
// 表单和校验
|
||||
const formRef = ref(null);
|
||||
const form = reactive({
|
||||
id: null,
|
||||
name: '',
|
||||
phone: '',
|
||||
sex: 0,
|
||||
remark: ''
|
||||
});
|
||||
|
||||
// 表单校验规则
|
||||
const rules = reactive({
|
||||
name: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
|
||||
phone: [
|
||||
{ required: true, message: '请输入手机号码', trigger: 'blur' },
|
||||
{ pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: 'blur' }
|
||||
]
|
||||
});
|
||||
|
||||
// 监听传入的admin数据,更新表单
|
||||
watchEffect(() => {
|
||||
if (props.admin) {
|
||||
form.id = props.admin.id;
|
||||
form.name = props.admin.name;
|
||||
form.phone = props.admin.phone;
|
||||
form.sex = props.admin.sex;
|
||||
form.remark = props.admin.remark;
|
||||
}
|
||||
});
|
||||
|
||||
// 根据类型获取标签文本
|
||||
function getTypeLabel(type) {
|
||||
switch (type) {
|
||||
case 'school':
|
||||
return '全校管理员';
|
||||
case 'custom':
|
||||
return '自定义管理员';
|
||||
case 'teacher':
|
||||
return '班主任';
|
||||
default:
|
||||
return '管理员';
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitForm() {
|
||||
formRef.value?.validate((valid) => {
|
||||
if (valid) {
|
||||
// 这里模拟保存
|
||||
emit('submit', {
|
||||
id: form.id,
|
||||
name: form.name,
|
||||
phone: form.phone,
|
||||
sex: form.sex,
|
||||
remark: form.remark,
|
||||
scope: props.admin?.scope || ''
|
||||
});
|
||||
|
||||
ElMessage.success('保存成功');
|
||||
visible.value = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 取消
|
||||
function cancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 暴露组件以修复导出问题
|
||||
defineExpose({
|
||||
submitForm,
|
||||
cancel
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,165 @@
|
||||
<template>
|
||||
<el-dialog :title="getScopeDialogTitle(type)" v-model="visible" width="600px" append-to-body destroy-on-close>
|
||||
<el-form :model="form" label-width="100px">
|
||||
<el-form-item :label="getScopeName(type)">
|
||||
<div v-if="type === 'custom'">
|
||||
<el-checkbox-group v-model="form.selectedScopes">
|
||||
<el-checkbox v-for="item in scopeOptions.custom" :key="item.id" :label="item.id">
|
||||
{{ item.name }}
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
<div v-else-if="type === 'teacher'">
|
||||
<el-checkbox-group v-model="form.selectedScopes">
|
||||
<el-checkbox v-for="item in scopeOptions.teacher" :key="item.id" :label="item.id">
|
||||
{{ item.name }}
|
||||
</el-checkbox>
|
||||
</el-checkbox-group>
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="cancel">取 消</el-button>
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed } from 'vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
admin: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
default: 'custom'
|
||||
}
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:modelValue', 'submit']);
|
||||
|
||||
// 计算属性:对话框可见性
|
||||
const visible = computed({
|
||||
get: () => props.modelValue,
|
||||
set: (value) => emit('update:modelValue', value)
|
||||
});
|
||||
|
||||
// 范围选项(模拟数据)
|
||||
const scopeOptions = {
|
||||
custom: [
|
||||
{ id: 1, name: '高一年级' },
|
||||
{ id: 2, name: '高二年级' },
|
||||
{ id: 3, name: '高三年级' },
|
||||
{ id: 4, name: '初一年级' },
|
||||
{ id: 5, name: '初二年级' },
|
||||
{ id: 6, name: '初三年级' }
|
||||
],
|
||||
teacher: [
|
||||
{ id: 101, name: '高一(1)班' },
|
||||
{ id: 102, name: '高一(2)班' },
|
||||
{ id: 103, name: '高一(3)班' },
|
||||
{ id: 104, name: '高二(1)班' },
|
||||
{ id: 105, name: '高二(2)班' },
|
||||
{ id: 106, name: '高三(1)班' },
|
||||
{ id: 107, name: '高三(2)班' }
|
||||
]
|
||||
};
|
||||
|
||||
// 表单数据
|
||||
const form = reactive({
|
||||
selectedScopes: [] as number[]
|
||||
});
|
||||
|
||||
// 获取范围对话框标题
|
||||
function getScopeDialogTitle(type: string) {
|
||||
const name = props.admin?.name || '';
|
||||
switch (type) {
|
||||
case 'custom':
|
||||
return `为【${name}】分配管理范围`;
|
||||
case 'teacher':
|
||||
return `为【${name}】分配班级`;
|
||||
default:
|
||||
return `为【${name}】分配范围`;
|
||||
}
|
||||
}
|
||||
|
||||
// 获取范围名称
|
||||
function getScopeName(type: string) {
|
||||
switch (type) {
|
||||
case 'custom':
|
||||
return '管理范围';
|
||||
case 'teacher':
|
||||
return '所管理班级';
|
||||
default:
|
||||
return '管理范围';
|
||||
}
|
||||
}
|
||||
|
||||
// 提交表单
|
||||
function submitForm() {
|
||||
// 组装要提交的数据
|
||||
const selectedIds = form.selectedScopes;
|
||||
let scopeName = '';
|
||||
|
||||
// 根据类型获取选中的名称
|
||||
if (type.value === 'custom') {
|
||||
scopeName = scopeOptions.custom
|
||||
.filter((item) => selectedIds.includes(item.id))
|
||||
.map((item) => item.name)
|
||||
.join(', ');
|
||||
} else if (type.value === 'teacher') {
|
||||
scopeName = scopeOptions.teacher
|
||||
.filter((item) => selectedIds.includes(item.id))
|
||||
.map((item) => item.name)
|
||||
.join(', ');
|
||||
}
|
||||
|
||||
// 提交
|
||||
emit('submit', {
|
||||
sourceIds: selectedIds,
|
||||
scopeName: scopeName
|
||||
});
|
||||
|
||||
ElMessage.success('分配成功');
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 取消
|
||||
function cancel() {
|
||||
visible.value = false;
|
||||
}
|
||||
|
||||
// 从props获取类型的响应式引用
|
||||
const type = computed(() => props.type);
|
||||
|
||||
// 暴露组件以修复导出问题
|
||||
defineExpose({
|
||||
submitForm,
|
||||
cancel
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.dialog-footer {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
}
|
||||
.el-checkbox-group {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.el-checkbox {
|
||||
margin-right: 15px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,391 @@
|
||||
<template>
|
||||
<div class="p-2 page-container">
|
||||
<el-card>
|
||||
<el-tabs v-model="activeTab">
|
||||
<el-tab-pane label="全校管理员" name="school">
|
||||
<!-- 检索栏(全校管理员) -->
|
||||
<div class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
<el-form :inline="true" :model="schoolSearchForm" class="search-form">
|
||||
<el-form-item label="姓名">
|
||||
<el-input v-model="schoolSearchForm.name" placeholder="请输入姓名" clearable @keyup.enter="handleSearch('school')" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号码">
|
||||
<el-input v-model="schoolSearchForm.phone" placeholder="请输入手机号码" clearable @keyup.enter="handleSearch('school')" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleSearch('school')">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="handleReset('school')">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
<!-- 按钮+列表区域 -->
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="onAdd('school')">新增管理员</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
<el-table :data="filteredAdmins('school')" border>
|
||||
<el-table-column prop="name" label="姓名" align="center" />
|
||||
<el-table-column prop="phone" label="手机号码" align="center" />
|
||||
<el-table-column prop="sex" label="性别" align="center">
|
||||
<template #default="scope">
|
||||
{{ scope.row.sex === 0 ? '男' : '女' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="remark" label="备注" align="center" />
|
||||
<el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="编辑" placement="top">
|
||||
<el-button link type="primary" plain icon="Edit" @click="onEdit('school', scope.row)" />
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button link type="danger" plain icon="Delete" @click="onDelete('school', scope.row)" />
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="自定义管理员" name="custom">
|
||||
<!-- 检索栏(自定义管理员) -->
|
||||
<div class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
<el-form :inline="true" :model="customSearchForm" class="search-form">
|
||||
<el-form-item label="姓名">
|
||||
<el-input v-model="customSearchForm.name" placeholder="请输入姓名" clearable @keyup.enter="handleSearch('custom')" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号码">
|
||||
<el-input v-model="customSearchForm.phone" placeholder="请输入手机号码" clearable @keyup.enter="handleSearch('custom')" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleSearch('custom')">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="handleReset('custom')">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="onAdd('custom')">新增管理员</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
<el-table :data="filteredAdmins('custom')" border>
|
||||
<el-table-column prop="name" label="姓名" align="center" />
|
||||
<el-table-column prop="phone" label="手机号码" align="center" />
|
||||
<el-table-column prop="sex" label="性别" align="center">
|
||||
<template #default="scope">
|
||||
{{ scope.row.sex === 0 ? '男' : '女' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="scope" label="管理范围" align="center" />
|
||||
<el-table-column prop="remark" label="备注" align="center" />
|
||||
<el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="编辑" placement="top">
|
||||
<el-button link type="primary" plain icon="Edit" @click="onEdit('custom', scope.row)" />
|
||||
</el-tooltip>
|
||||
<el-tooltip content="分配范围" placement="top">
|
||||
<el-button link type="warning" plain icon="Setting" @click="onScope('custom', scope.row)" />
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button link type="danger" plain icon="Delete" @click="onDelete('custom', scope.row)" />
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="班主任" name="teacher">
|
||||
<!-- 检索栏(班主任) -->
|
||||
<div class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
<el-form :inline="true" :model="teacherSearchForm" class="search-form">
|
||||
<el-form-item label="姓名">
|
||||
<el-input v-model="teacherSearchForm.name" placeholder="请输入姓名" clearable @keyup.enter="handleSearch('teacher')" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号码">
|
||||
<el-input v-model="teacherSearchForm.phone" placeholder="请输入手机号码" clearable @keyup.enter="handleSearch('teacher')" />
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleSearch('teacher')">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="handleReset('teacher')">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
<el-card shadow="never">
|
||||
<template #header>
|
||||
<el-row :gutter="10" class="mb8">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="onAdd('teacher')">新增班主任</el-button>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</template>
|
||||
<el-table :data="filteredAdmins('teacher')" border>
|
||||
<el-table-column prop="name" label="姓名" align="center" />
|
||||
<el-table-column prop="phone" label="手机号码" align="center" />
|
||||
<el-table-column prop="sex" label="性别" align="center">
|
||||
<template #default="scope">
|
||||
{{ scope.row.sex === 0 ? '男' : '女' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="scope" label="所管理班级" align="center" />
|
||||
<el-table-column prop="remark" label="备注" align="center" />
|
||||
<el-table-column label="操作" align="center" width="200" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="编辑" placement="top">
|
||||
<el-button link type="primary" plain icon="Edit" @click="onEdit('teacher', scope.row)" />
|
||||
</el-tooltip>
|
||||
<el-tooltip content="分配班级" placement="top">
|
||||
<el-button link type="warning" plain icon="Setting" @click="onScope('teacher', scope.row)" />
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button link type="danger" plain icon="Delete" @click="onDelete('teacher', scope.row)" />
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<admin-dialog v-model="dialogVisible" :mode="dialogMode" :admin="currentAdmin" :type="activeTab" @submit="onDialogSubmit" />
|
||||
<scope-dialog v-model="scopeDialogVisible" :admin="currentAdmin" :type="scopeType" @submit="onScopeSubmit" />
|
||||
</el-card>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import AdminDialog from './components/AdminDialog.vue';
|
||||
import ScopeDialog from './components/ScopeDialog.vue';
|
||||
import { ElMessage, ElMessageBox } from 'element-plus';
|
||||
|
||||
// 暴露组件以修复导出问题
|
||||
defineExpose({});
|
||||
|
||||
// 导入改为使用模拟数据
|
||||
// import { getAdminList, deleteAdmin, assignScope, getScopeNames } from '@/api/studentMsg/authmsg';
|
||||
|
||||
const activeTab = ref('school');
|
||||
|
||||
// 各tab独立检索表单
|
||||
const schoolSearchForm = reactive({ name: '', phone: '' });
|
||||
const customSearchForm = reactive({ name: '', phone: '' });
|
||||
const teacherSearchForm = reactive({ name: '', phone: '' });
|
||||
|
||||
// 管理员数据
|
||||
const schoolAdmins = ref([]);
|
||||
const customAdmins = ref([]);
|
||||
const teacherAdmins = ref([]);
|
||||
|
||||
const dialogVisible = ref(false);
|
||||
const dialogMode = ref<'add' | 'edit'>('add');
|
||||
const currentAdmin = ref<any>(null);
|
||||
const scopeDialogVisible = ref(false);
|
||||
const scopeType = ref('');
|
||||
|
||||
// 模拟数据
|
||||
const mockData = {
|
||||
school: [
|
||||
{ id: 1, name: '张校长', phone: '13800138001', sex: 0, remark: '全校管理员' },
|
||||
{ id: 2, name: '李主任', phone: '13800138002', sex: 1, remark: '教务处负责人' }
|
||||
],
|
||||
custom: [
|
||||
{ id: 3, name: '王组长', phone: '13800138003', sex: 0, scope: '高一年级', remark: '年级组长' },
|
||||
{ id: 4, name: '赵主管', phone: '13800138004', sex: 1, scope: '高二年级', remark: '年级负责人' }
|
||||
],
|
||||
teacher: [
|
||||
{ id: 5, name: '刘老师', phone: '13800138005', sex: 0, scope: '高一(1)班', remark: '数学教师' },
|
||||
{ id: 6, name: '陈老师', phone: '13800138006', sex: 1, scope: '高一(2)班', remark: '语文教师' }
|
||||
]
|
||||
};
|
||||
|
||||
// 获取管理员列表
|
||||
async function fetchAdmins(type: string) {
|
||||
// 实际项目中这里会调用API
|
||||
// 此处使用模拟数据
|
||||
try {
|
||||
// 模拟API检索过滤
|
||||
const searchForm = getSearchForm(type);
|
||||
const filteredData = mockData[type].filter((item) => {
|
||||
const nameMatch = !searchForm.name || item.name.includes(searchForm.name);
|
||||
const phoneMatch = !searchForm.phone || item.phone.includes(searchForm.phone);
|
||||
return nameMatch && phoneMatch;
|
||||
});
|
||||
|
||||
// 更新对应类型的管理员数据
|
||||
switch (type) {
|
||||
case 'school':
|
||||
schoolAdmins.value = filteredData;
|
||||
break;
|
||||
case 'custom':
|
||||
customAdmins.value = filteredData;
|
||||
break;
|
||||
case 'teacher':
|
||||
teacherAdmins.value = filteredData;
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取管理员列表失败:', error);
|
||||
ElMessage.error('获取管理员列表失败');
|
||||
}
|
||||
}
|
||||
|
||||
function getSearchForm(type: string) {
|
||||
switch (type) {
|
||||
case 'school':
|
||||
return schoolSearchForm;
|
||||
case 'custom':
|
||||
return customSearchForm;
|
||||
case 'teacher':
|
||||
return teacherSearchForm;
|
||||
default:
|
||||
return schoolSearchForm;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
fetchAdmins('school');
|
||||
fetchAdmins('custom');
|
||||
fetchAdmins('teacher');
|
||||
});
|
||||
|
||||
function onAdd(type: string) {
|
||||
dialogMode.value = 'add';
|
||||
currentAdmin.value = { id: null, name: '', phone: '', sex: 0, remark: '', scope: '' };
|
||||
activeTab.value = type; // 确保当前标签页与点击的按钮一致
|
||||
dialogVisible.value = true;
|
||||
}
|
||||
|
||||
function onEdit(type: string, admin: any) {
|
||||
dialogMode.value = 'edit';
|
||||
currentAdmin.value = { ...admin };
|
||||
activeTab.value = type; // 确保当前标签页与编辑的管理员类型一致
|
||||
dialogVisible.value = true;
|
||||
}
|
||||
|
||||
async function onDelete(type: string, admin: any) {
|
||||
// 二次确认
|
||||
ElMessageBox.confirm(`确定要删除管理员【${admin.name}】吗?`, '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning'
|
||||
})
|
||||
.then(async () => {
|
||||
try {
|
||||
// 模拟删除成功
|
||||
mockData[type] = mockData[type].filter((item) => item.id !== admin.id);
|
||||
ElMessage.success('删除成功');
|
||||
fetchAdmins(type); // 删除后刷新
|
||||
} catch (e) {
|
||||
ElMessage.error('删除失败');
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
// 用户取消
|
||||
});
|
||||
}
|
||||
|
||||
function onScope(type: string, admin: any) {
|
||||
currentAdmin.value = { ...admin };
|
||||
scopeType.value = type;
|
||||
scopeDialogVisible.value = true;
|
||||
}
|
||||
|
||||
function onDialogSubmit(admin: any) {
|
||||
// 模拟添加或编辑操作
|
||||
if (dialogMode.value === 'add') {
|
||||
// 生成新ID
|
||||
const newId = Math.max(...mockData[activeTab.value].map((item) => item.id), 0) + 1;
|
||||
admin.id = newId;
|
||||
mockData[activeTab.value].push(admin);
|
||||
} else {
|
||||
// 编辑
|
||||
const index = mockData[activeTab.value].findIndex((item) => item.id === admin.id);
|
||||
if (index !== -1) {
|
||||
mockData[activeTab.value][index] = admin;
|
||||
}
|
||||
}
|
||||
|
||||
// 刷新列表数据
|
||||
fetchAdmins(activeTab.value);
|
||||
dialogVisible.value = false;
|
||||
}
|
||||
|
||||
async function onScopeSubmit(scope: any) {
|
||||
try {
|
||||
// 模拟分配范围
|
||||
const index = mockData[scopeType.value].findIndex((item) => item.id === currentAdmin.value.id);
|
||||
if (index !== -1) {
|
||||
mockData[scopeType.value][index].scope = scope.scopeName;
|
||||
}
|
||||
|
||||
// 成功后刷新数据并提示
|
||||
ElMessage.success('管理范围分配成功');
|
||||
fetchAdmins(scopeType.value);
|
||||
scopeDialogVisible.value = false;
|
||||
} catch (error) {
|
||||
ElMessage.error('管理范围分配失败');
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
function getListByType(type: string) {
|
||||
switch (type) {
|
||||
case 'school':
|
||||
return schoolAdmins;
|
||||
case 'custom':
|
||||
return customAdmins;
|
||||
case 'teacher':
|
||||
return teacherAdmins;
|
||||
default:
|
||||
return schoolAdmins;
|
||||
}
|
||||
}
|
||||
|
||||
// 过滤
|
||||
function filteredAdmins(type: string) {
|
||||
return getListByType(type).value;
|
||||
}
|
||||
|
||||
function handleSearch(type: string) {
|
||||
fetchAdmins(type);
|
||||
}
|
||||
|
||||
function handleReset(type: string) {
|
||||
switch (type) {
|
||||
case 'school':
|
||||
schoolSearchForm.name = '';
|
||||
schoolSearchForm.phone = '';
|
||||
break;
|
||||
case 'custom':
|
||||
customSearchForm.name = '';
|
||||
customSearchForm.phone = '';
|
||||
break;
|
||||
case 'teacher':
|
||||
teacherSearchForm.name = '';
|
||||
teacherSearchForm.phone = '';
|
||||
break;
|
||||
}
|
||||
fetchAdmins(type);
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.el-card {
|
||||
padding: 8px !important;
|
||||
}
|
||||
.search-form {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,713 @@
|
||||
<template>
|
||||
<div class="p-2">
|
||||
<el-row :gutter="20">
|
||||
<!-- 部门树 -->
|
||||
<el-col :lg="4" :xs="24" style="">
|
||||
<el-card shadow="hover">
|
||||
<el-input v-model="deptName" placeholder="请输入院系名称" prefix-icon="Search" clearable />
|
||||
<el-tree
|
||||
ref="deptTreeRef"
|
||||
class="mt-2"
|
||||
node-key="id"
|
||||
:data="deptOptions"
|
||||
:props="{ label: 'label', children: 'children' }"
|
||||
:expand-on-click-node="false"
|
||||
:filter-node-method="filterNode"
|
||||
highlight-current
|
||||
default-expand-all
|
||||
@node-click="handleNodeClick"
|
||||
/>
|
||||
</el-card>
|
||||
</el-col>
|
||||
<el-col :lg="20" :xs="24">
|
||||
<transition enter-active-class="animate__animated animate__fadeIn" leave-active-class="animate__animated animate__fadeOut">
|
||||
<div v-show="showSearch" class="mb-[10px]">
|
||||
<el-card shadow="hover">
|
||||
<el-form ref="queryFormRef" :model="queryParams" inline>
|
||||
<el-form-item label="学生姓名" prop="studentName">
|
||||
<el-input v-model="queryParams.studentName" placeholder="请输入学生姓名" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="学号" prop="studentNo">
|
||||
<el-input v-model="queryParams.studentNo" placeholder="请输入学号" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
<el-form-item label="手机号码" prop="phonenumber">
|
||||
<el-input v-model="queryParams.phonenumber" placeholder="请输入手机号码" clearable @keyup.enter="handleQuery" />
|
||||
</el-form-item>
|
||||
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select v-model="queryParams.status" placeholder="学生状态" clearable>
|
||||
<el-option v-for="dict in sys_normal_disable" :key="dict.value" :label="dict.label" :value="dict.value" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="创建时间" style="width: 308px">
|
||||
<el-date-picker
|
||||
v-model="dateRange"
|
||||
value-format="YYYY-MM-DD HH:mm:ss"
|
||||
type="daterange"
|
||||
range-separator="-"
|
||||
start-placeholder="开始日期"
|
||||
end-placeholder="结束日期"
|
||||
:default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
|
||||
></el-date-picker>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
|
||||
<el-button icon="Refresh" @click="resetQuery">重置</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<el-card shadow="hover">
|
||||
<template #header>
|
||||
<el-row :gutter="10">
|
||||
<el-col :span="1.5">
|
||||
<el-button type="primary" plain icon="Plus" @click="handleAdd()">新增</el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button :disabled="single" icon="Edit" @click="handleUpdate()"> 修改 </el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-button :disabled="multiple" icon="Delete" @click="handleDelete()"> 删除 </el-button>
|
||||
</el-col>
|
||||
<el-col :span="1.5">
|
||||
<el-dropdown class="mt-[1px]">
|
||||
<el-button>
|
||||
更多
|
||||
<el-icon class="el-icon--right"><arrow-down /></el-icon>
|
||||
</el-button>
|
||||
<template #dropdown>
|
||||
<el-dropdown-menu>
|
||||
<el-dropdown-item icon="Download" @click="importTemplate">下载模板</el-dropdown-item>
|
||||
<el-dropdown-item icon="Top" @click="handleImport">导入数据</el-dropdown-item>
|
||||
<el-dropdown-item icon="Download" @click="handleExport">导出数据</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</template>
|
||||
</el-dropdown>
|
||||
</el-col>
|
||||
<right-toolbar v-model:show-search="showSearch" :columns="columns" :search="true" @query-table="getList"></right-toolbar>
|
||||
</el-row>
|
||||
</template>
|
||||
|
||||
<el-table v-loading="loading" border :data="studentList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" width="50" align="center" />
|
||||
<el-table-column v-if="columns[0].visible" key="studentId" label="学生编号" align="center" prop="studentId" />
|
||||
<el-table-column v-if="columns[1].visible" key="studentNo" label="学号" align="center" prop="studentNo" :show-overflow-tooltip="true" />
|
||||
<el-table-column
|
||||
v-if="columns[2].visible"
|
||||
key="studentName"
|
||||
label="姓名"
|
||||
align="center"
|
||||
prop="studentName"
|
||||
:show-overflow-tooltip="true"
|
||||
/>
|
||||
<el-table-column v-if="columns[3].visible" key="deptName" label="院系" align="center" prop="deptName" :show-overflow-tooltip="true" />
|
||||
<el-table-column v-if="columns[4].visible" key="majorName" label="专业" align="center" prop="majorName" :show-overflow-tooltip="true" />
|
||||
<el-table-column v-if="columns[5].visible" key="className" label="班级" align="center" prop="className" :show-overflow-tooltip="true" />
|
||||
<el-table-column v-if="columns[6].visible" key="phonenumber" label="手机号码" align="center" prop="phonenumber" width="120" />
|
||||
<el-table-column v-if="columns[7].visible" key="status" label="状态" align="center">
|
||||
<template #default="scope">
|
||||
<el-switch v-model="scope.row.status" active-value="0" inactive-value="1" @change="handleStatusChange(scope.row)"></el-switch>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column v-if="columns[8].visible" label="创建时间" align="center" prop="createTime" width="160">
|
||||
<template #default="scope">
|
||||
<span>{{ scope.row.createTime }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="操作" fixed="right" width="240" class-name="small-padding fixed-width">
|
||||
<template #default="scope">
|
||||
<el-tooltip content="修改" placement="top">
|
||||
<el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"></el-button>
|
||||
</el-tooltip>
|
||||
<el-tooltip content="删除" placement="top">
|
||||
<el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"></el-button>
|
||||
</el-tooltip>
|
||||
|
||||
<el-tooltip content="重置密码" placement="top">
|
||||
<el-button link type="primary" icon="Key" @click="handleResetPwd(scope.row)"></el-button>
|
||||
</el-tooltip>
|
||||
|
||||
<el-tooltip content="详细信息" placement="top">
|
||||
<el-button link type="primary" icon="View" @click="handleDetail(scope.row)"></el-button>
|
||||
</el-tooltip>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<pagination
|
||||
v-show="total > 0"
|
||||
v-model:page="queryParams.pageNum"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
:total="total"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
||||
<!-- 添加或修改学生配置对话框 -->
|
||||
<el-dialog v-model="dialog.visible" :title="dialog.title" width="600px" append-to-body @close="closeDialog">
|
||||
<el-form ref="studentFormRef" :model="form" :rules="rules" label-width="80px">
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="学生姓名" prop="studentName">
|
||||
<el-input v-model="form.studentName" placeholder="请输入学生姓名" maxlength="30" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="昵称" prop="nickName">
|
||||
<el-input v-model="form.nickName" placeholder="请输入昵称" maxlength="30" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="归属院系" prop="deptId">
|
||||
<el-tree-select
|
||||
v-model="form.deptId"
|
||||
:data="deptOptions"
|
||||
:props="{ value: 'id', label: 'label', children: 'children' }"
|
||||
value-key="id"
|
||||
placeholder="请选择归属院系"
|
||||
check-strictly
|
||||
@change="handleDeptChange"
|
||||
/>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="专业" prop="majorId">
|
||||
<el-select v-model="form.majorId" placeholder="请选择专业" @change="handleMajorChange">
|
||||
<el-option v-for="item in majorOptions" :key="item.majorId" :label="item.majorName" :value="item.majorId"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="班级" prop="classId">
|
||||
<el-select v-model="form.classId" placeholder="请选择班级">
|
||||
<el-option v-for="item in classOptions" :key="item.classId" :label="item.className" :value="item.classId"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="手机号码" prop="phonenumber">
|
||||
<el-input v-model="form.phonenumber" placeholder="请输入手机号码" maxlength="11" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="邮箱" prop="email">
|
||||
<el-input v-model="form.email" placeholder="请输入邮箱" maxlength="50" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="身份证号" prop="idCard">
|
||||
<el-input v-model="form.idCard" placeholder="请输入身份证号" maxlength="18" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item v-if="form.studentId == undefined" label="学号" prop="studentNo">
|
||||
<el-input v-model="form.studentNo" placeholder="请输入学号" maxlength="20" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item v-if="form.studentId == undefined" label="密码" prop="password">
|
||||
<el-input v-model="form.password" placeholder="请输入密码" type="password" maxlength="20" show-password />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="学生性别">
|
||||
<el-select v-model="form.sex" placeholder="请选择">
|
||||
<el-option v-for="dict in sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="状态">
|
||||
<el-radio-group v-model="form.status">
|
||||
<el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="地址" prop="address">
|
||||
<el-input v-model="form.address" type="textarea" placeholder="请输入地址"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
<el-row>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="备注">
|
||||
<el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
</el-row>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
||||
<el-button @click="cancel()">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 学生详情对话框 -->
|
||||
<el-dialog v-model="detailDialog.visible" :title="detailDialog.title" width="700px" append-to-body>
|
||||
<el-descriptions :column="2" border>
|
||||
<el-descriptions-item label="学生姓名">{{ detailForm.studentName }}</el-descriptions-item>
|
||||
<el-descriptions-item label="学号">{{ detailForm.studentNo }}</el-descriptions-item>
|
||||
<el-descriptions-item label="院系">{{ detailForm.deptName }}</el-descriptions-item>
|
||||
<el-descriptions-item label="专业">{{ detailForm.majorName }}</el-descriptions-item>
|
||||
<el-descriptions-item label="班级">{{ detailForm.className }}</el-descriptions-item>
|
||||
<el-descriptions-item label="性别">
|
||||
{{ detailForm.sex === '0' ? '男' : detailForm.sex === '1' ? '女' : '未知' }}
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="手机号码">{{ detailForm.phonenumber }}</el-descriptions-item>
|
||||
<el-descriptions-item label="邮箱">{{ detailForm.email }}</el-descriptions-item>
|
||||
<el-descriptions-item label="身份证号">{{ detailForm.idCard }}</el-descriptions-item>
|
||||
<el-descriptions-item label="状态">
|
||||
<el-tag :type="detailForm.status === '0' ? 'success' : 'danger'">
|
||||
{{ detailForm.status === '0' ? '正常' : '停用' }}
|
||||
</el-tag>
|
||||
</el-descriptions-item>
|
||||
<el-descriptions-item label="地址" :span="2">{{ detailForm.address }}</el-descriptions-item>
|
||||
<el-descriptions-item label="备注" :span="2">{{ detailForm.remark }}</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button @click="detailDialog.visible = false">关 闭</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 学生导入对话框 -->
|
||||
<el-dialog v-model="upload.open" :title="upload.title" width="400px" append-to-body>
|
||||
<el-upload
|
||||
ref="uploadRef"
|
||||
:limit="1"
|
||||
accept=".xlsx, .xls"
|
||||
:headers="upload.headers"
|
||||
:action="upload.url + '?updateSupport=' + upload.updateSupport"
|
||||
:disabled="upload.isUploading"
|
||||
:on-progress="handleFileUploadProgress"
|
||||
:on-success="handleFileSuccess"
|
||||
:auto-upload="false"
|
||||
drag
|
||||
>
|
||||
<el-icon class="el-icon--upload">
|
||||
<i-ep-upload-filled />
|
||||
</el-icon>
|
||||
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
|
||||
<template #tip>
|
||||
<div class="text-center el-upload__tip">
|
||||
<div class="el-upload__tip"><el-checkbox v-model="upload.updateSupport" />是否更新已经存在的学生数据</div>
|
||||
<span>仅允许导入xls、xlsx格式文件。</span>
|
||||
<el-link type="primary" :underline="false" style="font-size: 12px; vertical-align: baseline" @click="importTemplate">下载模板</el-link>
|
||||
</div>
|
||||
</template>
|
||||
</el-upload>
|
||||
<template #footer>
|
||||
<div class="dialog-footer">
|
||||
<el-button type="primary" @click="submitFileForm">确 定</el-button>
|
||||
<el-button @click="upload.open = false">取 消</el-button>
|
||||
</div>
|
||||
</template>
|
||||
</el-dialog>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import api from '@/api/studentMsg/index';
|
||||
import { StudentForm, StudentQuery, StudentVO } from '@/api/studentMsg/types';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { getCurrentInstance, ref, reactive, toRefs, watchEffect, onMounted } from 'vue';
|
||||
import { ElMessageBox, ElMessage } from 'element-plus';
|
||||
import { to } from 'await-to-js';
|
||||
import type { UploadFile, UploadInstance } from 'element-plus';
|
||||
import type { FormInstance, TreeInstance } from 'element-plus';
|
||||
|
||||
interface ComponentInternalInstance {
|
||||
proxy?: any;
|
||||
}
|
||||
|
||||
const router = useRouter();
|
||||
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
|
||||
const sys_normal_disable = ref([
|
||||
{ value: '0', label: '正常' },
|
||||
{ value: '1', label: '停用' }
|
||||
]);
|
||||
const sys_user_sex = ref([
|
||||
{ value: '0', label: '男' },
|
||||
{ value: '1', label: '女' },
|
||||
{ value: '2', label: '未知' }
|
||||
]);
|
||||
|
||||
const studentList = ref<StudentVO[]>([]);
|
||||
const loading = ref(true);
|
||||
const showSearch = ref(true);
|
||||
const ids = ref<Array<number | string>>([]);
|
||||
const single = ref(true);
|
||||
const multiple = ref(true);
|
||||
const total = ref(0);
|
||||
const dateRange = ref<[string, string]>(['', '']);
|
||||
const deptName = ref('');
|
||||
const deptOptions = ref([]);
|
||||
const majorOptions = ref([]);
|
||||
const classOptions = ref([]);
|
||||
|
||||
// 列显隐信息
|
||||
const columns = ref([
|
||||
{ key: 0, label: `学生编号`, visible: false },
|
||||
{ key: 1, label: `学号`, visible: true },
|
||||
{ key: 2, label: `姓名`, visible: true },
|
||||
{ key: 3, label: `院系`, visible: true },
|
||||
{ key: 4, label: `专业`, visible: true },
|
||||
{ key: 5, label: `班级`, visible: true },
|
||||
{ key: 6, label: `手机号码`, visible: true },
|
||||
{ key: 7, label: `状态`, visible: true },
|
||||
{ key: 8, label: `创建时间`, visible: true }
|
||||
]);
|
||||
|
||||
const deptTreeRef = ref<TreeInstance>();
|
||||
const queryFormRef = ref<FormInstance>();
|
||||
const studentFormRef = ref<FormInstance>();
|
||||
const uploadRef = ref<UploadInstance>();
|
||||
|
||||
const initPassword = ref('123456');
|
||||
const dialog = reactive({
|
||||
visible: false,
|
||||
title: ''
|
||||
});
|
||||
|
||||
const detailDialog = reactive({
|
||||
visible: false,
|
||||
title: '学生详情'
|
||||
});
|
||||
|
||||
const detailForm = reactive<StudentVO>({
|
||||
studentId: '',
|
||||
studentNo: '',
|
||||
studentName: ''
|
||||
});
|
||||
|
||||
// 导入参数
|
||||
const upload = reactive({
|
||||
// 是否显示弹出层
|
||||
open: false,
|
||||
// 弹出层标题
|
||||
title: '',
|
||||
// 是否禁用上传
|
||||
isUploading: false,
|
||||
// 是否更新已经存在的数据
|
||||
updateSupport: false,
|
||||
// 设置上传的请求头部
|
||||
headers: { Authorization: 'Bearer ' },
|
||||
// 上传的地址
|
||||
url: '/api/studentMsg/student/importData'
|
||||
});
|
||||
|
||||
const initFormData: StudentForm = {
|
||||
studentId: undefined,
|
||||
deptId: undefined,
|
||||
studentNo: '',
|
||||
studentName: '',
|
||||
nickName: '',
|
||||
password: '',
|
||||
phonenumber: '',
|
||||
email: '',
|
||||
idCard: '',
|
||||
sex: '0',
|
||||
status: '0',
|
||||
majorId: undefined,
|
||||
classId: undefined,
|
||||
address: '',
|
||||
remark: ''
|
||||
};
|
||||
|
||||
const form = reactive<StudentForm>({
|
||||
...initFormData
|
||||
});
|
||||
|
||||
const rules = reactive({
|
||||
studentName: [{ required: true, message: '学生姓名不能为空', trigger: 'blur' }],
|
||||
studentNo: [{ required: true, message: '学号不能为空', trigger: 'blur' }],
|
||||
password: [{ required: true, message: '密码不能为空', trigger: 'blur' }],
|
||||
deptId: [{ required: true, message: '归属院系不能为空', trigger: 'blur' }],
|
||||
majorId: [{ required: true, message: '专业不能为空', trigger: 'blur' }],
|
||||
classId: [{ required: true, message: '班级不能为空', trigger: 'blur' }],
|
||||
email: [{ type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }],
|
||||
phonenumber: [{ pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/, message: '请输入正确的手机号码', trigger: 'blur' }],
|
||||
idCard: [{ pattern: /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/, message: '请输入正确的身份证号码', trigger: 'blur' }]
|
||||
});
|
||||
|
||||
const queryParams = reactive<StudentQuery>({
|
||||
pageNum: 1,
|
||||
pageSize: 10,
|
||||
studentName: '',
|
||||
studentNo: '',
|
||||
phonenumber: '',
|
||||
status: '',
|
||||
deptId: undefined
|
||||
});
|
||||
|
||||
/** 通过条件过滤节点 */
|
||||
const filterNode = (value: string, data: any) => {
|
||||
if (!value) return true;
|
||||
return data.label.indexOf(value) !== -1;
|
||||
};
|
||||
|
||||
/** 根据名称筛选部门树 */
|
||||
watchEffect(
|
||||
() => {
|
||||
deptTreeRef.value?.filter(deptName.value);
|
||||
},
|
||||
{ flush: 'post' }
|
||||
);
|
||||
|
||||
/** 查询学生列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true;
|
||||
const res = await api.listStudent(queryParams);
|
||||
loading.value = false;
|
||||
studentList.value = res.data.data.rows;
|
||||
total.value = res.data.data.total;
|
||||
};
|
||||
|
||||
/** 查询部门下拉树结构 */
|
||||
const getDeptTree = async () => {
|
||||
try {
|
||||
const res = await api.XgDeptTreeSelect(101);
|
||||
// XgDeptTreeSelect返回的数据结构与deptTreeSelect不同,需要进行适当处理
|
||||
if (res.data && Array.isArray(res.data)) {
|
||||
deptOptions.value = res.data;
|
||||
} else {
|
||||
console.warn('部门树数据格式不符合预期');
|
||||
// 回退到默认处理
|
||||
const backup = await api.deptTreeSelect();
|
||||
deptOptions.value = backup.data.data;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取部门树失败:', error);
|
||||
// 如果API调用失败,可以使用默认的deptTreeSelect作为备选
|
||||
const backup = await api.deptTreeSelect();
|
||||
deptOptions.value = backup.data.data;
|
||||
}
|
||||
};
|
||||
|
||||
/** 节点单击事件 */
|
||||
const handleNodeClick = (data: any) => {
|
||||
queryParams.deptId = data.id;
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNum = 1;
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
dateRange.value = ['', ''];
|
||||
queryFormRef.value?.resetFields();
|
||||
queryParams.pageNum = 1;
|
||||
queryParams.deptId = undefined;
|
||||
deptTreeRef.value?.setCurrentKey(undefined);
|
||||
handleQuery();
|
||||
};
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (row?: StudentVO) => {
|
||||
const studentIds = row?.studentId || ids.value;
|
||||
const [err] = await to(ElMessageBox.confirm('是否确认删除学生编号为"' + studentIds + '"的数据项?', '提示'));
|
||||
if (!err) {
|
||||
await api.delStudent(studentIds);
|
||||
await getList();
|
||||
ElMessage.success('删除成功');
|
||||
}
|
||||
};
|
||||
|
||||
/** 学生状态修改 */
|
||||
const handleStatusChange = async (row: StudentVO) => {
|
||||
const text = row.status === '0' ? '启用' : '停用';
|
||||
try {
|
||||
await ElMessageBox.confirm('确认要"' + text + '""' + row.studentName + '"学生吗?', '提示');
|
||||
await api.changeStudentStatus(row.studentId, row.status);
|
||||
ElMessage.success(text + '成功');
|
||||
} catch (err) {
|
||||
row.status = row.status === '0' ? '1' : '0';
|
||||
}
|
||||
};
|
||||
|
||||
/** 查看详情按钮操作 */
|
||||
const handleDetail = async (row: StudentVO) => {
|
||||
Object.assign(detailForm, row);
|
||||
detailDialog.visible = true;
|
||||
};
|
||||
|
||||
/** 重置密码按钮操作 */
|
||||
const handleResetPwd = async (row: StudentVO) => {
|
||||
const [err, res] = await to(
|
||||
ElMessageBox.prompt('请输入"' + row.studentName + '"的新密码', '提示', {
|
||||
confirmButtonText: '确定',
|
||||
cancelButtonText: '取消',
|
||||
closeOnClickModal: false,
|
||||
inputPattern: /^.{6,20}$/,
|
||||
inputErrorMessage: '密码长度必须介于 6 和 20 之间'
|
||||
})
|
||||
);
|
||||
if (!err && res) {
|
||||
// 实际项目中需要调用重置密码API
|
||||
ElMessage.success('修改成功,新密码是:' + res.value);
|
||||
}
|
||||
};
|
||||
|
||||
/** 选择条数 */
|
||||
const handleSelectionChange = (selection: StudentVO[]) => {
|
||||
ids.value = selection.map((item) => item.studentId);
|
||||
single.value = selection.length != 1;
|
||||
multiple.value = !selection.length;
|
||||
};
|
||||
|
||||
/** 导入按钮操作 */
|
||||
const handleImport = () => {
|
||||
upload.title = '学生导入';
|
||||
upload.open = true;
|
||||
};
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = () => {
|
||||
// 实际项目中需要调用导出API
|
||||
ElMessage.success('导出成功');
|
||||
};
|
||||
|
||||
/** 下载模板操作 */
|
||||
const importTemplate = () => {
|
||||
// 实际项目中需要调用下载模板API
|
||||
ElMessage.success('下载模板成功');
|
||||
};
|
||||
|
||||
/**文件上传中处理 */
|
||||
const handleFileUploadProgress = () => {
|
||||
upload.isUploading = true;
|
||||
};
|
||||
|
||||
/** 文件上传成功处理 */
|
||||
const handleFileSuccess = (response: any) => {
|
||||
upload.open = false;
|
||||
upload.isUploading = false;
|
||||
uploadRef.value?.clearFiles();
|
||||
ElMessageBox.alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + '</div>', '导入结果', {
|
||||
dangerouslyUseHTMLString: true
|
||||
});
|
||||
getList();
|
||||
};
|
||||
|
||||
/** 提交上传文件 */
|
||||
const submitFileForm = () => {
|
||||
uploadRef.value?.submit();
|
||||
};
|
||||
|
||||
/** 重置操作表单 */
|
||||
const reset = () => {
|
||||
Object.assign(form, initFormData);
|
||||
studentFormRef.value?.resetFields();
|
||||
majorOptions.value = [];
|
||||
classOptions.value = [];
|
||||
};
|
||||
|
||||
/** 取消按钮 */
|
||||
const cancel = () => {
|
||||
dialog.visible = false;
|
||||
reset();
|
||||
};
|
||||
|
||||
/** 新增按钮操作 */
|
||||
const handleAdd = async () => {
|
||||
reset();
|
||||
dialog.visible = true;
|
||||
dialog.title = '新增学生';
|
||||
form.password = initPassword.value;
|
||||
};
|
||||
|
||||
/** 修改按钮操作 */
|
||||
const handleUpdate = async (row?: StudentForm) => {
|
||||
reset();
|
||||
const studentId = row?.studentId || ids.value[0];
|
||||
const { data } = await api.getStudent(studentId);
|
||||
dialog.visible = true;
|
||||
dialog.title = '修改学生';
|
||||
Object.assign(form, data.data.student);
|
||||
majorOptions.value = data.data.majors;
|
||||
classOptions.value = data.data.classes;
|
||||
};
|
||||
|
||||
/** 院系变更事件 */
|
||||
const handleDeptChange = (deptId: number) => {
|
||||
form.majorId = undefined;
|
||||
form.classId = undefined;
|
||||
majorOptions.value = [];
|
||||
classOptions.value = [];
|
||||
// 根据院系ID过滤专业选项
|
||||
const majors = api.getStudent().then((res) => {
|
||||
return res.data.data.majors.filter((item: any) => item.deptId === deptId);
|
||||
});
|
||||
majors.then((data) => {
|
||||
majorOptions.value = data;
|
||||
});
|
||||
};
|
||||
|
||||
/** 专业变更事件 */
|
||||
const handleMajorChange = (majorId: number) => {
|
||||
form.classId = undefined;
|
||||
classOptions.value = [];
|
||||
// 根据专业ID过滤班级选项
|
||||
const classes = api.getStudent().then((res) => {
|
||||
return res.data.data.classes.filter((item: any) => item.majorId === majorId);
|
||||
});
|
||||
classes.then((data) => {
|
||||
classOptions.value = data;
|
||||
});
|
||||
};
|
||||
|
||||
/** 提交按钮 */
|
||||
const submitForm = () => {
|
||||
studentFormRef.value?.validate(async (valid: boolean) => {
|
||||
if (valid) {
|
||||
if (form.studentId !== undefined) {
|
||||
await api.updateStudent(form);
|
||||
} else {
|
||||
await api.addStudent(form);
|
||||
}
|
||||
ElMessage.success('操作成功');
|
||||
dialog.visible = false;
|
||||
await getList();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* 关闭学生弹窗
|
||||
*/
|
||||
const closeDialog = () => {
|
||||
dialog.visible = false;
|
||||
reset();
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getDeptTree(); // 初始化部门数据
|
||||
getList(); // 初始化列表数据
|
||||
});
|
||||
</script>
|
||||
Reference in new issue
Block a user