【新增】班级管理页面新增
This commit is contained in:
64
src/api/exam/class/index.ts
Normal file
64
src/api/exam/class/index.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import request from '@/config/axios'
|
||||
|
||||
// 学生班级 VO
|
||||
export interface ClassVO {
|
||||
id: number // 班级编号
|
||||
name: string // 名字
|
||||
status: number // 状态
|
||||
remark: string // 备注
|
||||
}
|
||||
|
||||
export interface ClassIdVO {
|
||||
id: number // 班级编号
|
||||
name: string // 名字
|
||||
}
|
||||
|
||||
export interface ClassStudentSaveReqVO {
|
||||
studentClassDOS: any
|
||||
}
|
||||
// 学生班级 API
|
||||
export const ClassApi = {
|
||||
// 查询学生班级分页
|
||||
getClassPage: async (params: any) => {
|
||||
return await request.get({ url: `/exam/class/page`, params })
|
||||
},
|
||||
|
||||
// 查询学生班级详情
|
||||
getClass: async (id: number) => {
|
||||
return await request.get({ url: `/exam/class/get?id=` + id })
|
||||
},
|
||||
|
||||
// 查询班级名称
|
||||
getClassName: async () => {
|
||||
return await request.get({ url: `/exam/class/getClassName` })
|
||||
},
|
||||
// 查询班级ID
|
||||
getClassIdName: async () => {
|
||||
return await request.get({ url: `/exam/class/getClassIdName` })
|
||||
},
|
||||
|
||||
// 绑定学生班级
|
||||
bindingClass: async (data: ClassStudentSaveReqVO) => {
|
||||
console.log(data)
|
||||
return await request.post({ url: `/exam/class/binding`, data })
|
||||
},
|
||||
// 新增学生班级
|
||||
createClass: async (data: ClassVO) => {
|
||||
return await request.post({ url: `/exam/class/create`, data })
|
||||
},
|
||||
|
||||
// 修改学生班级
|
||||
updateClass: async (data: ClassVO) => {
|
||||
return await request.put({ url: `/exam/class/update`, data })
|
||||
},
|
||||
|
||||
// 删除学生班级
|
||||
deleteClass: async (id: number) => {
|
||||
return await request.delete({ url: `/exam/class/delete?id=` + id })
|
||||
},
|
||||
|
||||
// 导出学生班级 Excel
|
||||
exportClass: async (params) => {
|
||||
return await request.download({ url: `/exam/class/export-excel`, params })
|
||||
}
|
||||
}
|
110
src/views/exam/class/ClassForm.vue
Normal file
110
src/views/exam/class/ClassForm.vue
Normal file
@@ -0,0 +1,110 @@
|
||||
<template>
|
||||
<Dialog :title="dialogTitle" v-model="dialogVisible">
|
||||
<el-form
|
||||
ref="formRef"
|
||||
:model="formData"
|
||||
:rules="formRules"
|
||||
label-width="100px"
|
||||
v-loading="formLoading"
|
||||
>
|
||||
<el-form-item label="名字" prop="name">
|
||||
<el-input v-model="formData.name" placeholder="请输入名字" />
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-radio-group v-model="formData.status">
|
||||
<el-radio
|
||||
v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
|
||||
:key="dict.value"
|
||||
:label="dict.value"
|
||||
>
|
||||
{{ dict.label }}
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
</el-form-item>
|
||||
<el-form-item label="备注" prop="remark">
|
||||
<el-input v-model="formData.remark" placeholder="请输入备注" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="submitForm" type="primary" :disabled="formLoading">确 定</el-button>
|
||||
<el-button @click="dialogVisible = false">取 消</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { ClassApi, ClassVO } from '@/api/exam/class'
|
||||
import {DICT_TYPE, getIntDictOptions} from "@/utils/dict";
|
||||
|
||||
/** 学生班级 表单 */
|
||||
defineOptions({ name: 'ClassForm' })
|
||||
|
||||
const { t } = useI18n() // 国际化
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dialogTitle = ref('') // 弹窗的标题
|
||||
const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用
|
||||
const formType = ref('') // 表单的类型:create - 新增;update - 修改
|
||||
const formData = ref({
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
status: undefined,
|
||||
remark: undefined
|
||||
})
|
||||
const formRules = reactive({
|
||||
})
|
||||
const formRef = ref() // 表单 Ref
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async (type: string, id?: number) => {
|
||||
dialogVisible.value = true
|
||||
dialogTitle.value = t('action.' + type)
|
||||
formType.value = type
|
||||
resetForm()
|
||||
// 修改时,设置数据
|
||||
if (id) {
|
||||
formLoading.value = true
|
||||
try {
|
||||
formData.value = await ClassApi.getClass(id)
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 提交表单 */
|
||||
const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调
|
||||
const submitForm = async () => {
|
||||
// 校验表单
|
||||
await formRef.value.validate()
|
||||
// 提交请求
|
||||
formLoading.value = true
|
||||
try {
|
||||
const data = formData.value as unknown as ClassVO
|
||||
if (formType.value === 'create') {
|
||||
await ClassApi.createClass(data)
|
||||
message.success(t('common.createSuccess'))
|
||||
} else {
|
||||
await ClassApi.updateClass(data)
|
||||
message.success(t('common.updateSuccess'))
|
||||
}
|
||||
dialogVisible.value = false
|
||||
// 发送操作成功的事件
|
||||
emit('success')
|
||||
} finally {
|
||||
formLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置表单 */
|
||||
const resetForm = () => {
|
||||
formData.value = {
|
||||
id: undefined,
|
||||
name: undefined,
|
||||
status: undefined,
|
||||
remark: undefined
|
||||
}
|
||||
formRef.value?.resetFields()
|
||||
}
|
||||
</script>
|
121
src/views/exam/class/StudentTable.vue
Normal file
121
src/views/exam/class/StudentTable.vue
Normal file
@@ -0,0 +1,121 @@
|
||||
<template>
|
||||
<Dialog v-model="dialogVisible" title="归属学生" width="800px">
|
||||
<!-- 列表 -->
|
||||
<el-row>
|
||||
<el-table
|
||||
ref="tableRef"
|
||||
v-loading="dbTableLoading"
|
||||
:data="dbTableList"
|
||||
height="260px"
|
||||
@row-click="handleRowClick"
|
||||
@selection-change="handleSelectionChange"
|
||||
>
|
||||
<el-table-column type="selection" width="55" />
|
||||
<el-table-column :show-overflow-tooltip="true" label="姓名" prop="name" />
|
||||
<el-table-column :show-overflow-tooltip="true" label="学号" prop="code" />
|
||||
<el-table-column :show-overflow-tooltip="true" label="电话" prop="phone" />
|
||||
</el-table>
|
||||
</el-row>
|
||||
<!-- 操作 -->
|
||||
<template #footer>
|
||||
<el-button
|
||||
:disabled="tableList.length === 0 || dbTableLoading"
|
||||
type="primary"
|
||||
@click="handleImportTable"
|
||||
>
|
||||
导入
|
||||
</el-button>
|
||||
<el-button @click="close">关闭</el-button>
|
||||
</template>
|
||||
</Dialog>
|
||||
</template>
|
||||
<script lang="ts" setup>
|
||||
import * as StudentApi from '@/api/exam/student'
|
||||
import * as ClassApi from '@/api/exam/class'
|
||||
import * as DataSourceConfigApi from '@/api/infra/dataSourceConfig'
|
||||
import { ElTable } from 'element-plus'
|
||||
|
||||
defineOptions({ name: 'InfraCodegenImportTable' })
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
|
||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||
const dbTableLoading = ref(true) // 数据源的加载中
|
||||
const dbTableList = ref<StudentApi.StudentVO[]>([]) // 表的列表
|
||||
const queryParams = reactive({
|
||||
name: undefined,
|
||||
comment: undefined,
|
||||
dataSourceConfigId: 0
|
||||
})
|
||||
const dataSourceConfigList = ref<DataSourceConfigApi.DataSourceConfigVO[]>([]) // 数据源列表
|
||||
const props = defineProps<{
|
||||
classId: undefined // 租户ID(主表的关联字段)
|
||||
}>()
|
||||
const newClassId = ref();
|
||||
|
||||
watch(
|
||||
() => props.classId,
|
||||
async (val) => {
|
||||
if (val != undefined) {
|
||||
newClassId.value = val
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
)
|
||||
/** 查询表数据 */
|
||||
const getList = async () => {
|
||||
dbTableLoading.value = true
|
||||
try {
|
||||
dbTableList.value = await StudentApi.StudentApi.getStuList();
|
||||
} finally {
|
||||
dbTableLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/** 打开弹窗 */
|
||||
const open = async () => {
|
||||
// 加载数据源的列表
|
||||
dataSourceConfigList.value = await DataSourceConfigApi.getDataSourceConfigList()
|
||||
queryParams.dataSourceConfigId = dataSourceConfigList.value[0].id as number
|
||||
dialogVisible.value = true
|
||||
// 加载表的列表
|
||||
await getList()
|
||||
}
|
||||
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
|
||||
|
||||
/** 关闭弹窗 */
|
||||
const close = () => {
|
||||
dialogVisible.value = false
|
||||
tableList.value = []
|
||||
}
|
||||
|
||||
const tableRef = ref<typeof ElTable>() // 表格的 Ref
|
||||
const tableList = ref<string[]>([]) // 选中的表名
|
||||
|
||||
/** 处理某一行的点击 */
|
||||
const handleRowClick = (row) => {
|
||||
unref(tableRef)?.toggleRowSelection(row)
|
||||
}
|
||||
|
||||
/** 多选框选中数据 */
|
||||
const handleSelectionChange = (selection) => {
|
||||
tableList.value = selection.map(item => ({ studentId: item.id , classId: newClassId.value }))
|
||||
}
|
||||
|
||||
/** 导入按钮操作 */
|
||||
const handleImportTable = async () => {
|
||||
dbTableLoading.value = true
|
||||
try {
|
||||
await ClassApi.ClassApi.bindingClass({
|
||||
studentClassDOS: tableList.value
|
||||
})
|
||||
message.success('绑定成功')
|
||||
emit('success')
|
||||
close()
|
||||
} finally {
|
||||
dbTableLoading.value = false
|
||||
}
|
||||
}
|
||||
const emit = defineEmits(['success'])
|
||||
</script>
|
212
src/views/exam/class/index.vue
Normal file
212
src/views/exam/class/index.vue
Normal file
@@ -0,0 +1,212 @@
|
||||
<template>
|
||||
<ContentWrap>
|
||||
<!-- 搜索工作栏 -->
|
||||
<el-form
|
||||
class="-mb-15px"
|
||||
:model="queryParams"
|
||||
ref="queryFormRef"
|
||||
:inline="true"
|
||||
label-width="68px"
|
||||
>
|
||||
<el-form-item label="名字" prop="name">
|
||||
<el-input
|
||||
v-model="queryParams.name"
|
||||
placeholder="请输入名字"
|
||||
clearable
|
||||
@keyup.enter="handleQuery"
|
||||
class="!w-240px"
|
||||
/>
|
||||
</el-form-item>
|
||||
<el-form-item label="状态" prop="status">
|
||||
<el-select
|
||||
v-model="queryParams.status"
|
||||
placeholder="请选择状态"
|
||||
clearable
|
||||
class="!w-240px"
|
||||
>
|
||||
<el-option label="请选择字典生成" value="" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button>
|
||||
<el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button>
|
||||
<el-button
|
||||
type="primary"
|
||||
plain
|
||||
@click="openForm('create')"
|
||||
v-hasPermi="['exam:class:create']"
|
||||
>
|
||||
<Icon icon="ep:plus" class="mr-5px" /> 新增
|
||||
</el-button>
|
||||
<el-button
|
||||
type="success"
|
||||
plain
|
||||
@click="handleExport"
|
||||
:loading="exportLoading"
|
||||
v-hasPermi="['exam:class:export']"
|
||||
>
|
||||
<Icon icon="ep:download" class="mr-5px" /> 导出
|
||||
</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</ContentWrap>
|
||||
|
||||
<!-- 列表 -->
|
||||
<ContentWrap>
|
||||
<el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
|
||||
<el-table-column label="班级编号" align="center" prop="id" />
|
||||
<el-table-column label="名字" align="center" prop="name" />
|
||||
<el-table-column label="状态" align="center" prop="status" />
|
||||
<el-table-column label="备注" align="center" prop="remark" />
|
||||
<el-table-column
|
||||
label="创建时间"
|
||||
align="center"
|
||||
prop="createTime"
|
||||
:formatter="dateFormatter"
|
||||
width="180px"
|
||||
/>
|
||||
<el-table-column label="操作" align="center" min-width="120px">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openStudentTable(scope.row.id)"
|
||||
v-hasPermi="['exam:class:delete']"
|
||||
>
|
||||
归属学生
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openStudentTable(scope.row.id)"
|
||||
v-hasPermi="['exam:class:delete']"
|
||||
>
|
||||
归属教师
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
@click="openForm('update', scope.row.id)"
|
||||
v-hasPermi="['exam:class:update']"
|
||||
>
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
link
|
||||
type="danger"
|
||||
@click="handleDelete(scope.row.id)"
|
||||
v-hasPermi="['exam:class:delete']"
|
||||
>
|
||||
删除
|
||||
</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
<!-- 分页 -->
|
||||
<Pagination
|
||||
:total="total"
|
||||
v-model:page="queryParams.pageNo"
|
||||
v-model:limit="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
</ContentWrap>
|
||||
<!-- 弹窗:导入表 -->
|
||||
<StudentTable ref="importRef" @success="getList" :class-id="classId"/>
|
||||
<!-- 表单弹窗:添加/修改 -->
|
||||
<ClassForm ref="formRef" @success="getList"/>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { dateFormatter } from '@/utils/formatTime'
|
||||
import download from '@/utils/download'
|
||||
import { ClassApi, ClassVO } from '@/api/exam/class'
|
||||
import ClassForm from './ClassForm.vue'
|
||||
import StudentTable from './StudentTable.vue'
|
||||
|
||||
/** 学生班级 列表 */
|
||||
defineOptions({ name: 'Class' })
|
||||
|
||||
const message = useMessage() // 消息弹窗
|
||||
const { t } = useI18n() // 国际化
|
||||
|
||||
const loading = ref(true) // 列表的加载中
|
||||
const list = ref<ClassVO[]>([]) // 列表的数据
|
||||
const total = ref(0) // 列表的总页数
|
||||
const queryParams = reactive({
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
name: undefined,
|
||||
status: undefined
|
||||
})
|
||||
const queryFormRef = ref() // 搜索的表单
|
||||
const exportLoading = ref(false) // 导出的加载中
|
||||
/** 绑定操作 */
|
||||
const importRef = ref()
|
||||
const classId = ref()
|
||||
const openStudentTable = (id: Number) => {
|
||||
classId.value = id
|
||||
importRef.value.open()
|
||||
}
|
||||
/** 查询列表 */
|
||||
const getList = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const data = await ClassApi.getClassPage(queryParams)
|
||||
list.value = data.list
|
||||
total.value = data.total
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 搜索按钮操作 */
|
||||
const handleQuery = () => {
|
||||
queryParams.pageNo = 1
|
||||
getList()
|
||||
}
|
||||
|
||||
/** 重置按钮操作 */
|
||||
const resetQuery = () => {
|
||||
queryFormRef.value.resetFields()
|
||||
handleQuery()
|
||||
}
|
||||
|
||||
/** 添加/修改操作 */
|
||||
const formRef = ref()
|
||||
const openForm = (type: string, id?: number) => {
|
||||
formRef.value.open(type, id)
|
||||
}
|
||||
|
||||
/** 删除按钮操作 */
|
||||
const handleDelete = async (id: number) => {
|
||||
try {
|
||||
// 删除的二次确认
|
||||
await message.delConfirm()
|
||||
// 发起删除
|
||||
await ClassApi.deleteClass(id)
|
||||
message.success(t('common.delSuccess'))
|
||||
// 刷新列表
|
||||
await getList()
|
||||
} catch {}
|
||||
}
|
||||
|
||||
/** 导出按钮操作 */
|
||||
const handleExport = async () => {
|
||||
try {
|
||||
// 导出的二次确认
|
||||
await message.exportConfirm()
|
||||
// 发起导出
|
||||
exportLoading.value = true
|
||||
const data = await ClassApi.exportClass(queryParams)
|
||||
download.excel(data, '学生班级.xls')
|
||||
} catch {
|
||||
} finally {
|
||||
exportLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 初始化 **/
|
||||
onMounted(() => {
|
||||
getList()
|
||||
})
|
||||
</script>
|
Reference in New Issue
Block a user