import Vue from 'vue'
import VueRouter from 'vue-router'
// import 首页 from '../views/首页.vue'
// import 市场主体分析 from '../views/市场主体分析.vue'
// import 市场风险分析 from '../views/市场风险分析.vue'
// import 行情分析 from '../views/行情分析.vue'
// import 事件分析 from '../views/事件分析.vue'

import Main from '../views/Main.vue'
import Home from '../views/Home.vue'
import register from '@/user/register'
import test from "@/views/test";
import 	市场主体分析	from   '../views/市场主体分析.vue'
import 	系统性风险分析	from   '../views/系统性风险分析.vue'
import systemRiskV2 from "@/components/systemRiskComponent";
import 	个体风险分析	from   '../views/个体风险分析.vue'
import  login from "@/user/login";
import 	高影响力主体分析	from '../views/高影响力主体分析.vue'
import 	预警服务	from       '../views/预警服务.vue'
import 	风险预警	from       '../views/风险预警.vue'
import 	异常检测	from       '../views/异常检测.vue'
import warn from '@/views/404'
import 	健康指数	from       '../views/健康指数.vue'
import 	压力测试	from       '../views/压力测试.vue'
import 	行情分析	from       '../views/行情分析.vue'
import 	事件分析	from       '../views/事件分析.vue'
import 	事件图谱	from       '../views/事件图谱.vue'
import graphViewV4 from "@/views/graphViewV4";
import 风险传导 from "@/views/风险传导"
import 	大屏	from       '../bigscreen/大屏.vue'
import 	大屏1	from       '../bigscreen1/大屏.vue'
import 	大屏2	from       '../bigscreen2/大屏.vue'
import 	agriculture	from       '@/agriculture/index.vue'
import 	UserManagement	from     '../views/UserManagement.vue'

import SSE from "@/views/SSE";
// import tab from "@/store/tab";


// 解决重复点击页面报NavigationDuplicated: Avoided redundant navigation to current locat
const originalPush = VueRouter.prototype.push

VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}



Vue.use(VueRouter)


//1.import 创建路由组件
//2.将路由与组件进行映射


const routes = [


    //主路由

  { path:'/',
    name:'agriculture',
    component:agriculture,
  },
  // 登录
  {path:'/login',name :'login',component: login},
  // {path:'/login2',name :'login2',component: login2},

  // 注册
  {path:'/register',name :'register',component: register},


  //大屏
  {path:'/bigscreen',name :'bigscreen',component: 大屏,},
  {path:'/bigscreen1',name :'bigscreen1',component: 大屏1,},
  {path:'/bigscreen2',name :'bigscreen2',component: 大屏2},
  // {path:'/agriculture',name :'agriculture',component: agriculture},
  {path:'/test',name :'test',component: test,},
  {path:'/sse',name :'sse',component: SSE,},
  {path:'/systemrisk',name :'systemrisk',component: systemRiskV2,}
  ]


  //3.创建router实例
  const router = new VueRouter({
    mode: 'history', // 去掉url中的#
    routes
  })
  
  export default router
export  const isLogin=false;
//4.在main.js挂载


//路由守卫
router.beforeEach(async(to,from,next) => {
  const allowedRoutes = ['/login','/register','/agriculture'];
  const name=sessionStorage.getItem('user')
  // if (allowedRoutes.includes(to.path)) {
  //   next();
  // } else {
  //   next('/'); // 重定向到首页或其他允许的路由
  // }
  if (to.meta.requireAuth){//需要认证
    if (name || !name && (to.name==='/user' || to.name==='/login')){
      next()
    }else {
      next('/login')
      // return{
      //   path:'/login',
      //   query:{redirect:to.fullPath}
      // }
    }
  }
  else {
    next()
  }
})

