chore: sync changes for v0.1.1
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
import type { Router } from 'vue-router';
|
||||
|
||||
import { LOGIN_PATH } from '@vben/constants';
|
||||
import { preferences } from '@vben/preferences';
|
||||
import { preferences, updatePreferences } from '@vben/preferences';
|
||||
import { useAccessStore, useUserStore } from '@vben/stores';
|
||||
import { startProgress, stopProgress } from '@vben/utils';
|
||||
|
||||
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
||||
import { useAuthStore } from '#/store';
|
||||
import { NO_LOGIN_ROUTES } from '#/router/routes';
|
||||
import { APP_LAYOUT_BY_PREFIX } from '#/preferences';
|
||||
|
||||
import { generateAccess } from './access';
|
||||
|
||||
@@ -21,6 +23,13 @@ function setupCommonGuard(router: Router) {
|
||||
router.beforeEach((to) => {
|
||||
to.meta.loaded = loadedPaths.has(to.path);
|
||||
|
||||
// 根据前缀切换布局(由配置驱动,可接后端/站点设置)
|
||||
const first = to.path.replace(/^\/+/, '').split('/')[0] as string;
|
||||
const desiredLayout = APP_LAYOUT_BY_PREFIX[first];
|
||||
if (desiredLayout && preferences.app.layout !== desiredLayout) {
|
||||
updatePreferences({ app: { layout: desiredLayout as any } });
|
||||
}
|
||||
|
||||
// 页面加载进度条
|
||||
if (!to.meta.loaded && preferences.transition.progress) {
|
||||
startProgress();
|
||||
@@ -36,6 +45,14 @@ function setupCommonGuard(router: Router) {
|
||||
if (preferences.transition.progress) {
|
||||
stopProgress();
|
||||
}
|
||||
|
||||
// 设置标题:路由标题 + 站点/网站名(如有)
|
||||
const titleParts: string[] = [];
|
||||
if (typeof to.meta?.title === 'string') titleParts.push(to.meta.title);
|
||||
// 这里可扩展注入 store 的网站/站点名
|
||||
const websiteName = '';
|
||||
if (websiteName) titleParts.push(websiteName);
|
||||
if (titleParts.length) document.title = titleParts.join(' - ');
|
||||
});
|
||||
}
|
||||
|
||||
@@ -67,6 +84,11 @@ function setupAccessGuard(router: Router) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// addon 定义的免登录白名单
|
||||
if (NO_LOGIN_ROUTES?.includes(to.path)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 没有访问权限,跳转登录页面
|
||||
if (to.fullPath !== LOGIN_PATH) {
|
||||
return {
|
||||
@@ -105,6 +127,8 @@ function setupAccessGuard(router: Router) {
|
||||
accessStore.setAccessMenus(accessibleMenus);
|
||||
accessStore.setAccessRoutes(accessibleRoutes);
|
||||
accessStore.setIsAccessChecked(true);
|
||||
|
||||
// 计算首次进入首页路径
|
||||
let redirectPath: string;
|
||||
if (from.query.redirect) {
|
||||
redirectPath = from.query.redirect as string;
|
||||
@@ -115,6 +139,7 @@ function setupAccessGuard(router: Router) {
|
||||
} else {
|
||||
redirectPath = to.fullPath;
|
||||
}
|
||||
|
||||
return {
|
||||
...router.resolve(decodeURIComponent(redirectPath)),
|
||||
replace: true,
|
||||
|
||||
Reference in New Issue
Block a user