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

// 主界面
import TheLayout from '@/pages/layout/TheLayout.vue'
import login from '@/pages/login/login.vue'
import register from '@/pages/login/register.vue'
import TopologicalGraphShow from '@/components/TopologyView/TopologicalGraphShow.vue'
import ServiceStatusUpdate from '@/components/TopologyView/ServiceStatusUpdate.vue'
// 配置管理
import BasicConfigurationManagement from '@/components/ConfigurationManagement/BasicConfigurationManagement/BasicConfigurationManagement.vue'
import SubnetConfigurationManagement from '@/components/TopologyManagement/SubnetConfigurationManagement/SubnetConfigurationManagement.vue'
import LocationConfigurationManagement from '@/components/ConfigurationManagement/LocationConfigurationManagement/LocationConfigurationManagement.vue'
import CabinetConfigurationManagement from '@/components/ConfigurationManagement/CabinetConfigurationManagement/CabinetConfigurationManagement.vue'
import DeviceCreatPort from '@/components/TopologyManagement/DeviceConfigurationManagement/DeviceCreatPort.vue'
// 资源管理
import ElementDiscoveryTemplateManagement from '@/components/ResourceManagement/ElementDiscoveryTemplateManagement.vue'
import DeviceManagement from '@/components/ResourceManagement/DeviceManagement.vue'
import BookManagement from '@/components/ResourceManagement/BookManagement.vue'
import ElementDiscoveryManagement from '@/components/ResourceManagement/ElementDiscoveryManagement.vue'
// 设备管理
import DeviceConfigurationManagement from '@/components/TopologyManagement/DeviceConfigurationManagement/DeviceConfigurationManagement.vue'
import LinkConfigurationManagement from '@/components/TopologyManagement/LinkConfigurationManagement/LinkConfigurationManagement.vue'
import ManualStartDeviceConfiguration from '@/components/ManualStartDeviceConfiguration/ManualStartDeviceConfiguration.vue'
import TraditionDeviceConfigurationManagement from '@/components/TopologyManagement/TraditionDeviceConfigurationManagement/TraditionDeviceConfigurationManagement.vue'
import FirmWareConfigurationManagement from '@/components/TopologyManagement/DeviceConfigurationManagement/FirmWareConfigurationManagement.vue'
// 业务管理
import ServiceTypeConfigurationManagement from '@/components/BusinessManagement/ServiceTypeConfigurationManagement.vue'
import CDPProfile from '@/components/BusinessManagement/CDPProfile.vue'
import EveSubnetConfigurationManagementFather from '@/components/BusinessManagement/EveSubnetConfigurationManagementFather.vue'
import EthernetELineServiceConfigurationManagementFather from '@/components/BusinessManagement/EthernetELineServiceConfigurationManagementFather.vue'
import EveModelConfigurationManagement from '@/components/BusinessManagement/EveModelConfigurationManagement.vue'
import EveModelConfigurationManagementFather from '@/components/BusinessManagement/EveModelConfigurationManagementFather.vue'
import NetworkPhysicsLinkConfigurationManagement from '@/components/BusinessManagement/NetworkPhysicsLinkConfigurationManagement.vue'
import TopologicalDynamicConfiguration from '@/components/BusinessManagement/TopologicalDynamicConfiguration.vue'
// 告警管理
import AlarmConfigManagement from '@/components/AlarmManagement/AlarmConfigManagement.vue'
import AlarmLevelManagement from '@/components/AlarmManagement/AlarmLevelManagement.vue'
import AlarmFilerManagement from '@/components/AlarmManagement/AlarmFilerManagement.vue'
import AlarmQuery from '@/components/AlarmManagement/AlarmQuery.vue'
import AlarmStatistics from '@/components/AlarmManagement/AlarmStatistics.vue'
import EventOperation from '@/components/AlarmManagement/EventOperation.vue'
import AlarmReports from '@/components/AlarmManagement/AlarmReports.vue'
import AlarmMangExp from '@/components/AlarmManagement/AlarmMangExp.vue'
// 性能管理
import PerformanceMonitor from '@/components/PerformanceManagement/PerformanceMonitor.vue'
import PerformanceDataQuery from '@/components/PerformanceManagement/PerformanceDataQuery.vue'
import PerformanceStatistics from '@/components/PerformanceManagement/PerformanceStatistics.vue'
import PerformanceReports from '@/components/PerformanceManagement/PerformanceReports.vue'
import RtPerformance from '@/components/PerformanceManagement/RtPerformance.vue'
import TopNPerformanceReport from '@/components/PerformanceManagement/TopNPerformanceReport.vue'

