perf: 拷贝一份新的路由配置、注释产品路由校验

This commit is contained in:
rd
2025-08-14 14:46:51 +08:00
parent 1f3826e9dc
commit 9b9f66b5af
20 changed files with 989 additions and 13 deletions

View File

@ -0,0 +1,20 @@
/*
* @Author: RenXiaoDong
* @Date: 2025-06-19 01:45:53
*/
import { appRoutes } from '../routes';
const mixinRoutes = [...appRoutes];
const appClientMenus = mixinRoutes.map((el) => {
const { name, path, meta, redirect, children } = el;
return {
name,
path,
meta,
redirect,
children,
};
});
export default mixinRoutes;

View File

@ -0,0 +1,30 @@
/*
* @Author: RenXiaoDong
* @Date: 2025-06-24 16:50:35
*/
export const WHITE_LIST = [
{ name: 'notFound', children: [] },
{ name: 'login', children: [] },
];
export const NOT_FOUND = {
name: 'notFound',
};
export const REDIRECT_ROUTE_NAME = 'Redirect';
export const DEFAULT_ROUTE_NAME = 'main';
export const DEFAULT_ROUTE = {
title: '首页',
name: DEFAULT_ROUTE_NAME,
fullPath: '/',
};
export const MENU_GROUP_IDS = {
DATA_ENGINE_ID: 1, // 全域数据分析
MANAGEMENT_ID: -1, // 管理中心
PROPERTY_ID: 10, // 资产营销平台
WORK_BENCH_ID: -99, // 工作台
AGENT: 2, // 智能体
};

View File

@ -0,0 +1,27 @@
/*
* @Author: 田鑫
* @Date: 2023-03-05 18:14:17
* @LastEditors: Please set LastEditors
* @LastEditTime: 2025-06-23 04:10:41
* @Description:
*/
import type { Router } from 'vue-router';
import { setRouteEmitter } from '@/utils/route-listener';
import setupUserLoginInfoGuard from './userLoginInfo';
import { MENU_GROUP_IDS } from '@/router/constants';
// import setupPermissionGuard from './permission';
function setupPageGuard(router: Router) {
router.beforeEach(async (to) => {
// emit route change
setRouteEmitter(to);
});
}
export default function createRouteGuard(router: Router) {
setupPageGuard(router);
setupUserLoginInfoGuard(router);
// setupPermissionGuard(router);
}

View File

@ -0,0 +1,29 @@
/*
* @Author: 田鑫
* @Date: 2023-03-05 14:46:43
* @LastEditors: Please set LastEditors
* @LastEditTime: 2025-06-23 04:07:43
* @Description: 路由权限守卫
*/
// import type { Router, RouteRecordNormalized } from 'vue-router';
// import NProgress from 'nprogress'; // progress bar
// import { useAppStore } from '@/stores';
// export default function setupPermissionGuard(router: Router) {
// router.beforeEach(async (to, from, next) => {
// console.log('access permission router guard');
// const appStore = useAppStore();
// //* 菜单是否为服务端渲染
// if (appStore.menuFromServer) {
// //* 没有服务端渲染的菜单
// if (!appStore.appAsyncMenus) {
// // todo 请求服务端渲染菜单的接口当前为mock数据
// // await appStore.fetchServerMenuConfig();
// }
// next();
// } else {
// next();
// }
// NProgress.done();
// });
// }

View File

@ -0,0 +1,45 @@
/*
* @Author: RenXiaoDong
* @Date: 2025-06-22 22:59:16
*/
import type { Router } from 'vue-router';
import NProgress from 'nprogress';
import { goUserLogin } from '@/utils/user';
// import router from '@/router';
import { checkRoutePermission } from '@/permission/permission';
import { useUserStore } from '@/stores/modules/user';
export default function setupUserLoginInfoGuard(router: Router) {
router.beforeEach(async (to, from, next) => {
NProgress.start();
const userStore = useUserStore();
const routeName = to?.name as string;
const requiresAuth = to?.meta?.requiresAuth || false;
const requireLogin = to?.meta?.requireLogin || false;
const query = to?.query ?? {};
if (requireLogin && !userStore.isLogin) {
goUserLogin(query);
next();
return;
}
// if (requiresAuth) {
// const hasPermission = checkRoutePermission(routeName);
// if (!hasPermission) {
// AMessage.error('您没有权限访问该页面');
// next('/');
// return;
// }
// next();
// return;
// }
next();
});
router.afterEach((to) => {
NProgress.done();
});
}

