| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- import {createRouter, createWebHashHistory} from 'vue-router'
- import {CONFIG, refreshRoleRoute} from "@/utils/roleUtils.js";
- import {Message} from "@/utils/message/Message.js";
- import {refreshAllDictData} from "@/utils/dictUtils.js";
- const routes = [
- {
- path: '/',
- redirect: () => {
- // 判断域名,返回对应路由
- if (window.location.hostname === 'blockly.learn-ai.com.cn') {
- return '/blockly-login';
- } else {
- return '/login';
- }
- }
- },
- { path: '/login', component: () => import('../views/Login.vue') },
- // 免登录
- { path: '/quick-login', component: () => import('../views/QuickLogin.vue') },
- { path: '/promotion-login', component: () => import('../views/PromotionLogin.vue') },
- //【AI实验课】登录
- { path: '/ai-login', component: () => import('../views/AiCourseLogin.vue') },
- //【blockly编程课】免租户登录
- { path: '/blockly-login', meta: {TENANT: '内部测试租户'}, component: () => import('../views/BlocklyLogin.vue') },
- // 网页版登录注册页
- {
- path: '/register-login',
- component: () => import('../views/RegisterLogin.vue')
- },
- // 管理界面
- {
- path: '/management-interface',
- component: () => import('../views/ManagementInterface.vue')
- },
- // 【通识课】首页
- {
- path: '/home',
- component: () => import('../components/HomePage.vue')
- },
- // 智能课
- {
- path: '/ai-general-course',
- component: () => import('../views/AIPage/AIGeneralCourse.vue')
- },
- // AI实验室
- {
- path: '/ai-laboratory',
- component: () => import('../views/AIPage/AILaboratory.vue')
- },
- // 英文数字人老师
- {
- path: '/ai-ennumerals',
- component: () => import('../views/EnNumerals/index.vue')
- },
- // 能力测评 问卷列表
- {
- path: '/evaluation',
- component: () => import('../views/evaluation/testList.vue')
- },
- // 在线测试
- {
- path: '/testTopic',
- component: () => import('../views/evaluation/testTopic.vue')
- },
- // 个性化学习
- {
- path: '/personalized',
- component: () => import('../views/personalized/Personalized.vue')
- },
- // 测试提交
- {
- path: '/testSubmit',
- component: () => import('../views/evaluation/testSubmit.vue')
- },
- // 智能绘画
- {
- path: '/ai-painting',
- component: () => import('../views/AIPage/AIPainting.vue')
- },
- // 图生图
- {
- path: '/ai-image',
- component: () => import('../views/AIPage/AIImageToImage.vue')
- },
- // AI头像
- {
- path: '/ai-avatar',
- component: () => import('../views/AIPage/AIAvatar.vue')
- },
- // 图生视频
- {
- path: '/ai-video',
- component: () => import('../views/AIPage/AIImageToVideo.vue')
- },
- // 大运河
- {
- path: '/ai-grandcanal',
- component: () => import('../views/AIPage/GrandCanal.vue')
- },
- // 植物专家
- {
- path: '/ai-plantexperts',
- component: () => import('../views/AIPage/PlantExperts.vue')
- },
- // 智能问答
- {
- path: '/ai-questions',
- component: () => import('../views/AIPage/AIQuestions.vue')
- },
- // 发展历程
- {
- path: '/ai-develop',
- component: () => import('../views/AIPage/AIDevelop.vue')
- },
- // 虚拟实验室
- {
- path: '/virtual-laboratory',
- component: () => import('../views/virtuallaboratory/index.vue')
- },
- // AI 古诗
- {
- path: '/ai-poetry',
- component: () => import('../views/AIPage/AIPoetry.vue')
- },
- // 【blockly编程课】首页
- {
- path: '/blocklyHome',
- component: () => import('../views/programming/ProgrammingGame.vue')
- },
- // Blockly
- { path: '/blockly', component: () => import('../views/blockly/Blockly.vue') },
- // Blockly2
- { path: '/blockly2', component: () => import('../views/blockly/Blockly2.vue') },
- { path: '/mapGame', component: () => import('../views/blockly/MapGame.vue') },
- // 编程游戏列表
- { path: '/programming02', component: () => import('../views/gamepage/GameIndex.vue') },
- // 编程课列表
- {
- path: '/programmingList',
- component: () => import('../views/programming/ProgrammingList.vue')
- },
- // 编程课列表内容
- {
- path: '/programmingCourset',
- component: () => import('../views/programming/ProgrammingCourset.vue')
- },
- // 编程课视频
- {
- path: '/interface',
- component: () => import('../views/programming/Interface.vue')
- },
- // 【AI实验课】首页
- // 实验室主题
- {
- path: '/aiCourseHome',
- component: () => import('../views/laboratory/ExperimentalTheme.vue')
- },
- // 实验室类型
- {
- path: '/experiment-type',
- component: () => import('../views/laboratory/ExperimentType.vue')
- },
- // 实验课程
- {
- path: '/experimental-course',
- component: () => import('../views/laboratory/ExperimentalCourses.vue')
- },
- // 实验界面
- {
- path: '/experimental-interface',
- component: () => import('../views/laboratory/ExperimentalInterface.vue')
- },
- ]
- // 定义主页及其子路由映射
- const homeRoutes = {
- home: '/home',
- login: '/login',
- role: 'course',
- children: [
- '/ai-general-course',
- '/ai-laboratory',
- '/ai-ennumerals',
- '/evaluation',
- '/testTopic',
- '/personalized',
- '/testSubmit',
- '/ai-painting',
- '/ai-image',
- '/ai-avatar',
- '/ai-video',
- '/ai-questions',
- '/ai-develop',
- '/ai-grandcanal',
- '/ai-plantexperts',
- '/virtual-laboratory',
- '/ai-poetry',
- '/management-interface',
- ]
- }
- const blocklyRoutes = {
- home: '/blocklyHome',
- login: '/blockly-login',
- role: 'blockly',
- children: [
- '/blockly',
- '/blockly2',
- '/mapGame',
- '/programming02',
- '/programmingList',
- '/programmingCourset',
- '/interface'
- ]
- }
- const aiCourseRoutes = {
- home: '/aiCourseHome',
- login: '/ai-login',
- role: 'aiCourse',
- children: [
- '/experiment-type',
- '/experimental-course',
- '/experimental-interface'
- ]
- }
- // 定义登录页面与主页的映射关系
- const loginToHomeMap = {
- '/login': homeRoutes.home,
- '/quick-login': homeRoutes.home,
- '/promotion-login': homeRoutes.home,
- '/blockly-login': blocklyRoutes.home,
- '/ai-login': aiCourseRoutes.home,
- '/register-login': homeRoutes.home
- }
- const router = createRouter({
- history: createWebHashHistory(),
- routes
- })
- // 导航守卫
- router.beforeEach(async (to, from, next) => {
- if (to.path === "/"){
- await refreshAllDictData()
- await refreshRoleRoute()
- }
- // 从localStorage获取角色路由数据
- const roleRouteStr = localStorage.getItem(CONFIG.USER_ROLE_ROUTE_KEY)
- const roleRouteSet = roleRouteStr ? JSON.parse(roleRouteStr) : []
- // 如果是登录页面,直接放行并存储登录信息
- if (Object.keys(loginToHomeMap).includes(to.path)) {
- localStorage.setItem('loginPath', to.path)
- next()
- return
- }
- // 获取当前登录类型
- const loginPath = localStorage.getItem('loginPath')
- // 获取当前登录类型对应的主页
- let allowedHome = loginToHomeMap[loginPath]
- // 检查目标路由是否在允许的路由范围内
- let isAllowed = false
- // 首先检查用户是否有权限访问对应的主页
- const hasHomePermission = roleRouteSet.includes(homeRoutes.role)
- const hasBlocklyPermission = roleRouteSet.includes(blocklyRoutes.role)
- const hasAiCoursePermission = roleRouteSet.includes(aiCourseRoutes.role)
- // 如果用户没有当前登录类型对应的权限,切换到用户有权限的主页
- if (!((allowedHome === homeRoutes.home && hasHomePermission) ||
- (allowedHome === blocklyRoutes.home && hasBlocklyPermission) ||
- (allowedHome === aiCourseRoutes.home && hasAiCoursePermission))) {
- // 找到用户有权限的主页
- if (hasAiCoursePermission) {
- allowedHome = aiCourseRoutes.home
- } else if (hasBlocklyPermission) {
- allowedHome = blocklyRoutes.home
- } else if (hasHomePermission) {
- allowedHome = homeRoutes.home
- } else {
- // 如果没有任何权限,可以考虑重定向到登录页面或其他公共页面
- next(loginPath)
- return
- }
- }
- // 检查目标路由是否在允许的范围内
- if ((to.path === homeRoutes.home || homeRoutes.children.includes(to.path)) && hasHomePermission) {
- isAllowed = true
- } else if ((to.path === blocklyRoutes.home || blocklyRoutes.children.includes(to.path)) && hasBlocklyPermission) {
- isAllowed = true
- } else if ((to.path === aiCourseRoutes.home || aiCourseRoutes.children.includes(to.path)) && hasAiCoursePermission) {
- isAllowed = true
- }
- if (isAllowed) {
- next()
- } else {
- // 不允许访问时,重定向到用户有权限的主页
- if (to.path !== "/")Message().warning('您没有权限访问该页面,已自动切换到您有权限的主页!', true);
- next(allowedHome)
- }
- })
- export default router;
- export { homeRoutes, blocklyRoutes, aiCourseRoutes };
|