import Vue from 'vue'
import Router from 'vue-router'
import store from '../store/index'
import request from '@/request'
import { Notification, MessageBox, Message } from 'element-ui'
import tools from '../common/tools'
Vue.use(Router)

let bankAdmin = ['/person-center/bank-record','/person-center/my-bank/index','/person-center/free-bank/index','/person-center/my-collect','/person-center/my-wrong','/person-center/my-bank/bank-detail/','/person-center/my-bank/bank-statistics/','/person-center/my-bank/bank-explain-detail/','/person-center/free-bank/bank-detail/','/person-center/free-bank/bank-statistics/','/person-center/free-bank/bank-explain-detail/','/bank-exam-continue/','/bank-exam/','/subject/collect-bank/','/bank-exam-explain/','/bank-report/'];
let canToBank = null;
let courseAdmin = ['/my-course-detail/','/course-exam/']
let canToCourse = null;

const router =  new Router({
  mode:'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: [
    {
      path: '*',
      redirect: '/home',
      component: resolve => require(['@/pages/home/index'],resolve)
    },
    {
      path: '/refresh',
      name: '刷新页',
      component: resolve => require(['@/pages/refresh'],resolve),
    },
    {
      path: '/home',
      name: '首页',
      component: resolve => require(['@/pages/home/index'],resolve),
      meta: {
        title: '祥粤云学堂-建造师造价师在线教育培训平台报名报考',
        content: {
          keywords: '祥粤云学堂-一级建造师,二级建造师,造价工程师,一级消防工程师,BIM,在线教育,职业教育,报考条件,报名时间,建造师注册,建造工程师',
          description: '祥粤云学堂-职业教育一站式学习平台，专注一建，二建，造价工程师，一级消防工程师，BIM等工程师技能知识培训服务热线：020-87085982'
        }
      }
    },
    {
      path: '/login',
      name: '登录',
      component: resolve => require(['@/pages/login/index'],resolve),
      meta: {
        title: '祥粤云学堂-建造师造价师在线教育培训平台报名报考',
        content: {
          keywords: '祥粤云学堂-一级建造师,二级建造师,造价工程师,一级消防工程师,BIM,在线教育,职业教育,报考条件,报名时间,建造师注册,建造工程师',
          description: '祥粤云学堂-职业教育一站式学习平台，专注一建，二建，造价工程师，一级消防工程师，BIM等工程师技能知识培训服务热线：020-87085982'
        }
      }
    },
    {
      path: '/about',
      name: '走进祥粤',
      component: resolve => require(['@/pages/about/index'],resolve),
      meta: {
        title: '祥粤云学堂-建造师造价师在线教育培训报名报考平台',
        content: {
          keywords: '祥粤云学堂-建造师造价师在线教育培训平台报名报考',
          description: '祥粤云学堂-建造师造价师在线教育培训平台报名报考'
        }
      }
    },
    {
      path: '/cart',
      name: '购物车',
      component: resolve => require(['@/pages/cart/index'],resolve),
    },
    {
      path: '/payment',
      name: '支付',
      component: resolve => require(['@/pages/payment/index'],resolve),
      meta: {
        title: '祥粤云学堂-建造师造价师在线教育培训平台报名报考',
        content: {
          keywords: '祥粤云学堂-一级建造师,二级建造师,造价工程师,一级消防工程师,BIM,在线教育,职业教育,报考条件,报名时间,建造师注册,建造工程师',
          description: '祥粤云学堂-职业教育一站式学习平台，专注一建，二建，造价工程师，一级消防工程师，BIM等工程师技能知识培训服务热线：020-87085982'
        }
      }
    },
    {
      path: '/payment-success',
      name: '支付成功',
      component: resolve => require(['@/pages/payment-success/index'],resolve),
      meta: {
        title: '祥粤云学堂-建造师造价师在线教育培训平台报名报考',
        content: {
          keywords: '祥粤云学堂-一级建造师,二级建造师,造价工程师,一级消防工程师,BIM,在线教育,职业教育,报考条件,报名时间,建造师注册,建造工程师',
          description: '祥粤云学堂-职业教育一站式学习平台，专注一建，二建，造价工程师，一级消防工程师，BIM等工程师技能知识培训服务热线：020-87085982'
        }
      }
    },
    {
      path: '/course-list',
      name: '课程列表',
      component: resolve => require(['@/pages/course-list/index'],resolve),
      meta: {
        title: '祥粤云学堂-一二级建造师、工程师、建筑师视频课程、免费直播课',
        content: {
          keywords: '祥粤云学堂-一级建造师视频课件,二级建造师视频课件,建筑师工程师学习视频课程',
          description: '祥粤云学堂-提供一二级建造师视频学习、免费直播公开课  ，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料。'
        }
      }
    },
    {
      path: '/bank-list',
      name: '题库列表',
      component: resolve => require(['@/pages/bank-list/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    
    {
      path: '/live-list',
      name: '直播列表',
      component: resolve => require(['@/pages/live-list/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/course-detail/:goodsId',
      name: '课程详情',
      component: resolve => require(['@/pages/goods-detail/course-detail'],resolve),
      meta: {
        title: '祥粤云学堂-一二级建造师、工程师、建筑师视频课程、免费直播课',
        content: {
          keywords: '祥粤云学堂-一级建造师视频课件,二级建造师视频课件,建筑师工程师学习视频课程',
          description: '祥粤云学堂-提供一二级建造师视频学习、免费直播公开课  ，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料。'
        }
      }
    },
    {
      path: '/bank-detail/:goodsId',
      name: '题库详情',
      component: resolve => require(['@/pages/goods-detail/bank-detail'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/live-detail/:goodsId',
      name: '直播详情',
      component: resolve => require(['@/pages/goods-detail/live-detail'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/my-course-detail/:goodsId',
      name: '课程详情',
      component: resolve => require(['@/pages/course-detail/index'],resolve),
      meta: {
        title: '祥粤云学堂-一二级建造师、工程师、建筑师视频课程、免费直播课',
        content: {
          keywords: '祥粤云学堂-一级建造师视频课件,二级建造师视频课件,建筑师工程师学习视频课程',
          description: '祥粤云学堂-提供一二级建造师视频学习、免费直播公开课  ，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料。'
        }
      }
    },
    
    {
      path: '/my-live-detail/:goodsId',
      name: '直播详情',
      component: resolve => require(['@/pages/live-detail/index'],resolve),
      meta: {
        title: '祥粤云学堂-一二级建造师、工程师、建筑师视频课程、免费直播课',
        content: {
          keywords: '祥粤云学堂-一级建造师视频课件,二级建造师视频课件,建筑师工程师学习视频课程',
          description: '祥粤云学堂-提供一二级建造师视频学习、免费直播公开课  ，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料。'
        }
      }
    },
    {
      path: '/living-room/:channelId',
      name: '课程详情',
      component: resolve => require(['@/pages/living-room/index'],resolve),
      meta: {
        title: '祥粤云学堂-一二级建造师、工程师、建筑师视频课程、免费直播课',
        content: {
          keywords: '祥粤云学堂-一级建造师视频课件,二级建造师视频课件,建筑师工程师学习视频课程',
          description: '祥粤云学堂-提供一二级建造师视频学习、免费直播公开课  ，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料。'
        }
      }
    },
    
    {
      path: '/mock-countdown',
      name: '课程详情',
      component: resolve => require(['@/pages/mock-countdown/index'],resolve),
      meta: {
        title: '祥粤云学堂-一二级建造师、工程师、建筑师视频课程、免费直播课',
        content: {
          keywords: '祥粤云学堂-一级建造师视频课件,二级建造师视频课件,建筑师工程师学习视频课程',
          description: '祥粤云学堂-提供一二级建造师视频学习、免费直播公开课  ，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料。'
        }
      }
    },
    
    {
      path: '/mock-report',
      name: '课程详情',
      component: resolve => require(['@/pages/mock-report/index'],resolve),
      meta: {
        title: '祥粤云学堂-一二级建造师、工程师、建筑师视频课程、免费直播课',
        content: {
          keywords: '祥粤云学堂-一级建造师视频课件,二级建造师视频课件,建筑师工程师学习视频课程',
          description: '祥粤云学堂-提供一二级建造师视频学习、免费直播公开课  ，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料。'
        }
      }
    },
    {
      path: '/course-report',
      name: '试卷报告',
      component: resolve => require(['@/pages/course-report/index'],resolve),
      meta: {
        title: '祥粤云学堂-建造师造价师在线教育培训平台报名报考',
        content: {
          keywords: '祥粤云学堂-一级建造师,二级建造师,造价工程师,一级消防工程师,BIM,在线教育,职业教育,报考条件,报名时间,建造师注册,建造工程师',
          description: '祥粤云学堂-职业教育一站式学习平台，专注一建，二建，造价工程师，一级消防工程师，BIM等工程师技能知识培训服务热线：020-87085982'
        }
      }
    },
    
    {
      path: '/bank-report/:goodsId',
      name: '试卷报告',
      component: resolve => require(['@/pages/bank-report/index'],resolve),
      meta: {
        title: '祥粤云学堂-建造师造价师在线教育培训平台报名报考',
        content: {
          keywords: '祥粤云学堂-一级建造师,二级建造师,造价工程师,一级消防工程师,BIM,在线教育,职业教育,报考条件,报名时间,建造师注册,建造工程师',
          description: '祥粤云学堂-职业教育一站式学习平台，专注一建，二建，造价工程师，一级消防工程师，BIM等工程师技能知识培训服务热线：020-87085982'
        }
      }
    },
    {
      path: '/course-exam/:goodsId',
      name: '做题',
      component: resolve => require(['@/pages/course-exam/index'],resolve),
      meta: {
        title: '祥粤云学堂-一二级建造师、工程师、建筑师视频课程、免费直播课',
        content: {
          keywords: '祥粤云学堂-一级建造师视频课件,二级建造师视频课件,建筑师工程师学习视频课程',
          description: '祥粤云学堂-提供一二级建造师视频学习、免费直播公开课  ，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料。'
        }
      }
    },
    {
      path: '/bank-exam/:goodsId',
      name: '做题',
      component: resolve => require(['@/pages/bank-exam/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/mock-exam',
      name: '模考',
      component: resolve => require(['@/pages/mock-exam/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    
    {
      path: '/bank-exam-continue/:goodsId',
      name: '继续做题',
      component: resolve => require(['@/pages/bank-exam-continue/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/bank-exam-all-explain/:recordId',
      name: '全部解析',
      component: resolve => require(['@/pages/bank-exam-all-explain/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/bank-exam-wrong-explain/:recordId',
      name: '错题解析',
      component: resolve => require(['@/pages/bank-exam-wrong-explain/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/mock-exam-all-explain/:recordId',
      name: '全部解析',
      component: resolve => require(['@/pages/mock-exam-all-explain/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/mock-exam-wrong-explain/:recordId',
      name: '错题解析',
      component: resolve => require(['@/pages/mock-exam-wrong-explain/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/bank-exam-explain/:goodsId',
      name: '题目解析',
      component: resolve => require(['@/pages/bank-exam-explain/index'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    
    {
      path: '/subject/wrong-type-bank/:type',
      name: '错题',
      component: resolve => require(['@/pages/subject/wrong-type-bank'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/subject/wrong-bank/:examId',
      name: '错题',
      component: resolve => require(['@/pages/subject/wrong-bank'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/subject/collect-type-bank/:type',
      name: '收藏',
      component: resolve => require(['@/pages/subject/collect-type-bank'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/subject/collect-bank/:examId',
      name: '收藏',
      component: resolve => require(['@/pages/subject/collect-bank'],resolve),
      meta: {
        title: '祥粤云学堂-题库-一建二建试题下载_考试科目题库_考题答案_历年试题_在线真题_水平测试_历年真题_在线题库',
        content: {
          keywords: '祥粤云学堂-模拟试题练习,试题答案,一级建造师试题查找,二级建造师试题练习,题目类型,考试书籍,考试图书,考试教材',
          description: '祥粤云学堂-提供一二级建造师学习资料、教材教辅，一二级建造师考试专业培训辅导课程，免费试听，建造师内部习题资料、工程师教学辅导视频、建筑考试课件视频等资料'
        }
      }
    },
    {
      path: '/person-center',
      name: '个人中心',
      component: resolve => require(['@/pages/person-center/index'],resolve),
      beforeEnter:(to,from,next) => {
        let token = window.localStorage.getItem('token');

        if(token == null || token == '' || token === undefined){

          next('/login')

        }else{

          next();

        }
      },
      children:[
        {
          path: '/',
          // redirect: 'my-course',
        },
        {
          path: 'my-course',
          component: resolve => require(['@/pages/person-center/my-course/index'],resolve),
          name: '我的课程'
        },
        {
          path: 'my-live',
          component: resolve => require(['@/pages/person-center/my-live/index'],resolve),
          name: '我的直播课'
        },
        {
          path: 'play-record',
          component: resolve => require(['@/pages/person-center/play-record/index'],resolve),
          name: '播放记录'
        },
        {
          path: 'my-bank',
          component: resolve => require(['@/pages/person-center/my-bank/index'],resolve),
          name:'自购题卷',
          children:[
            {
              path: '/',
              redirect: 'index',
            },
            {
              path: 'index',
              component: resolve => require(['@/pages/person-center/my-bank/index/index'],resolve),
              name: '自购题卷',
            },
            {
              path: 'bank-detail/:goodsId',
              component: resolve => require(['@/pages/person-center/my-bank/bank-detail/index'],resolve),
              name: '题库详情'
            },
            {
              path: 'bank-statistics/:goodsId',
              component: resolve => require(['@/pages/person-center/my-bank/bank-statistics/index'],resolve),
              name: '做题统计'
            },
            {
              path: 'bank-explain-detail/:goodsId',
              component: resolve => require(['@/pages/person-center/my-bank/bank-explain-detail/index'],resolve),
              name: '详情'
            },
          ]
        },
        {
          path: 'free-bank',
          component: resolve => require(['@/pages/person-center/free-bank/index'],resolve),
          name:'赠送题卷',
          children:[
            {
              path: '/',
              redirect: 'index',
            },
            {
              path: 'index',
              component: resolve => require(['@/pages/person-center/free-bank/index/index'],resolve),
              name: '赠送题卷',
            },
            {
              path: 'bank-detail/:goodsId',
              component: resolve => require(['@/pages/person-center/free-bank/bank-detail/index'],resolve),
              name: '题库详情'
            },
            {
              path: 'bank-statistics/:goodsId',
              component: resolve => require(['@/pages/person-center/free-bank/bank-statistics/index'],resolve),
              name: '做题统计'
            },
            {
              path: 'bank-explain-detail/:goodsId',
              component: resolve => require(['@/pages/person-center/free-bank/bank-explain-detail/index'],resolve),
              name: '详情'
            },
          ]
        },
        {
          path: 'bank-record',
          component: resolve => require(['@/pages/person-center/bank-record/index'],resolve),
          name: '做题记录'
        },
        {
          path: 'mock-record',
          component: resolve => require(['@/pages/person-center/mock-record/index'],resolve),
          name: '模考记录'
        },
        {
          path: 'my-collect',
          component: resolve => require(['@/pages/person-center/my-collect/index'],resolve),
          name: '收藏集'
        },
        
        {
          path: 'my-wrong',
          component: resolve => require(['@/pages/person-center/my-wrong/index'],resolve),
          name: '错题集'
        },
        
        {
          path: 'record-list/:goodsId',
          component: resolve => require(['@/pages/person-center/bank-record/record-list/index'],resolve),
          name: '更多记录'
        },
        {
          path: 'mock-record-list/:goodsId',
          component: resolve => require(['@/pages/person-center/mock-record/record-list/index'],resolve),
          name: '更多模考记录'
        },
        {
          path: 'my-order',
          component: resolve => require(['@/pages/person-center/my-order/index'],resolve),
          name: '我的订单'
        },
        {
          path: 'my-examination',
          component: resolve => require(['@/pages/person-center/my-examination/index'],resolve),
          name: '我的考试'
        },
        {
          path: 'my-mock',
          component: resolve => require(['@/pages/person-center/my-mock/index'],resolve),
          name: '我的模考'
        },
        {
          path: 'my-message',
          component: resolve => require(['@/pages/person-center/my-message/index'],resolve),
          name: '我的消息'
        },
        {
          path: 'my-info',
          component: resolve => require(['@/pages/person-center/my-info/index'],resolve),
          name: '我的资料'
        },
        {
          path: 'my-invoice',
          name: '我的发票',
          component: resolve => require(['@/pages/person-center/my-invoice/index'],resolve),
          children:[
            
            {
              path: '/',
              redirect: 'index',
            },
            {
              path: 'index',
              component: resolve => require(['@/pages/person-center/my-invoice/index/index'],resolve),
              name: '我的发票',
            },
            {
              path: 'add',
              component: resolve => require(['@/pages/person-center/my-invoice/add/index'],resolve),
              name: '申请发票',
            },
          ]
        },
        {
          path: 'my-classhour',
          component: resolve => require(['@/pages/person-center/my-classhour/index'],resolve),
          name: '我的学时',
          children:[
            {
              path: '/',
              redirect: 'index',
            },
            {
              path: 'index',
              component: resolve => require(['@/pages/person-center/my-classhour/index/index'],resolve),
              name: '我的学时',
            },
            {
              path: 'appointment',
              component: resolve => require(['@/pages/person-center/my-classhour/appointment/index'],resolve),
              name: '预约考试',
            },
            {
              path: 'appointment-add',
              component: resolve => require(['@/pages/person-center/my-classhour/appointment-add/index'],resolve),
              name: '预约考试',
            },
            {
              path: 'appointment-add-kp',
              component: resolve => require(['@/pages/person-center/my-classhour/appointment-add-kp/index'],resolve),
              name: '预约考试',
            }
          ]
        },
      ]
    }
  ]
})

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

router.beforeEach((to,from,next) => {
  console.log(to,'to')
  console.log(from,'from')
  if (to.meta.content) {
		let head = document.getElementsByTagName('head');
		let meta = document.createElement('meta');
		document.querySelector('meta[name="keywords"]').setAttribute('content', to.meta.content.keywords)
		document.querySelector('meta[name="description"]').setAttribute('content', to.meta.content.description)
		meta.content = to.meta.content;
		head[0].appendChild(meta)
	}
	if (to.meta.title) {
		document.title = to.meta.title;
	}
  if(to.path === '/login'){

    next();

  }else{

    let token = window.localStorage.getItem('token');

    //进入页面有token获取用户信息
    if(token){
      store.token = token;
      if(!store.state.userInfo) {
        //获取用户信息
        store.dispatch('getUserInfo')
        store.dispatch('getbusinessList')
      }

      // //题库页面要检测是否需要锁定
      let isBankLock = bankAdmin.some(item => {
        return to.path.indexOf(item) != -1
      })
      console.log(isBankLock,'isBankLock')
      if(isBankLock) {
        
        //没有执行定时器，开启锁定
        if(!canToBank) {
          request
            .lockLockStatus({
              action: "bank",
              uuid:tools.getUuid()
            })
            .then((res) => {
              //有其他端在操作，不能学习
              Message({
                type: "warning",
                message: res.msg,
              });
              
              if(from.path=='/') {
                next('/')
              }

            }).catch(err => {
              //可以学习，开启锁定
                canToBank = 1;
              request.lockLockAction({
                action:'bank',
                uuid:tools.getUuid()
              }).then(res => {
              })
              canToBank = setInterval(() => {
                request.lockLockAction({
                  action:'bank',
                  uuid:tools.getUuid()
                }).then(res => {
                  
                })
              }, 10000);
              next()
            })

            return;
        } else {
          //正在执行定时器，可以直接进入
          next()
        }
        
        return;
      } else {
        //从题库页面离开删除锁定

        let isLeaveBank = bankAdmin.some(item => {
          return from.path.indexOf(item) != -1
        })

        if(isLeaveBank) {
          
          clearInterval(canToBank)
          canToBank = null;
          request.lockDelLock({
            action:'bank',
            uuid:tools.getUuid()
          }).then(res => {
            
          })
        }
      }
      
      let isCourseLock = courseAdmin.some(item => {
        return to.path.indexOf(item) != -1
      })

      console.log(isCourseLock,'isCourseLock')
      if(isCourseLock) {
        
        //没有执行定时器，开启锁定
        if(!canToCourse) {
          
          request.goodsDetail(to.params.goodsId).then(res => {
            //继续教育锁定
            // if(res.data.educationName == '继续教育') {
              request
                .lockLockStatus({
                  action: "jxjy",
                  uuid:tools.getUuid()
                })
                .then((res) => {
                  //有其他端在操作，不能学习
                  Message({
                    type: "warning",
                    message: res.msg,
                  });
                  
                  if(from.path=='/') {
                    next('/')
                  }

                }).catch(err => {
                  //可以学习，开启锁定
                  canToCourse = 1;
                  request.lockLockAction({
                    action:'jxjy',
                    uuid:tools.getUuid()
                  }).then(res => {
                  })
                  canToCourse = setInterval(() => {
                    request.lockLockAction({
                      action:'jxjy',
                      uuid:tools.getUuid()
                    }).then(res => {
                      
                    })
                  }, 10000);
                  next()
                })
            // } else {
            //   next()
            // }
          })
          

            return;
        } else {
          //正在执行定时器，可以直接进入
          next()
        }
        
        return;
      } else {
        //非题库页面删除锁定
        let isLeaveCouese = courseAdmin.some(item => {
          return from.path.indexOf(item) != -1
        })

        if(isLeaveCouese) {
          
          clearInterval(canToCourse)
          canToCourse = null;
          request.lockDelLock({
            action:'jxjy',
            uuid:tools.getUuid()
          }).then(res => {
            
          })
        }
      }
      
      next()
    } else {
      
      next()
    }

  }
})

export default router;