更改校端权限

This commit is contained in:
chenxing
2026-09-07 09:32:38 +08:00
parent 9200fa2135
commit 7e37f2ada6
15 changed files with 461 additions and 120 deletions
+43
View File
@@ -0,0 +1,43 @@
import { computed, ref } from "vue";
import { Message } from "view-ui-plus";
import { useDefaultStore } from "@/store";
import { UserRoleEnum } from "@/types";
/**
* 应用管理页学校上下文(管理端权限分级改造 §4.3)。<br>
* SCHOOL 模式专属:多校管理员(schoolGroupIds.length > 1)页面顶部出现「学校」下拉,
* currentSchoolId 随接口下发给 AppList/AppSortList/AppSort/EditApp/EditType/AppTypeSort,
* 覆盖只对所选学校生效;单校管理员不显示下拉(后端自动取唯一学校),
* 超管/局端不进入本上下文(局端无应用管理菜单)。
*/
export function useAppSchoolScope() {
const store = useDefaultStore();
const isSchoolMode = computed(() => store.userRole === UserRoleEnum.School);
const schoolGroupIds = computed<number[]>(() => store.userScope?.schoolGroupIds ?? []);
const multiSchool = computed(() => isSchoolMode.value && schoolGroupIds.value.length > 1);
const schoolList = ref<{ id: number; name: string }[]>([]);
// 默认不选中(currentSchoolId=undefined):查询走后端「多校并集」模式;
// 写操作(编辑/排序)要求先选定学校,由页面用 requireSchool() 守卫
const currentSchoolId = ref<number | undefined>(undefined);
/** 多校模式下写操作前置校验:未选学校时提示并阻断,返回 false */
function requireSchool(): boolean {
if (multiSchool.value && !currentSchoolId.value) {
Message.warning("您管理多所学校,请先在顶部选择学校后再操作");
return false;
}
return true;
}
if (multiSchool.value) {
// 下拉数据源(SUPER/BUREAU 后端返回空数组,前端也不渲染下拉)
Promise.resolve(Apis.AppSettings.schoolList({ cacheFor: null }))
.then((list: any) => {
schoolList.value = Array.isArray(list) ? list : [];
})
.catch(e => console.warn("获取可管理学校列表失败", e));
}
return { isSchoolMode, multiSchool, schoolList, currentSchoolId, requireSchool };
}