fix: avoid blocking route navigation

fix/non-blocking-route-navigation
chenyuan 1 week ago
parent f07d09635f
commit 5c51a585f9

@ -105,7 +105,22 @@ const getCurrentTeachingClassId = async () => {
}
return classId;
};
router.beforeEach(async (to, from, next) => {
const updateVisitCountInBackground = (projectName) => {
getCurrentTeachingClassId()
.then((currentClassId) => {
if (!currentClassId) return;
return indexApi.updateVisitCount({
classId: currentClassId,
projectName,
schoolId: userStore.userInfo.schoolId,
userId: userStore.userInfo.userId,
});
})
.catch((error) => {
console.warn("更新模块访问次数失败", error);
});
};
router.beforeEach((to, from, next) => {
if (isDemo.value) { next(); return; }
const disabledTitles = proxy.$cache.session.getJSON("disabledTitles");
const routess = Array.isArray(disabledTitles) ? disabledTitles : [];
@ -135,21 +150,9 @@ router.beforeEach(async (to, from, next) => {
}
start(toModule);
if (module.includes(fromModule)) {
const currentClassId = await getCurrentTeachingClassId();
if (!currentClassId) {
next();
return;
}
// 访
indexApi
.updateVisitCount({
classId: currentClassId,
projectName: fromModule,
schoolId: userStore.userInfo.schoolId,
userId: userStore.userInfo.userId,
})
.then((res) => {});
}
// 访
updateVisitCountInBackground(fromModule);
}
}
next();
});

@ -37,8 +37,25 @@ router.beforeEach((to, from, next) => {
next({ path: "/index" });
NProgress.done();
}
} else {
} else {
const userStore = useUserStore();
const requiresSchoolProductConfig = to.matched.some((record) =>
record.meta?.requiresFacultyManagement
|| record.meta?.requiresMajorManagement
|| record.meta?.requiresAdminClass
);
const continueNavigation = () => {
usePermissionStore()
.getRoutersPermission()
.then(() => next()); // hack方法 确保addRoutes已完成
};
// 普通页面无需等待学校配置接口;仅管理页需要用该配置做访问校验。
if (!requiresSchoolProductConfig) {
continueNavigation();
return;
}
userStore
.ensureSchoolProductConfig()
.then((config) => {
@ -56,12 +73,17 @@ router.beforeEach((to, from, next) => {
NProgress.done();
return null;
}
return usePermissionStore().getRoutersPermission();
return true;
})
.then((allowed) => {
if (allowed === null) return;
continueNavigation();
})
.then((accessRoutes) => {
if (accessRoutes === null) return;
next(); // hack方法 确保addRoutes已完成
});
.catch(() => {
ElMessage.error("学校配置加载失败,请稍后重试");
next(false);
NProgress.done();
});
}
} else {
// 没有token

Loading…
Cancel
Save