初始化

This commit is contained in:
2026-02-22 18:56:10 +08:00
commit 26677972a6
3112 changed files with 255972 additions and 0 deletions

View File

@@ -0,0 +1,42 @@
import type {
ComponentRecordType,
GenerateMenuAndRoutesOptions,
} from '@easyflow/types';
import { generateAccessible } from '@easyflow/access';
import { preferences } from '@easyflow/preferences';
import { ElMessage } from 'element-plus';
import { getAllMenusApi } from '#/api';
import { BasicLayout, IFrameView } from '#/layouts';
import { $t } from '#/locales';
const forbiddenComponent = () => import('#/views/_core/fallback/forbidden.vue');
async function generateAccess(options: GenerateMenuAndRoutesOptions) {
const pageMap: ComponentRecordType = import.meta.glob('../views/**/*.vue');
const layoutMap: ComponentRecordType = {
BasicLayout,
IFrameView,
};
return await generateAccessible(preferences.app.accessMode, {
...options,
fetchMenuListAsync: async () => {
ElMessage({
duration: 1500,
message: `${$t('common.loadingMenu')}...`,
});
return await getAllMenusApi();
},
// 可以指定没有权限跳转403页面
forbiddenComponent,
// 如果 route.meta.menuVisibleWithForbidden = true
layoutMap,
pageMap,
});
}
export { generateAccess };

View File

@@ -0,0 +1,133 @@
import type { Router } from 'vue-router';
import { LOGIN_PATH } from '@easyflow/constants';
import { preferences } from '@easyflow/preferences';
import { useAccessStore, useUserStore } from '@easyflow/stores';
import { startProgress, stopProgress } from '@easyflow/utils';
import { accessRoutes, coreRouteNames } from '#/router/routes';
import { useAuthStore } from '#/store';
import { generateAccess } from './access';
/**
* 通用守卫配置
* @param router
*/
function setupCommonGuard(router: Router) {
// 记录已经加载的页面
const loadedPaths = new Set<string>();
router.beforeEach((to) => {
to.meta.loaded = loadedPaths.has(to.path);
// 页面加载进度条
if (!to.meta.loaded && preferences.transition.progress) {
startProgress();
}
return true;
});
router.afterEach((to) => {
// 记录页面是否加载,如果已经加载,后续的页面切换动画等效果不在重复执行
loadedPaths.add(to.path);
// 关闭页面加载进度条
if (preferences.transition.progress) {
stopProgress();
}
});
}
/**
* 权限访问守卫配置
* @param router
*/
function setupAccessGuard(router: Router) {
router.beforeEach(async (to, from) => {
const accessStore = useAccessStore();
const userStore = useUserStore();
const authStore = useAuthStore();
// 基本路由,这些路由不需要进入权限拦截
if (coreRouteNames.includes(to.name as string)) {
if (to.path === LOGIN_PATH && accessStore.accessToken) {
return decodeURIComponent(
(to.query?.redirect as string) ||
userStore.userInfo?.homePath ||
preferences.app.defaultHomePath,
);
}
return true;
}
// accessToken 检查
if (!accessStore.accessToken) {
// 明确声明忽略权限访问权限,则可以访问
if (to.meta.ignoreAccess) {
return true;
}
// 没有访问权限,跳转登录页面
if (to.fullPath !== LOGIN_PATH) {
return {
path: LOGIN_PATH,
// 如不需要,直接删除 query
query:
to.fullPath === preferences.app.defaultHomePath
? {}
: { redirect: encodeURIComponent(to.fullPath) },
// 携带当前跳转的页面,登录后重新跳转该页面
replace: true,
};
}
return to;
}
// 是否已经生成过动态路由
if (accessStore.isAccessChecked) {
return true;
}
// 生成路由表
// 当前登录用户拥有的角色标识列表
const userInfo = userStore.userInfo || (await authStore.fetchUserInfo());
const userRoles = userInfo.roles ?? [];
// 生成菜单和路由
const { accessibleMenus, accessibleRoutes } = await generateAccess({
roles: userRoles,
router,
// 则会在菜单中显示但是访问会被重定向到403
routes: accessRoutes,
});
// 保存菜单信息和路由信息
accessStore.setAccessMenus(accessibleMenus);
accessStore.setAccessRoutes(accessibleRoutes);
accessStore.setIsAccessChecked(true);
const redirectPath = (from.query.redirect ??
(to.path === preferences.app.defaultHomePath
? userInfo.homePath || preferences.app.defaultHomePath
: to.fullPath)) as string;
return {
...router.resolve(decodeURIComponent(redirectPath)),
replace: true,
};
});
}
/**
* 项目守卫配置
* @param router
*/
function createRouterGuard(router: Router) {
/** 通用 */
setupCommonGuard(router);
/** 权限访问 */
setupAccessGuard(router);
}
export { createRouterGuard };

