import Vue from 'vue'
import VueRouter from 'vue-router'
import Cookies from "js-cookie";
import Store from '@/store'
Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
  {
    path: "/",
    name:'/',
    component: () => import('@/views/index'),
  },

  {
    path:'/admin/login',
    name:'Login',
    meta: {
      title: '系统登录',
      // loginRequest:false
    },
    component: () => import("../views/login/index.vue")
  },
  {
    path: "/admin",
    meta:{
      title:'报告管理系统'
    },
    component: () => import('@/views/layout/index.vue'),
    children: [
      {
        path:'/admin/rManage',
        meta:{
          active: 'rManage',
          title:'报告管理系统',
          // loginRequest:true
        },
        component: () => import('@/views/report/index.vue')
      },
      {
        path: '/admin/task',
        meta:{
          active: 'task'
        },
        name: "task",
        // redirect:"/task/job",
        component: () => import('@/views/task/index.vue'),
        children: [
          {
            path: 'MyInitiate',
            name:"MyInitiate",
            component: () => import('@/views/task/MyInitiate.vue'),
            meta:{
              active:'task/MyInitiate'
            },
          },
          {
            path: 'MyHandle',
            name:"MyHandle",
            component: () => import('@/views/task/MyHandle.vue'),
            meta:{
              active:'task/MyHandle'
            },
          },
        ],
      },
      //无效分析、第三方意见、稳定性分析
      {
        path: '/InvalidIndex',
        name:"InvalidIndex",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/Invalid/index.vue'),
      },
      //FTO风险排查
      {
        path: '/FTOIndex',
        name:"FTOIndex",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/FTO/index.vue'),
      },
      //侵权分析
      {
        path: '/tortIndex',
        name:"tortIndex",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/tort/index.vue'),
      },
      //回避设计
      {
        path: '/avoid',
        name:"avoid",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/avoid/index.vue'),
      },
      {
        path:'/patentDetails',
        name:"patentDetails",
        meta:{
          aside:true
        },
        component:() => import('@/views/components/common/PatentDetails')
      },
      {
        path: '/Incomplete',
        name:"Incomplete",
        meta:{
          aside:true
        },
        component: () => import('@/views/task/components/Incomplete.vue'),
      },

      {
        path: '/ContrastIndex/:id',
        name:"ContrastIndex/:id",
        meta:{
          aside:true
        },
        component:() => import('@/views/task/components/contrastPatent.vue'),
      },

      {
        path: '/FTOContrast/:id',
        name:"FTOContrast/:id",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/FTO/FTOPage/FTOContrast.vue'),
      },

      {
        path: '/result',
        name:"result",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/Invalid/InvalidPage/Result.vue'),
      },
      {
        path: '/rDetails',
        name:"rDetails",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/reportDetails/index.vue'),
      },
      {
        path: '/FTOrDetails',
        name:"FTOrDetails",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/FTO/FTOPage/ReportDetails/index.vue'),
      },
      {
        path: '/taskReportDetails',
        name:"taskReportDetails",
        meta:{
          aside:true
        },
        component:() => import('@/views/task/components/taskReportDetails.vue'),
      },
      {
        path: '/import',
        name:"import",
        meta:{
          aside:true
        },
        component:() => import('@/views/components/import'),
      },
      {
        path: '/SelectedPatent',
        name:"SelectedPatent",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/reportDetails/components/SelectedPatent.vue'),
      },
      {
        path: '/export/patent',
        name:"/export/patent",
        meta:{
          aside:true
        },
        component:() => import('@/views/components/export/patent.vue'),
      },
      {
        path: '/AssignTasks',
        name:"/AssignTasks",
        meta:{
          aside:true
        },
        component:() => import('@/views/report/Invalid/InvalidPage/AssignTasks.vue'),
      },
    ]
  },
  {
    path: '/identificationCode',
    name:"identificationCode",
    meta:{
      allowPath:true
    },
    component: () => import('@/views/components/identificationCode'),
  },
  
  {
    path: "/admins",
    meta: {
      title: '报告管理系统'
    },
    component: () => import('@/views/layout/ReportAdmin.vue'),
    children: [
      {
        path: '/Incompletes',
        name:"Incompletes",
        meta:{
          allowPath:true,
          aside:true
        },
        component: () => import('@/views/task/components/Incomplete.vue'),
      },
      {
        path: '/FTOContrasts/:id',
        name:"FTOContrasts/:id",
        meta:{
          allowPath:true,
          aside:true
        },
        component:() => import('@/views/report/FTO/FTOPage/FTOContrast.vue'),
      },
    ]
  },
 
  // {
  //   path: '/customer_review',
  //   name:"customer_review",
  //   component:() => import('@/views/components/common/customer_review.vue'),
  // },
  // {
  //   path: '/ReportAdmin',
  //   name:"ReportAdmin",
  //   component: () => import('@/views/layout/ReportAdmin.vue'),
  //   children: [
  //     {
  //       path: '/InvalidIndex',
  //       name:"InvalidIndex",
  //       component:() => import('@/views/report/Invalid/index.vue'),
  //     },

  //     {
  //       path:'/patentDetails',
  //       name:"patentDetails",
  //       component:() => import('@/views/components/common/PatentDetails')
  //     },
  //     {
  //       path: '/Incomplete',
  //       name:"Incomplete",
  //       component: () => import('@/views/task/components/Incomplete.vue'),
  //     },

  //     {
  //       path: '/ContrastIndex/:id',
  //       name:"ContrastIndex/:id",
  //       component:() => import('@/views/task/components/contrastPatent.vue'),
  //     },

  //     {
  //       path: '/result',
  //       name:"result",
  //       component:() => import('@/views/report/Invalid/InvalidPage/Result.vue'),
  //     },
  //     {
  //       path: '/rDetails',
  //       name:"rDetails",
  //       component:() => import('@/views/report/reportDetails/index.vue'),
  //     },
  //     {
  //       path: '/import',
  //       name:"import",
  //       component:() => import('@/views/components/import'),
  //     }
  //   ]
  // },
  {
    path: '/showFile',
    name:"showFile",
    component:() => import('@/views/components/common/showFile.vue'),
  },
  
 
]

const router = new VueRouter({
  mode: 'history',
  base: '/',
  routes
})

router.beforeEach((to, from, next) => {

  if (to.path === '/admin/login'||to.path==='/'){next()} 
  else if(to.meta.allowPath){
    next()
  }
  else{
    const tokenStr = Cookies.get('token')

    switch(tokenStr){
      case undefined:
        next({name:'Login',params:{ redirect:to.fullPath}})
        break
      default:
        next()
        break;
    }
  }
  
  // 增加判断条件
  // if (tokenStr)
  // {
  //   next()
  //   // return next({name:'Login',params:{ redirect:to.fullPath}})
  // }
  // else if(!tokenStr && (to.path !== '/admin/login'||to.path!=='/')){
  //   // next()
  //   // console.log(tokenStr)
  //   next({name:'Login',params:{ redirect:to.fullPath}})
  //   return 0
  // }
  

  // if(Cookies.get('token')){
  //   if (to.meta.title) {
  //     document.title = to.meta.title;
  //   }
  //   next()
  // }else{
  //   next({
  //     name:'Login',
  //     params:{
  //       redirect:to.fullPath
  //     }
  //   })
  // }
  // console.log(to.fullPath)

  
})

router.afterEach((to, from) => {

});

export default router
