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

Vue.use(Router)

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

/* Router Modules */

/** note: sub-menu only appear when children.length>=1
 *  detail see  https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 **/

/**
* 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 : {
    roles: ['admin','editor']    will control the page roles (you can set multiple roles)
    title: 'title'               the name show in sub-menu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    noCache: true                if true, the page will no be cached(default is false)
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
    affix: true                  if true, the tag will affix in the tags-view
  }
**/
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
  },
  {
    path: '/register',
    component: () => import('@/views/login/register'),
    hidden: true
  },
  {
    path: '/resetpw',
    component: () => import('@/views/login/resetpw'),
    hidden: true
  },
  {
    path: '/face/compare',
    component: () => import('@/views/face/compare'),
    hidden: true
  },
  {
    path: '/face/detect',
    component: () => import('@/views/face/detect'),
    hidden: true
  },
  {
    path: '/face/search',
    component: () => import('@/views/face/search'),
    hidden: true
  },
  {
    path: '/face/bodyAnalysis',
    component: () => import('@/views/face/bodyAnalysis'),
    hidden: true
  },
  {
    path: '/face/bodyAttr',
    component: () => import('@/views/face/bodyAttr'),
    hidden: true
  },
  {
    path: '/face/bodyNum',
    component: () => import('@/views/face/bodyNum'),
    hidden: true
  },
  {
    path: '/face/gesture',
    component: () => import('@/views/face/gesture'),
    hidden: true
  },
  {
    path: '/face/faceVerify',
    component: () => import('@/views/face/faceVerify'),
    hidden: true
  },
  {
    path: '/face/bankCard',
    component: () => import('@/views/face/bankCard'),
    hidden: true
  },
  {
    path: '/face/idCard',
    component: () => import('@/views/face/idCard'),
    hidden: true
  },
  {
    path: '/face/hVideo',
    component: () => import('@/views/face/hVideo'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/authredirect'),
    hidden: true
  },
  {
    path: '/404',
    redirect: 'dashboard',
    component: () => import('@/views/errorPage/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/errorPage/401'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/home/index'),
        name: 'Dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', noCache: true, affix: true }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  /* {
    path: '/permission',
    component: Layout,
    redirect: '/permission/index',
    alwaysShow: true, // will always show the root menu
    meta: {
      title: 'permission',
      icon: 'lock',
      roles: ['admin', 'editor'] // you can set roles in root nav
    },
    children: [
      {
        path: 'page',
        component: () => import('@/views/permission/page'),
        name: 'PagePermission',
        meta: {
          title: 'pagePermission',
          roles: ['admin'] // or you can only set roles in sub nav
        }
      },
      {
        path: 'directive',
        component: () => import('@/views/permission/directive'),
        name: 'DirectivePermission',
        meta: {
          title: 'directivePermission'
          // if do not set roles, means: this page does not require permission
        }
      }
    ]
  },*/
  // role = 1 管理员
  // role = 2 开发者
  // role = 3 vip开发者
  {
    path: '/apimngr',
    component: Layout,
    name: 'apimngr',
    meta: { title: '接口管理', icon: 'el-icon-files' },
    children: [
      {
        path: 'datasource',
        component: () => import('@/views/api/datasource'),
        name: 'datasource',
        meta: { title: '数据源管理', roles: ['1'] }
      },
      {
        path: 'datasourcelist',
        component: () => import('@/views/api/datasourcelist.vue'),
        name: 'datasourcelist',
        hidden: true,
        meta: { title: '数据源查看', roles: ['1'],noCache:false }
      },
      {
        path: 'apitype',
        component: () => import('@/views/api/type'),
        name: 'apitype',
        meta: { title: '接口类型', roles: ['1'] }
      },
      {
        path: 'apimanage',
        component: () => import('@/views/api/apimanage'),
        name: 'apimanage',
        meta: { title: '接口生产', roles: ['1'] }
      },
      {
        path: 'apisql',
        component: () => import('@/views/api/apisql.vue'),
        name: 'apisql',
        hidden: true,
        meta: { title: '自定义SQL', roles: ['1'],noCache:false }
      },
      {
        path: 'apiedit3',
        component: () => import('@/views/api/apiedit3.vue'),
        name: 'apiSqlEdit',
        hidden: true,
        meta: { title: 'sql入库', roles: ['1'],noCache:false }
      },
      {
        path: 'apilist',
        component: () => import('@/views/api/list'),
        name: 'apilist',
        meta: { title: '接口列表', roles: ['1'] }
      },
      // {
      //   path: 'apiapprove',
      //   component: () => import('@/views/api/approve'),
      //   name: 'apiapprove',
      //   meta: { title: '接口审核', roles: ['1'] }
      // },
      {
        path: 'apiexamine',
        component: () => import('@/views/api/examine'),
        name: 'apiexamine',
        meta: { title: '授权审核', roles: ['1'] }
      },
      // {
      //   path: 'auth',
      //   component: () => import('@/views/api/auth'),
      //   name: 'auth',
      //   meta: { title: '接口权限', roles: ['1'] }
      // },
      {
        path: 'apply',
        component: () => import('@/views/api/apply'),
        name: 'apply',
        meta: { title: '需求审核', roles: ['1'] }
      },
      {
        path: 'detail/:id',
        component: () => import('@/views/api/detail.vue'),
        name: 'detail',
        hidden: true,
        meta: { title: '接口详情', icon: 'ic_report', roles: ['1'], noCache: true }
      }
      // {
      //   path: 'test',
      //   component: () => import('@/views/api/test'),
      //   name: 'test',
      //   meta: { title: '测试', roles: ['1'] }
      // }
    ]
  },
  {
    path: '/appmngr',
    component: Layout,
    name: 'app',
    meta: { title: '应用管理', icon: 'ic_appmngr' },
    children: [
      {
        path: 'apptype',
        component: () => import('@/views/app/type'),
        name: 'apptype',
        meta: { title: '应用类型', roles: ['1'] }
      },
      {
        path: 'appapprove',
        component: () => import('@/views/app/approve'),
        name: 'appapprove',
        meta: { title: '应用审核', roles: ['1'] }
      },
      {
        path: 'applist',
        component: () => import('@/views/app/list'),
        name: 'list',
        meta: { title: '应用列表', roles: ['1'] }
      },
      {
        path: 'detail',
        component: () => import('@/views/app/detail.vue'),
        name: 'detail',
        hidden: true,
        meta: { title: '应用详情', icon: 'ic_report', roles: ['1'], noCache: true }
      }
    ]
  },
  {
    path: '/developermngr',
    component: Layout,
    name: 'developer',
    meta: { title: '开发者管理', icon: 'ic_devmngr' },
    children: [
      /* {
        path: 'devapprove',
        component: () => import('@/views/developer/approve'),
        name: 'devapprove',
        meta: { title: '开发者审核', roles: ['1'] }
      },*/
      {
        path: 'devlist',
        component: () => import('@/views/developer/list'),
        name: 'devlist',
        meta: { title: '开发者列表', roles: ['1'] }
      }
    ]
  },
  /* {
    path: '/report',
    component: Layout,
    name: 'report',
    meta: { title: '统计报表', icon: 'international' },
    children: [
      {
        path: 'reportapi',
        component: () => import('@/views/report/api'),
        name: 'reportapi',
        meta: { title: '接口统计', roles: ['1'] }
      },
      {
        path: 'reportlog',
        component: () => import('@/views/report/log'),
        name: 'reportlog',
        meta: { title: '日志统计', roles: ['1'] }
      }
    ]
  },*/
  {
    path: '/apilist',
    component: Layout,
    children: [
      {
        path: 'apilist',
        component: () => import('@/views/devbase/app/apilist'),
        name: 'apilist',
        meta: { title: '接口列表', icon: 'ic_report', roles: ['2', '3'] }
      },
      {
        path: 'detail/:id',
        component: () => import('@/views/devbase/app/applistdetail.vue'),
        name: 'detail',
        hidden: true,
        meta: { title: '接口详情', icon: 'ic_report', roles: ['2', '3'], noCache: true }
      }
    ]
  },
  {
    path: '/devapp',
    component: Layout,
    children: [
      {
        path: 'mngr',
        component: () => import('@/views/devbase/app/mngr'),
        name: 'mngr',
        meta: { title: '我的应用', icon: 'ic_appmngr', roles: ['2', '3'] }
      }
    ]
  },
  {
    path: '/devreport',
    component: Layout,
    children: [
      {
        path: 'devreport',
        component: () => import('@/views/devbase/app/devreport'),
        name: 'devreport',
        meta: { title: '调用统计', icon: 'ic_report', roles: ['2', '3'] }
      }
    ]
  },
  {
    path: '/devappreport',
    component: Layout,
    children: [
      {
        path: 'appreport',
        component: () => import('@/views/devbase/app/report'),
        name: 'appreport',
        meta: { title: '日志管理', icon: 'ic_report', roles: ['1', '2', '3'] }
      }
    ]
  },
  {
    path: '/devappdetail',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'appdetail',
        component: () => import('@/views/devbase/app/detail'),
        name: 'appdetail',
        hidden: true,
        meta: { title: '应用详情', roles: ['2', '3'] }
      },
      {
        path: 'viewdetail',
        component: () => import('@/views/devbase/app/viewDetail'),
        name: 'viewdetail',
        hidden: true,
        meta: { title: '应用详情', roles: ['2', '3'] }
      }
    ]
  },
  // 收藏列表
  {
    path: '/collect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/collect/index'),
        name: 'collect',
        meta: { title: '收藏列表', icon: 'ic_collect', roles: ['2', '3'] }
      }
    ]
  },
  // 我的申请
  {
    path: '/apply',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'apply',
        component: () => import('@/views/devbase/app/apply'),
        name: 'apply',
        meta: { title: '我的申请', icon: 'ic_collect', roles: ['2', '3'] }
      }
    ]
  },
  /* {
    path: '/devapp',
    component: Layout,
    name: 'devapp',
    meta: { title: '应用管理', icon: 'international' },
    children: [
      {
        path: 'mngr',
        component: () => import('@/views/devbase/app/mngr'),
        name: 'mngr',
        meta: { title: '管理应用', roles: ['2', '3'] }
      },
      {
        path: 'appreport',
        component: () => import('@/views/devbase/app/report'),
        name: 'appreport',
        meta: { title: '监控报表', roles: ['2', '3'] }
      },
      {
        path: 'appdetail',
        component: () => import('@/views/devbase/app/detail'),
        name: 'appdetail',
        hidden: true,
        meta: { title: '应用详情', roles: ['2', '3'] }
      }
    ]
  },
  {
    path: '/devapi',
    component: Layout,
    name: 'devapi',
    meta: { title: '接口管理', icon: 'international' },
    children: [
      {
        path: 'devapireport',
        component: () => import('@/views/devbase/api/report'),
        name: 'devapireport',
        meta: { title: '接口调用统计', roles: ['2', '3'] }
      },
      {
        path: 'devapilog',
        component: () => import('@/views/devbase/api/log'),
        name: 'devapilog',
        meta: { title: '接口调用日志', roles: ['2', '3'] }
      }
    ]
  },*/
  {
    path: '/system',
    component: Layout,
    name: 'system',
    meta: { title: '系统管理', icon: 'ic_system' },
    children: [
      {
        path: 'user',
        component: () => import('@/views/system/user'),
        name: 'user',
        meta: { title: '账号管理', roles: ['1'] }
      },
      {
        path: 'role',
        component: () => import('@/views/system/role'),
        name: 'role',
        meta: { title: '角色管理', roles: ['1'] }
      },
      // {
      //   path: 'errorcode',
      //   component: () => import('@/views/system/errorcode'),
      //   name: 'errorcode',
      //   meta: { title: '错误管理', roles: ['1'] }
      // },
      {
        path: 'log',
        component: () => import('@/views/system/log'),
        name: 'log',
        meta: { title: '系统日志', roles: ['1'] }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