View File

@@ -0,0 +1,37 @@
import {
createRouter,
createWebHashHistory,
createWebHistory,
} from 'vue-router';
import { resetStaticRoutes } from '@easyflow/utils';
import { createRouterGuard } from './guard';
import { routes } from './routes';
/**
* @zh_CN 创建vue-router实例
*/
const router = createRouter({
history:
import.meta.env.VITE_ROUTER_HISTORY === 'hash'
? createWebHashHistory(import.meta.env.VITE_BASE)
: createWebHistory(import.meta.env.VITE_BASE),
// 应该添加到路由的初始路由列表。
routes,
scrollBehavior: (to, _from, savedPosition) => {
if (savedPosition) {
return savedPosition;
}
return to.hash ? { behavior: 'smooth', el: to.hash } : { left: 0, top: 0 };
},
// 是否应该禁止尾部斜杠。
// strict: true,
});
const resetRoutes = () => resetStaticRoutes(router, routes);
// 创建路由守卫
createRouterGuard(router);
export { resetRoutes, router };

View File

@@ -0,0 +1,108 @@
import type { RouteRecordRaw } from 'vue-router';
import { LOGIN_PATH } from '@easyflow/constants';
import { preferences } from '@easyflow/preferences';
import { $t } from '#/locales';
const BasicLayout = () => import('#/layouts/basic.vue');
const AuthPageLayout = () => import('#/layouts/auth.vue');
/** 全局404页面 */
const fallbackNotFoundRoute: RouteRecordRaw = {
component: () => import('#/views/_core/fallback/not-found.vue'),
meta: {
hideInBreadcrumb: true,
hideInMenu: true,
hideInTab: true,
title: '404',
},
name: 'FallbackNotFound',
path: '/:path(.*)*',
};
/** 基本路由,这些路由是必须存在的 */
const coreRoutes: RouteRecordRaw[] = [
{
component: () => import('#/views/_core/authentication/oauth-page.vue'),
meta: {
hideInBreadcrumb: true,
hideInMenu: true,
hideInTab: true,
title: 'OAuth',
},
name: 'OAuth',
path: '/oauth',
},
/**
* 根路由
* 使用基础布局作为所有页面的父级容器子级就不必配置BasicLayout。
* 此路由必须存在,且不应修改
*/
{
component: BasicLayout,
meta: {
hideInBreadcrumb: true,
title: 'Root',
},
name: 'Root',
path: '/',
redirect: preferences.app.defaultHomePath,
children: [],
},
{
component: AuthPageLayout,
meta: {
hideInTab: true,
title: 'Authentication',
},
name: 'Authentication',
path: '/auth',
redirect: LOGIN_PATH,
children: [
{
name: 'Login',
path: 'login',
component: () => import('#/views/_core/authentication/login.vue'),
meta: {
title: $t('page.auth.login'),
},
},
{
name: 'CodeLogin',
path: 'code-login',
component: () => import('#/views/_core/authentication/code-login.vue'),
meta: {
title: $t('page.auth.codeLogin'),
},
},
{
name: 'QrCodeLogin',
path: 'qrcode-login',
component: () =>
import('#/views/_core/authentication/qrcode-login.vue'),
meta: {
title: $t('page.auth.qrcodeLogin'),
},
},
{
name: 'ForgetPassword',
path: 'forget-password',
component: () =>
import('#/views/_core/authentication/forget-password.vue'),
meta: {
title: $t('page.auth.forgetPassword'),
},
},
{
name: 'Register',
path: 'register',
component: () => import('#/views/_core/authentication/register.vue'),
meta: {
title: $t('page.auth.register'),
},
},
],
},
];
export { coreRoutes, fallbackNotFoundRoute };

