feat: 完善学校管理模块
- 后端:学校新增时自动生成学校编码(格式:SCH + 年份后两位 + 6位序号) - 前端:列表页显示学校编码列 - 前端:编辑弹窗显示学校编码(只读) - 前端:优化年级/班级选项数据格式转换
This commit is contained in:
parent
50e291d2b4
commit
bb14acd923
|
|
@ -91,9 +91,33 @@ public class PgSchoolServiceImpl implements IPgSchoolService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int insert(PgSchool school) {
|
public int insert(PgSchool school) {
|
||||||
|
// 自动生成学校编码
|
||||||
|
String schoolCode = generateSchoolCode();
|
||||||
|
school.setSchoolCode(schoolCode);
|
||||||
return baseMapper.insert(school);
|
return baseMapper.insert(school);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 生成学校编码,格式:SCH + 年份后两位 + 6位序号
|
||||||
|
*/
|
||||||
|
private String generateSchoolCode() {
|
||||||
|
String yearSuffix = String.valueOf(java.time.Year.now().getValue()).substring(2);
|
||||||
|
String prefix = "SCH" + yearSuffix;
|
||||||
|
// 查询当前最大编码
|
||||||
|
LambdaQueryWrapper<PgSchool> wrapper = new LambdaQueryWrapper<>();
|
||||||
|
wrapper.likeRight(PgSchool::getSchoolCode, prefix);
|
||||||
|
wrapper.orderByDesc(PgSchool::getSchoolCode);
|
||||||
|
wrapper.last("LIMIT 1");
|
||||||
|
PgSchool lastSchool = baseMapper.selectOne(wrapper);
|
||||||
|
int nextSeq = 1;
|
||||||
|
if (lastSchool != null && lastSchool.getSchoolCode() != null) {
|
||||||
|
String lastCode = lastSchool.getSchoolCode();
|
||||||
|
String seqStr = lastCode.substring(prefix.length());
|
||||||
|
nextSeq = Integer.parseInt(seqStr) + 1;
|
||||||
|
}
|
||||||
|
return prefix + String.format("%06d", nextSeq);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int update(PgSchool school) {
|
public int update(PgSchool school) {
|
||||||
return baseMapper.updateById(school);
|
return baseMapper.updateById(school);
|
||||||
|
|
|
||||||
|
|
@ -46,8 +46,8 @@ const generateCaptcha = () => {
|
||||||
return { code, img: base64 }
|
return { code, img: base64 }
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取验证码
|
// 获取验证码(路径与后端一致:/auth/code)
|
||||||
Mock.mock(/\/api\/captchaImage/, 'get', () => {
|
Mock.mock(/\/auth\/code/, 'get', () => {
|
||||||
const uuid = Mock.Random.guid()
|
const uuid = Mock.Random.guid()
|
||||||
const captcha = generateCaptcha()
|
const captcha = generateCaptcha()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -74,6 +74,7 @@ const fetchSchoolGrades = async (schoolId) => {
|
||||||
try {
|
try {
|
||||||
const res = await getSchoolGradeTree(schoolId)
|
const res = await getSchoolGradeTree(schoolId)
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
|
// res.data 是 PgSchoolGrade 列表,包含 id(学校年级关联ID)、gradeId、gradeName
|
||||||
schoolGradeOptions.value = res.data || []
|
schoolGradeOptions.value = res.data || []
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
@ -86,10 +87,11 @@ const fetchClassOptions = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getClassOptions()
|
const res = await getClassOptions()
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
// 转换为选项格式
|
// 转换为选项格式 { value: classId, label: className }
|
||||||
classOptions.value = (res.data || []).map(item => ({
|
classOptions.value = (res.data || []).map(item => ({
|
||||||
value: item.classId,
|
value: item.classId,
|
||||||
label: item.className
|
label: item.className,
|
||||||
|
disabled: false
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -60,10 +60,11 @@ const fetchGradeOptions = async () => {
|
||||||
try {
|
try {
|
||||||
const res = await getGradeOptions()
|
const res = await getGradeOptions()
|
||||||
if (res.code === 200) {
|
if (res.code === 200) {
|
||||||
// 转换为选项格式
|
// 转换为选项格式 { value: gradeId, label: gradeName }
|
||||||
gradeOptions.value = (res.data || []).map(item => ({
|
gradeOptions.value = (res.data || []).map(item => ({
|
||||||
value: item.gradeId,
|
value: item.gradeId,
|
||||||
label: item.gradeName
|
label: item.gradeName,
|
||||||
|
disabled: false
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,11 @@
|
||||||
:rules="rules"
|
:rules="rules"
|
||||||
label-width="100px"
|
label-width="100px"
|
||||||
>
|
>
|
||||||
|
<el-form-item v-if="isEdit" label="学校编码">
|
||||||
|
<el-input v-model="form.schoolCode" disabled />
|
||||||
|
</el-form-item>
|
||||||
<el-form-item label="学校名称" prop="schoolName">
|
<el-form-item label="学校名称" prop="schoolName">
|
||||||
<el-input v-model="form.schoolName" placeholder="请输入学校名称" />
|
<el-input v-model="form.schoolName" placeholder="请输入学校名称" maxlength="100" show-word-limit />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="学校类型" prop="schoolType">
|
<el-form-item label="学校类型" prop="schoolType">
|
||||||
<el-select v-model="form.schoolType" placeholder="请选择学校类型" style="width: 100%">
|
<el-select v-model="form.schoolType" placeholder="请选择学校类型" style="width: 100%">
|
||||||
|
|
@ -84,6 +87,7 @@ const isEdit = ref(false)
|
||||||
// 表单数据
|
// 表单数据
|
||||||
const form = ref({
|
const form = ref({
|
||||||
schoolId: null,
|
schoolId: null,
|
||||||
|
schoolCode: '',
|
||||||
schoolName: '',
|
schoolName: '',
|
||||||
schoolType: '',
|
schoolType: '',
|
||||||
regionId: null,
|
regionId: null,
|
||||||
|
|
@ -145,6 +149,7 @@ const open = (row) => {
|
||||||
// 编辑模式:回显数据
|
// 编辑模式:回显数据
|
||||||
form.value = {
|
form.value = {
|
||||||
schoolId: row.schoolId,
|
schoolId: row.schoolId,
|
||||||
|
schoolCode: row.schoolCode || '',
|
||||||
schoolName: row.schoolName,
|
schoolName: row.schoolName,
|
||||||
schoolType: row.schoolType,
|
schoolType: row.schoolType,
|
||||||
regionId: row.regionId,
|
regionId: row.regionId,
|
||||||
|
|
@ -156,6 +161,7 @@ const open = (row) => {
|
||||||
// 新增模式:重置表单
|
// 新增模式:重置表单
|
||||||
form.value = {
|
form.value = {
|
||||||
schoolId: null,
|
schoolId: null,
|
||||||
|
schoolCode: '',
|
||||||
schoolName: '',
|
schoolName: '',
|
||||||
schoolType: '',
|
schoolType: '',
|
||||||
regionId: null,
|
regionId: null,
|
||||||
|
|
|
||||||
|
|
@ -52,13 +52,14 @@
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="tableData" border stripe :header-cell-style="{ background: '#f5f7fa', color: '#606266' }" style="width: 100%">
|
<el-table v-loading="loading" :data="tableData" border stripe :header-cell-style="{ background: '#f5f7fa', color: '#606266' }" style="width: 100%">
|
||||||
|
<el-table-column prop="schoolCode" label="学校编码" width="130" />
|
||||||
<el-table-column prop="schoolName" label="学校名称" min-width="150" show-overflow-tooltip />
|
<el-table-column prop="schoolName" label="学校名称" min-width="150" show-overflow-tooltip />
|
||||||
<el-table-column prop="schoolType" label="学校类型" width="100" align="center">
|
<el-table-column prop="schoolType" label="学校类型" width="100" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
{{ schoolTypeMap[row.schoolType] || row.schoolType }}
|
{{ schoolTypeMap[row.schoolType] || row.schoolType }}
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column prop="regionName" label="所属区域" min-width="180" show-overflow-tooltip />
|
<el-table-column prop="regionName" label="所属区域" min-width="150" show-overflow-tooltip />
|
||||||
<el-table-column prop="status" label="状态" width="80" align="center">
|
<el-table-column prop="status" label="状态" width="80" align="center">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<el-tag :type="row.status === '0' ? 'success' : 'danger'">
|
<el-tag :type="row.status === '0' ? 'success' : 'danger'">
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue