feat: 新增年级/班级时已添加的选项禁用显示

- 新增年级弹窗:已挂载的年级显示为灰色不可选(已添加)
- 新增班级弹窗:已挂载的班级显示为灰色不可选(已添加)
- 从树形数据中获取已有年级/班级的ID列表传递给弹窗
This commit is contained in:
神码-方晓辉 2026-02-02 17:48:59 +08:00
parent 20d9fd24d1
commit 40fe55b42a
3 changed files with 35 additions and 9 deletions

View File

@ -16,8 +16,8 @@
<el-checkbox-group v-model="form.classIds">
<el-row :gutter="10">
<el-col :span="8" v-for="item in classOptions" :key="item.value">
<el-checkbox :label="item.value" style="margin-bottom: 8px;">
{{ item.label }}
<el-checkbox :label="item.value" :disabled="item.disabled" style="margin-bottom: 8px;">
{{ item.label }}{{ item.disabled ? '(已添加)' : '' }}
</el-checkbox>
</el-col>
</el-row>
@ -56,6 +56,9 @@ const form = ref({
classIds: []
})
// ID
const existingClassIds = ref([])
//
const fetchClassOptions = async () => {
try {
@ -65,7 +68,7 @@ const fetchClassOptions = async () => {
classOptions.value = (res.data || []).map(item => ({
value: item.classId,
label: item.className,
disabled: false
disabled: existingClassIds.value.includes(item.classId)
}))
}
} catch (error) {
@ -74,15 +77,19 @@ const fetchClassOptions = async () => {
}
//
// schoolData: { schoolId, schoolName, schoolGradeId, gradeName }
// schoolData: { schoolId, schoolName, schoolGradeId, gradeName, existingClassIds }
const open = (schoolData) => {
dialogVisible.value = true
currentSchool.value = schoolData
// ID
existingClassIds.value = schoolData.existingClassIds || []
form.value = {
schoolId: schoolData.schoolId,
schoolGradeId: schoolData.schoolGradeId,
classIds: []
}
//
fetchClassOptions()
}
//

View File

@ -16,8 +16,8 @@
<el-checkbox-group v-model="form.gradeIds">
<el-row :gutter="10">
<el-col :span="8" v-for="item in gradeOptions" :key="item.value">
<el-checkbox :label="item.value" style="margin-bottom: 8px;">
{{ item.label }}
<el-checkbox :label="item.value" :disabled="item.disabled" style="margin-bottom: 8px;">
{{ item.label }}{{ item.disabled ? '(已添加)' : '' }}
</el-checkbox>
</el-col>
</el-row>
@ -55,6 +55,9 @@ const form = ref({
gradeIds: []
})
// ID
const existingGradeIds = ref([])
//
const fetchGradeOptions = async () => {
try {
@ -64,7 +67,7 @@ const fetchGradeOptions = async () => {
gradeOptions.value = (res.data || []).map(item => ({
value: item.gradeId,
label: item.gradeName,
disabled: false
disabled: existingGradeIds.value.includes(item.gradeId)
}))
}
} catch (error) {
@ -76,10 +79,14 @@ const fetchGradeOptions = async () => {
const open = (school) => {
dialogVisible.value = true
currentSchool.value = school
// ID
existingGradeIds.value = school.existingGradeIds || []
form.value = {
schoolId: school.schoolId,
gradeIds: []
}
//
fetchGradeOptions()
}
//

View File

@ -232,9 +232,15 @@ const handleEdit = (row) => {
// -
const handleAddGrade = (row) => {
// ID
const existingGradeIds = (row.children || [])
.filter(child => child.type === 'grade')
.map(child => child.gradeId)
const schoolData = {
schoolId: row.id,
schoolName: row.name
schoolName: row.name,
existingGradeIds: existingGradeIds
}
gradeDialogRef.value?.open(schoolData)
}
@ -243,11 +249,17 @@ const handleAddGrade = (row) => {
const handleAddClass = (row) => {
// treeData
const school = treeData.value.find(s => s.id === row.schoolId)
// ID
const existingClassIds = (row.children || [])
.filter(child => child.type === 'class')
.map(child => child.classId)
const schoolData = {
schoolId: row.schoolId,
schoolName: school ? school.name : '',
schoolGradeId: row.id,
gradeName: row.name
gradeName: row.name,
existingClassIds: existingClassIds
}
classDialogRef.value?.open(schoolData)
}