48
src/router copy/index.ts Normal file
View File

@ -0,0 +1,48 @@
/*
* @Author: RenXiaoDong
* @Date: 2025-06-22 22:59:16
*/
import { createRouter, createWebHistory } from 'vue-router';
import { appRoutes } from './routes';
import { NOT_FOUND_ROUTE } from './routes/base';
import NProgress from 'nprogress';
import 'nprogress/nprogress.css';
import { MENU_GROUP_IDS } from './constants';
import createRouteGuard from './guard';
NProgress.configure({ showSpinner: false }); // NProgress Configuration
export const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
routes: [
{
path: '/login',
name: 'UserLogin',
component: () => import('@/views/components/login'),
meta: {
requiresAuth: false,
requireLogin: false,
},
},
{
path: '/',
name: 'Home',
component: () => import('@/views/components/workplace'),
meta: {
hideSidebar: true,
requiresAuth: false,
requireLogin: true,
id: MENU_GROUP_IDS.WORK_BENCH_ID,
},
},
...appRoutes,
NOT_FOUND_ROUTE,
],
scrollBehavior() {
return { top: 0 };
},
});
createRouteGuard(router);
export default router;

View File

@ -0,0 +1,35 @@
import type { RouteRecordRaw } from 'vue-router';
import { REDIRECT_ROUTE_NAME } from '@/router/constants';
// export const REDIRECT_MAIN: RouteRecordRaw = {
// path: '/redirect',
// name: 'redirect',
// meta: {
// requiresAuth: false,
// requireLogin: false,
// hideInMenu: true,
// },
// children: [
// {
// path: '/redirect/:path',
// name: REDIRECT_ROUTE_NAME,
// component: () => import('@/layouts/Basic.vue'),
// meta: {
// requiresAuth: false,
// requireLogin: false,
// hideInMenu: true,
// },
// },
// ],
// };
export const NOT_FOUND_ROUTE: RouteRecordRaw = {
path: '/:pathMatch(.*)*',
name: 'notFound',
component: () => import('@/layouts/NotFound.vue'),
meta: {
requiresAuth: false,
hideInMenu: true,
hideSidebar: true,
},
};

View File

@ -0,0 +1,22 @@
import type { RouteRecordNormalized } from 'vue-router';
// import { REDIRECT_MAIN, NOT_FOUND_ROUTE } from './base';
import { MENU_GROUP_IDS } from '@/router/constants';
const modules = import.meta.glob('./modules/*.ts', { eager: true });
// const externalModules = import.meta.glob('./externalModules/*.ts', {
// eager: true,
// });
function formatModules(_modules: any, result: RouteRecordNormalized[]) {
Object.keys(_modules).forEach((key) => {
const defaultModule = _modules[key].default;
if (!defaultModule) return;
const moduleList = Array.isArray(defaultModule) ? [...defaultModule] : [defaultModule];
result.push(...moduleList);
});
return result;
}
export const appRoutes: RouteRecordNormalized[] = formatModules(modules, []);
// export const appExternalRoutes: RouteRecordNormalized[] = formatModules(externalModules, []);

View File

