import Vue from 'vue'
import VueRouter from 'vue-router'
import operate from '@/views/resource/finance/operate' // 经营情况
import annual from '@/views/resource/finance/annual' // 年度审计
import special from '@/views/resource/finance/special/index.vue' // 专项审计情况
import paytaxes from '@/views/resource/finance/paytaxes/index.vue' // 企业所得税纳税情况
import organization from '@/views/resource/manpower/organization/index.vue' // 组织架构
import employee from '@/views/resource/manpower/employee/index.vue' // 职工管理

import technology from '@/views/resource/manpower/technology/index.vue' // 科学专家
import knowledge from '@/views/resource/achievement/knowledge/index.vue' // 知识产权
import knowledgeEdit from '@/views/resource/achievement/knowledge/knowledgeEdit.vue' // 知识产权编辑
import knowledgeDetial from '@/views/resource/achievement/knowledge/knowledgeDetial.vue' // 知识产权详情
import paper from '@/views/resource/achievement/paper/index.vue' // 论文管理
import paperDetail from '@/views/resource/achievement/paper/paperDetail.vue' // 论文管理详情
import standardDetial from '@/views/resource/achievement/standard/standardDetial.vue' // 标准详情
import standardEdit from '@/views/resource/achievement/standard/standardEdit.vue' // 标准编辑
import paperAdd from '@/views/resource/achievement/paper/paperAdd.vue' // 论文管理新增
import standard from '@/views/resource/achievement/standard/index.vue' // 论文管理
import enterprise from '@/views/resource/qualification/enterprise/index.vue' 
import corporatehonors from '@/views/resource/qualification/corporatehonors/index.vue' 
import corporatehonorsDetail from '@/views/resource/qualification/corporatehonors/corporatehonorsDetail.vue' //企业荣誉详情
import corporatehonorsEdit from '@/views/resource/qualification/corporatehonors/corporatehonorsEdit.vue' //企业荣誉编辑
import enterpriseDetail from '@/views/resource/qualification/enterprise/enterpriseDetail.vue'  //资质详情
import enterpriseEdit from '@/views/resource/qualification/enterprise/enterpriseEdit.vue'  //资质编辑
import systemnotice from '@/views/resource/systemnotice/index.vue' 
import systemnoticeEdit from '@/views/resource/systemnotice/systemnoticeEdit.vue' //制度编辑
import systemnoticeDetail from '@/views/resource/systemnotice/systemnoticeDetail.vue' //制度详情
import Schoolenterprise from '@/views/resource/Schoolenterprise/index.vue' 
import SchoolenterpriseDetail from '@/views/resource/Schoolenterprise/SchoolenterpriseDetail.vue' //校企合作详情
import SchoolenterpriseEdit from '@/views/resource/Schoolenterprise/SchoolenterpriseEdit.vue' //校企合作编辑
import examstatus from '@/views/project/Workhourmanagement/examstatus/index.vue'
import examstatusEdint from '@/views/project/Workhourmanagement/examstatus/examstatusEdint.vue'//工时编辑
import examstatusDetail from '@/views/project/Workhourmanagement/examstatus/examstatusDetail.vue'//工时详情
import personnel from '@/views/project/Workhourmanagement/personnel/index.vue'  //人员降薪
import personnelEdint from '@/views/project/Workhourmanagement/personnel/personnelEdint.vue'  //人员降薪编辑
import personnelDetail from '@/views/project/Workhourmanagement/personnel/personnelDetail.vue'  //人员降薪详情
import projecthours from '@/views/project/projectmanagement/ProjectStatus/index.vue'
import projecthoursDetai from '@/views/project/projectmanagement/projecthoursDetai.vue' //项目主页
import lixiangziliao from '@/views/project/projectmanagement/lixiangziliao/index.vue' //立项阶段资料
import lixiangziliaoEdint from '@/views/project/projectmanagement/lixiangziliao/lixiangziliaoEdint.vue' //立项阶段资料编辑
import lixiangyusuan from '@/views/project/projectmanagement/lixiangyusuan/index.vue' //立即预算编辑
import renwuqingdan from '@/views/project/projectmanagement/renwuqingdan/index.vue' //任务清单编辑
import chengyuan from '@/views/project/projectmanagement/chengyuan/index.vue' //任务清单编辑
import hetongmingxin from '@/views/project/projectmanagement/hetongmingxin/index.vue' //合同明细编辑
import hetongmingxinDetails from '@/views/project/projectmanagement/hetongmingxin/indexDetails.vue' //合同明细编辑
import jindubaogao from '@/views/project/projectmanagement/jindubaogao/index.vue' //进度报告编辑
import jindubaogaoDetail from '@/views/project/projectmanagement/jindubaogao/jindubaogaoDetail.vue' //进度报告详情
import feiyongmingxi from '@/views/project/projectmanagement/feiyongmingxi/index.vue' //支出费用编辑
import feiyongmingxikeji from '@/views/project/projectmanagement/feiyongmingxi/keji/index.vue' //支出费用编辑
import indexzhu from '@/views/project/projectmanagement/feiyongmingxi/indexzhu.vue' //支出费用主页
import feiyongmingxiDetail from '@/views/project/projectmanagement/feiyongmingxi/feiyongmingxiDetail.vue' //支出费用详情
import projectmanagementEdint from '@/views/project/projectmanagement/projectmanagementEdint/index.vue' //项目主页
import xiangmujiedian from '@/views/project/projectmanagement/xiangmujiedian/index.vue' //项目节点
import xiangmujiedianEdint from '@/views/project/projectmanagement/xiangmujiedian/xiangmujiedianEdint.vue' //项目节点详情
import zhongqi from '@/views/project/projectmanagement/zhongqi/index.vue' //中期检查编辑
import zhongqiDetai from '@/views/project/projectmanagement/zhongqi/zhongqiDetai.vue' //中期检查详情
import jianti from '@/views/project/projectmanagement/jianti/index.vue' //结题情况编辑
import jiantiDetial from '@/views/project/projectmanagement/jianti/jiantiDetial.vue' //结题情况详情
import wendang from '@/views/project/projectmanagement/wendang/index.vue' //文档编辑
import wendangDetai from '@/views/project/projectmanagement/wendang/wendangDetai.vue' //文档详情
import kejichengguo from '@/views/project/projectmanagement/kejichengguo/index.vue' //科技成果编辑
import kejichengguoDetail from '@/views/project/projectmanagement/kejichengguo/kejichengguoDetail.vue' //科技成果详情
import chengguo from '@/views/project/projectmanagement/chengguo/index.vue' //成果图示编辑
import touziyusuanEdit from '@/views/project/projectmanagement/touziyusuan/touziyusuanEdit.vue' //投资预算编辑
import touziyusuanDetail from '@/views/project/projectmanagement/touziyusuan/touziyusuanDetail.vue' //投资预算详情

