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

// 页面刷新时，重新赋值token
if (window.sessionStorage.getItem('token')) {
  // eslint-disable-next-line
  store.commit(types.LOGIN, window.sessionStorage.getItem('token'));
}

export const constantRouterMap = [
  {
    path: '/',
    name: '/',
    redirect: '/versionList'
  },
  {
    path: '/haoban',
    name: '好办运维后台',
    redirect: '/versionList',
    component: _import('haoban', 'haobanIndex'),
    children: [
      {
        path: '/versionList',
        name: '版本更新管理',
        component: _import('haoban', 'versionList')
      },
      {
        path: '/addSet',
        name: '添加设置',
        component: _import('haoban', 'addSet')
      },
      {
        path: '/setDetail',
        name: '详情',
        component: _import('haoban', 'setDetail')
      },
      {
        path: '/adList',
        name: '广告列表',
        component: _import('haoban', 'adList')
      }
    ]
  },

  {
    path: '/401',
    name: '无权访问',
    component: _import('error', '401')
  },
  {
    path: '/404',
    name: '不存在',
    component: _import('error', '404')
  },

  { path: '*', redirect: '/404', hidden: true }
];
export default new Router({
  routes: constantRouterMap
  // scrollBehavior: () => ({ y: 0 })

  //使用keep-alive标签后部分安卓机返回缓存页位置不精确问题
  // scrollBehavior(to, from, savedPosition) {
  //   if (savedPosition && to.meta.keepAlive) {
  //     return savedPosition;
  //   }
  //   const layoutRight = document.querySelector('.layout-right');
  //   if (layoutRight) {
  //     layoutRight.scrollTo(0,0);
  //   }
  // }
});