@ -0,0 +1,65 @@
import type { AppRouteRecordRaw } from '../types';
import { MENU_GROUP_IDS } from '@/router/constants';
import IconRepository from '@/assets/svg/svg-agent.svg';
const COMPONENTS: AppRouteRecordRaw[] = [
{
path: '/agent',
name: 'Agent',
redirect: 'agent/index',
meta: {
locale: '灵机ai',
icon: IconRepository,
requiresAuth: true,
requireLogin: true,
roles: ['*'],
id: MENU_GROUP_IDS.AGENT,
},
children: [
{
path: 'index',
name: 'AgentIndex',
component: () => import('@/views/agent/index'),
meta: {
locale:'智能体应用',
requiresAuth: false,
requireLogin: true,
hideFooter: true,
isAgentRoute: true
},
},
{
path: 'chat',
name: 'AgentChat',
component: () => import('@/views/agent/chat'),
meta: {
hideSidebar: true,
requiresAuth: false,
requireLogin: true,
hideFooter: true,
id: MENU_GROUP_IDS.AGENT,
isAgentRoute: true,
hideInMenu: true,
},
},
{
path: 'workFlow',
name: 'AgentWorkFlow',
component: () => import('@/views/agent/work-flow'),
meta: {
hideSidebar: true,
requiresAuth: false,
requireLogin: true,
hideFooter: true,
id: MENU_GROUP_IDS.AGENT,
isAgentRoute: true,
hideInMenu: true,
},
},
],
},
];
export default COMPONENTS;

View File

