import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import ParentView from '@/components/ParentView'

/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * roles: ['admin', 'common']       // 访问路由的角色权限
 * permissions: ['a:a:a', 'b:b:b']  // 访问路由的菜单权限
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect')
      }
    ]
  },
  {
    path: '/login',
    component: () => import('@/views/login'),
    hidden: true
  },
  {
    path: '/postcheck',
    component: () => import('@/views/postcheck'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error/404'),
    hidden: true
  },
  {
    path: '',
    redirect: 'index',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/home/index'),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/401',
    component: () => import('@/views/error/401'),
    hidden: true
  },
  // {
  //   path: '',
  //   component: Layout,
  //   redirect: 'index',
  //   children: [
  //     {
  //       path: 'index',
  //       component: () => import('@/views/index'),
  //       name: 'Index',
  //       meta: { title: '首页', icon: 'dashboard', affix: true }
  //     }
  //   ]
  // },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: () => import('@/views/system/user/profile/index'),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  },
  // {
  //   path: '/postResponsibility',
  //   component: Layout,
  //   redirect: "noRedirect",
  //   meta: { title: '岗位责任制管理' },
  //   redirect: "noRedirect",
  //   alwaysShow: true,
  //   children: [
  //     {
  //       path: 'postResponsibilityOrganization',
  //       name: 'postResponsibilityOrganization',
  //       component: () => import('@/views/postResponsibility/postResponsibilityOrganization/index.vue'),
  //       meta: { title: '岗位责任制编制'}
  //     },
  //     {
  //       path: 'postResponsibilityOrganizationLook',
  //       name: 'postResponsibilityOrganizationLook',
  //       hidden: true,
  //       component: () => import('@/views/postResponsibility/postResponsibilityOrganization/lookPage.vue'),
  //       meta: { title: '责任清单'}
  //     },
  //     {
  //       path: 'assign',
  //       name: 'assign',
  //       hidden: true ,
  //       component: () => import('@/views/postResponsibility/postResponsibilityOrganization/assign.vue'),
  //       meta: { title: '批量处理'}
  //     },
  //     {
  //       path: 'inventoryReview',
  //       name: 'inventoryReview',
  //       component: () => import('@/views/postResponsibility/inventoryReview/index.vue'),
  //       meta: { title: '责任制清单审核'}
  //     },
  //     {
  //       path: 'inventoryRelease',
  //       name: 'inventoryRelease',
  //       component: () => import('@/views/postResponsibility/inventoryRelease/index.vue'),
  //       meta: { title: '责任制清单查看'}
  //     },
  //   ]
  // },
  // {
  //   path: '/postInspectionPlanning',
  //   component: Layout,
  //   redirect: "noRedirect",
  //   meta: { title: '岗检策划' },
  //   children: [
  //     {
  //       path: 'projectManagement',
  //       name: 'projectManagement',
  //       component: () => import('@/views/postInspectionPlanning/schemeReview/index'),
  //       meta: { title: '岗检方案管理'}
  //     //   children: [
  //     //     {
  //     //       path: 'postStation',
  //     //       component: () => import('@/views/postInspectionPlanning/projectManagement/index'),
  //     //       name: 'postStation',
  //     //       meta: { title: '(岗位)岗检方案'}
  //     //     }
  //     //   ]
  //     // },
  //     // {
  //     //   path: 'schemeReview',
  //     //   name: 'schemeReview',
  //     //   component: ParentView,
  //     //   redirect: "noRedirect",
  //     //   meta: { title: '岗检方案审核'},
  //     //   alwaysShow: true,
  //     //   children: [
  //     //     {
  //     //       path: 'auditDepartment',
  //     //       component: () => import('@/views/postInspectionPlanning/schemeReview/index'),
  //     //       name: 'auditDepartment',
  //     //       meta: { title: '(审核部门)岗检方案'}
  //     //     }
  //     //   ]
  //     },
      // {
      //   path: 'teamManagement',
      //   name: 'teamManagement',
      //   component: ParentView,
      //   redirect: "noRedirect",
      //   meta: { title: '岗检小组管理'},
      //   alwaysShow: true,
      //   children: [
      //     {
      //       path: 'institutionalFramework',
      //       component: () => import('@/views/postInspectionPlanning/teamManagement/index'),
      //       name: 'institutionalFramework',
      //       meta: { title: '组织机构'}
      //     },
      //     {
      //       path: 'teamMembers',
      //       hidden: true,
      //       component: () => import('@/views/postInspectionPlanning/teamManagement/teamMembers.vue'),
      //       name: 'teamMembers',
      //       meta: { title: '小组配置'}
      //     },
      //     {
      //       path: 'personnelAllocation',
      //       component: () => import('@/views/postInspectionPlanning/teamManagement/personnelAllocation.vue'),
      //       name: 'personnelAllocation',
      //       meta: { title: '人员配置'}
      //     },
      //     {
      //       path: 'guideGroup',
      //       component: () => import('@/views/postInspectionPlanning/teamManagement/guideGroup.vue'),
      //       name: 'guideGroup',
      //       hidden: true,
      //       meta: { title: '岗检领导小组配置'}
      //     },
      //     {
      //       path: 'jointOffice',
      //       component: () => import('@/views/postInspectionPlanning/teamManagement/jointOffice.vue'),
      //       name: 'jointOffice',
      //       hidden: true,
      //       meta: { title: '岗检联合办公室'}
      //     },
      //     {
      //       path: 'workingGroup',
      //       component: () => import('@/views/postInspectionPlanning/teamManagement/workingGroup.vue'),
      //       name: 'workingGroup',
      //       hidden: true,
      //       meta: { title: '综合岗检工作组'}
      //     }
      //   ]
      // },
  //     {
  //       path: 'planManagement',
  //       name: 'planManagement',
  //       component: ParentView,
  //       redirect: "noRedirect",
  //       meta: { title: '岗检计划管理'},
  //       alwaysShow: true,
  //       children: [
  //         {
  //           path: 'jobPlan',
  //           component: () => import('@/views/postInspectionPlanning/planManagement/jobPlan.vue'),
  //           name: 'jobPlan',
  //           meta: { title: '岗检计划创建'}
  //         },
  //         {
  //           path: 'jobPlanAudit',
  //           component: () => import('@/views/postInspectionPlanning/planManagement/jobPlanAudit.vue'),
  //           name: 'jobPlanAudit',
  //           meta: { title: '岗检计划审核'}
  //         },
  //         {
  //           path: 'jobPlanLook',
  //           component: () => import('@/views/postInspectionPlanning/planManagement/jobPlanLook.vue'),
  //           name: 'jobPlanLook',
  //           meta: { title: '岗检计划查看'}
  //         }
  //       ]
  //     },
  //     {
  //       path: 'tableManagement',
  //       name: 'tableManagement',
  //       component: ParentView,
  //       redirect: "noRedirect",
  //       alwaysShow: true,
  //       meta: { title: '岗检表管理'},
  //       children: [
  //         {
  //           path: 'addTableManagement',
  //           component: () => import('@/views/postInspectionPlanning/tableManagement/index.vue'),
  //           name: 'addTableManagement',
  //           meta: { title: '岗检表创建'}
  //         },
  //         {
  //           path: 'tableManagementAudit',
  //           component: () => import('@/views/postInspectionPlanning/tableManagement/tableManagementAudit.vue'),
  //           name: 'tableManagementAudit',
  //           meta: { title: '岗检表审核'}
  //         },
  //         {
  //           path: 'tableManagementLook',
  //           component: () => import('@/views/postInspectionPlanning/tableManagement/tableManagementLook.vue'),
  //           name: 'tableManagementLook',
  //           meta: { title: '岗检表查看'}
  //         }
  //       ]
  //     }
  //   ]
  // },
  // {
  //   path: '/postImplementation',
  //   component: Layout,
  //   redirect: "noRedirect",
  //   meta: { title: '岗检实施' },
  //   alwaysShow: true,
  //   children: [
  //     {
  //       path: 'recordUpload',
  //       name: 'recordUpload',
  //       component: () => import('@/views/postImplementation/recordUpload.vue'),
  //       meta: { title: '岗检记录上传'}
  //     },
  //     {
  //       path: 'problemEntry',
  //       name: 'problemEntry',
  //       component: () => import('@/views/postImplementation/problemEntry.vue'),
  //       meta: { title: '岗检问题录入'}
  //     },
  //     {
  //       path: 'rectificationProblem',
  //       name: 'rectificationProblem',
  //       component: ParentView,
  //       redirect: "noRedirect",
  //       meta: { title: '岗检问题整改'},
  //       alwaysShow: true,
  //       children: [
  //         {
  //           path: 'remediationAction',
  //           component: () => import('@/views/postImplementation/rectificationProblem/remediationAction/index.vue'),
  //           name: 'remediationAction',
  //           meta: { title: '整改实施'}
  //         },
  //         {
  //           path: 'rectificationVerification',
  //           component: () => import('@/views/postImplementation/rectificationProblem/rectificationVerification/index.vue'),
  //           name: 'rectificationVerification',
  //           meta: { title: '整改验证'}
  //         }
  //       ]
  //     },
  //     {
  //       path: 'reportManagement',
  //       name: 'reportManagement',
  //       component: () => import('@/views/postImplementation/reportManagement/index.vue'),
  //       meta: { title: '岗检报告管理'}
  //     },
  //     {
  //       path: 'reportReview',
  //       name: 'reportReview',
  //       component: () => import('@/views/postImplementation/reportReview.vue'),
  //       meta: { title: '岗检报告审核'}
  //     }
  //   ]
  // },
  // {
  //   path: '/examineCompetition',
  //   component: Layout,
  //   meta: { title: '考核评比' },
  //   redirect: "noRedirect",
  //   alwaysShow: true,
  //   children: [
  //     {
  //       path: 'examineRanking',
  //       name: 'examineRanking',
  //       component: () => import('@/views/examineCompetition/examineRanking/index.vue'),
  //       meta: { title: '考核排名'}
  //     },
  //     {
  //       path: 'ruleManagement',
  //       name: 'ruleManagement',
  //       component: ParentView,
  //       redirect: "noRedirect",
  //       meta: { title: '考核评比规则管理'},
  //       alwaysShow: true,
  //       children: [
  //         {
  //           path: 'assessment',
  //           component: () => import('@/views/examineCompetition/assessment/index.vue'),
  //           name: 'assessment',
  //           meta: { title: '互评'}
  //         },
  //         {
  //           path: 'assessmentEditOrLook',
  //           component: () => import('@/views/examineCompetition/assessment/isEditDialog.vue'),
  //           name: 'assessmentEditOrLook',
  //           meta: { title: '职能互评表'},
  //           hidden: true,
  //         },
  //         {
  //           path: 'produceScore',
  //           component: () => import('@/views/examineCompetition/assessment/produceScore.vue'),
  //           name: 'produceScore',
  //           meta: { title: '生产部门日常得分'},
  //           hidden: true,
  //         },
  //         {
  //           path: 'assessmentRules',
  //           component: () => import('@/views/examineCompetition/assessmentRules/index.vue'),
  //           name: 'assessmentRules',
  //           meta: { title: '考核规则'}
  //         },
          // {
          //   path: 'functionalDepartment',
          //   component: () => import('@/views/examineCompetition/ruleManagement/functionalDepartment.vue'),
          //   name: 'functionalDepartment',
          //   meta: { title: '职能部门互评表'}
          // },
          // {
          //   path: 'productionDepartment',
          //   component: () => import('@/views/examineCompetition/ruleManagement/productionDepartment.vue'),
          //   name: 'productionDepartment',
          //   meta: { title: '生产部门日常得分'}
          // }
  //       ]
  //     },
  //     {
  //       path: 'ruleReview',
  //       name: 'ruleReview',
  //       component: () => import('@/views/examineCompetition/ruleReview/index.vue'),
  //       meta: { title: '考核规则审核'}
  //     },
  //   ]
  // },
  // {
  //   path: '/statisticAnalysis',
  //   component: Layout,
  //   redirect: "noRedirect",
  //   meta: { title: '统计分析' },
  //   alwaysShow: true,
  //   children: [
  //     {
  //       path: 'checkStatistics',
  //       name: 'checkStatistics',
  //       component: ParentView,
  //       meta: { title: '检查统计'},
  //       redirect: "noRedirect",
  //       alwaysShow: true,
  //       children: [
  //         {
  //           path: 'problemStatistics',
  //           component: () => import('@/views/statisticAnalysis/checkStatistics/index.vue'),
  //           name: 'problemStatistics',
  //           meta: { title: '问题统计'}
  //         },
  //         {
  //           path: 'lookDialogPage',
  //           hidden: true,
  //           component: () => import('@/views/statisticAnalysis/lookDialogPage.vue'),
  //           name: 'lookDialogPage',
  //           meta: { title: '统计-查看'}
  //         },
  //       ]
  //     },
  //     {
  //       path: 'problemStatistics',
  //       name: 'problemStatistics',
  //       component: ParentView,
  //       meta: { title: '整改统计'},
  //       redirect: "noRedirect",
  //       alwaysShow: true,
  //       children: [
  //         {
  //           path: 'rectificationStatistics',
  //           component: () => import('@/views/statisticAnalysis/problemStatistics/index.vue'),
  //           name: 'rectificationStatistics',
  //           meta: { title: '整改统计'}
  //         }
  //       ]
  //     },
  //   ]
  // },
  // {
  //   path: '/jobinspectionHistory',
  //   component: Layout,
  //   meta: { title: '岗检历史' },
  //   redirect: "noRedirect",
  //   alwaysShow: true,
  //   children: [
  //     {
  //       path: 'jobinspectionHistory',
  //       name: 'jobinspectionHistory',
  //       component: () => import('@/views/jobinspectionHistory/jobinspectionHistory/jobinspectionHistory.vue'),
  //       meta: { title: '岗检历史'}
  //     },
  //     {
  //       path: 'jobinspectionHistoryLook',
  //       name: 'jobinspectionHistoryLook',
  //       hidden: true,
  //       component: () => import('@/views/jobinspectionHistory/jobinspectionHistory/jobinspectionHistoryLook.vue'),
  //       meta: { title: '岗检历史-查看'}
  //     },
  //     {
  //       path: 'jobinspectionProblem',
  //       name: 'jobinspectionProblem',
  //       component: () => import('@/views/jobinspectionHistory/jobinspectionProblem/index.vue'),
  //       meta: { title: '岗检问题库'}
  //     },
  //     {
  //       path: 'jobinspectionHighlights',
  //       name: 'jobinspectionHighlights',
  //       component: () => import('@/views/jobinspectionHistory/jobinspectionHighlights/index.vue'),
  //       meta: { title: '岗检亮点'}
  //     },
  //   ]
  // },
]

