docs: complete project code annotations

This commit is contained in:
2026-09-28 16:09:07 +08:00
parent 1f016bb8a2
commit fce2cbbd2e
112 changed files with 1233 additions and 350 deletions
+5 -1
View File
@@ -11,6 +11,7 @@ import { PAGE_NOT_FOUND_ROUTE } from '@/utils/route/constant';
NProgress.configure({ showSpinner: false });
/** 在每次导航前检查登录状态、初始化权限路由并维护进度条。 */
router.beforeEach(async (to, from, next) => {
NProgress.start();
@@ -29,12 +30,14 @@ router.beforeEach(async (to, from, next) => {
const { asyncRoutes } = permissionStore;
// 用户资料加载成功后,首次进入受保护页面时再构建动态菜单路由。
if (asyncRoutes && asyncRoutes.length === 0) {
const routeList = await permissionStore.buildAsyncRoutes();
routeList.forEach((item: RouteRecordRaw) => {
router.addRoute(item);
});
// 路由刚添加时需要重新匹配当前 URL,避免首次导航落到 404。
if (to.name === PAGE_NOT_FOUND_ROUTE.name) {
// 动态添加路由后,此处应当重定向到fullPath,否则会加载404页面内容
next({ path: to.fullPath, replace: true, query: to.query });
@@ -60,7 +63,7 @@ router.beforeEach(async (to, from, next) => {
NProgress.done();
}
} else {
/* white list router */
// 未登录用户仅可进入白名单;其他地址记录目标路径后转向登录页。
if (whiteListRouters.includes(normalizePath(to.path))) {
next();
} else {
@@ -73,6 +76,7 @@ router.beforeEach(async (to, from, next) => {
}
});
/** 路由完成后收尾进度条;进入登录页时同步清理用户和动态路由状态。 */
router.afterEach((to) => {
if (normalizePath(to.path) === '/login') {
const userStore = useUserStore();