// 性能管理new
import PerformanceThreshold from '@/components/PerformanceManagement/PerformanceThreshold.vue'
import IndexTemplate from '@/components/PerformanceManagement/IndexTemplate.vue'
import CollectTask from '@/components/PerformanceManagement/CollectTask.vue'
import TaskDetail from '@/components/PerformanceManagement/TaskDetail.vue'

// 报表管理
import ReportTemplateManagement from '@/components/StatementManagement/ReportTemplateManagement.vue'
import AlarmDistributionStatisticReport from '@/components/StatementManagement/AlarmDistributionStatisticReport.vue'
import AlarmTrendStatisticReport from '@/components/StatementManagement/AlarmTrendStatisticReport.vue'
import AlarmTopBottomStatisticReport from '@/components/StatementManagement/AlarmTopBottomStatisticReport.vue'
import PerformDistributionStatisticReport from '@/components/StatementManagement/PerformDistributionStatisticReport.vue'
import PerformTrendStatisticReport from '@/components/StatementManagement/PerformTrendStatisticReport.vue'
import PerformTopBottomStatisticReport from '@/components/StatementManagement/PerformTopBottomStatisticReport.vue'
import ReportTask from '@/components/StatementManagement/ReportTask.vue'
import PeriodReport from '@/components/StatementManagement/PeriodReport.vue'

// 安全管理
import AuthorityManagement from '@/components/SafeManagement/AuthorityManagement.vue'
import UserManagement from '@/components/SafeManagement/UserManagement.vue'
import LoginLogManagement from '@/components/SafeManagement/LoginLogManagement.vue'
import OperationLogManagement from '@/components/SafeManagement/OperationLogManagement.vue'
import ModifyPersonalInfo from '@/components/SafeManagement/ModifyPersonalInfo.vue'

// 监控助手
import DatabaseMonitor from '@/components/SafeManagement/DatabaseMonitor.vue'

// 数据维护
import DataSafeGuard from '@/components/DataSafe/DataSafeGuard.vue'
import SnapShot from '@/components/DataSafe/SnapShot.vue'
// 在线帮助
import TheOnlineHelp from '../components/TheOnlineHelp/TheOnlineHelp'
import About from '../components/TheOnlineHelp/AboutInformation'

Vue.use(Router)

/* 免登录白名单页面 */
const whiteList = [
  '/',
  '/login',
  '/register'
]

