import Vue from 'vue'
import VueRouter from 'vue-router'
import Cookies from 'js-cookie'

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: "/",
    component: () => import('@/views/index'),
  },

  {
    path:'/login',
    name:'Login',
    meta: {
      title: '系统登录'
    },
    component: () => import("@/views/login/index.vue")
  },
  {
    path: "",
    component: () => import('@/views/layout/index.vue'),
    children: [
      {
        path: '/home',
        name: 'Home',
        meta: {
          title: '首页',
        },
        component: () => import('@/views/home/index.vue'),
      },
      //专题库
      {
        path: '/workspace',
        name:'Workspace',
        component:{render(c){return c('router-view')}},
        redirect:'/workspace',
        children:[
          {
            path:'/',
            meta: {
              title: '专题库',
            },
            component: () => import('@/views/workspace/index.vue'),
          },
          {
            path: 'folder',
            meta: {
              // keepAlive: true,
              title: '专利文件夹',
              // button: ['a', 'b', 'c', 'd'],
              showProjectName:true
            },
            component: () => import('@/views/workspace/folder/index.vue')
          },
          {
            path: 'folder/:id',
            meta: {
              title: '专利文章',
              // button: [],
              showProjectName:true
            },
            component: () => import('@/views/workspace/folder/articles')
          },
        ],
      },
      // 产品
      {
        path: '/product',
        name:'Product',
        component:{render(c){return c('router-view')}},
        redirect:'/product',
        children:[
          {
            path:'/',
            meta: {
              title: '产品',
            },
            component: () => import('@/views/product/index.vue'),
          },
          {
            path: "/productDetails",
            meta: {
             title: '产品详情',
            },
            component: () => import('@/views/product/components/productDetails'),
          },
          {
            path: "/categoryDetails",
            meta: {
             title: '产品类别详情',
            },
            component: () => import('@/views/product/components/categoryDetails'),
          },
          {
            path: "/mindIndex",
            meta: {
             title: '可视化',
             button: [],
           },
           component: () => import('@/views/product/components/jsMind'),
         },
         {
            path: "/chartIndex",
            meta: {
              title: '趋势图',
              button: [],
            },
            component: () => import('@/views/product/components/echarts'),
          },
          {
            path: "/frameworkIndex",
            meta: {
             title: '产品架构',
             button: [],
           },
           component: () => import('@/views/product/components/framework/index.vue'),
         
         },
          {
            path: "/relatedPatentsIndex",
            meta: {
             title: '产品相关专利',
             button: [],
           },
           component: () => import('@/views/product/components/relatedPatents/index.vue'),
         
         },
        ],
        
      },
      //事件
      {
        path: '/questionEvent',
        name:'QuestionEvent',
        component:{render(c){return c('router-view')}},
        redirect:'/questionEvent',
        children:[
          {
            path:'/',
            meta: {
              title: '事件',
            },
            component: () => import('@/views/questionEvent/index.vue'),
          }
        ],
      },
      //报告
      {
        path: '/AllReport',
        name:'AllReport',
        component:{render(c){return c('router-view')}},
        redirect:'/AllReport',
        children:[
          {
            path:'/',
            meta: {
              title: '报告',
            },
            component: () => import('@/views/report/index.vue'),
          },
          //无效分析、第三方意见、稳定性分析
          {
            path: '/InvalidIndex',
            name:"InvalidIndex",
            meta:{
              aside: true,
              showHeader:true,
            },
            component:() => import('@/views/report/Invalid/index.vue'),
          },
          //FTO风险排查
          {
            path: '/FTOIndex',
            name:"FTOIndex",
            meta:{
              aside: true,
              showHeader:true,
            },
            component:() => import('@/views/report/FTO/index.vue'),
          },
          //侵权分析
          {
            path: '/tortIndex',
            name:"tortIndex",
            meta:{
              aside: true,
              showHeader:true,
            },
            component:() => import('@/views/report/tort/index.vue'),
          },
          //回避设计
          {
            path: '/avoid',
            name:"avoid",
            meta:{
              aside: true,
              showHeader:true,
            },
            component:() => import('@/views/report/avoid/index.vue'),
          },
          //无效分析、第三方意见、稳定性分析报告详情
          {
            path: '/rDetails',
            name:"rDetails",
            meta:{
              aside: true,
              showHeader:true,
            },
            component:() => import('@/views/report/reportDetails/index.vue'),
          },
          //FTO风险排查、侵权分析报告详情
          {
            path: '/FTOrDetails',
            name:"FTOrDetails",
            meta:{
              aside: true,
              showHeader:true,
            },
            component:() => import('@/views/report/FTO/FTOPage/ReportDetails/index.vue'),
          },
          //回避设计报告详情
          {
            path: '/avoidAside',
            name:"avoidAside",
            meta:{
              aside: true,
              showHeader:true,
            },
            component:() => import('@/views/report/avoid/avoidAsid/index.vue'),
          },
          //无效应对报告详情
          {
            path:'/InvalidResponse',
            name:'InvalidResponse',
            meta:{
              title:'无效应对',
              aside:true,
              showHeader:true,
            },
            component:() => import('@/views/report/InvalidResponse/index'),
          },
          //添加无效证据和理由
          {
            path:'/invalidIdexRouter',
            name:'invalidIdexRouter',
            meta:{
              title:'无效证据和理由',
              aside:true,
              showHeader:true,
            },
            component:() => import('@/views/report/InvalidResponse/components/invalidIdexRouter.vue'),
          },
          //导入证据文献
          {
            path:'/evidenceAndRequestIndex',
            name:'evidenceAndRequestIndex',
            meta:{
              title:'证据详情',
              aside:true,
              showHeader:true,
            },
            component:() => import('@/views/report/InvalidResponse/components/evidenceAndRequestRouter.vue'),
          },
          //任务分配
          {
            path: '/SelectedPatent',
            name:"SelectedPatent",
            meta:{
              aside:true
            },
            component:() => import('@/views/report/reportDetails/components/SelectedPatent.vue'),
          },
          //添加对比文件
          {
            path:'/addPatentList',
            name:'/addPatentList',
            meta:{
              title:'添加对比文件',
              aside:true,
              showHeader:true,
              // hiddenHeader:true
            },
            component:() => import('@/views/report/components/addPatentList'),
          },
          //查看单个专利详情
          {
            path:'/patentDetails',
            name:"patentDetails",
            meta:{
              aside:true
            },
            component:() => import('@/views/components/common/PatentDetails')
          },
          //无效应对证据文献详情
          {
            path:'/checkFileDetails/:key',
            name:'checkFileDetails/:key',
            meta:{
              title:'证据文献详情',
              aside:true,
              showHeader:true,
            },
            component:() => import('@/views/report/InvalidResponse/components/FileDetails/index.vue'),
          },
        ],
      },
      //场景可视化
      {
        path: '/visual',
        meta: {
          // keepAlive: true,
          title: '场景可视化',
        },
        component: () => import('@/views/visual')
      },
      {
        path: '/visual/:title',
        meta: {
          // keepAlive: false,
          title: '可视化平台',
        },
        component: () => import('@/views/visual/title/index.vue')
      },
      //图标分析
      {
        path: "/analyse",
        component:{render(c){return c('router-view')}},
        redirect:'/analyse',
        children: [
          {
            path: "custom",
            component: () => import('@/views/analyse/custom'),
            meta: {
              title: '自定义分析列表'
            }
          },
          {
            path: "report",
            component: () => import('@/views/analyse/report/create'),
            meta: {
              title: '一键生成报告'
            }
          },
        ]
      },
      
      {
        path: "custom",
        component: () => import('@/views/analyse/custom'),
        meta: {
          title: '自定义分析列表'
        }
      },
      {
        path: "report",
        component: () => import('@/views/analyse/report/create'),
        meta: {
          title: '一键生成报告'
        }
      },
      //查看文件
      {
        path:'/checkFile',
        name:'/checkFile',
        meta:{
          aside:true,
          hiddenHeader:true
        },
        component:() => import('@/views/workspace/components/menu/component/checkFile.vue'),
      },
      //excel导入
      {
        path: '/import',
        name:"import",
        meta:{
          aside: true,
          showHeader:true,
        },
        // component:() => import('@/views/components/import'),
        component:() => import('@/views/components/import/excelImport'),
      },
      //专利号导入
      {
        path: '/PatentNoImport',
        name:"PatentNoImport",
        meta:{
          aside: true,
          showHeader:true,
        },
        // component:() => import('@/views/components/import'),
        component:() => import('@/views/components/import/PatentNoImport'),
      },
      //检索导入
      {
        path: '/conditionImport',
        name:"conditionImport",
        meta:{
          title: '专利检索',
          aside: true,
          showHeader:true,
        },
        // component:() => import('@/views/components/import'),
        component:() => import('@/views/components/import/conditionImport'),
      },
      //检索结果
      {
        path: "/searchResult",
        meta: {
          title: '检索结果',
          // button: [],
        },
        component: () => import('@/views/components/import/conditionImport/searchResultIndex.vue'),
      },
      //检索专利详情
      {
        path: "/search/patentDetail",
        meta: {
          title: '专利详情',
          // button: [],
        },
        component: () => import('@/views/components/import/conditionImport/patentDetails/patentIndex.vue'),
      },
      //任务清单
      {
        path: "/taskList",
        meta: {
          title: '任务清单',
          button: [],
        },
        component: () => import('@/views/task/taskIndex.vue'),
      },
      //标注库
      {
        path: "/indicia",
        meta: {
          title: '标注库',
          button: [],
        },
        component: () => import('@/views/indicia'),
      },
      //检索组件
      {
        path: "/search",
        meta: {
          title: '检索',
          button: [],
        },
        component: () => import('@/views/components/common/retrieval'),
      },
      //事件可视化
      {
        path: "/eventVisual",
        meta: {
          title: '事件可视化',
          button: [],
        },
        component: () => import('@/views/home/components/visualRouter'),
      },
    ]
  },
]

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

router.beforeEach((to, from, next) => {
   if (to.path === '/login'||to.path==='/'){
    if (to.meta.title) {
      document.title = to.meta.title;
    }
    next()
  } 
  else if(to.meta.allowPath){
    if (to.meta.title) {
      document.title = to.meta.title;
    }
    next()
  }
  else{
    const tokenStr = Cookies.get('token')

    switch(tokenStr){
      case undefined:
        if (to.meta.title) {
          document.title = to.meta.title;
        }
        next({name:'Login',params:{ redirect:to.fullPath}})
        break
      default:
        if (to.meta.title) {
          document.title = to.meta.title;
        }
        next()
        break;
    }
  }
})

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

});

export default router
