diff --git a/src/layout/components/Sidebar/index.vue b/src/layout/components/Sidebar/index.vue
index ea0dde7..bbecc29 100644
--- a/src/layout/components/Sidebar/index.vue
+++ b/src/layout/components/Sidebar/index.vue
@@ -724,7 +724,7 @@ function filterTeacherManageNavigation(sections) {
.filter((section) => (section.children ? section.children.length > 0 : isSchoolNavigationVisible(section)));
}
watch(
- () => userStore.schoolProductConfig?.organizationMode,
+ () => JSON.stringify(userStore.schoolProductConfig),
(organizationMode, previousOrganizationMode) => {
if (organizationMode === previousOrganizationMode) return;
if ([2, 3].includes(Number(userStore.userInfo.roleId))) {
@@ -734,5 +734,12 @@ watch(
);
onMounted(() => {
getTaskList();
+ window.addEventListener("focus", refreshSchoolConfiguration);
});
+onBeforeUnmount(() => window.removeEventListener("focus", refreshSchoolConfiguration));
+function refreshSchoolConfiguration() {
+ if ([2, 3].includes(Number(userStore.userInfo.roleId))) {
+ userStore.ensureSchoolProductConfig().catch(() => null);
+ }
+}
diff --git a/src/permission.js b/src/permission.js
index 0805ed6..a368561 100644
--- a/src/permission.js
+++ b/src/permission.js
@@ -41,7 +41,7 @@ router.beforeEach((to, from, next) => {
}
} else {
const userStore = useUserStore();
- const requiresSchoolProductConfig = to.matched.some((record) =>
+ const requiresSchoolProductConfig = [2, 3].includes(Number(userStore.userInfo?.roleId)) || to.matched.some((record) =>
record.meta?.requiresFacultyManagement
|| record.meta?.requiresMajorManagement
|| record.meta?.requiresAdminClass
@@ -77,7 +77,7 @@ router.beforeEach((to, from, next) => {
return;
}
- // 普通页面无需等待学校配置接口;仅管理页需要用该配置做访问校验。
+ // 学校管理员和教师导航时刷新配置,管理页额外校验对应能力。
if (!requiresSchoolProductConfig) {
continueNavigation();
return;
@@ -86,10 +86,10 @@ router.beforeEach((to, from, next) => {
userStore
.ensureSchoolProductConfig()
.then((config) => {
- const legacyAdminEnabled = config?.organizationMode !== "TEACHING_CLASS_ONLY";
- const facultyEnabled = config?.facultyManagementEnabled ?? legacyAdminEnabled;
- const majorEnabled = config?.majorManagementEnabled ?? legacyAdminEnabled;
- const adminClassEnabled = config?.adminClassManagementEnabled ?? legacyAdminEnabled;
+ if (!config) throw new Error("学校配置尚未就绪");
+ const facultyEnabled = config.facultyManagementEnabled === true;
+ const majorEnabled = config.majorManagementEnabled === true;
+ const adminClassEnabled = config.adminClassManagementEnabled === true;
const unavailableManagementRoute = to.matched.some((record) =>
(record.meta?.requiresFacultyManagement && !facultyEnabled)
|| (record.meta?.requiresMajorManagement && !majorEnabled)
diff --git a/src/store/modules/user.js b/src/store/modules/user.js
index e5328a2..44ee0fc 100644
--- a/src/store/modules/user.js
+++ b/src/store/modules/user.js
@@ -10,6 +10,7 @@ import { login, logout, getInfo } from "@/api/login";
import { getCurrentSchoolProductConfig } from "@/api/schoolProductConfig";
import { getToken, setToken, removeToken, setUserInfo, removeUserInfo, getUserInfo } from "@/utils/auth";
import defAva from "@/assets/images/profile.jpg";
+const schoolConfigRequests = new WeakMap();
const useUserStore = defineStore("user", {
state: () => ({
token: getToken(),
@@ -32,6 +33,7 @@ const useUserStore = defineStore("user", {
.then((res) => {
setToken(res.data.token);
this.token = res.data.token;
+ this.schoolProductConfig = null;
this.userInfo = res.data;
setUserInfo(JSON.stringify(res.data));
resolve();
@@ -65,16 +67,25 @@ const useUserStore = defineStore("user", {
});
},
ensureSchoolProductConfig() {
- if (this.schoolProductConfig) {
- return Promise.resolve(this.schoolProductConfig);
- }
if (this.userInfo?.roleId == 1) {
+ this.schoolProductConfig = null;
return Promise.resolve(null);
}
- return getCurrentSchoolProductConfig().then((res) => {
+ const requestToken = this.token;
+ const pending = schoolConfigRequests.get(this);
+ if (pending?.token === requestToken) return pending.promise;
+ const promise = getCurrentSchoolProductConfig().then((res) => {
+ if (this.token !== requestToken) return null;
this.schoolProductConfig = res.data;
return this.schoolProductConfig;
+ }).catch((error) => {
+ if (this.token === requestToken) this.schoolProductConfig = null;
+ throw error;
+ }).finally(() => {
+ if (schoolConfigRequests.get(this)?.promise === promise) schoolConfigRequests.delete(this);
});
+ schoolConfigRequests.set(this, { token: requestToken, promise });
+ return promise;
},
// 退出系统
logOut() {
diff --git a/src/views/platformAdmin/school/index.vue b/src/views/platformAdmin/school/index.vue
index 434a85f..80d2e57 100644
--- a/src/views/platformAdmin/school/index.vue
+++ b/src/views/platformAdmin/school/index.vue
@@ -147,7 +147,7 @@
取消
- 保存
+ 保存
@@ -167,6 +167,9 @@ const total = ref(0);
const loading = ref(false);
const dialogVisible = ref(false);
const editingId = ref("");
+const configLoading = ref(false);
+const saving = ref(false);
+let editRequestId = 0;
const form = ref({});
const defaultProductConfig = () => ({
organizationMode: "ADMIN_CLASS_ENABLED",
@@ -206,6 +209,9 @@ const handleSizeChange = () => {
};
const openCreate = () => {
+ if (saving.value) return;
+ editRequestId++;
+ configLoading.value = false;
editingId.value = "";
form.value = {
schoolName: "",
@@ -226,11 +232,20 @@ const openDetail = (row) => {
};
const openEdit = async (row) => {
+ if (saving.value) return;
+ const requestId = ++editRequestId;
editingId.value = row.schoolId;
form.value = { ...row };
- const res = await getPlatformSchoolProductConfig(row.schoolId);
- productConfig.value = normalizeProductConfig(res.data);
- dialogVisible.value = true;
+ configLoading.value = true;
+ dialogVisible.value = false;
+ try {
+ const res = await getPlatformSchoolProductConfig(row.schoolId);
+ if (requestId !== editRequestId) return;
+ productConfig.value = normalizeProductConfig(res.data);
+ dialogVisible.value = true;
+ } finally {
+ if (requestId === editRequestId) configLoading.value = false;
+ }
};
const handleProvinceChange = () => {
@@ -306,22 +321,29 @@ const buildSchoolPayload = () => ({
});
const submit = async () => {
+ if (configLoading.value || saving.value) return;
+ const schoolId = editingId.value;
const payload = buildSchoolPayload();
- if (editingId.value) {
- await updatePlatformSchoolProductConfig(editingId.value, {
- organizationMode: productConfig.value.organizationMode,
- studentRosterOwner: productConfig.value.studentRosterOwner,
- facultyManagementEnabled: productConfig.value.facultyManagementEnabled,
- majorManagementEnabled: productConfig.value.majorManagementEnabled,
- adminClassManagementEnabled: productConfig.value.adminClassManagementEnabled,
- });
- await updatePlatformSchool(editingId.value, payload);
- } else {
- await addPlatformSchool(payload);
+ saving.value = true;
+ try {
+ if (schoolId) {
+ await updatePlatformSchoolProductConfig(schoolId, {
+ organizationMode: productConfig.value.organizationMode,
+ studentRosterOwner: productConfig.value.studentRosterOwner,
+ facultyManagementEnabled: productConfig.value.facultyManagementEnabled,
+ majorManagementEnabled: productConfig.value.majorManagementEnabled,
+ adminClassManagementEnabled: productConfig.value.adminClassManagementEnabled,
+ });
+ await updatePlatformSchool(schoolId, payload);
+ } else {
+ await addPlatformSchool(payload);
+ }
+ ElMessage.success("保存成功");
+ dialogVisible.value = false;
+ load({ showLoading: false });
+ } finally {
+ saving.value = false;
}
- ElMessage.success("保存成功");
- dialogVisible.value = false;
- load({ showLoading: false });
};
const remove = async (row) => {
diff --git a/src/views/teacherEnd/class/index.vue b/src/views/teacherEnd/class/index.vue
index 84d6afd..af80d7a 100644
--- a/src/views/teacherEnd/class/index.vue
+++ b/src/views/teacherEnd/class/index.vue
@@ -299,7 +299,7 @@ import * as indexApi from "@/api/teacher"
const { proxy } = getCurrentInstance()
const userStore = useUserStore()
-const activeClassType = ref("ADMIN")
+const activeClassType = ref(userStore.schoolProductConfig?.adminClassManagementEnabled === true ? "ADMIN" : "TEACHING")
const dialogVisible = ref(false)
const memberDialogVisible = ref(false)
const loading = ref(false)
@@ -318,11 +318,10 @@ const selectedTeachingClass = ref(null)
const currentUserId = computed(() => userStore.userInfo.userId)
const currentSchoolId = computed(() => userStore.userInfo.schoolId)
-const legacyAdminEnabled = computed(() => userStore.schoolProductConfig?.organizationMode !== "TEACHING_CLASS_ONLY")
-const facultyManagementEnabled = computed(() => userStore.schoolProductConfig?.facultyManagementEnabled ?? legacyAdminEnabled.value)
-const majorManagementEnabled = computed(() => userStore.schoolProductConfig?.majorManagementEnabled ?? legacyAdminEnabled.value)
-const adminClassManagementEnabled = computed(() => userStore.schoolProductConfig?.adminClassManagementEnabled ?? legacyAdminEnabled.value)
-const isTeacherRosterMode = computed(() => !facultyManagementEnabled.value && !majorManagementEnabled.value && !adminClassManagementEnabled.value)
+const facultyManagementEnabled = computed(() => userStore.schoolProductConfig?.facultyManagementEnabled === true)
+const majorManagementEnabled = computed(() => userStore.schoolProductConfig?.majorManagementEnabled === true)
+const adminClassManagementEnabled = computed(() => userStore.schoolProductConfig?.adminClassManagementEnabled === true)
+const isTeacherRosterMode = computed(() => userStore.schoolProductConfig?.studentRosterOwner === "TEACHER")
const canCreateCurrentClass = computed(() => activeClassType.value === "ADMIN" || activeClassType.value === "TEACHING")
const paramsquery = ref({
@@ -434,13 +433,16 @@ function normalizeClassType(schoolClass) {
}
function canOperateClass(schoolClass) {
+ if (!schoolClass || schoolClass.schoolId !== currentSchoolId.value) {
+ return false
+ }
if (schoolClass?.dataSource === "ZHIYUN") {
return false
}
if (normalizeClassType(schoolClass) === "ADMIN") {
- return !schoolClass?.schoolId || schoolClass.schoolId === currentSchoolId.value
+ return adminClassManagementEnabled.value
}
- return schoolClass?.createdBy === currentUserId.value
+ return userStore.userInfo.teacherAdmin === true || schoolClass.createdBy === currentUserId.value
}
function getList(options = {}) {
@@ -933,9 +935,7 @@ onMounted(() => {
getFacultyList()
})
-// 学校配置可能晚于页面挂载才返回(permission.js 仅对带 requires* meta 的路由等待该接口),
-// 这里响应式修正:行政班管理关闭(TEACHING_CLASS_ONLY)的学校固定为教学班视角,
-// 避免一次性 onMounted 判断在配置未就绪时把页面定格在行政班、过滤掉全部教学班。
+// 配置未加载或刷新失败时同样不得显示行政班;只有后端明确开启才展示行政班入口。
watch(adminClassManagementEnabled, (enabled) => {
if (!enabled) {
activeClassType.value = "TEACHING"
diff --git a/src/views/teacherEnd/teacher/index.vue b/src/views/teacherEnd/teacher/index.vue
index 6385ade..0cc2eb6 100644
--- a/src/views/teacherEnd/teacher/index.vue
+++ b/src/views/teacherEnd/teacher/index.vue
@@ -214,10 +214,9 @@ const dialogVisible = ref(false)
const loading = ref(false)
const currentUserId = computed(() => userStore.userInfo.userId)
const isManagerTeacher = computed(() => userStore.userInfo.teacherAdmin === true || String(userStore.userInfo.roleId || userStore.userInfo.role) === "1")
-const legacyOrganizationManagementEnabled = computed(() => userStore.schoolProductConfig?.organizationMode !== "TEACHING_CLASS_ONLY")
-const facultyManagementEnabled = computed(() => userStore.schoolProductConfig?.facultyManagementEnabled ?? legacyOrganizationManagementEnabled.value)
-const majorManagementEnabled = computed(() => userStore.schoolProductConfig?.majorManagementEnabled ?? legacyOrganizationManagementEnabled.value)
-const adminClassManagementEnabled = computed(() => userStore.schoolProductConfig?.adminClassManagementEnabled ?? legacyOrganizationManagementEnabled.value)
+const facultyManagementEnabled = computed(() => userStore.schoolProductConfig?.facultyManagementEnabled === true)
+const majorManagementEnabled = computed(() => userStore.schoolProductConfig?.majorManagementEnabled === true)
+const adminClassManagementEnabled = computed(() => userStore.schoolProductConfig?.adminClassManagementEnabled === true)
const isOrganizationManagementEnabled = computed(() => facultyManagementEnabled.value || majorManagementEnabled.value || adminClassManagementEnabled.value)
const formatDate = (cellValue) => {
const numeric = Number(cellValue)
diff --git a/tests/school-organization-controls.test.cjs b/tests/school-organization-controls.test.cjs
new file mode 100644
index 0000000..85fd04a
--- /dev/null
+++ b/tests/school-organization-controls.test.cjs
@@ -0,0 +1,185 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const path = require("node:path");
+const vm = require("node:vm");
+const Vue = require("vue");
+const { ref, reactive, computed, watch, nextTick, createSSRApp, h } = Vue;
+const { renderToString } = require("@vue/server-renderer");
+const { compile } = require("@vue/compiler-dom");
+const { parse, compileScript, compileTemplate } = require("@vue/compiler-sfc");
+
+const read = (file) => fs.readFileSync(path.resolve(__dirname, "../src", file), "utf8");
+const stripImports = (source) => source.replace(/^import .*;?\r?\n/gm, "");
+
+function storeHarness(fetchConfig) {
+ const context = { defineStore: (_, definition) => definition, getToken: () => "token-A", getUserInfo: () => '{"roleId":3}', getCurrentSchoolProductConfig: fetchConfig };
+ const source = stripImports(read("store/modules/user.js")).replaceAll("import.meta.env.VITE_APP_BASE_API", '"/"').replace("export default useUserStore;", "globalThis.definition = useUserStore;");
+ vm.runInNewContext(source, context);
+ const state = context.definition.state();
+ state.ensureSchoolProductConfig = function () { return context.definition.actions.ensureSchoolProductConfig.call(this); };
+ return state;
+}
+
+test("configuration refresh follows platform changes and clears failed cached permissions", async () => {
+ let enabled = true;
+ let fail = false;
+ let calls = 0;
+ const state = storeHarness(async () => {
+ calls++;
+ if (fail) throw new Error("offline");
+ return { data: { adminClassManagementEnabled: enabled } };
+ });
+ await state.ensureSchoolProductConfig();
+ enabled = false;
+ assert.equal((await state.ensureSchoolProductConfig()).adminClassManagementEnabled, false);
+ assert.equal(calls, 2);
+ fail = true;
+ await assert.rejects(state.ensureSchoolProductConfig(), /offline/);
+ assert.equal(state.schoolProductConfig, null);
+});
+
+test("concurrent loads share a request and an old login cannot overwrite the current school", async () => {
+ const pending = [];
+ const state = storeHarness(() => new Promise((resolve) => pending.push(resolve)));
+ const first = state.ensureSchoolProductConfig();
+ assert.equal(state.ensureSchoolProductConfig(), first);
+ state.token = "token-B";
+ const second = state.ensureSchoolProductConfig();
+ pending[1]({ data: { schoolId: "B" } });
+ await second;
+ pending[0]({ data: { schoolId: "A" } });
+ await first;
+ assert.equal(state.schoolProductConfig.schoolId, "B");
+});
+
+test("ordinary teacher navigation refreshes configuration before continuing", async () => {
+ let refreshed = 0;
+ const state = { userInfo: { roleId: 3 }, ensureSchoolProductConfig: async () => { refreshed++; return { facultyManagementEnabled: true }; } };
+ let guard;
+ const context = { router: { beforeEach: (fn) => { guard = fn; }, afterEach() {} }, NProgress: { configure() {}, start() {}, done() {} }, getToken: () => "token", getUserInfo: () => '{"roleId":3}', useUserStore: () => state, usePermissionStore: () => ({ getRoutersPermission: async () => {} }), ElMessage: { error: (message) => assert.fail(message) } };
+ vm.runInNewContext(stripImports(read("permission.js")), context);
+ await new Promise((resolve) => guard({ path: "/teacher/index", matched: [{ meta: {} }] }, {}, resolve));
+ assert.equal(refreshed, 1);
+ const sidebar = read("layout/components/Sidebar/index.vue");
+ assert.match(sidebar, /addEventListener\("focus", refreshSchoolConfiguration\)/);
+ assert.match(sidebar, /removeEventListener\("focus", refreshSchoolConfiguration\)/);
+ assert.match(sidebar, /JSON\.stringify\(userStore\.schoolProductConfig\)/);
+});
+
+test("late school responses cannot overwrite the school being edited or its save target", async () => {
+ const filename = "views/platformAdmin/school/index.vue";
+ const { descriptor, errors } = parse(read(filename));
+ assert.deepEqual(errors, []);
+ compileScript(descriptor, { id: "school-editor" });
+ assert.deepEqual(compileTemplate({ source: descriptor.template.content, filename, id: "school-editor" }).errors, []);
+ const pending = {};
+ const saved = [];
+ const context = { ref, reactive, computed, chinaRegions: [], onMounted() {}, ElMessage: { success() {} }, getPlatformSchools: async () => ({ data: { list: [], total: 0 } }), getPlatformSchoolProductConfig: (id) => new Promise((resolve) => { pending[id] = resolve; }), updatePlatformSchoolProductConfig: async (id, config) => saved.push({ id, ...config }), updatePlatformSchool: async () => {} };
+ vm.runInNewContext(stripImports(descriptor.scriptSetup.content) + "\nglobalThis.page = {openEdit, openCreate, submit, editingId, productConfig, configLoading};", context);
+ const page = context.page;
+ const a = page.openEdit({ schoolId: "A" });
+ const b = page.openEdit({ schoolId: "B" });
+ await page.submit();
+ assert.equal(saved.length, 0);
+ pending.B({ data: { schoolId: "B", organizationMode: "TEACHING_CLASS_ONLY", adminClassManagementEnabled: false } });
+ await b;
+ pending.A({ data: { schoolId: "A", organizationMode: "ADMIN_CLASS_ENABLED", adminClassManagementEnabled: true } });
+ await a;
+ assert.equal(page.productConfig.value.schoolId, "B");
+ await page.submit();
+ assert.equal(saved[0].id, "B");
+ assert.equal(saved[0].adminClassManagementEnabled, false);
+ const c = page.openEdit({ schoolId: "C" });
+ page.openCreate();
+ pending.C({ data: { schoolId: "C" } });
+ await c;
+ assert.equal(page.editingId.value, "");
+ assert.equal(page.productConfig.value.schoolId, undefined);
+});
+
+test("custom organization modes use the teacher roster import and template in both pages", async () => {
+ const source = read("views/teacherEnd/class/index.vue");
+ const declarations = source.split(/\r?\n/).filter((line) => /^const (legacyAdminEnabled|facultyManagementEnabled|majorManagementEnabled|adminClassManagementEnabled|isTeacherRosterMode) =/.test(line)).join("\n");
+ const sheets = [];
+ let imported = false;
+ const xlsx = { utils: { aoa_to_sheet: (rows) => { sheets.push(rows); return {}; }, book_new: () => ({}), book_append_sheet() {} }, writeFile() {} };
+ const context = { computed, userStore: { schoolProductConfig: { organizationMode: "CUSTOM", studentRosterOwner: "TEACHER", facultyManagementEnabled: true, majorManagementEnabled: true, adminClassManagementEnabled: false } }, selectedTeachingClass: { value: { schoolClassId: "class-A" } }, indexApi: { importTeacherRosterMembers: async (id) => { imported = id === "class-A"; } }, FormData: class { append() {} }, handleMemberImportSuccess() {}, xlsx };
+ const upload = source.slice(source.indexOf("function uploadMemberImport("), source.indexOf("function handleMemberImportSuccess("));
+ const download = source.slice(source.indexOf("async function downloadMemberImportTemplate("), source.indexOf("/* 2026-10-12 停用:名单创建模板下载"));
+ vm.runInNewContext(declarations + "\n" + upload + "\n" + download.replace('await import("xlsx")', "xlsx") + "\nglobalThis.page={uploadMemberImport,downloadMemberImportTemplate,isTeacherRosterMode};", context);
+ const studentMode = read("views/teacherEnd/student/index.vue").split(/\r?\n/).find((line) => line.startsWith("const isTeacherRosterMode ="));
+ const student = { computed, userStore: context.userStore };
+ vm.runInNewContext(studentMode + "\nglobalThis.mode=isTeacherRosterMode.value;", student);
+ assert.equal(context.page.isTeacherRosterMode.value, student.mode);
+ await context.page.uploadMemberImport({ file: {} });
+ assert.equal(imported, true);
+ await context.page.downloadMemberImportTemplate();
+ assert.deepEqual(Array.from(sheets[0][0]), ["学生姓名", "学号"]);
+});
+
+test("class actions allow same school managers and owners while preserving restrictions", () => {
+ const source = read("views/teacherEnd/class/index.vue");
+ const context = { currentUserId: { value: "manager-A" }, currentSchoolId: { value: "school-A" }, adminClassManagementEnabled: { value: true }, userStore: { userInfo: { teacherAdmin: true } } };
+ vm.runInNewContext(source.slice(source.indexOf("function normalizeClassType("), source.indexOf("function getList(")) + "\nglobalThis.allowed=canOperateClass;", context);
+ const teaching = { schoolId: "school-A", createdBy: "teacher-B", classType: "TEACHING", dataSource: "LOCAL" };
+ assert.equal(context.allowed(teaching), true);
+ assert.equal(context.allowed({ ...teaching, schoolId: "school-B" }), false);
+ assert.equal(context.allowed({ ...teaching, dataSource: "ZHIYUN" }), false);
+ context.userStore.userInfo.teacherAdmin = false;
+ assert.equal(context.allowed(teaching), false);
+ assert.equal(context.allowed({ ...teaching, createdBy: "manager-A" }), true);
+ context.adminClassManagementEnabled.value = false;
+ assert.equal(context.allowed({ ...teaching, classType: "ADMIN" }), false);
+});
+
+test("teaching only page never renders administrative tabs during loading failures or recovery", async () => {
+ let fail = false;
+ const state = reactive(storeHarness(async () => {
+ if (fail) throw new Error("offline");
+ return { data: { organizationMode: "TEACHING_CLASS_ONLY", studentRosterOwner: "TEACHER", facultyManagementEnabled: false, majorManagementEnabled: false, adminClassManagementEnabled: false } };
+ }));
+ const source = read("views/teacherEnd/class/index.vue");
+ const declarations = source.split(/\r?\n/).filter((line) => /^const (activeClassType|legacyAdminEnabled|facultyManagementEnabled|majorManagementEnabled|adminClassManagementEnabled|isTeacherRosterMode) =/.test(line)).join("\n");
+ const modeWatch = source.slice(source.indexOf("watch(adminClassManagementEnabled,"), source.indexOf("", source.indexOf("watch(adminClassManagementEnabled,")));
+ const context = { ref, computed, watch, userStore: state };
+ vm.runInNewContext(declarations + "\n" + modeWatch + "\nglobalThis.page={activeClassType,adminClassManagementEnabled};", context);
+ const tabsTemplate = source.match(//)[0];
+ const render = new Function("Vue", compile(tabsTemplate, { prefixIdentifiers: true }).code)(Vue);
+ async function renderTabs() {
+ const app = createSSRApp({ setup: () => ({ ...context.page, adminClassCount: 2, teachingClassCount: 3, handleTabChange() {} }), render });
+ app.component("el-tabs", { setup: (_, { slots }) => () => h("nav", slots.default?.()) });
+ app.component("el-tab-pane", { props: ["label"], setup: (props) => () => h("span", props.label) });
+ return renderToString(app);
+ }
+ async function expectTeachingOnly() {
+ await nextTick();
+ assert.equal(context.page.adminClassManagementEnabled.value, false);
+ assert.equal(context.page.activeClassType.value, "TEACHING");
+ assert.doesNotMatch(await renderTabs(), /行政班/);
+ }
+ await expectTeachingOnly();
+ for (let i = 0; i < 3; i++) {
+ await state.ensureSchoolProductConfig();
+ await expectTeachingOnly();
+ }
+ fail = true;
+ await assert.rejects(state.ensureSchoolProductConfig(), /offline/);
+ await expectTeachingOnly();
+ fail = false;
+ await state.ensureSchoolProductConfig();
+ await expectTeachingOnly();
+ state.schoolProductConfig = { organizationMode: "ADMIN_CLASS_ENABLED", adminClassManagementEnabled: true };
+ await nextTick();
+ assert.match(await renderTabs(), /行政班/);
+});
+
+test("missing school configuration blocks management navigation instead of enabling administrative classes", async () => {
+ let guard;
+ const messages = [];
+ const context = { router: { beforeEach: (fn) => { guard = fn; }, afterEach() {} }, NProgress: { configure() {}, start() {}, done() {} }, getToken: () => "token", getUserInfo: () => '{"roleId":3}', useUserStore: () => ({ userInfo: { roleId: 3 }, ensureSchoolProductConfig: async () => null }), usePermissionStore: () => ({ getRoutersPermission: async () => assert.fail("navigation must be blocked") }), ElMessage: { error: (message) => messages.push(message) } };
+ vm.runInNewContext(stripImports(read("permission.js")), context);
+ const result = await new Promise((resolve) => guard({ path: "/class/index", matched: [{ meta: { awaitSchoolProductConfig: true } }] }, {}, resolve));
+ assert.equal(result, false);
+ assert.equal(messages.length, 1);
+});
diff --git a/tests/school-product-config.static.test.cjs b/tests/school-product-config.static.test.cjs
index 14695e7..d3bcceb 100644
--- a/tests/school-product-config.static.test.cjs
+++ b/tests/school-product-config.static.test.cjs
@@ -24,7 +24,7 @@ assert(/requiresFacultyManagement:\s*true/.test(sidebar), "the teacher course-st
assert(/requiresMajorManagement:\s*true/.test(sidebar), "the teacher course-style major item must declare its capability");
assert(/filterTeacherManageNavigation\(teacherManageNav\)/.test(sidebar), "the teacher course-style sidebar must filter its hard-coded navigation before rendering");
assert(/currentCourseNav = computed\([\s\S]*?filterTeacherManageNavigation\(teacherManageNav\)/.test(sidebar), "teachers must render the filtered course-style navigation instead of the raw hard-coded menu");
-assert(/watch\(\s*\(\) => userStore\.schoolProductConfig\?\.organizationMode/.test(sidebar), "sidebar must refresh when the asynchronous school configuration arrives");
+assert(/watch\(\s*\(\) => JSON\.stringify\(userStore\.schoolProductConfig\)/.test(sidebar), "sidebar must refresh when any school capability changes, including custom modes");
assert(/organizationMode/.test(platformSchool) && /updatePlatformSchoolProductConfig/.test(platformSchool), "platform school editor must manage organization mode");
assert(/行政班管理/.test(platformSchool), "platform school editor must expose administrative-class management controls");
assert(/v-model="productConfig\.facultyManagementEnabled"/.test(platformSchool), "platform school editor must configure faculty management with a switch");
@@ -34,7 +34,7 @@ assert(/requiresFacultyManagement/.test(router) && /requiresMajorManagement/.tes
assert(/adminClassManagementEnabled/.test(teacherClass), "teacher class page must derive administrative-class controls from the switch");
assert(/isTeacherRosterMode/.test(teacherClass), "teacher class page must recognize teacher-managed roster mode");
assert(!/!this\.userInfo\?\.schoolId\s*\|\|\s*this\.userInfo\?\.roleId\s*==\s*1/.test(userStore), "school configuration loading must not be skipped because cached user info lacks schoolId");
-assert(/this\.userInfo\?\.roleId\s*==\s*1/.test(userStore) && /return getCurrentSchoolProductConfig\(\)/.test(userStore), "every non-platform user must load school configuration from the backend token");
+assert(/this\.userInfo\?\.roleId\s*==\s*1/.test(userStore) && /getCurrentSchoolProductConfig\(\)/.test(userStore), "every non-platform user must load school configuration from the backend token");
assert(/await userStore\.ensureSchoolProductConfig\(\)/.test(sidebar), "school menus must load the product configuration before they are generated");
assert(/const facultyEnabled = config\?\.facultyManagementEnabled === true;/.test(sidebar), "faculty menus must fail closed until their school capability is confirmed");
assert(/const majorEnabled = config\?\.majorManagementEnabled === true;/.test(sidebar), "major menus must fail closed until their school capability is confirmed");