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

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in subMenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
  }
**/
/**
 * 静态路由
 */
export const constantRouterMap = [
  {// 重定向
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path*',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  // 登录页面
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  // 404错误页面
  { path: '/404', component: () => import('@/views/errorPage/404'), hidden: true },
  // 401 错误页面
  { path: '/401', component: () => import('@/views/errorPage/401'), hidden: true },
  // 主页
  {
    path: '/',
    component: Layout,
    redirect: 'dashboard',
    name: 'Dashboard',
    // hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      name: 'Dashboard',
      meta: { title: '首页', icon: 'dashboard', noCache: true, affix: true }
    }]
  }
]
// 实例化vue的时候直挂载constantRouter
export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

// 异步挂载路由
// 动态需要根据权限加载的路由表
export const asyncRouterMap = [
  {
    path: 'overview',
    component: Layout,
    redirect: '/overview',
    meta: {
      title: '窨井状态总览',
      icon: 'icon-config', // 图标
      permission: ['/overview']// 权限名称
    },
    children: [
      {
        path: '/overview',
        // component: () => import('@/views/overview/overview'),
        component: () => import('@/views/overview/overview_cmap'),
        name: 'overview',
        meta: { title: '窨井状态总览', icon: 'icon-config', permission: ['/overview'] }
      }
    ]
  },
  {
    path: 'alarmManage',
    component: Layout,
    redirect: '/alarmNow',
    name: 'AlarmManage',
    alwaysShow: true,
    meta: {
      title: '告警管理',
      icon: 'icon-config', // 图标
      permission: ['/alarm']// 权限名称
    },
    children: [
      {
        path: '/alarmNow',
        name: 'AlarmNow',
        component: () => import('@/views/alarmManage/listAlarmNow'),
        meta: { title: '当前告警', icon: 'icon-config', permission: ['/alarm/now'] }
      },
      {
        path: '/alarmRecords',
        name: 'AlarmRecords',
        component: () => import('@/views/alarmManage/listAlarmRecords'),
        meta: { title: '告警记录', icon: 'icon-config', keepAlive: true, permission: ['/alarm/list'] }
      },
      {
        path: '/listJob',
        name: 'ListJob',
        component: () => import('@/views/jobManage/listJobs'),
        meta: { title: '告警工单', icon: 'icon-config', keepAlive: true, permission: ['/job'] }
      },
      {
        path: '/listOvertimeGetJob',
        name: 'ListJobOvertimeGet',
        component: () => import('@/views/jobManage/listJobsOvertimeGet'),
        meta: { title: '超时未接收工单', icon: 'icon-config', keepAlive: true, permission: ['/job/overtimeGetList'] }
      },
      {
        path: '/listOvertimeHandleJob',
        name: 'ListJobOvertimeHandle',
        component: () => import('@/views/jobManage/listJobsOvertimeHandle'),
        meta: { title: '超时未处理工单', icon: 'icon-config', keepAlive: true, permission: ['/job/overtimeHandleList'] }
      },
      {
        path: '/detailJob/:id(\\d+)',
        name: 'DetailJob',
        component: () => import('@/views/jobManage/detailJob'),
        hidden: true,
        meta: { title: '工单详情', icon: 'icon-config', permission: ['/job/info'] }
      },
      {
        path: '/listRule',
        name: 'ListRule',
        component: () => import('@/views/alarmRule/alarmRule'),
        meta: { title: '告警规则', icon: 'icon-config', permission: ['/alarmRule'] }
      }
    ]
  },
  {
    path: 'wellManage',
    component: Layout,
    redirect: '/wellList',
    name: 'WellManage',
    alwaysShow: true,
    meta: {
      title: 'Well',
      icon: 'icon-config', // 图标
      permission: ['/well'], // 权限名称
      keepAlive: true,
      isBack: false
    },
    children: [
      {
        path: '/wellList',
        name: 'WellList',
        component: () => import('@/views/wellManage/listWell'),
        meta: { title: '窨井列表', icon: 'icon-config', keepAlive: true, permission: ['/well/list'] }
      },
      {
        path: '/addWell',
        name: 'AddWell',
        component: () => import('@/views/wellManage/addWell'),
        meta: { title: '新增窨井', icon: 'icon-config', permission: ['/well/add'] }
      }
    ]
  },
  {
    path: 'deviceManage',
    component: Layout,
    redirect: '/concenList',
    name: 'DeviceManage',
    alwaysShow: true,
    meta: {
      title: '设备管理',
      icon: 'icon-config', // 图标
      permission: ['/device']// 权限名称
    },
    children: [
      {
        path: '/concenList',
        name: 'ConcenList',
        component: () => import('@/views/concentrator/listConcentrator'),
        meta: { title: '集中器管理', icon: 'icon-config', permission: ['/concentrator'] }
      },
      {
        path: '/deviceList',
        name: 'DeviceList',
        component: () => import('@/views/deviceManage/listDevice'),
        meta: { title: '设备管理', icon: 'icon-config', permission: ['/device/list'] }
      },
      {
        path: '/deviceConfig',
        name: 'DeviceConfig',
        component: () => import('@/views/deviceConfig/deviceConfig'),
        meta: { title: '设备配置', icon: 'icon-config', permission: ['/device/config'] }
      },
      {
        path: '/nbDevice',
        name: 'NbDevice',
        component: () => import('@/views/nbDevice/listNbDevice'),
        meta: { title: 'NB注册', icon: 'icon-config', permission: ['/nbdevice'] }
      }
    ]
  },
  {
    path: 'data',
    component: Layout,
    redirect: '/dataManage',
    name: 'Data',
    alwaysShow: true,
    meta: {
      title: '数据管理',
      icon: 'icon-config', // 图标
      permission: ['/data']// 权限名称
    },
    children: [
      {
        path: '/dataManage',
        name: 'DataManage',
        component: () => import('@/views/dataManage/dataManage'),
        meta: { title: '历史数据', icon: 'icon-config', permission: ['/datalist'] }
      },
      {
        path: '/dataAnalyse',
        name: 'DataAnalyse',
        component: () => import('@/views/dataStatics/dataStatics'),
        meta: { title: '数据分析', icon: 'icon-config', permission: ['/dataAnalyse'] }
      },
      {
        path: '/deviceStatics',
        name: 'DeviceStatics',
        component: () => import('@/views/deviceStatics/deviceStatics'),
        meta: { title: '设备统计', icon: 'icon-config', permission: ['/deviceStatics'] }
      },
      {
        path: '/alarmStatics',
        name: 'AlarmStatics',
        component: () => import('@/views/alarmStatics/alarmStatics'),
        meta: { title: '报警统计', icon: 'icon-config', permission: ['/alarm/statics'] }
      }
    ]
  },
  {
    path: '/smartAnalysis',
    component: Layout,
    redirect: '/smartDataList',
    name: 'SmartAnalysis',
    alwaysShow: true,
    meta: {
      title: '智能分析',
      icon: 'icon-config', // 图标
      permission: ['/smartAnalysis']// 权限名称
    },
    children: [
      {
        path: '/smartDataList',
        name: 'SmartDataList',
        component: () => import('@/views/smartAnalysis/dataManage'),
        meta: { title: '数据列表', icon: 'icon-config', permission: ['/smartDataList'] }
      },
      {
        path: '/smartDataOverview',
        name: 'SmartDataOverview',
        component: () => import('@/views/smartAnalysis/smartOverview'),
        meta: { title: '可视化', icon: 'icon-config', permission: ['/smartOverview'] }
      }
    ]
  },
  {
    path: 'system',
    component: Layout,
    redirect: '/resource',
    name: 'System',
    alwaysShow: true,
    meta: {
      title: '系统管理',
      icon: 'icon-config', // 图标
      permission: ['/system']// 权限名称
    },
    children: [
      {
        path: '/resource',
        name: 'Resource',
        component: () => import('@/views/system/resource/listResource'),
        meta: { title: '资源管理', icon: 'function', permission: ['/resource'] }
      },
      {
        path: '/dict',
        name: 'Dict',
        component: () => import('@/views/system/dict/listDict'),
        meta: { title: '字典管理', icon: 'function', permission: ['/dict'] }
      },
      {
        path: '/area',
        name: 'Area',
        component: () => import('@/views/system/area/listArea'),
        meta: { title: '区域管理', icon: 'function', permission: ['/area'] }
      },
      {
        path: '/dept',
        name: 'Dept',
        component: () => import('@/views/system/dept/listDept'),
        meta: { title: '组织管理', icon: 'tree', permission: ['/dept'] }
      },
      {
        path: '/role',
        component: () => import('@/views/system/role/listRole'), // Parent router-view
        name: 'Role',
        meta: { title: '角色管理', permission: ['/role'] }
      },
      {
        path: '/user',
        component: () => import('@/views/system/user/listUser'), // Parent router-view
        name: 'User',
        meta: { title: '用户管理', permission: ['/mgr'] }
      },
      {
        path: '/log',
        component: () => import('@/views/system/log/listLog'), // Parent router-view
        name: 'Log',
        meta: { title: '日志管理', permission: ['/log'] }
      },
      {
        path: '/loginLog',
        component: () => import('@/views/system/log/loginLog'), // Parent router-view
        name: 'LoginLog',
        meta: { title: '登录日志', permission: ['/loginLog'] }
      }
    ]
  },
  {
    path: 'systemConfig',
    component: Layout,
    redirect: '/',
    name: 'SystemConfig',
    alwaysShow: true,
    meta: {
      title: '系统配置',
      icon: 'icon-config', // 图标
      permission: ['/sysconfig']// 权限名称
    },
    children: [
      {
        path: '/responsibleUser',
        name: 'ResponsibleUser',
        component: () => import('@/views/systemConfig/responsibleUser/listResponsibleUser'),
        meta: { title: '联系人配置', icon: 'function', permission: ['/responsibleUser'] }
      },
      {
        path: '/alarmLevel',
        name: 'AlarmLevel',
        component: () => import('@/views/systemConfig/alarmLevel/listLevel'),
        meta: { title: '告警等级', icon: 'function', permission: ['/alarmLevel'] }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
