diff --git a/src/views/teacherEnd/student/index.vue b/src/views/teacherEnd/student/index.vue index 43839c5..d4eb0a3 100644 --- a/src/views/teacherEnd/student/index.vue +++ b/src/views/teacherEnd/student/index.vue @@ -124,6 +124,8 @@ const { proxy } = getCurrentInstance(); import useUserStore from "@/store/modules/user"; const userStore = useUserStore(); const currentUserId = computed(() => userStore.userInfo.userId); +const currentSchoolId = computed(() => userStore.userInfo.schoolId); +const isManagerTeacher = computed(() => userStore.userInfo.teacherAdmin === true || String(userStore.userInfo.roleId || userStore.userInfo.role) === "1"); import * as indexApi from "@/api/teacher"; const dialogVisible = ref(false); const loading = ref(false); @@ -277,13 +279,21 @@ const normalizeClassType = (schoolClass) => { if (schoolClass?.classType) return schoolClass.classType; return schoolClass?.createdBy ? "TEACHING" : "ADMIN"; }; +const sameValue = (left, right) => String(left || "") === String(right || ""); +const canUseAdminClassForStudent = (schoolClass) => { + if (normalizeClassType(schoolClass) !== "ADMIN") return false; + if (isManagerTeacher.value) { + return !schoolClass?.schoolId || sameValue(schoolClass.schoolId, currentSchoolId.value); + } + return sameValue(schoolClass?.createdBy, currentUserId.value); +}; const teachingClassList = computed(() => classList.value.filter((item) => normalizeClassType(item) === "TEACHING")); const classOwnerMap = computed(() => { return new Map(classList.value.map((item) => [item.schoolClassId, item.createdBy])); }); const canOperateStudent = (row) => { const teachingClassId = paramsquery.value.schoolClassId || row.schoolClassId; - return classOwnerMap.value.get(teachingClassId) === currentUserId.value; + return sameValue(classOwnerMap.value.get(teachingClassId), currentUserId.value); }; const getClassList = () => { indexApi.getClassListBySchoolId({ schoolId: userStore.userInfo.schoolId }).then((res) => { @@ -296,7 +306,7 @@ const getClassByMajor = () => { if (!formInline.value.schoolMajorId) return; formInline.value.schoolClassId = ""; indexApi.getClassListByMajorId({ schoolMajorId: formInline.value.schoolMajorId }).then((res) => { - classList1.value = (res.data || []).filter((item) => normalizeClassType(item) === "TEACHING" && item.createdBy === currentUserId.value); + classList1.value = (res.data || []).filter((item) => canUseAdminClassForStudent(item)); }); }; //初始化密码