import Vue from 'vue'
import Router from 'vue-router'
import _import from './_import.js'
Vue.use(Router);

// const error403 = (r) => {
//   import('views/errorPage/403.vue').then((module) => {
//     r(module)
//   })
// };
// const error404 = (r) => {
//   import('views/errorPage/404.vue').then((module) => {
//     r(module)
//   })
// };
// const error500 = (r) => {
//   import('views/errorPage/500.vue').then((module) => {
//     r(module)
//   })
// };
const errorPage = (r) => {
  import('views/errorPage/index.vue').then((module) => {
    r(module)
  })
};
// 页面刷新时，重新赋值token
if (window.sessionStorage.getItem('token')) {
  store.commit(types.LOGIN, window.sessionStorage.getItem('token'))
}
export const constantRouterMap = [
  {
    path: '/login',
    name: '登录',
    component: _import('login','index')
  },
  {
    path: '/index',
    name: 'index',
    component: _import('index','index'),
  },
  {
    path: '/contacts',
    name: '通讯录',
    component: _import('contacts','index'),
    children: [
      // 通讯录
      {
        path: '/administrativeFrame',
        name: '行政架构',
        component: _import('contacts','administrativeFrame')
      },
      {
        path: '/storeFrame',
        name: '门店架构',
        component: _import('contacts','storeFrame')
      },
      {
        path: '/employee',
        name: '在职员工',
        component: _import('contacts','employee')
      },
      {
        path: '/unemployee',
        name: '离职员工',
        component: _import('contacts','unemployee')
      },
      {
        path: '/fileSet',
        name: '档案设置',
        component: _import('contacts','fileSet')
      },
      {
        path: '/shareContact',
        name: '共享通讯录',
        component: _import('contacts','shareContact')
      },
    ]
  },
  {
    // 企业应用
    path: '/enterpriseApp',
    name: '企业应用',
    component: _import('enterpriseApp','index'),
  },
  {
    // 审核中心
    path: '/reviewCenter',
    name: '审核中心',
    component: _import('reviewCenter','index'),
    children: [
      {
        path: '/reviewed',
        name: '已审核',
        component: _import('reviewCenter','reviewed')
      },
      {
        path: '/unreview',
        name: '未审核',
        component: _import('reviewCenter','unreview')
      },
    ]
  },
  {
    path: '/staffRecordsTemplate',
    name: '员工档案设置',
    component: _import('contacts','staffRecordsTemplate')
  },
  {
    path: '/403',
    name: '无权访问',
    component: errorPage
  },
  {
    path: '/404',
    name: 'error404',
    component: errorPage
  },
  {
    path: '/500',
    name: 'error500',
    component: errorPage
  },
  { path: '*', redirect: '/404', hidden: true },
];
export default new Router({
  // mode:'history',
  routes: constantRouterMap,
  scrollBehavior: () => ({ y: 0 }),
})
