mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 06:29:20 +08:00
refactor: 移除初始化向导
This commit is contained in:
@@ -5,45 +5,11 @@ import { preferences } from '@vben/preferences';
|
||||
import { useAccessStore, useUserStore } from '@vben/stores';
|
||||
import { startProgress, stopProgress } from '@vben/utils';
|
||||
|
||||
import { getInitStatusApi } from '#/api/system/license';
|
||||
import { INIT_PATH, accessRoutes, coreRouteNames } from '#/router/routes';
|
||||
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
import { generateAccess } from './access';
|
||||
|
||||
/** 缓存初始化状态,避免每次路由切换都请求 */
|
||||
let initStatusCache: { checked: boolean; initialized: boolean } = {
|
||||
checked: false,
|
||||
initialized: true,
|
||||
};
|
||||
|
||||
/** 初始化完成后清除缓存(激活成功后可由页面调用) */
|
||||
export function resetInitStatusCache() {
|
||||
initStatusCache = { checked: false, initialized: true };
|
||||
}
|
||||
|
||||
async function ensureInitialized(toPath: string): Promise<boolean | { path: string; replace: boolean }> {
|
||||
if (toPath === INIT_PATH || toPath.startsWith(`${INIT_PATH}/`)) {
|
||||
return true;
|
||||
}
|
||||
if (!initStatusCache.checked) {
|
||||
try {
|
||||
const status = await getInitStatusApi();
|
||||
initStatusCache = {
|
||||
checked: true,
|
||||
initialized: status.initialized,
|
||||
};
|
||||
} catch {
|
||||
// 后端不可达时不阻断(本地纯前端开发)
|
||||
initStatusCache = { checked: true, initialized: true };
|
||||
}
|
||||
}
|
||||
if (!initStatusCache.initialized) {
|
||||
return { path: INIT_PATH, replace: true };
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用守卫配置
|
||||
* @param router
|
||||
@@ -84,12 +50,6 @@ function setupAccessGuard(router: Router) {
|
||||
const userStore = useUserStore();
|
||||
const authStore = useAuthStore();
|
||||
|
||||
// 未初始化则强制进入初始化向导(Init 路由本身跳过)
|
||||
const initCheck = await ensureInitialized(to.path);
|
||||
if (initCheck !== true) {
|
||||
return initCheck;
|
||||
}
|
||||
|
||||
// 基本路由,这些路由不需要进入权限拦截
|
||||
if (coreRouteNames.includes(to.name as string)) {
|
||||
if (to.path === LOGIN_PATH && accessStore.accessToken) {
|
||||
|
||||
@@ -20,9 +20,6 @@ const fallbackNotFoundRoute: RouteRecordRaw = {
|
||||
path: '/:path(.*)*',
|
||||
};
|
||||
|
||||
/** 系统初始化路径(未初始化时强制跳转) */
|
||||
export const INIT_PATH = '/init';
|
||||
|
||||
/** 基本路由,这些路由是必须存在的 */
|
||||
const coreRoutes: RouteRecordRaw[] = [
|
||||
/**
|
||||
@@ -41,17 +38,6 @@ const coreRoutes: RouteRecordRaw[] = [
|
||||
redirect: preferences.app.defaultHomePath,
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
name: 'Init',
|
||||
path: INIT_PATH,
|
||||
component: () => import('#/views/init/InitWizard.vue'),
|
||||
meta: {
|
||||
hideInBreadcrumb: true,
|
||||
hideInMenu: true,
|
||||
hideInTab: true,
|
||||
title: '系统初始化',
|
||||
},
|
||||
},
|
||||
{
|
||||
component: AuthPageLayout,
|
||||
meta: {
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import { mergeRouteModules, traverseTreeValues } from '@vben/utils';
|
||||
|
||||
import { coreRoutes, fallbackNotFoundRoute, INIT_PATH } from './core';
|
||||
import { coreRoutes, fallbackNotFoundRoute } from './core';
|
||||
|
||||
const dynamicRouteFiles = import.meta.glob('./modules/**/*.ts', {
|
||||
eager: true,
|
||||
@@ -41,4 +41,4 @@ const routes: RouteRecordRaw[] = [
|
||||
|
||||
/** 有权限校验的路由列表,包含动态路由 */
|
||||
const accessRoutes = [...dynamicRoutes];
|
||||
export { accessRoutes, coreRouteNames, INIT_PATH, routes };
|
||||
export { accessRoutes, coreRouteNames, routes };
|
||||
|
||||
Reference in New Issue
Block a user