2026-02-02 16:04:47 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="app-container">
|
|
|
|
|
|
<el-row :gutter="16">
|
|
|
|
|
|
<!-- 左侧学校树 -->
|
|
|
|
|
|
<el-col :span="5">
|
|
|
|
|
|
<el-card shadow="never">
|
|
|
|
|
|
<template #header>
|
|
|
|
|
|
<span>学校筛选</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-input v-model="treeFilterText" placeholder="输入关键字过滤" clearable style="margin-bottom: 12px" />
|
|
|
|
|
|
<el-scrollbar height="calc(100vh - 260px)">
|
|
|
|
|
|
<el-tree
|
|
|
|
|
|
ref="treeRef"
|
|
|
|
|
|
:data="schoolTree"
|
2026-02-02 19:49:12 +08:00
|
|
|
|
:props="{ label: 'name', children: 'children' }"
|
2026-02-02 16:04:47 +08:00
|
|
|
|
node-key="id"
|
|
|
|
|
|
highlight-current
|
|
|
|
|
|
:filter-node-method="filterNode"
|
|
|
|
|
|
@node-click="handleNodeClick"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-scrollbar>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 右侧列表 -->
|
|
|
|
|
|
<el-col :span="19">
|
|
|
|
|
|
<!-- 搜索区域 -->
|
|
|
|
|
|
<el-card shadow="never" class="search-wrapper">
|
|
|
|
|
|
<el-form :model="queryParams" :inline="true">
|
|
|
|
|
|
<el-form-item label="学生姓名">
|
2026-02-02 21:00:57 +08:00
|
|
|
|
<el-input v-model="queryParams.studentName" placeholder="请输入学生姓名" clearable style="width: 150px" @keyup.enter="handleQuery" />
|
2026-02-02 16:04:47 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="学号">
|
|
|
|
|
|
<el-input v-model="queryParams.studentNo" placeholder="请输入学号" clearable style="width: 150px" @keyup.enter="handleQuery" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="性别">
|
|
|
|
|
|
<el-select v-model="queryParams.gender" placeholder="全部" clearable style="width: 100px">
|
|
|
|
|
|
<el-option label="男" value="1" />
|
|
|
|
|
|
<el-option label="女" value="2" />
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</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>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 表格区域 -->
|
|
|
|
|
|
<el-card shadow="never" style="margin-top: 12px">
|
|
|
|
|
|
<el-row :gutter="10" style="margin-bottom: 12px">
|
|
|
|
|
|
<el-col :span="1.5">
|
|
|
|
|
|
<el-button type="primary" :icon="Plus" @click="handleAdd">新增</el-button>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="1.5">
|
|
|
|
|
|
<el-button type="success" :icon="Upload" @click="handleImport">导入</el-button>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
|
|
|
|
|
|
|
|
|
|
|
<el-table v-loading="loading" :data="tableData" border stripe :header-cell-style="{ background: '#f5f7fa', color: '#606266' }" style="width: 100%">
|
|
|
|
|
|
<el-table-column prop="studentNo" label="学号" width="130" />
|
2026-02-02 19:57:14 +08:00
|
|
|
|
<el-table-column prop="studentName" label="姓名" width="100" />
|
2026-02-02 16:04:47 +08:00
|
|
|
|
<el-table-column prop="gender" label="性别" width="60" align="center">
|
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
|
{{ row.gender === '1' ? '男' : row.gender === '2' ? '女' : '未知' }}
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
2026-02-02 20:33:10 +08:00
|
|
|
|
<el-table-column prop="birthday" label="出生日期" width="110">
|
2026-02-02 19:57:14 +08:00
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
|
{{ row.birthday ? formatDate(row.birthday) : '' }}
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
2026-02-02 16:04:47 +08:00
|
|
|
|
<el-table-column prop="schoolName" label="学校" min-width="150" show-overflow-tooltip />
|
|
|
|
|
|
<el-table-column prop="gradeName" label="年级" width="80" />
|
|
|
|
|
|
<el-table-column prop="className" label="班级" width="80" />
|
2026-02-03 17:04:07 +08:00
|
|
|
|
<el-table-column label="归属用户" width="180">
|
2026-02-02 19:57:14 +08:00
|
|
|
|
<template #default="{ row }">
|
2026-02-03 17:04:07 +08:00
|
|
|
|
<template v-if="row.members && row.members.length > 0">
|
|
|
|
|
|
<el-tooltip v-if="row.members.length > 1" placement="top">
|
|
|
|
|
|
<template #content>
|
|
|
|
|
|
<div v-for="(m, idx) in row.members" :key="idx" style="line-height: 1.6">
|
|
|
|
|
|
{{ m.nickname || m.phone }}{{ m.relation ? `(${m.relation})` : '' }}
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
<el-tag size="small">{{ row.memberCount }}人绑定</el-tag>
|
|
|
|
|
|
</el-tooltip>
|
|
|
|
|
|
<span v-else>
|
|
|
|
|
|
{{ row.members[0].nickname || row.members[0].phone }}
|
|
|
|
|
|
<span v-if="row.members[0].relation" style="color: #909399">({{ row.members[0].relation }})</span>
|
|
|
|
|
|
</span>
|
|
|
|
|
|
</template>
|
2026-02-02 19:57:14 +08:00
|
|
|
|
<span v-else style="color: #909399">未绑定</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
2026-02-02 16:04:47 +08:00
|
|
|
|
<el-table-column prop="createTime" label="创建时间" width="160" />
|
|
|
|
|
|
<el-table-column label="操作" width="150" fixed="right" align="center">
|
|
|
|
|
|
<template #default="{ row }">
|
|
|
|
|
|
<el-button type="primary" link :icon="Edit" @click="handleEdit(row)">编辑</el-button>
|
|
|
|
|
|
<el-button type="danger" link :icon="Delete" @click="handleDelete(row)">删除</el-button>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 分页 -->
|
|
|
|
|
|
<el-pagination
|
|
|
|
|
|
v-model:current-page="queryParams.pageNum"
|
|
|
|
|
|
v-model:page-size="queryParams.pageSize"
|
|
|
|
|
|
:page-sizes="[10, 20, 50, 100]"
|
|
|
|
|
|
:total="total"
|
|
|
|
|
|
layout="total, sizes, prev, pager, next, jumper"
|
|
|
|
|
|
style="margin-top: 16px; justify-content: flex-end"
|
|
|
|
|
|
@size-change="handleQuery"
|
|
|
|
|
|
@current-change="handleQuery"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</el-card>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 新增/编辑弹窗 -->
|
|
|
|
|
|
<StudentDialog ref="studentDialogRef" @success="handleQuery" />
|
|
|
|
|
|
|
|
|
|
|
|
<!-- 导入弹窗 -->
|
|
|
|
|
|
<ImportDialog ref="importDialogRef" @success="handleQuery" />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 学生管理页面
|
|
|
|
|
|
* @author pangu
|
|
|
|
|
|
*/
|
|
|
|
|
|
import { Delete, Edit, Plus, Refresh, Search, Upload } from '@element-plus/icons-vue'
|
|
|
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
|
|
|
import { onMounted, ref, watch } from 'vue'
|
|
|
|
|
|
import request from '@/utils/request'
|
|
|
|
|
|
import ImportDialog from './components/ImportDialog.vue'
|
|
|
|
|
|
import StudentDialog from './components/StudentDialog.vue'
|
|
|
|
|
|
|
|
|
|
|
|
// 学校树相关
|
|
|
|
|
|
const treeRef = ref()
|
|
|
|
|
|
const treeFilterText = ref('')
|
|
|
|
|
|
const schoolTree = ref([])
|
|
|
|
|
|
|
|
|
|
|
|
// 表格相关
|
|
|
|
|
|
const loading = ref(false)
|
|
|
|
|
|
const tableData = ref([])
|
|
|
|
|
|
const total = ref(0)
|
|
|
|
|
|
|
|
|
|
|
|
// 查询参数
|
|
|
|
|
|
const queryParams = ref({
|
|
|
|
|
|
pageNum: 1,
|
|
|
|
|
|
pageSize: 10,
|
2026-02-02 21:00:57 +08:00
|
|
|
|
studentName: '',
|
2026-02-02 16:04:47 +08:00
|
|
|
|
studentNo: '',
|
|
|
|
|
|
gender: '',
|
2026-02-02 21:00:57 +08:00
|
|
|
|
schoolId: null,
|
|
|
|
|
|
schoolGradeId: null,
|
|
|
|
|
|
schoolClassId: null
|
2026-02-02 16:04:47 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 弹窗引用
|
|
|
|
|
|
const studentDialogRef = ref()
|
|
|
|
|
|
const importDialogRef = ref()
|
|
|
|
|
|
|
|
|
|
|
|
// 监听树过滤
|
|
|
|
|
|
watch(treeFilterText, (val) => {
|
|
|
|
|
|
treeRef.value?.filter(val)
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
// 树节点过滤
|
|
|
|
|
|
const filterNode = (value, data) => {
|
|
|
|
|
|
if (!value) return true
|
2026-02-02 19:49:12 +08:00
|
|
|
|
return data.name?.includes(value)
|
2026-02-02 16:04:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取学校树
|
|
|
|
|
|
const getSchoolTree = async () => {
|
|
|
|
|
|
const res = await request.get('/business/student/schoolTree')
|
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
|
schoolTree.value = res.data
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 获取学生列表
|
|
|
|
|
|
const getList = async () => {
|
|
|
|
|
|
loading.value = true
|
|
|
|
|
|
try {
|
|
|
|
|
|
const res = await request.get('/business/student/list', { params: queryParams.value })
|
|
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
|
tableData.value = res.rows
|
|
|
|
|
|
total.value = res.total
|
|
|
|
|
|
}
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
loading.value = false
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 树节点点击
|
|
|
|
|
|
const handleNodeClick = (data) => {
|
2026-02-02 21:00:57 +08:00
|
|
|
|
// 根据节点层级设置筛选条件,子节点需要带上父级条件
|
2026-02-03 22:23:38 +08:00
|
|
|
|
// 注意:使用专门的 ID 字段,不是 id(id 是带前缀的唯一标识)
|
2026-02-02 16:04:47 +08:00
|
|
|
|
if (data.type === 'school') {
|
2026-02-02 21:00:57 +08:00
|
|
|
|
// 点击学校:只筛选学校
|
2026-02-03 22:23:38 +08:00
|
|
|
|
queryParams.value.schoolId = data.schoolId
|
2026-02-02 21:00:57 +08:00
|
|
|
|
queryParams.value.schoolGradeId = null
|
|
|
|
|
|
queryParams.value.schoolClassId = null
|
2026-02-02 16:04:47 +08:00
|
|
|
|
} else if (data.type === 'grade') {
|
2026-02-02 21:00:57 +08:00
|
|
|
|
// 点击年级:筛选学校 + 年级
|
|
|
|
|
|
queryParams.value.schoolId = data.schoolId
|
2026-02-03 22:23:38 +08:00
|
|
|
|
queryParams.value.schoolGradeId = data.schoolGradeId
|
2026-02-02 21:00:57 +08:00
|
|
|
|
queryParams.value.schoolClassId = null
|
2026-02-02 16:04:47 +08:00
|
|
|
|
} else if (data.type === 'class') {
|
2026-02-02 21:00:57 +08:00
|
|
|
|
// 点击班级:筛选学校 + 年级 + 班级
|
|
|
|
|
|
queryParams.value.schoolId = data.schoolId
|
|
|
|
|
|
queryParams.value.schoolGradeId = data.schoolGradeId
|
2026-02-03 22:23:38 +08:00
|
|
|
|
queryParams.value.schoolClassId = data.classId // 使用 classId(pg_school_class 表的 ID)
|
2026-02-02 16:04:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
queryParams.value.pageNum = 1
|
|
|
|
|
|
getList()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 搜索
|
|
|
|
|
|
const handleQuery = () => {
|
|
|
|
|
|
queryParams.value.pageNum = 1
|
|
|
|
|
|
getList()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 重置
|
|
|
|
|
|
const resetQuery = () => {
|
|
|
|
|
|
queryParams.value = {
|
|
|
|
|
|
pageNum: 1,
|
|
|
|
|
|
pageSize: 10,
|
2026-02-02 21:00:57 +08:00
|
|
|
|
studentName: '',
|
2026-02-02 16:04:47 +08:00
|
|
|
|
studentNo: '',
|
|
|
|
|
|
gender: '',
|
2026-02-02 21:00:57 +08:00
|
|
|
|
schoolId: null,
|
|
|
|
|
|
schoolGradeId: null,
|
|
|
|
|
|
schoolClassId: null
|
2026-02-02 16:04:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
treeRef.value?.setCurrentKey(null)
|
|
|
|
|
|
getList()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 新增
|
|
|
|
|
|
const handleAdd = () => {
|
|
|
|
|
|
studentDialogRef.value?.open()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 编辑
|
|
|
|
|
|
const handleEdit = (row) => {
|
|
|
|
|
|
studentDialogRef.value?.open(row)
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 导入
|
|
|
|
|
|
const handleImport = () => {
|
|
|
|
|
|
importDialogRef.value?.open()
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-02 19:57:14 +08:00
|
|
|
|
// 格式化日期
|
|
|
|
|
|
const formatDate = (date) => {
|
|
|
|
|
|
if (!date) return ''
|
|
|
|
|
|
const d = new Date(date)
|
|
|
|
|
|
const year = d.getFullYear()
|
|
|
|
|
|
const month = String(d.getMonth() + 1).padStart(2, '0')
|
2026-02-02 20:33:10 +08:00
|
|
|
|
const day = String(d.getDate()).padStart(2, '0')
|
|
|
|
|
|
return `${year}-${month}-${day}`
|
2026-02-02 19:57:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2026-02-02 16:04:47 +08:00
|
|
|
|
// 删除
|
|
|
|
|
|
const handleDelete = (row) => {
|
2026-02-02 19:57:14 +08:00
|
|
|
|
ElMessageBox.confirm(`确定要删除学生"${row.studentName}"吗?`, '提示', {
|
2026-02-02 16:04:47 +08:00
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
|
|
type: 'warning'
|
|
|
|
|
|
}).then(async () => {
|
2026-02-02 19:57:14 +08:00
|
|
|
|
const res = await request.delete(`/business/student/${row.studentId}`)
|
2026-02-02 16:04:47 +08:00
|
|
|
|
if (res.code === 200) {
|
|
|
|
|
|
ElMessage.success('删除成功')
|
|
|
|
|
|
getList()
|
|
|
|
|
|
}
|
|
|
|
|
|
}).catch(() => {})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
getSchoolTree()
|
|
|
|
|
|
getList()
|
|
|
|
|
|
})
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
.app-container {
|
|
|
|
|
|
padding: 16px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.search-wrapper {
|
|
|
|
|
|
margin-bottom: 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
</style>
|