const routes = [
  {
    path: '/',
    name: 'login',
    component: login
  },
  {
    path: '/TheLayout',
    redirect: '/TheLayout/main'
  },
  {
    path: '/TheLayout',
    name: 'TheLayout',
    meta: {
      requireAuth: true // 添加该字段，表示进入这个路由是需要登录的
    },
    component: TheLayout,
    children: [
      {
        path: 'main',
        name: '拓扑图',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.topologyShow'
        },
        component: TopologicalGraphShow
      },
      {
        path: 'ServiceStatusUpdate',
        name: '业务状态更新',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.serviceStatusUpdate'
        },
        component: ServiceStatusUpdate
      },
      {
        path: 'BasicConfigurationManagement',
        name: '服务器配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.basicConfigurationManagement'
        },
        component: BasicConfigurationManagement
      },
      {
        path: 'ElementDiscoveryTemplateManagement',
        name: '网元发现模板管理',
        meta: {
          requireAuth: true,
          title: 'TheLayoutHeader.elementDiscoveryTemplateManagement'
        },
        component: ElementDiscoveryTemplateManagement
      },
      {
        path: 'ElementDiscoveryManagement',
        name: '网元发现',
        meta: {
          requireAuth: true,
          title: 'TheLayoutHeader.elementDiscoveryManagement'
        },
        component: ElementDiscoveryManagement
      },
      {
        path: 'DeviceManagement',
        name: '网元管理',
        meta: {
          requireAuth: true,
          title: 'TheLayoutHeader.elementManagement'
        },
        component: DeviceManagement
      },
      {
        path: 'BookManagement',
        name: '网元台账管理',
        meta: {
          requireAuth: true,
          title: 'TheLayoutHeader.BookManagement'
        },
        component: BookManagement
      },
      {
        path: 'SubnetConfigurationManagement',
        name: '子网配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.subnetConfigurationManagement'
        },
        component: SubnetConfigurationManagement
      },
      {
        path: 'LocationConfigurationManagement',
        name: '机房配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.locationConfigurationManagement'
        },
        component: LocationConfigurationManagement
      },
      {
        path: 'CabinetConfigurationManagement',
        name: '机架配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.cabinetConfigurationManagement'
        },
        component: CabinetConfigurationManagement
      },
      {
        path: 'DeviceCreatPort',
        name: '接入业务配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.deviceCreatPort'
        },
        component: DeviceCreatPort
      },
      {
        path: 'DeviceConfigurationManagement',
        name: '网元配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.deviceConfigurationManagement'
        },
        component: DeviceConfigurationManagement
      },
      {
        path: 'LinkConfigurationManagement',
        name: '链路配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.linkConfigurationManagement'
        },
        component: LinkConfigurationManagement
      },
      {
        path: 'ManualStartDeviceConfiguration',
        name: '网元配置文件管理',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.manualStartDeviceConfiguration'
        },
        component: ManualStartDeviceConfiguration
      },
      {
        path: 'TraditionDeviceConfigurationManagement',
        name: '设备发现',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.tradDeviceManagement'
        },
        component: TraditionDeviceConfigurationManagement
      },
      {
        path: 'FirmWareConfigurationManagement',
        name: '固件配置',
        meta: {
          requireAuth: true,
          title: 'TheLayoutHeader.firmWareConfigurationManagement'
        },
        component: FirmWareConfigurationManagement
      },
      {
        path: 'TopologicalDynamicConfiguration',
        name: '拓扑动态配置',
        meta: {
          requireAuth: true,
          title: 'TheLayoutHeader.topologicalDynamicConfiguration'
        },
        component: TopologicalDynamicConfiguration
      },
      {
        path: 'ServiceTypeConfigurationManagement',
        name: '业务类型配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.serviceTypeConfigurationManagement'
        },
        component: ServiceTypeConfigurationManagement
      },
      {
        path: 'CDPProfile',
        name: 'QoS配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.CDPProfile'
        },
        component: CDPProfile
      },
      {
        path: 'EveSubnetConfigurationManagementFather',
        name: '业务子网配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.EveSubnetConfigurationManagement'
        },
        component: EveSubnetConfigurationManagementFather
      },
      {
        path: 'EthernetELineServiceConfigurationManagementFather',
        name: 'eline业务配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.ethernetELineServiceConfigurationManagement'
        },
        component: EthernetELineServiceConfigurationManagementFather
      },
      {
        path: 'EveModelConfigurationManagement',
        name: '业务模板配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.serviceTemplateConfiguration'
        },
        component: EveModelConfigurationManagement
      },
      {
        path: 'NetworkPhysicsLinkConfigurationManagement',
        name: '网络物理连接配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.NetworkPhysicsLinkConfigurationManagement'
        },
        component: NetworkPhysicsLinkConfigurationManagement
      },

      {
        path: 'EveModelConfigurationManagementFather',
        name: '业务模板配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.serviceTemplateConfiguration'
        },
        component: EveModelConfigurationManagementFather
      },
      {
        path: 'AlarmLevelManagement',
        name: '告警类型配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.alarmTypeConfiguration'
        },
        component: AlarmLevelManagement
      },
      {
        path: 'AlarmConfigManagement',
        name: '告警等级配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.alarmLevelConfiguration'
        },
        component: AlarmConfigManagement
      },
      {
        path: 'AlarmFilerManagement',
        name: '告警过滤配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.alarmFilterConfiguration'
        },
        component: AlarmFilerManagement
      },
      {
        path: 'AlarmQuery',
        name: '告警查询',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.alarmQuery'
        },
        component: AlarmQuery
      },
      {
        path: 'AlarmStatistics',
        name: '告警统计',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.alarmStatistics'
        },
        component: AlarmStatistics
      },
      {
        path: 'EventOperation',
        name: '事件查询',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.eventQuery'
        },
        component: EventOperation
      },
      {
        path: 'AlarmReports',
        name: '告警报表',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.alarmReports'
        },
        component: AlarmReports
      },
      {
        path: 'AlarmMangExp',
        name: '告警经验维护',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.AlarmMangExp'
        },
        component: AlarmMangExp
      },
      {
        path: 'PerformanceMonitor',
        name: '性能配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.performanceConfiguration'
        },
        component: PerformanceMonitor
      },
      {
        path: 'PerformanceThreshold',
        name: '性能门限管理',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.performanceThreshold'
        },
        component: PerformanceThreshold
      },
      {
        path: 'IndexTemplate',
        name: '指标模板管理',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.IndexTemplate'
        },
        component: IndexTemplate
      },
      {
        path: 'CollectTask',
        name: '采集任务管理',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.CollectTask'
        },
        component: CollectTask
      },
      {
        path: 'TaskDetail',
        name: '任务详情',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.TaskDetail'
        },
        component: TaskDetail
      },
      {
        path: 'PerformanceDataQuery',
        name: '性能查询',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.performanceQuery'
        },
        component: PerformanceDataQuery
      },
      {
        path: 'PerformanceStatistics',
        name: '性能统计',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.performanceStatistics'
        },
        component: PerformanceStatistics
      },
      {
        path: 'RtPerformance',
        name: '实时性能',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.rtPerformance'
        },
        component: RtPerformance
      },
      {
        path: 'PerformanceReports',
        name: '性能报表',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.performanceReports'
        },
        component: PerformanceReports
      },
      {
        path: 'TopNPerformanceReport',
        name: 'TopN性能查询',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.TopNPerformanceReport'
        },
        component: TopNPerformanceReport
      },
      {
        path: 'ReportTemplateManagement',
        name: '报表模板管理',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.ReportTemplateManagement'
        },
        component: ReportTemplateManagement
      },
      {
        path: 'AlarmDistributionStatisticReport',
        name: '告警分布统计报表',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.AlarmDistributionStatisticReport'
        },
        component: AlarmDistributionStatisticReport
      },
      {
        path: 'AlarmTrendStatisticReport',
        name: '告警趋势统计报表',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.AlarmTrendStatisticReport'
        },
        component: AlarmTrendStatisticReport
      },
      {
        path: 'AlarmTopBottomStatisticReport',
        name: '告警TOP/BOTTOM N统计报表',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.AlarmTopBottomStatisticReport'
        },
        component: AlarmTopBottomStatisticReport
      },
      {
        path: 'PerformDistributionStatisticReport',
        name: '性能分布统计报表',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.PerformDistributionStatisticReport'
        },
        component: PerformDistributionStatisticReport
      },
      {
        path: 'PerformTrendStatisticReport',
        name: '性能趋势统计报表',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.PerformTrendStatisticReport'
        },
        component: PerformTrendStatisticReport
      },
      {
        path: 'PerformTopBottomStatisticReport',
        name: '性能TOP/BOTTOM N统计报表',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.PerformTopBottomStatisticReport'
        },
        component: PerformTopBottomStatisticReport
      },
      {
        path: 'ReportTask',
        name: '报表任务',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.ReportTask'
        },
        component: ReportTask
      },
      {
        path: 'PeriodReport',
        name: '周期报表',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.PeriodReport'
        },
        component: PeriodReport
      },
      {
        path: 'AuthorityManagement',
        name: '用户组权限配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.userGroupAuthorityConfiguration'
        },
        component: AuthorityManagement
      },
      {
        path: 'UserManagement',
        name: '用户配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.userConfiguration'
        },
        component: UserManagement
      },
      {
        path: 'LoginLogManagement',
        name: '登录日志查询',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.loginLogQuery'
        },
        component: LoginLogManagement
      },
      {
        path: 'OperationLogManagement',
        name: '操作日志查询',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.optionLogQuery'
        },
        component: OperationLogManagement
      },
      {
        path: 'ModifyPersonalInfo',
        name: '登录用户配置',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.modifyUserInfo'
        },
        component: ModifyPersonalInfo
      },

      {
        path: 'DataSafeGuard',
        name: '数据安全维护',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.dataSafeGuard'
        },
        component: DataSafeGuard
      },
      {
        path: 'SnapShot',
        name: '快照管理',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.snapShot'
        },
        component: SnapShot
      },
      {
        path: 'DatabaseMonitor',
        name: '数据库监控',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.databaseMonitor'
        },
        component: DatabaseMonitor
      },

      {
        path: 'TheOnlineHelp',
        name: '在线帮助',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.theOnlineHelpPage'
        },
        component: TheOnlineHelp
      },
      {
        path: 'About',
        name: '关于',
        meta: {
          requireAuth: true, // 添加该字段，表示进入这个路由是需要登录的
          title: 'TheLayoutHeader.aboutInformation'
        },
        component: About
      }

    ]
  }
]

const router = new Router({
  routes
})

router.beforeEach((to, from, next) => {
  /* 免登录页面 */
  if (whiteList.indexOf(to.fullPath) >= 0) {
    return next()
  }
  if (to.meta.requireAuth) { // 判断该路由是否需要登录权限
    if (to.params.token !== undefined) {
      return next()
    }
    if (window.sessionStorage.getItem('token') !== null) { // 通过vuex state获取当前的token是否存在
      next()
    } else {
      // TODO:登录界面应为/login
      next({
        path: '/',
        query: {redirect: to.fullPath} // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  } else {
    next()
  }
})

export default router