import contract from '@/views/resource/contract/index.vue' 
import conponentEdit from '@/views/resource/contract/conponentEdit.vue' //合同新增
import conponentDetail from '@/views/resource/contract/conponentDetail.vue' //合同详情
import productService from '@/views/businessScope/productService/index.vue' //经营项目
import productServiceDetail from '@/views/businessScope/productService/productServiceDetail.vue' //经营详情
import xiaoshouqingkuan from '@/views/businessScope/productService/xiaoshouqingkuan.vue' //经营销售详情
import salesperformance from '@/views/businessScope/salesperformance/index.vue'  //销售情况
import salesperformanceDetial from '@/views/businessScope/salesperformance/salesperformanceDetial.vue' 
import salesperformanceEdint from '@/views/businessScope/salesperformance/salesperformanceEdint.vue' 
import permissionnode from '@/views/auditmanagement/permissionnode/index.vue'
import mysubmission from '@/views/auditmanagement/mysubmission/index.vue'
import myreview from '@/views/auditmanagement/myreview/index.vue' //审核管理
import myreviewSee from '@/views/auditmanagement/myreview/myreviewSee.vue' //审核详情

import follow from '@/views/Innovation/follow/index.vue'
import government from '@/views/Innovation/government/index.vue'
import governmentAddress from '@/views/Innovation/government/address/index.vue'
import declarationmanagement from '@/views/declarationmanagement/index.vue'
import role from '@/views/system/permission/role/index.vue'
import user from '@/views/system/permission/user/index.vue'
import userbehavior from '@/views/system/logs/userbehavior/index.vue'
import operationlog from '@/views/system/logs/operationlog/index.vue'
import declarationstatus from '@/views/specializeds/declarationstatus/index.vue' //申报管理
import declarationstatusDetail from '@/views/specializeds/declarationstatus/declarationstatusDetail.vue' //申报管理主页
import specialized from '@/views/specialized/index.vue'
import specializedDetail from '@/views/specialized/specializedDetail.vue'
import rds from '@/views/specializeds/rds/index.vue'
import dictionary from '@/views/system/configuration/dictionary/index.vue'
import menu from '@/views/system/configuration/menu/index.vue'
import systemconfiguration from '@/views/system/configuration/systemconfiguration/index.vue'
import Layout from '@/views/Layout.vue' // 新建的布局组件
import corporateInformation from '@/views/homepage/corporateInformation/index' // 企业信息
import dataoverview from '@/views/homepage/dataoverview/index' // 数据概览
import dataretrieval from '@/views/homepage/dataretrieval/index' // 资料检索
import qiyeDetail from '@/views/resource/finance/operate/qiyeDetail.vue' // 企业详情
import qiyeEdit from '@/views/resource/finance/operate/qiyeEdit.vue' // 企业编辑
import zichangDetail from '@/views/resource/finance/operate/zichangDetail.vue' // 资产详情
import zichangEdit from '@/views/resource/finance/operate/zichangEdit.vue' // 资产详情
import auditDetail from '@/views/resource/finance/annual/auditDetail.vue' // 年度审计报告详情
import auditEdit from '@/views/resource/finance/annual/auditEdit.vue' // 年度审计报告编辑
import technologypiliang from '@/views/resource/manpower/technology/piliang.vue' // 年度审计报告编辑
import selectexperts from '@/views/resource/manpower/technology/selectexperts.vue' // 专家抽取设置
import extractdetail from '@/views/resource/manpower/technology/extractdetail.vue' // 抽取专家名单
import employeepidetial from '@/views/resource/manpower/employee/employeepi.vue' // 职工管理批量
import Login from '@/views/login/index.vue' // 登录页面
import messageCenter from '@/views/message/index.vue' // 消息中心
Vue.use(VueRouter)

