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

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/front',
      name: 'AutoReportLayer',
      component: (resolve) => {
        require(['@/views/AutoReportLayer/AutoReportLayer.vue'], resolve)
      },
      meta: {
        parentTitle: [],
        title: '',
        requireAuth: true,
        parentName: ''
      },
      children: [
        /* 数据管理 */
        /* 报表配置-分类下报表预览 */
        {
          path: '/front/viewByMenu/:id',
          name: 'AutomaticMenuReport',
          component: (resolve) => {
            require(['@/views/AutomaticReport/ListInMenu/AutomaticReportList.vue'], resolve)
          },
          meta: {
            parentTitle: ['报表配置'],
            title: '报表预览',
            requireAuth: true,
            parentName: 'Report'
          }
        }
      ]
    },
    /* iframe用 */
    /* 报表预览 */
    {
      path: '/iframe/report/:id',
      name: 'IframeReport',
      component: (resolve) => {
        require(['@/views/AutomaticReport/IframeList/AutomaticReportList.vue'], resolve)
      },
      meta: {
        parentTitle: [],
        title: '',
      }
    },
    {
      path: '/',
      name: 'Layer',
      component: (resolve) => {
        require(['@/views/Layer/Layer.vue'], resolve)
      },
      redirect: '/data',
      children: [
        /* 数据管理 */
        {
          path: '/data',
          name: 'Data',
          redirect: '/data/database',
          meta: {
            parentTitle: [],
            title: '数据管理',
            requireAuth: true
          }
        },
        /* 数据管理-数据库 */
        {
          path: '/data/database',
          name: 'DataBase',
          component: (resolve) => {
            require(['@/views/DataManagement/Database/List/DatabaseList.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理'],
            title: '数据库管理',
            requireAuth: true,
          }
        },
        {
          path: '/data/database/add',
          name: 'DatabaseAdd',
          component: (resolve) => {
            require(['@/views/DataManagement/Database/Detail/DatabaseDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','数据库管理'],
            title: '新建数据库',
            requireAuth: true,
            parentName: 'DataBase'
          }
        },
        {
          path: '/data/database/edit/:id',
          name: 'DatabaseEdit',
          component: (resolve) => {
            require(['@/views/DataManagement/Database/Detail/DatabaseDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','数据库管理'],
            title: '修改数据库',
            requireAuth: true,
            parentName: 'DataBase'
          }
        },
        /* 数据管理-接口管理 */
        {
          path: '/data/interface',
          name: 'Interface',
          component: (resolve) => {
            require(['@/views/DataManagement/interface/List/interfaceList.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理'],
            title: '接口管理',
            requireAuth: true,
          }
        },
        {
          path: '/data/interface/add',
          name: 'interfaceAdd',
          component: (resolve) => {
            require(['@/views/DataManagement/interface/Detail/interfaceDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','接口管理'],
            title: '新建接口',
            requireAuth: true,
            parentName: 'DataBase'
          }
        },
        {
          path: '/data/interface/edit/:id',
          name: 'interfaceEdit',
          component: (resolve) => {
            require(['@/views/DataManagement/interface/Detail/interfaceDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','接口管理'],
            title: '修改接口',
            requireAuth: true,
            parentName: 'DataBase'
          }
        },
        /* 数据管理-接口分类管理 */
        {
          path: '/data/interfaceClassify',
          name: 'InterfaceClassify',
          component: (resolve) => {
            require(['@/views/DataManagement/interface/classify/List/interfaceClassifyList.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理'],
            title: '接口分类管理',
            requireAuth: true,
          }
        },
        {
          path: '/data/interfaceClassify/add',
          name: 'interfaceClassifyAdd',
          component: (resolve) => {
            require(['@/views/DataManagement/interface/classify/Detail/interfaceClassifyDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','接口分类管理'],
            title: '新建接口分类',
            requireAuth: true,
            parentName: 'DataBase'
          }
        },
        {
          path: '/data/interfaceClassify/edit/:id',
          name: 'interfaceClassifyEdit',
          component: (resolve) => {
            require(['@/views/DataManagement/interface/classify/Detail/interfaceClassifyDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','接口分类管理'],
            title: '修改接口分类',
            requireAuth: true,
            parentName: 'DataBase'
          }
        },
        /* 数据管理-元数据 */
        {
          path: '/data/meta',
          name: 'MetaData',
          component: (resolve) => {
            require(['@/views/DataManagement/Metadata/List/MetadataList.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理'],
            title: '元数据管理',
            requireAuth: true,
            parentName: 'Data'
          }
        },
        {
          path: '/data/meta/ddl',
          name: 'CreateMetaDDL',
          component: (resolve) => {
            require(['@/views/DataManagement/Metadata/CreateMeta/DDL/CreateMetaDDL.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','元数据管理'],
            title: 'DDL',
            requireAuth: true,
            parentName: 'MetaData'
          }
        },
        {
          path: '/data/meta/guide',
          name: 'CreateMetaGuide',
          component: (resolve) => {
            require(['@/views/DataManagement/Metadata/CreateMeta/Guide/CreateMetaGuide.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','元数据管理'],
            title: '向导',
            requireAuth: true,
            parentName: 'MetaData'
          }
        },
        {
          path: '/data/meta/guide/:ifcopy/:id',
          name: 'EditMetaGuide',
          component: (resolve) => {
            require(['@/views/DataManagement/Metadata/CreateMeta/Guide/CreateMetaGuide.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','元数据管理'],
            title: '向导',
            requireAuth: true,
            parentName: 'MetaData'
          }
        },
        {
          path: '/data/meta/scan',
          name: 'CreateMetaScan',
          component: (resolve) => {
            require(['@/views/DataManagement/Metadata/CreateMeta/Scan/CreateMetaScan.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据管理','元数据管理'],
            title: '扫描',
            requireAuth: true,
            parentName: 'Metadata'
          }
        },

        /* 数据采集 */
        {
          path: '/collection',
          name: 'DataCollection',
          redirect: '/collecion/task',
          meta: {
            parentTitle: [],
            title: '数据采集',
            requireAuth: true
          }
        },
        /* 数据采集-任务管理 */
        {
          path: '/collection/task',
          name: 'TaskManagement',
          component: (resolve) => {
            require(['@/views/DataCollection/TaskManagement/List/TaskList.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据采集'],
            title: '任务管理',
            requireAuth: true,
          }
        },
        {
          path: '/collection/task/add',
          name: 'TaskAdd',
          component: (resolve) => {
            require(['@/views/DataCollection/TaskManagement/Detail/TaskDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据采集','任务管理'],
            title: '新增任务',
            requireAuth: true,
            parentName: 'TaskManagement'
          }
        },
        {
          path: '/collection/task/edit/:id',
          name: 'TaskEdit',
          component: (resolve) => {
            require(['@/views/DataCollection/TaskManagement/Detail/TaskDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据采集','任务管理'],
            title: '修改任务',
            requireAuth: true,
            parentName: 'TaskManagement'
          }
        },
        {
          path: '/collection/task/view/:readonly/:id',
          name: 'TaskView',
          component: (resolve) => {
            require(['@/views/DataCollection/TaskManagement/Detail/TaskDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据采集','任务管理'],
            title: '查看任务',
            requireAuth: true,
            parentName: 'TaskManagement'
          }
        },
        /* 数据采集-质量检查 */
        {
          path: '/collection/check',
          name: 'QualityCheck',
          component: (resolve) => {
            require(['@/views/DataCollection/QualityCheck/List/QualityList.vue'], resolve)
          },
          meta: {
            parentTitle: ['数据采集'],
            title: '质量检查',
            requireAuth: true,
          }
        },
        /* KPI配置 */
        {
          path: '/kpi',
          name: 'KPI',
          redirect: '/kpi/manage',
          meta: {
            parentTitle: [],
            title: 'KPI配置',
            requireAuth: true
          }
        },
        /* KPI配置-KPI管理 */
        {
          path: '/kpi/manage',
          name: 'KPIManage',
          component: (resolve) => {
            require(['@/views/KPI/Management/List/KPIList.vue'], resolve)
          },
          meta: {
            parentTitle: ['KPI配置'],
            title: 'KPI管理',
            requireAuth: true,
          }
        },
        {
          path: '/kpi/manage/add',
          name: 'KPIAdd',
          component: (resolve) => {
            require(['@/views/KPI/Management/Detail/KPIDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['KPI配置','KPI管理'],
            title: '新建KPI',
            requireAuth: true,
            parentName: 'KPIManage'
          }
        },
        {
          path: '/kpi/manage/addBatch',
          name: 'KPIBatch',
          component: (resolve) => {
            require(['@/views/KPI/Management/Batch/KPIBatch.vue'], resolve)
          },
          meta: {
            parentTitle: ['KPI配置','KPI管理'],
            title: '批量新建KPI',
            requireAuth: true,
            parentName: 'KPIManage'
          }
        },
        {
          path: '/kpi/manage/edit/:id',
          name: 'KPIEdit',
          component: (resolve) => {
            require(['@/views/KPI/Management/Detail/KPIDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['KPI配置','KPI管理'],
            title: '修改KPI',
            requireAuth: true,
            parentName: 'KPIManage'
          }
        },
        {
          path: '/kpi/manage/view/:readonly/:id',
          name: 'KPIView',
          component: (resolve) => {
            require(['@/views/KPI/Management/Detail/KPIDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['KPI配置','KPI管理'],
            title: '查看KPI',
            requireAuth: true,
            parentName: 'KPIManage'
          }
        },
        /* KPI配置-主题管理 */
        {
          path: '/kpi/theme',
          name: 'ThemeManage',
          component: (resolve) => {
            require(['@/views/KPI/ThemeManagement/Detail/ThemeDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['KPI配置'],
            title: '主题管理',
            requireAuth: true,
            parentName: 'KPI'
          }
        },

        /* 报表配置 */
        {
          path: '/report',
          name: 'Report',
          redirect: '/report/manage',
          meta: {
            parentTitle: [],
            title: '报表配置',
            requireAuth: true
          }
        },
        /* 报表配置-报表管理 */
        {
          path: '/report/manage',
          name: 'ReportManage',
          component: (resolve) => {
            require(['@/views/Report/ReportManagement/List/ReportList.vue'], resolve)
          },
          meta: {
            parentTitle: ['报表配置'],
            parentName: 'Report',
            title: '报表管理',
            requireAuth: true,
          }
        },
        {
          path: '/report/manage/add',
          name: 'ReportAdd',
          component: (resolve) => {
            require(['@/views/Report/ReportManagement/Detail/ReportDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['报表配置','报表管理'],
            title: '新建报表',
            requireAuth: true,
            parentName: 'ReportManage'
          }
        },
        {
          path: '/report/manage/edit/:id',
          name: 'ReportEdit',
          component: (resolve) => {
            require(['@/views/Report/ReportManagement/Detail/ReportDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['报表配置','报表管理'],
            title: '修改报表',
            requireAuth: true,
            parentName: 'ReportManage'
          }
        },
        /* 权限设置 */
        {
          path: '/report/manage/access',
          name: 'ReportAccess',
          component: (resolve) => {
            require(['@/views/Report/ReportManagement/AccessMultipleReports/AccessMultipleReports.vue'], resolve)
          },
          meta: {
            parentTitle: ['报表配置', '报表管理'],
            title: '权限设置',
            requireAuth: true,
            parentName: 'ReportManage'
          }
        },
        {
          path: '/report/manage/access/:id/:name',
          name: 'SignalReportAccess',
          component: (resolve) => {
            require(['@/views/Report/ReportManagement/AccessSingleReport/AccessSingleReport.vue'], resolve)
          },
          meta: {
            parentTitle: ['报表配置', '报表管理'],
            title: '权限设置',
            requireAuth: true,
            parentName: 'ReportManage'
          }
        },
        /* 报表配置-类型管理 */
        {
          path: '/report/type',
          name: 'TypeManage',
          component: (resolve) => {
            require(['@/views/Report/TypeManagement/Detail/TypeDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['报表配置'],
            title: '分类管理',
            requireAuth: true,
            parentName: 'Report'
          }
        },
        /* 报表配置-报表预览 */
        {
          path: '/report/manage/view/:id',
          name: 'AutomaticReport',
          component: (resolve) => {
            require(['@/views/AutomaticReport/List/AutomaticReportList.vue'], resolve)
          },
          meta: {
            parentTitle: ['报表配置'],
            title: '报表预览',
            requireAuth: true,
            parentName: 'Report'
          }
        },

        // 20190807

        /* 图表配置 */
        {
          path: '/graph',
          name: 'Graph',
          redirect: '/graph/manage',
          meta: {
            parentTitle: [],
            title: '图表配置',
            requireAuth: true
          }
        },
        /* 图表配置-图表预览 */
        {
          path: '/graph/manage/view/:id',
          name: 'AutomaticGraph',
          component: (resolve) => {
            require(['@/views/AutomaticGraph/List/index.vue'], resolve)
          },
          meta: {
            parentTitle: [],
            parentName: 'AutomaticGraph',
            title: '图表预览',
            requireAuth: true,
          }
        },
        /* 图表配置-图表管理 */
        {
          path: '/graph/manage',
          name: 'GraphManage',
          component: (resolve) => {
            require(['@/views/Graph/GraphManagement/List/GraphList.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置'],
            parentName: 'Graph',
            title: '图表管理',
            requireAuth: true,
          }
        },
        {
          path: '/graph/manage/add',
          name: 'GraphAdd',
          component: (resolve) => {
            require(['@/views/Graph/GraphManagement/Detail/GraphDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置','图表管理'],
            title: '新建图表',
            requireAuth: true,
            parentName: 'GraphManage'
          }
        },
        {
          path: '/graph/manage/edit/:id',
          name: 'GraphEdit',
          component: (resolve) => {
            require(['@/views/Graph/GraphManagement/Detail/GraphDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置','图表管理'],
            title: '修改图表',
            requireAuth: true,
            parentName: 'GraphManage'
          }
        },
        /* 权限设置 */
        {
          path: '/graph/manage/access',
          name: 'GraphAccess',
          component: (resolve) => {
            require(['@/views/Graph/GraphManagement/AccessMultipleGraphs/AccessMultipleGraphs.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置', '图表管理'],
            title: '权限设置',
            requireAuth: true,
            parentName: 'GraphManage'
          }
        },
        {
          path: '/graph/manage/access/:id/:name',
          name: 'SignalGraphAccess',
          component: (resolve) => {
            require(['@/views/Graph/GraphManagement/AccessSingleGraph/AccessSingleGraph.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置', '图表管理'],
            title: '权限设置',
            requireAuth: true,
            parentName: 'GraphManage'
          }
        },
        /* 图表配置-类型管理 */
        {
          path: '/graph/type',
          name: 'TypeManage',
          component: (resolve) => {
            require(['@/views/Graph/TypeManagement/Detail/TypeDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置'],
            title: '分类管理',
            requireAuth: true,
            parentName: 'Graph'
          }
        },
        /* 图表配置-图表预览 */
        // {
        //   path: '/graph/manage/view/:id',
        //   name: 'AutomaticGraph',
        //   component: (resolve) => {
        //     require(['@/views/AutomaticGraph/List/AutomaticGraphList.vue'], resolve)
        //   },
        //   meta: {
        //     parentTitle: ['图表配置'],
        //     title: '图表预览',
        //     requireAuth: true,
        //     parentName: 'Graph'
        //   }
        // },










        // /* 报表配置-分类下报表预览 */
        // {
        //   path: '/report/manage/viewByMenu/:id',
        //   name: 'AutomaticMenuReport',
        //   component: (resolve) => {
        //     require(['@/views/AutomaticReport/ListInMenu/AutomaticReportList.vue'], resolve)
        //   },
        //   meta: {
        //     parentTitle: ['报表配置'],
        //     title: '报表预览',
        //     requireAuth: true,
        //     parentName: 'Report'
        //   }
        // }
        {
          path: '/chart',
          name: 'Chart',
          redirect: '/chart/manage',
          meta: {
            parentTitle: [],
            title: '图表配置',
            requireAuth: true
          }
        },
        /* 图表配置-图表管理 */
        {
          path: '/chart/manage',
          name: 'ChartManage',
          component: (resolve) => {
            require(['@/views/Chart/ChartManagement/List/ChartList.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置'],
            parentName: 'Chart',
            title: '图表管理',
            requireAuth: true,
          }
        },
        {
          path: '/chart/manage/add',
          name: 'ChartAdd',
          component: (resolve) => {
            require(['@/views/Chart/ChartManagement/Detail/ChartDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置','图表管理'],
            title: '新建图表',
            requireAuth: true,
            parentName: 'ChartManage'
          }
        },
        {
          path: '/chart/manage/setChart/:id',
          name: 'ChartSet',
          component: (resolve) => {
            require(['@/views/Chart/ChartManagement/setChart/ChartCode.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置','图表管理'],
            title: '配置图表',
            requireAuth: true,
            parentName: 'ChartManage'
          }
        },
        {
          path: '/chart/manage/edit/:id',
          name: 'ChartEdit',
          component: (resolve) => {
            require(['@/views/Chart/ChartManagement/Detail/ChartDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置','图表管理'],
            title: '修改图表',
            requireAuth: true,
            parentName: 'ChartManage'
          }
        },
        {
          path: '/chart/manage/edit/:id/:readonly',
          name: 'ChartView',
          component: (resolve) => {
            require(['@/views/Chart/ChartManagement/Detail/ChartDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置','图表管理'],
            title: '查看图表',
            requireAuth: true,
            parentName: 'ChartManage'
          }
        },
        /* 图表配置-类型管理 */
        {
          path: '/chart/type',
          name: 'ChartTypeManage',
          component: (resolve) => {
            require(['@/views/Chart/TypeManagement/Detail/TypeDetail.vue'], resolve)
          },
          meta: {
            parentTitle: ['图表配置'],
            title: '分类管理',
            requireAuth: true,
            parentName: 'Chart'
          }
        },
        /***
         * 专题管理 */
        {
          path: '/topic',
          name: 'Topic',
          redirect: '/topic/manage',
          meta: {
            parentTitle: [],
            title: '专题配置',
            requireAuth: true
          }
        },
        /* 图表配置-图表管理 */
        {
          path: '/topic/manage',
          name: 'TopicManage',
          component: (resolve) => {
            require(['@/views/topic/topicManagement/List/topicList.vue'], resolve)
          },
          meta: {
            parentTitle: ['专题配置'],
            parentName: 'Topic',
            title: '专题管理',
            requireAuth: true,
          }
        },
      ]
    },
     /* 图表配置 */
    {
      path: '/login',
      name: 'Login',
      component: (resolve) => {
        require(['@/views/Login/Login.vue'], resolve)
      }
    }
  ]
})

//  判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => {
  if (to.matched.some(res => res.meta.requireAuth)) { // 判断是否需要登录权限
    if (localStorage.getItem('token')) { // 判断是否登录
      next()
    } else { // 没登录则跳转到登录界面

      document.getElementById('body').className = "theme-white"

      next({
        path: '/login',
        query: {redirect: to.fullPath}
      })
    }
  } else {
    next()
  }
})

export default router