View File

@@ -0,0 +1,47 @@
import type { RouteRecordRaw } from 'vue-router';
import { mergeRouteModules, traverseTreeValues } from '@easyflow/utils';
import { coreRoutes, fallbackNotFoundRoute } from './core';
const dynamicRouteFiles = import.meta.glob('./modules/**/*.ts', {
eager: true,
});
// 有需要可以自行打开注释,并创建文件夹
// const externalRouteFiles = import.meta.glob('./external/**/*.ts', { eager: true });
// const staticRouteFiles = import.meta.glob('./static/**/*.ts', { eager: true });
/** 动态路由 */
const dynamicRoutes: RouteRecordRaw[] = mergeRouteModules(dynamicRouteFiles);
/** 外部路由列表访问这些页面可以不需要Layout可能用于内嵌在别的系统(不会显示在菜单中) */
// const externalRoutes: RouteRecordRaw[] = mergeRouteModules(externalRouteFiles);
// const staticRoutes: RouteRecordRaw[] = mergeRouteModules(staticRouteFiles);
const staticRoutes: RouteRecordRaw[] = [];
const externalRoutes: RouteRecordRaw[] = [];
/** 路由列表由基本路由、外部路由和404兜底路由组成
* 无需走权限验证(会一直显示在菜单中) */
const routes: RouteRecordRaw[] = [
...coreRoutes,
...externalRoutes,
fallbackNotFoundRoute,
];
/** 基本路由列表,这些路由不需要进入权限拦截 */
const coreRouteNames = traverseTreeValues(coreRoutes, (route) => route.name);
/** 有权限校验的路由列表,包含动态路由和静态路由 */
const accessRoutes = [...dynamicRoutes, ...staticRoutes];
const componentKeys: string[] = Object.keys(
import.meta.glob('../../views/**/*.vue'),
)
.filter((item) => !item.includes('/modules/'))
.map((v) => {
const path = v.replace('../../views/', '/');
return path.endsWith('.vue') ? path.slice(0, -4) : path;
});
export { accessRoutes, componentKeys, coreRouteNames, routes };

View File

@@ -0,0 +1,32 @@
import type { RouteRecordRaw } from 'vue-router';
const routes: RouteRecordRaw[] = [
{
name: 'BotRun',
path: '/ai/bots/run/:botId/:sessionId?',
component: () => import('#/views/ai/bots/pages/Run.vue'),
meta: {
title: 'Bots',
noBasicLayout: true,
openInNewWindow: true,
hideInMenu: true,
hideInBreadcrumb: true,
hideInTab: true,
},
},
{
name: 'BotSetting',
path: '/ai/bots/setting/:id',
component: () => import('#/views/ai/bots/pages/setting/index.vue'),
meta: {
title: 'Bots',
openInNewWindow: true,
hideInMenu: true,
hideInBreadcrumb: true,
hideInTab: true,
activePath: '/ai/bots',
},
},
];
export default routes;

View File