const routes = [
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: { requiresAuth: false }
  },
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/role',
    redirect: to => {
      const isLogin = localStorage.getItem('isLogin') === 'true'
      const token = localStorage.getItem('token')
      if (isLogin || token) {
        return '/home/role'
      }
      return '/login'
    },
    meta: { requiresAuth: true }
  },
  {
    path: '/home',
    name: 'Layout',
    component: Layout, // 使用布局组件作为容器
    meta: { requiresAuth: true },
    redirect: '/home/', // 重定向到默认子路由
    children: [
      {
        path: 'dataretrieval', 
        name: 'dataretrieval',
        component: dataretrieval // 资料检索
      },
      {
        path: 'corporateInformation', 
        name: 'corporateInformation',
        component: corporateInformation // 企业信息
      },
      {
        path: '', 
        name: 'dataoverview',
        component: dataoverview // 数据概览
      },
      {
        path: 'operate',
        name: 'operate',
        component: operate
      },
      {
        path: 'dictionary',
        name: 'dictionary',
        component: dictionary
      },
      {
        path: 'menu',
        name: 'menu',
        component: menu
      },
      {
        path: 'systemconfiguration',
        name: 'systemconfiguration',
        component: systemconfiguration
      },
      {
        path: 'userbehavior',
        name: 'userbehavior',
        component: userbehavior
      },
      {
        path: 'operationlog',
        name: 'operationlog',
        component: operationlog
      },
      {
        path: 'role',
        name: 'role',
        component: role
      },
      {
        path: 'user',
        name: 'user',
        component: user
      },
      {
        path: 'follow',
        name: 'follow',
        component: follow
      },
      {
        path: 'government',
        name: 'government',
        component: government
      },
      {
        path: 'declarationstatus',
        name: 'declarationstatus',
        component: declarationstatus
      },
      {
        path: 'rds',
        name: 'rds',
        component: rds
      },
      {
        path: 'declarationmanagement',
        name: 'declarationmanagement',
        component: declarationmanagement
      },
      {
        path: 'specialized',
        name: 'specialized',
        component: specialized
      },
      {
        path: 'specializedDetail',
        name: 'specializedDetail',
        component: specializedDetail
      },
      {
        path: 'permissionnode',
        name: 'permissionnode',
        component: permissionnode
      },
      {
        path: 'mysubmission',
        name: 'mysubmission',
        component: mysubmission
      },
      {
        path: 'myreview',
        name: 'myreview',
        component: myreview
      },
      {
        path: 'productService',
        name: 'productService',
        component: productService
      },
     
      
      {
        path: 'salesperformance',
        name: 'salesperformance',
        component: salesperformance
      },
    
      {
        path: 'projecthours',
        name: 'projecthours',
        component: projecthours
      },
      {
        path: 'examstatus',
        name: 'examstatus',
        component: examstatus
      },
      {
        path: 'personnel',
        name: 'personnel',
        component: personnel
      },
      {
        path: 'Schoolenterprise',
        name: 'Schoolenterprise',
        component: Schoolenterprise
      },
      {
        path: 'contract',
        name: 'contract',
        component: contract
      },
      {
        path: 'systemnotice',
        name: 'systemnotice',
        component: systemnotice
      },
      {
        path: 'standard',
        name: 'standard',
        component: standard
      },
      {
        path: 'enterprise',
        name: 'enterprise',
        component: enterprise
      },
      {
        path: 'corporatehonors',
        name: 'corporatehonors',
        component: corporatehonors
      },
      {
        path: 'annual',
        name: 'annual',
        component: annual
      },
      {
        path: 'special',
        name: 'special',
        component: special
      },
      {
        path: 'paytaxes',
        name: 'paytaxes',
        component: paytaxes
      },
      {
        path: 'organization',
        name: 'organization',
        component: organization
      },
      {
        path: 'employee',
        name: 'employee',
        component: employee
      },
    
      {
        path: 'paper',
        name: 'paper',
        component: paper
      },
      {
        path: 'technology',
        name: 'technology',
        component: technology
      },
      {
        path: 'knowledge',
        name: 'knowledge',
        component: knowledge
      },
      {
        path: 'message',
        name: 'message',
        component: messageCenter
      },
      {
        path: 'government/address',
        name: 'governmentAddress',
        component: governmentAddress
      }
      // 可以继续添加其他内容路由
    ]
  },

  {
    path: '/projectmanagementEdint',
    name: 'projectmanagementEdint',
    component: projectmanagementEdint,
  
  },
  {
    path: '/projecthoursDetai',
    name: 'projecthoursDetai',
    component: projecthoursDetai,
  
  },
  {
    path: '/lixiangyusuan',
    name: 'lixiangyusuan',
    component: lixiangyusuan,
  
  },
  {
    
    path: '/hetongmingxinDetails',
    name: 'hetongmingxinDetails',
    component: hetongmingxinDetails,
  },
  {
    
    path: '/wendang',
    name: 'wendang',
    component: wendang,
  },
  {
    
    path: '/wendangDetai',
    name: 'wendangDetai',
    component: wendangDetai,
  },
  {
    
    path: '/jindubaogao',
    name: 'jindubaogao',
    component: jindubaogao,
  },
  {
    
    path: '/xiangmujiedian',
    name: 'xiangmujiedian',
    component: xiangmujiedian,
  },
  {
    
    path: '/zhongqi',
    name: 'zhongqi',
    component: zhongqi,
  },
  {
    
    path: '/zhongqiDetai',
    name: 'zhongqiDetai',
    component: zhongqiDetai,
  },
  {
    
    path: '/xiangmujiedianEdint',
    name: 'xiangmujiedianEdint',
    component: xiangmujiedianEdint,
  },
  
  {
    
    path: '/jindubaogaoDetail',
    name: 'jindubaogaoDetail',
    component: jindubaogaoDetail,
  },
  {
    
    path: '/feiyongmingxi',
    name: 'feiyongmingxi',
    component: feiyongmingxi,
  },
  {
    
    path: '/feiyongmingxikeji',
    name: 'feiyongmingxikeji',
    component: feiyongmingxikeji,
  },
  {
    
    path: '/indexzhu',
    name: 'indexzhu',
    component: indexzhu,
  },
  {
    
    path: '/feiyongmingxiDetail',
    name: 'feiyongmingxiDetail',
    component: feiyongmingxiDetail,
  },
  {
    
    path: '/chengyuan',
    name: 'chengyuan',
    component: chengyuan,
  },
  {
    
    path: '/hetongmingxin',
    name: 'hetongmingxin',
    component: hetongmingxin,
  },
  {
    path: '/renwuqingdan',
    name: 'renwuqingdan',
    component: renwuqingdan,
  
  },
  {
    path: '/lixiangziliao',
    name: 'lixiangziliao',
    component: lixiangziliao,
  
  },
  {
    path: '/lixiangziliaoEdint',
    name: 'lixiangziliaoEdint',
    component: lixiangziliaoEdint,
  
  },
  {
    path: '/corporatehonorsDetail',
    name: 'corporatehonorsDetail',
    component: corporatehonorsDetail
  },
  {
    path: '/systemnoticeEdit',
    name: 'systemnoticeEdit',
    component: systemnoticeEdit
  },
  {
    path: '/systemnoticeDetail',
    name: 'systemnoticeDetail',
    component: systemnoticeDetail
  },
  {
    path: '/corporatehonorsEdit',
    name: 'corporatehonorsEdit',
    component: corporatehonorsEdit
  },
  {
    path: '/enterpriseDetail',
    name: 'enterpriseDetail',
    component: enterpriseDetail
  },
  {
    path: '/enterpriseEdit',
    name: 'enterpriseEdit',
    component: enterpriseEdit
  },
  {
    path: '/employeepidetial',
    name: 'employeepidetial',
    component: employeepidetial
  },
  {
    path: '/paperDetail',
    name: 'paperDetail',
    component: paperDetail
  },
  {
    path: '/productServiceDetail',
    name: 'productServiceDetail',
    component: productServiceDetail
  },
  {
    path: '/standardDetial',
    name: 'standardDetial',
    component: standardDetial
  },
  {
    path: '/salesperformanceEdint',
    name: 'salesperformanceEdint',
    component: salesperformanceEdint
  },
  {
    path: '/chengguo',
    name: 'chengguo',
    component: chengguo
  },
  {
    path: '/touziyusuanEdit',
    name: 'touziyusuanEdit',
    component: touziyusuanEdit
  },
  {
    path: '/touziyusuanDetail',
    name: 'touziyusuanDetail',
    component: touziyusuanDetail
  },
  {
    path: '/standardEdit',
    name: 'standardEdit',
    component: standardEdit
  },
  {
    path: '/declarationstatusDetail',
    name: 'declarationstatusDetail',
    component: declarationstatusDetail
  },
  {
    path: '/specializedDetail',
    name: 'specializedDetail',
    component: specializedDetail
  },
  {
    path: '/paperAdd',
    name: 'paperAdd',
    component: paperAdd
  },
  {
    path: '/myreviewSee',
    name: 'myreviewSee',
    component: myreviewSee
  },
  {
    path: '/salesperformanceDetial',
    name: 'salesperformanceDetial',
    component: salesperformanceDetial
  },
  {
    path: '/salesperformanceEdint',
    name: 'salesperformanceEdint',
    component: salesperformanceEdint
  },
  {
    path: '/knowledgeEdit',
    name: 'knowledgeEdit',
    component: knowledgeEdit
  },
  {
    path: '/conponentDetail',
    name: 'conponentDetail',
    component: conponentDetail
  },
  {
    path: '/conponentEdit',
    name: 'conponentEdit',
    component: conponentEdit
  },
  {
    path: '/xiaoshouqingkuan',
    name: 'xiaoshouqingkuan',
    component: xiaoshouqingkuan
  },
  {
    path: '/SchoolenterpriseDetail',
    name: 'SchoolenterpriseDetail',
    component: SchoolenterpriseDetail
  },
  {
    path: '/SchoolenterpriseEdit',
    name: 'SchoolenterpriseEdit',
    component: SchoolenterpriseEdit
  },
  {
    path: '/knowledgeDetial',
    name: 'knowledgeDetial',
    component: knowledgeDetial
  },
  {
    path: '/qiyeDetail',
    name: 'qiyeDetail',
    component: qiyeDetail,
  },
  {
    path: '/selectexperts',
    name: 'selectexperts',
    component: selectexperts,
  },
  {
    path: '/extractdetail',
    name: 'extractdetail',
    component: extractdetail,
  },
  {
    path: '/jiantiDetial',
    name: 'jiantiDetial',
    component: jiantiDetial,
  },
  {
    path: '/jianti',
    name: 'jianti',
    component: jianti,
  },
  {
    path: '/technologypiliang',
    name: 'technologypiliang',
    component: technologypiliang,
  },
  {
    path: '/auditDetail',
    name: 'auditDetail',
    component: auditDetail,
  },
  {
    path: '/examstatusDetail',
    name: 'examstatusDetail',
    component: examstatusDetail,
  },
  {
    path: '/personnelEdint',
    name: 'personnelEdint',
    component: personnelEdint,
  },
  {
    path: '/personnelDetail',
    name: 'personnelDetail',
    component: personnelDetail,
  },
  {
    path: '/examstatusEdint',
    name: 'examstatusEdint',
    component: examstatusEdint,
  },
  {
    path: '/auditEdit',
    name: 'auditEdit',
    component: auditEdit,
  },
  {
    path: '/qiyeEdit',
    name: 'qiyeEdit',
    component: qiyeEdit,
  },
  {
    path: '/kejichengguo',
    name: 'kejichengguo',
    component: kejichengguo,
  },
  {
    path: '/kejichengguoDetail',
    name: 'kejichengguoDetail',
    component: kejichengguoDetail,
  },
  {
    path: '/zichangDetail',
    name: 'zichangDetail',
    component: zichangDetail,
  },
  {
    path: '/zichangEdit',
    name: 'zichangEdit',
    component: zichangEdit,
  },
  {
    path: '/follow',
    name: 'follow',
    component: follow,
    meta: { requiresAuth: true }
  },
  {
    path: '/government',
    name: 'government',
    component: government,
    meta: { requiresAuth: true }
  }
]

