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

Vue.use(Router)

import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    meta: { title: "登录" },
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'homePage' }
    }]
  },
  {
    path: '/alarm',
    component: Layout,
    redirect: '/dashboard',
    name: 'alarm',
    meta: { title: '告警管理', icon: 'alarm' },
    children: [
      {
        path: 'cableTime',
        name: 'cableTime',
        component: () => import('@/views/alarm/cableTime/index'),
        meta: { title: '漏缆监测告警' }
      },
      // {
      //   path: 'device',
      //   name: 'device',
      //   component: () => import('@/views/alarm/device/index'),
      //   meta: { title: '设备连接告警' }
      // },
      {
        path: 'statistics',
        name: 'statistics',
        component: () => import('@/views/alarm/statistics/index'),
        meta: { title: '告警信息统计' }
      }
    ]
  },
  {
    path: '/setting',
    component: Layout,
    redirect: '/setting/add',
    name: 'Setting',
    meta: { title: '配置管理', icon: 'setting' },
    children: [
      {
        path: 'add',
        name: 'settingAdd',
        component: () => import('@/views/setting/add/index'),
        meta: { title: '手动添加配置' }
      },
      {
        path: 'auto',
        name: 'settingAuto',
        component: () => import('@/views/setting/auto/index'),
        meta: { title: '自动添加配置' }
      },
      {
        path: 'statistics',
        name: 'settingAtatistics',

        component: () => import('@/views/setting/statistics/index'),
        meta: { title: '配置信息统计' },
        children: [

        ]
      },
      {
        path: 'parameter',
        name: 'parameter',
        component: () => import('@/views/setting/parameter/index'),
        meta: { title: '参数查询' }
      },
      {
        path: "/detail/",
        name: "detail",
        beforeEnter: (to, from, next) => {
          if (to.query.type == 1) {
            to.meta.title = '铁路线详情'
          }
          else if (to.query.type == 2) {
            to.meta.title = '站点详情'
          }
          else if (to.query.type == 3) {
            to.meta.title = 'FSU详情'
          }
          else if (to.query.type == 4) {
            to.meta.title = '监测设备详情'
          }
          else if (to.query.type == 5) {
            to.meta.title = '漏缆详情'
          }
          else if (to.query.type == 6) {
            to.meta.title = '天馈线详情'
          } else {
            to.meta.title = '详情'
          }
          next()
        },
        component: () => import('@/views/setting/statistics/detail'),
        hidden: true,
      },
    ]
  },
  {
    path: '/monitor',
    component: Layout,
    redirect: '/dashboard',
    name: '监测实时状态',
    meta: { title: '监测实时状态', icon: 'system' },
    children: [
      {
        path: 'leakageCable',
        name: '漏缆实时状态',
        component: () => import('@/views/monitor/leakageCable/index'),
        meta: { title: '漏缆实时状态' }
      },
      // {
      //   path: 'equipment',
      //   name: '设备实时状态',
      //   component: () => import('@/views/monitor/equipment/index'),
      //   meta: { title: '设备实时状态' }
      // }
    ]
  },
  {
    path: '/jobgroup',
    component: Layout,
    redirect: '/jobgroup',
    name: 'Jobgroup',
    meta: { title: '轮询管理', icon: 'history' },
    children: [
      {
        path: 'screen',
        name: 'screen',
        component: () => import('@/views/jobgroup/screen/index.vue'),
        meta: { title: '运行报表' }
      },
      {
        path: 'jobinfo',
        name: 'jobinfo',
        component: () => import('@/views/jobgroup/jobinfo/index.vue'),
        meta: { title: '任务管理' }
      },
      {
        path: 'joblog',
        name: 'joblog',
        component: () => import('@/views/jobgroup/joblog/index.vue'),
        meta: { title: '调度日志' }
      },
      {
        path: 'jobmanage',
        name: 'jobmanage',
        component: () => import('@/views/jobgroup/jobmanage/index.vue'),
        meta: { title: '执行器管理' }
      },
    ]
  },
  // {
  //   path: '/history',
  //   component: Layout,
  //   redirect: '/history/leakyCableStatus',
  //   name: 'History',
  //   meta: { title: '历史数据', icon: 'history' },
  //   children: [
  //     // {
  //     //   path: 'leakyCableStatus',
  //     //   name: 'leakyCableStatus',
  //     //   component: () => import('@/views/history/leakyCableStatus/index.vue'),
  //     //   meta: { title: '漏缆监测历史状态' }
  //     // },
  //     {
  //       path: 'leakyCableRepair',
  //       name: 'leakyCableRepair',
  //       component: () => import('@/views/history/leakyCableRepair/index.vue'),
  //       meta: { title: '漏缆监测维修历史' }
  //     },
  //     // {
  //     //   path: 'deviceLinkStatus',
  //     //   name: 'deviceLinkStatus',
  //     //   component: () => import('@/views/history/deviceLinkStatus/index.vue'),
  //     //   meta: { title: '设备连接历史状态' }
  //     // },
  //     {
  //       path: 'deviceLinkRepair',
  //       name: 'deviceLinkRepair',
  //       component: () => import('@/views/history/deviceLinkRepair/index.vue'),
  //       meta: { title: '设备连接维修历史' }
  //     }
  //   ]
  // }, 
  {
    path: '/backup',
    component: Layout,
    redirect: '/dashboard',
    name: '备份管理',
    meta: { title: '备份管理', icon: 'backup' },
    children: [
      {
        path: 'backups',
        name: '数据备份',
        component: () => import('@/views/backup/backups/index'),
        meta: { title: '数据备份' }
      },
      {
        path: 'synchronize',
        name: '时间同步',
        component: () => import('@/views/backup/synchronize/index'),
        meta: { title: '时间同步' }
      }
    ]
  }, {
    path: '/system',
    component: Layout,
    redirect: '/dashboard',
    name: '系统管理',
    meta: { title: '系统管理', icon: 'backup' },
    children: [
      {
        path: 'menu',
        name: '菜单管理',
        component: () => import('@/views/system/menu/index'),
        meta: { title: '菜单管理' }
      },
      {
        path: 'role',
        name: '角色管理',
        component: () => import('@/views/system/role/index'),
        meta: { title: '角色管理' }
      }
    ]
  },
]

export const asyncRoutes = [
  {
    path: '/user',
    component: Layout,
    redirect: '/dashboard',
    name: 'User',
    meta: { title: '用户管理', icon: 'user' },
    children: [{
      path: 'updateUser',
      name: 'UpdateUser',
      component: () => import('@/views/user/updateUser'),
      meta: { title: '个人信息管理', roles: ['admin', 'editor'] },

    },
    {
      path: 'userList',
      name: 'UserList',
      component: () => import('@/views/user/userList'),
      meta: { title: '用户信息列表', roles: ['admin'] },

    },
    {
      path: 'userLog',
      name: 'UserLog',
      component: () => import('@/views/user/userLog'),
      meta: { title: '用户操作日志', roles: ['admin'] },

    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
router.beforeResolve((to, from, next) => {
  window.document.title = to.meta.title
  next()
})
export default router