@@ -0,0 +1,38 @@
import type { RouteRecordRaw } from 'vue-router';
// import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
// {
// meta: {
// icon: 'lucide:layout-dashboard',
// order: -1,
// title: $t('page.dashboard.title'),
// },
// name: 'Dashboard',
// path: '/dashboard',
// children: [
// {
// name: 'Analytics',
// path: '/analytics',
// component: () => import('#/views/dashboard/analytics/index.vue'),
// meta: {
// affixTab: true,
// icon: 'lucide:area-chart',
// title: $t('page.dashboard.analytics'),
// },
// },
// {
// name: 'Workspace',
// path: '/workspace',
// component: () => import('#/views/dashboard/workspace/index.vue'),
// meta: {
// icon: 'carbon:workspace',
// title: $t('page.dashboard.workspace'),
// },
// },
// ],
// },
];
export default routes;

View File

@@ -0,0 +1,20 @@
import type { RouteRecordRaw } from 'vue-router';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
{
meta: {
icon: 'clarity:database',
title: $t('datacenterTable.title'),
hideInMenu: true,
hideInTab: true,
hideInBreadcrumb: true,
},
name: 'TableDetail',
path: '/datacenter/table/tableDetail',
component: () => import('#/views/datacenter/DatacenterTableDetail.vue'),
},
];
export default routes;

View File

@@ -0,0 +1,52 @@
// import type { RouteRecordRaw } from 'vue-router';
//
// import { $t } from '#/locales';
//
// const routes: RouteRecordRaw[] = [
// {
// meta: {
// icon: 'ic:baseline-view-in-ar',
// keepAlive: true,
// order: 1000,
// title: $t('demos.title'),
// },
// name: 'Demos',
// path: '/demos',
// children: [
// {
// meta: {
// title: $t('demos.elementPlus'),
// },
// name: 'NaiveDemos',
// path: '/demos/element',
// component: () => import('#/views/demos/element/index.vue'),
// },
// {
// meta: {
// title: '卡片组件',
// },
// name: 'NaiveDemos1',
// path: '/demos/cardTest',
// component: () => import('#/views/demos/cardTest/index.vue'),
// },
// {
// meta: {
// title: '分类组件',
// },
// name: 'NaiveDemos2',
// path: '/demos/categoryPanel',
// component: () => import('#/views/demos/categoryPanel/index.vue'),
// },
// {
// meta: {
// title: $t('demos.form'),
// },
// name: 'BasicForm',
// path: '/demos/form',
// component: () => import('#/views/demos/form/basic.vue'),
// },
// ],
// },
// ];
//
// export default routes;

View File

@@ -0,0 +1,21 @@
import type { RouteRecordRaw } from 'vue-router';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
{
meta: {
title: $t('documentCollection.documentManagement'),
hideInMenu: true,
hideInTab: true,
hideInBreadcrumb: true,
fullPathKey: true,
activePath: '/ai/documentCollection',
},
name: 'Document',
path: '/ai/documentCollection/document',
component: () => import('#/views/ai/documentCollection/Document.vue'),
},
];
export default routes;

View File

@@ -0,0 +1,63 @@
import type { RouteRecordRaw } from 'vue-router';
// import { APP_DOC_URL, APP_GITHUB_URL, APP_LOGO_URL } from '@easyflow/constants';
//
// import { IFrameView } from '#/layouts';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
// {
// meta: {
// badgeType: 'dot',
// icon: APP_LOGO_URL,
// order: 9998,
// title: $t('demos.easyflow.title'),
// },
// name: 'EasyFlowProject',
// path: '/easyflow-admin',
// children: [
// {
// name: 'EasyFlowDocument',
// path: '/easyflow-admin/document',
// component: IFrameView,
// meta: {
// icon: 'lucide:book-open-text',
// link: APP_DOC_URL,
// title: $t('demos.easyflow.document'),
// },
// },
// {
// name: 'EasyFlowGithub',
// path: '/easyflow-admin/github',
// component: IFrameView,
// meta: {
// icon: 'mdi:github',
// link: APP_GITHUB_URL,
// title: 'Github',
// },
// },
// ],
// },
// {
// name: 'EasyFlowAbout',
// path: '/easyflow-admin/about',
// component: () => import('#/views/_core/about/index.vue'),
// meta: {
// icon: 'lucide:copyright',
// title: $t('demos.easyflow.about'),
// order: 9999,
// },
// },
{
name: 'Profile',
path: '/profile',
component: () => import('#/views/_core/profile/index.vue'),
meta: {
icon: 'lucide:user',
hideInMenu: true,
title: $t('page.auth.profile'),
},
},
];
export default routes;