@ -0,0 +1,89 @@
import { IconBookmark } from '@arco-design/web-vue/es/icon';
import type { AppRouteRecordRaw } from '../types';
import { MENU_GROUP_IDS } from '@/router/constants';
const COMPONENTS: AppRouteRecordRaw[] = [
{
path: '/dataEngine',
name: 'DataEngine',
redirect: 'dataEngine/hotTranslation',
meta: {
locale: '全域数据引擎',
icon: IconBookmark,
requiresAuth: true,
requireLogin: true,
roles: ['*'],
id: MENU_GROUP_IDS.DATA_ENGINE_ID,
},
children: [
{
path: 'hotTranslation',
name: 'DataEngineHotTranslation',
meta: {
locale: '行业热门话题洞察',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/components/dataEngine/hotTranslation.vue'),
},
{
path: 'hotCloud',
name: 'DataEngineHotCloud',
meta: {
locale: '行业词云',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/components/dataEngine/hotCloud.vue'),
},
{
path: 'keyWord',
name: 'DataEngineKeyWord',
meta: {
locale: '行业关键词动向',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/components/dataEngine/keyWord.vue'),
},
{
path: 'userPainPoints',
name: 'DataEngineUserPainPoints',
meta: {
locale: '用户痛点观察',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/components/dataEngine/userPainPoints.vue'),
},
{
path: 'keyBrandMovement',
name: 'DataEngineKeyBrandMovement',
meta: {
locale: '重点品牌动向',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/components/dataEngine/keyBrandMovement.vue'),
},
{
path: 'userPersona',
name: 'DataEngineUserPersona',
meta: {
locale: '用户画像',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/components/dataEngine/userPersona.vue'),
},
],
},
];
export default COMPONENTS;

View File

@ -0,0 +1,56 @@
import { IconBookmark } from '@arco-design/web-vue/es/icon';
import type { AppRouteRecordRaw } from '../types';
import { MENU_GROUP_IDS } from '@/router/constants';
const COMPONENTS: AppRouteRecordRaw[] = [
{
path: '/management',
name: 'Management',
redirect: 'management/person',
meta: {
locale: '管理中心',
icon: IconBookmark,
requiresAuth: false,
requireLogin: true,
roles: ['*'],
id: MENU_GROUP_IDS.MANAGEMENT_ID,
},
children: [
{
path: 'person',
name: 'ManagementPerson',
component: () => import('@/views/components/management/person'),
meta: {
locale: '个人信息',
requiresAuth: false,
requireLogin: true,
roles: ['*'],
},
},
{
path: 'enterprise',
name: 'ManagementEnterprise',
component: () => import('@/views/components/management/enterprise'),
meta: {
locale: '企业信息',
requiresAuth: false,
requireLogin: true,
roles: ['*'],
},
},
{
path: 'account',
name: 'ManagementAccount',
component: () => import('@/views/components/management/account'),
meta: {
locale: '账号管理',
requiresAuth: false,
requireLogin: true,
roles: ['*'],
},
},
],
},
];
export default COMPONENTS;

View File

@ -0,0 +1,227 @@
/**
* 资产营销平台
*/
import type { AppRouteRecordRaw } from '../types';
import { MENU_GROUP_IDS } from '@/router/constants';
import IconRepository from '@/assets/svg/svg-repository.svg';
import IconMediaAccount from '@/assets/svg/svg-mediaAccount.svg';
import IconPutAccount from '@/assets/svg/svg-putAccount.svg';
import IconIntelligentSolution from '@/assets/svg/svg-intelligentSolution.svg';
import IconProjectManagement from '@/assets/svg/svg-projectManagement.svg';
const COMPONENTS: AppRouteRecordRaw[] = [
{
path: '/repository',
name: 'Repository',
redirect: 'repository/brandMaterials',
meta: {
locale: '品牌资产管理',
icon: IconRepository,
requiresAuth: true,
requireLogin: true,
roles: ['*'],
id: MENU_GROUP_IDS.PROPERTY_ID,
},
children: [
{
path: 'brandMaterials',
name: 'RepositoryBrandMaterials',
meta: {
locale: '品牌信息',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/property-marketing/brands/brand-materials/index.vue'),
},
],
},
{
path: '/media-account',
name: 'MediaAccount',
redirect: 'media-account/accountManagement',
meta: {
locale: '账号资源中心',
icon: IconMediaAccount,
requiresAuth: true,
requireLogin: true,
roles: ['*'],
id: MENU_GROUP_IDS.PROPERTY_ID,
},
children: [
{
path: 'manage',
name: 'MediaAccountAccountManagement',
meta: {
locale: '账号管理',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/property-marketing/media-account/account-manage'),
},
{
path: 'dashboard',
name: 'MediaAccountAccountDashboard',
meta: {
locale: '账号数据看板',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/property-marketing/media-account/account-dashboard'),
},
{
path: 'detail/:id',
name: 'MediaAccountAccountDetails',
meta: {
locale: '账号详情',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
hideInMenu: true,
activeMenu: 'MediaAccountAccountDashboard',
},
component: () => import('@/views/property-marketing/media-account/account-detail'),
},
],
},
{
path: '/put-account',
name: 'PutAccount',
redirect: 'put-account/accountManagement',
meta: {
locale: '投放资源中心',
icon: IconPutAccount,
requiresAuth: true,
requireLogin: true,
roles: ['*'],
id: MENU_GROUP_IDS.PROPERTY_ID,
},
children: [
{
path: 'manage',
name: 'PutAccountAccountManagement',
meta: {
locale: '账户管理',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/property-marketing/put-account/account-manage'),
},
{
path: 'data',
name: 'PutAccountAccountData',
meta: {
locale: '账户数据',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/property-marketing/put-account/account-data'),
},
{
path: 'account-dashboard',
name: 'PutAccountAccountDashboard',
meta: {
locale: '投放表现分析',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/property-marketing/put-account/account-dashboard'),
},
{
path: 'investmentGuidelines',
name: 'PutAccountInvestmentGuidelines',
meta: {
locale: '投放指南',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/property-marketing/put-account/investment-guidelines'),
},
{
path: 'detail/:id',
name: 'guideDetail',
meta: {
locale: '投放指南详情',
requiresAuth: true,
hideInMenu: true,
roles: ['*'],
activeMenu: 'PutAccountInvestmentGuidelines',
},
component: () => import('@/views/property-marketing/put-account/investment-guidelines/detail'),
},
],
},
// {
// path: '/intelligent-solution',
// name: 'IntelligentSolution',
// redirect: 'intelligent-solution/businessAnalysisReport',
// meta: {
// locale: '智能方案管理',
// icon: IconIntelligentSolution,
// requiresAuth: true,
// requireLogin: true,
// roles: ['*'],
// id: MENU_GROUP_IDS.PROPERTY_ID,
// },
// children: [
// {
// path: 'businessAnalysisReport',
// name: 'IntelligentSolutionBusinessAnalysisReport',
// meta: {
// locale: '业务洞察报告',
// requiresAuth: true,
// requireLogin: true,
// roles: ['*'],
// },
// component: () => import('@/views/property-marketing/intelligent-solution/businessAnalysisReport'),
// },
// {
// path: 'competitiveProductAnalysisReport',
// name: 'IntelligentSolutionCompetitiveProductAnalysisReport',
// meta: {
// locale: '竟品对比报告',
// requiresAuth: true,
// requireLogin: true,
// roles: ['*'],
// },
// component: () => import('@/views/property-marketing/intelligent-solution/competitiveProductAnalysisReport'),
// },
// ],
// },
{
path: '/project-manage',
name: 'ProjectManagement',
redirect: 'project-manage/project-list',
meta: {
locale: '项目管理',
icon: IconProjectManagement,
requiresAuth: true,
requireLogin: true,
roles: ['*'],
id: MENU_GROUP_IDS.PROPERTY_ID,
},
children: [
{
path: 'project-list',
name: 'ProjectList',
meta: {
locale: '项目列表',
requiresAuth: true,
requireLogin: true,
roles: ['*'],
},
component: () => import('@/views/property-marketing/project-manage/project-list'),
},
],
},
];
export default COMPONENTS;

View File

@ -0,0 +1,19 @@
/*
* @Author: RenXiaoDong
* @Date: 2025-06-19 01:45:53
*/
import type { RouteMeta, NavigationGuard, RouteComponent } from 'vue-router';
export interface AppRouteRecordRaw {
id?: number;
path: string;
name?: string | symbol;
meta?: RouteMeta;
redirect?: string;
component?: RouteComponent;
children?: AppRouteRecordRaw[];
alias?: string | string[];
props?: Record<string, any>;
beforeEnter?: NavigationGuard | NavigationGuard[];
fullPath?: string;
}

20
src/router copy/typeings.d.ts vendored Normal file
View File

@ -0,0 +1,20 @@
import { RouteComponent } from 'vue-router';
declare module 'vue-router' {
interface RouteMeta {
roles?: string[]; // Controls roles that have access to the page
requiresAuth?: boolean; // Whether login is required to access the current page (every route must declare)
icon?: RouteComponent | string; // The icon show in the side menu
locale?: string; // The locale name show in side menu and breadcrumb
needNavigate?: boolean; // if set true, the breadcrumb will support navigate
hideInMenu?: boolean; // If true, it is not displayed in the side menu
hideChildrenInMenu?: boolean; // if set true, the children are not displayed in the side menu
activeMenu?: string; // if set name, the menu will be highlighted according to the name you set
order?: number; // Sort routing menu items. If set key, the higher the value, the more forward it is
noAffix?: boolean; // if set true, the tag will not affix in the tab-bar
ignoreCache?: boolean; // if set true, the page will not be cached
hideSidebar?: boolean;
isAgentRoute?:boolean;
requireLogin?: boolean; // 是否需要登陆才能访问
}
}

View File

@ -26,16 +26,16 @@ export default function setupUserLoginInfoGuard(router: Router) {
return;
}
if (requiresAuth) {
const hasPermission = checkRoutePermission(routeName);
if (!hasPermission) {
AMessage.error('您没有权限访问该页面');
next('/');
return;
}
next();
return;
}
// if (requiresAuth) {
// const hasPermission = checkRoutePermission(routeName);
// if (!hasPermission) {
// AMessage.error('您没有权限访问该页面');
// next('/');
// return;
// }
// next();
// return;
// }
next();
});

17
src/views/home/index.vue Normal file
View File

@ -0,0 +1,17 @@
<script lang="jsx">
export default {
setup(props, { emit, expose }) {
return () => (
<div>
home
</div>
)
}
}
</script>
<style lang="scss" scoped>
@import './style.scss';
</style>

View File