// 动态路由，基于用户权限动态去加载
export const dynamicRoutes = [
  {
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:user:edit'],
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: () => import('@/views/system/user/authRole'),
        name: 'AuthRole',
        meta: { title: '分配角色', activeMenu: '/system/user' }
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    permissions: ['system:role:edit'],
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: () => import('@/views/system/role/authUser'),
        name: 'AuthUser',
        meta: { title: '分配用户', activeMenu: '/system/role' }
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    permissions: ['system:dict:list'],
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: () => import('@/views/system/dict/data'),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict' }
      }
    ]
  },
  {
    path: '/monitor/job-log',
    component: Layout,
    hidden: true,
    permissions: ['monitor:job:list'],
    children: [
      {
        path: 'index/:jobId(\\d+)',
        component: () => import('@/views/monitor/job/log'),
        name: 'JobLog',
        meta: { title: '调度日志', activeMenu: '/monitor/job' }
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    permissions: ['tool:gen:edit'],
    children: [
      {
        path: 'index/:tableId(\\d+)',
        component: () => import('@/views/tool/gen/editTable'),
        name: 'GenEdit',
        meta: { title: '修改生成配置', activeMenu: '/tool/gen' }
      }
    ]
  }
]

// 防止连续点击多次路由报错
let routerPush = Router.prototype.push;
let routerReplace = Router.prototype.replace;
// push
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(err => err)
}
// replace
Router.prototype.replace = function push(location) {
  return routerReplace.call(this, location).catch(err => err)
}

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
