feat: 新增license

This commit is contained in:
小蟑螂
2026-07-06 19:34:53 +08:00
parent 8a6cb23c07
commit ac890dcc5c
110 changed files with 10678 additions and 1368 deletions
@@ -5,11 +5,45 @@ import { preferences } from '@vben/preferences';
import { useAccessStore, useUserStore } from '@vben/stores';
import { startProgress, stopProgress } from '@vben/utils';
import { accessRoutes, coreRouteNames } from '#/router/routes';
import { getInitStatusApi } from '#/api/system/license';
import { INIT_PATH, 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
@@ -50,6 +84,12 @@ 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,6 +20,9 @@ const fallbackNotFoundRoute: RouteRecordRaw = {
path: '/:path(.*)*',
};
/** 系统初始化路径(未初始化时强制跳转) */
export const INIT_PATH = '/init';
/** 基本路由,这些路由是必须存在的 */
const coreRoutes: RouteRecordRaw[] = [
/**
@@ -38,6 +41,17 @@ 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 } from './core';
import { coreRoutes, fallbackNotFoundRoute, INIT_PATH } from './core';
const dynamicRouteFiles = import.meta.glob('./modules/**/*.ts', {
eager: true,
@@ -41,4 +41,4 @@ const routes: RouteRecordRaw[] = [
/** 有权限校验的路由列表,包含动态路由 */
const accessRoutes = [...dynamicRoutes];
export { accessRoutes, coreRouteNames, routes };
export { accessRoutes, coreRouteNames, INIT_PATH, routes };
@@ -63,6 +63,16 @@ const routes: RouteRecordRaw[] = [
requiresAuth: true,
},
},
{
name: 'SystemLicense',
path: '/platform-admin/license',
component: () => import('#/views/system/license/LicenseInfo.vue'),
meta: {
icon: 'lucide:key-round',
title: 'License 管理',
requiresAuth: true,
},
},
];
export default routes;