| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- import { createRouter, createWebHashHistory } from 'vue-router'
- import Index from '../views/Index.vue'
- import Chat from '../views/Chat.vue'
- import AIWriting from '../views/AIWriting.vue'
- import Admin from '../views/Admin.vue'
- import ExamWorkshop from '../views/ExamWorkshop.vue'
- import HazardDetection from '../views/HazardDetection.vue'
- import PolicyDocument from '../views/PolicyDocument.vue'
- import SafetyHazard from '../views/SafetyHazard.vue'
- import TemplateEditor from '../views/TemplateEditor.vue'
- import MobileIndex from '../views/mobile/m-Index.vue'
- import MobileChat from '../views/mobile/m-Chat.vue'
- import MobileSafetyHazard from '../views/mobile/m-SafetyHazard.vue'
- import MobileExamWorkshop from '../views/mobile/m-ExamWorkshop.vue'
- import MobileHazardDetection from '../views/mobile/m-HazardDetection.vue'
- import MobileAIWriting from '../views/mobile/m-AIWriting.vue'
- import MobilePolicyDocument from '../views/mobile/m-PolicyDocument.vue'
- import NotFound from '../views/NotFound.vue'
- import { isMobile } from '../utils/mobileDetector.js'
- // ===== 注释掉:登录页已废弃,改用票据认证 =====
- // import Login from '../views/Login.vue'
- // import { isLoggedIn } from '../utils/auth.js'
- const routes = [
- {
- path: '/',
- name: 'Index',
- component: Index,
- beforeEnter: (to, from, next) => {
- // 如果是移动设备,重定向到移动端首页
- if (isMobile()) {
- console.log('📱 检测到移动设备,重定向到 /mobile')
- console.log('📍 原始 URL:', window.location.href)
- console.log('📍 原始查询参数:', to.query)
- // 重定向时保留所有查询参数(包括票据)
- // 使用 replace 而不是 push,避免在历史记录中留下 /
- next({
- path: '/mobile',
- query: to.query, // 保留查询参数
- replace: true
- });
- } else {
- next();
- }
- }
- },
- {
- path: '/mobile',
- name: 'MobileIndex',
- component: MobileIndex
- },
- {
- path: '/mobile/chat',
- name: 'MobileChat',
- component: MobileChat
- },
- {
- path: '/mobile/safety-hazard',
- name: 'MobileSafetyHazard',
- component: MobileSafetyHazard
- },
- {
- path: '/mobile/exam-workshop',
- name: 'MobileExamWorkshop',
- component: MobileExamWorkshop
- },
- {
- path: '/mobile/hazard-detection',
- name: 'MobileHazardDetection',
- component: MobileHazardDetection
- },
- {
- path: '/mobile/ai-writing',
- name: 'MobileAIWriting',
- component: MobileAIWriting
- },
- {
- path: '/mobile/policy-document',
- name: 'MobilePolicyDocument',
- component: MobilePolicyDocument
- },
- {
- path: '/chat',
- name: 'Chat',
- component: Chat
- },
- {
- path: '/ai-writing',
- name: 'AIWriting',
- component: AIWriting
- },
- {
- path: '/admin',
- name: 'Admin',
- component: Admin
- },
- {
- path: '/exam-workshop',
- name: 'ExamWorkshop',
- component: ExamWorkshop
- },
- {
- path: '/hazard-detection',
- name: 'HazardDetection',
- component: HazardDetection
- },
- {
- path: '/policy-document',
- name: 'PolicyDocument',
- component: PolicyDocument
- },
- {
- path: '/safety-hazard',
- name: 'SafetyHazard',
- component: SafetyHazard
- },
- {
- path: '/template-editor',
- name: 'TemplateEditor',
- component: TemplateEditor
- },
- // ===== 注释掉:登录路由已废弃,改用票据认证 =====
- // {
- // path: '/login',
- // name: 'Login',
- // component: Login
- // }
- // ===== 新增:404错误页面 =====
- {
- path: '/404',
- name: 'NotFound',
- component: NotFound
- },
- // 捕获所有未定义的路由
- {
- path: '/:pathMatch(.*)*',
- redirect: '/404'
- }
- ]
- const router = createRouter({
- history: createWebHashHistory(),
- routes
- })
- // 全局前置守卫 - 系统停机维护拦截
- const isMaintenance = true; // 是否开启停机维护模式
- router.beforeEach((to, from, next) => {
- if (isMaintenance) {
- // 允许访问的维护页面(即显示了公告的主界面)
- const allowedPaths = ['/', '/mobile'];
- if (!allowedPaths.includes(to.path)) {
- console.log('🚧 系统维护中,拦截访问:', to.path);
- // 根据设备类型重定向到对应的主界面(带上原有参数防丢失)
- if (isMobile()) {
- return next({ path: '/mobile', query: to.query, replace: true });
- } else {
- return next({ path: '/', query: to.query, replace: true });
- }
- }
- }
- next();
- })
- // ===== 注释掉:登录认证守卫已废弃,改用票据认证 =====
- // 全局前置守卫 - 登录认证
- // router.beforeEach((to, from, next) => {
- // // 如果是访问登录页,直接放行
- // if (to.path === '/login') {
- // next()
- // return
- // }
- //
- // // 检查是否已登录
- // if (!isLoggedIn()) {
- // // 未登录,重定向到登录页,并保存原始访问路径
- // console.log('🔒 未登录,重定向到登录页')
- // next({
- // path: '/login',
- // query: { redirect: to.fullPath }
- // })
- // } else {
- // // 已登录,放行
- // next()
- // }
- // })
- export default router
|