import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
const routes = [
  {
    path: "/",
    component: () => import('@/views/index'),
  },

  {
    path:'/admin/login',
    name:'Login',
    meta: {
      title: '系统登录'
    },
    component: () => import("../views/login/index.vue")
  },
  {
    path: "/admin",
    component: () => import('@/views/layout/index.vue'),
    children: [
      {
        path: 'user',
        meta: {
          title: '人员管理',
          active: 'user'
        },
        component: () => import('@/views/user/index.vue')
      },
      {
        path: 'admin',
        meta: {
          title: '管理员管理',
          active: 'admin'
        },
        component: () => import('@/views/admin/index.vue')
      },
      {
        path: 'role',
        meta: {
          title: '角色管理',
          active: 'role'
        },
        component: () => import('@/views/role/index.vue')
      },
      {
        path: 'department',
        meta: {
          title: '部门管理',
          active: 'department'
        },
        component: () => import('@/views/department/index.vue')
      },
      {
        path: 'client',
        meta: {
          title: '租户管理',
          active: 'client'
        },
        component: () => import('@/views/client/index.vue')
      },
      {
        path: 'apply',
        meta: {
          title: '应用管理',
          active: 'apply'
        },
        component: () => import('@/views/apply/index.vue')
      },
      {
        path: 'function',
        meta: {
          title: '功能管理',
          active: 'function'
        },
        component: () => import('@/views/function/index.vue')
      },
      {
        path: 'position',
        meta: {
          title: '职位管理',
          active: 'position'
        },
        component: () => import('@/views/position/index.vue')
      },
      {
        path: 'departmentRole',
        meta: {
          title: '部门角色管理',
          active: 'departmentRole'
        },
        component: () => import('@/views/departmentRole/index.vue')
      },
      {
        path: 'group',
        meta: {
          title: '用户组管理',
          active: 'group'
        },
        component: () => import('@/views/group/index.vue')
      },
      {
        path: 'dataPermission',
        meta: {
          title: '数据权限管理',
          active: 'dataPermission'
        },
        component: () => import('@/views/dataPermission/index.vue')
      },
    ]
  },
 
]

const router = new VueRouter({
  mode: 'history',
  base: '/',
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  }
  next();
})

router.afterEach((to, from) => {

});

export default router