const router = new VueRouter({
  routes,
  mode: 'hash', // 确保使用 hash 模式
  scrollBehavior(to, from, savedPosition) {
    // 如果浏览器有保存的滚动位置，恢复它（支持回退）
    if (savedPosition) {
      return savedPosition
    } else {
      return { x: 0, y: 0 }
    }
  }
})

// 路由守卫
router.beforeEach((to, from, next) => {
  try {
    // 确保从 localStorage 正确读取值
    const isLoginValue = localStorage.getItem('isLogin')
    const token = localStorage.getItem('token')
    const isLogin = isLoginValue === 'true' || isLoginValue === true
    // 确保 token 不是空字符串、null 或 undefined
    const hasToken = !!localStorage.getItem('token'); // 简化为布尔值
    const hasAuth = isLogin && hasToken; // ✅ 必须同时满足登录态和 Token
    
    // 开发环境下打印路由信息（强制输出，帮助排查）
    console.log('🔍 路由守卫检查:', {
      to: to.path,
      from: from.path,
      hasAuth,
      isLogin,
      isLoginValue,
      isLoginType: typeof isLoginValue,
      hasToken,
      tokenLength: token ? token.length : 0,
      tokenPreview: token ? (token.length > 20 ? token.substring(0, 20) + '...' : token) : '未设置',
      meta: to.meta,
      matched: to.matched.length,
      allStorage: {
        isLogin: localStorage.getItem('isLogin'),
        token: localStorage.getItem('token') ? '已设置' : '未设置',
        userId: localStorage.getItem('userId')
      }
    })
    
    // 如果已登录
    if (hasAuth) {
      // 如果访问登录页，跳转到主页
      if (to.path === '/') {
        next('/home')
        return
      }
      // 如果访问根路径，跳转到主页
      if (to.path === '/') {
        next('/home')
        return
      }
      // 已登录用户允许访问所有其他路由
      next()
      return
    }
    
    // 未登录的情况
    // 如果访问登录页，允许访问
    if (to.path === '/login') {
      next()
      return
    }
    
    // 如果需要登录但未登录，跳转到登录页
    if (to.meta && to.meta.requiresAuth === true) {
      if (process.env.NODE_ENV === 'development') {
        console.warn('路由守卫: 需要登录但未登录，重定向到登录页', {
          path: to.path,
          meta: to.meta
        })
      }
      next('/login')
      return
    }
    
    // 对于 /home 及其子路由，需要登录
    if (to.path.startsWith('/home')) {
      if (!hasAuth) {
        // 开发环境下，提供详细的提示和解决方案
        if (process.env.NODE_ENV === 'development') {
          console.warn('⚠️ 路由守卫: 访问 /home 需要登录，但检测到未登录状态')
          console.warn('📋 当前 localStorage 状态:')
          console.warn('  isLogin:', localStorage.getItem('isLogin') || '未设置')
          console.warn('  token:', localStorage.getItem('token') ? '已设置' : '未设置')
          console.warn('  userId:', localStorage.getItem('userId') || '未设置')
          console.warn('')
          console.warn('💡 解决方案:')
          console.warn('  1. 请先访问登录页面进行登录: http://localhost:8080/#/login')
          console.warn('  2. 登录成功后，isLogin 和 token 会被自动设置')
          console.warn('  3. 然后就可以正常访问 /home 页面了')
          console.warn('')
          console.warn('🔧 临时调试方案（仅开发环境）:')
          console.warn('  在控制台执行以下命令，然后刷新页面:')
          console.warn('  localStorage.setItem("isLogin", "true")')
          console.warn('  localStorage.setItem("token", "temp_token_for_dev")')
        }
        
        // 静默重定向到登录页（不抛出错误，避免控制台报错）
        next('/login')
        return
      }
    }
    
    // 其他路由，如果是公开路由（明确标记为不需要登录），允许访问
    if (to.meta && to.meta.requiresAuth === false) {
      next()
      return
    }
    
    // 默认情况下，未登录用户跳转到登录页
    if (process.env.NODE_ENV === 'development') {
      console.warn('路由守卫: 默认重定向到登录页', {
        path: to.path,
        meta: to.meta
      })
    }
    next('/login')
  } catch (error) {
    console.error('路由守卫错误:', error)
    // 发生错误时，允许访问登录页
    if (to.path === '/login') {
      next()
    } else {
      next('/login')
    }
  }
})

export default router