View File

@@ -0,0 +1,32 @@
import type { RouteRecordRaw } from 'vue-router';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
{
meta: {
title: $t('plugin.toolsManagement'),
hideInMenu: true,
hideInTab: true,
hideInBreadcrumb: true,
fullPathKey: true,
},
name: 'PluginTools',
path: '/ai/plugin/tools',
component: () => import('#/views/ai/plugin/PluginTools.vue'),
},
{
meta: {
title: $t('plugin.toolsManagement'),
hideInMenu: true,
hideInTab: true,
hideInBreadcrumb: true,
fullPathKey: true,
},
name: 'PluginToolEdit',
path: '/ai/plugin/tool/edit',
component: () => import('#/views/ai/plugin/PluginToolEdit.vue'),
},
];
export default routes;

View File

@@ -0,0 +1,20 @@
import type { RouteRecordRaw } from 'vue-router';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
{
name: 'SysFeedbackDetail',
path: '/sys/sysFeedback/:id',
component: () => import('#/views/system/sysFeedback/sysFeedbackDetail.vue'),
meta: {
title: $t('menus.system.sysFeedback'),
hideInMenu: true,
hideInBreadcrumb: true,
hideInTab: true,
activePath: '/sys/sysFeedback',
},
},
];
export default routes;

View File

@@ -0,0 +1,20 @@
import type { RouteRecordRaw } from 'vue-router';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
{
meta: {
icon: 'clarity:time-line',
title: $t('sysJobLog.title'),
hideInMenu: true,
hideInTab: true,
hideInBreadcrumb: true,
},
name: 'SysJobLog',
path: '/sys/sysJob/sysJobLog',
component: () => import('#/views/system/sysJob/SysJobLogList.vue'),
},
];
export default routes;

View File

@@ -0,0 +1,56 @@
import type { RouteRecordRaw } from 'vue-router';
import { $t } from '#/locales';
const routes: RouteRecordRaw[] = [
{
meta: {
icon: 'ant-design:apartment-outlined',
title: $t('datacenterTable.title'),
hideInMenu: true,
hideInTab: true,
hideInBreadcrumb: true,
},
name: 'WorkflowDesign',
path: '/ai/workflow/design',
component: () => import('#/views/ai/workflow/WorkflowDesign.vue'),
},
{
meta: {
title: '运行',
hideInMenu: true,
hideInTab: true,
hideInBreadcrumb: true,
activePath: '/ai/workflow',
},
name: 'RunPage',
path: '/ai/workflow/run',
component: () => import('#/views/ai/workflow/RunPage.vue'),
},
{
meta: {
title: $t('aiWorkflowExecRecord.moduleName'),
hideInMenu: true,
hideInTab: true,
hideInBreadcrumb: true,
},
name: 'ExecRecord',
path: '/ai/workflow/executeRecords',
component: () =>
import('#/views/ai/workflow/execute/WorkflowExecResultList.vue'),
},
{
meta: {
title: $t('aiWorkflowRecordStep.moduleName'),
hideInMenu: true,
hideInTab: true,
hideInBreadcrumb: true,
},
name: 'RecordStep',
path: '/ai/workflow/executeSteps',
component: () =>
import('#/views/ai/workflow/execute/WorkflowExecStepList.vue'),
},
];
export default routes;