import Vue from 'vue' 
 | 
import VueRouter from 'vue-router' 
 | 
import AppLayout from '@/layouts/AppLayout' 
 | 
import { getUserInfo } from '@/api/system/common' 
 | 
const Login = () => import('@/views/login') 
 | 
const ErrorNoPermissions = () => import('@/views/no-permissions') 
 | 
const Error404 = () => import('@/views/not-found') 
 | 
  
 | 
Vue.use(VueRouter) 
 | 
  
 | 
const router = new VueRouter({ 
 | 
  // + (process.env.VUE_APP_ROUTER_MODE === 'hash' ? '#' : '') 
 | 
  base: process.env.VUE_APP_CONTEXT_PATH, 
 | 
  mode: process.env.VUE_APP_ROUTER_MODE, 
 | 
  routes: [ 
 | 
    // 登录 
 | 
    { 
 | 
      name: 'login', 
 | 
      path: '/login', 
 | 
      component: Login 
 | 
    }, 
 | 
    // 无权限 
 | 
    { 
 | 
      name: 'no-permissions', 
 | 
      path: '/no-permissions', 
 | 
      component: ErrorNoPermissions 
 | 
    }, 
 | 
    // 404 
 | 
    { 
 | 
      name: 'not-found', 
 | 
      path: '/not-found', 
 | 
      component: Error404 
 | 
    }, 
 | 
    // 内容页(动态加载) 
 | 
    { 
 | 
      name: 'layout', 
 | 
      path: '', 
 | 
      component: AppLayout, 
 | 
      children: [] 
 | 
    } 
 | 
  ] 
 | 
}) 
 | 
router.beforeEach((to, from, next) => { 
 | 
  // 无权访问&404页面可直接访问 
 | 
  if (to.name === 'no-permissions' || to.name === 'not-found') { 
 | 
    next() 
 | 
    return 
 | 
  } 
 | 
  // 如果访问的是layout(回退时可能存在该情况),直奔index 
 | 
  if (to.name === 'layout') { 
 | 
    next({ name: 'index' }) 
 | 
    return 
 | 
  } 
 | 
  // 验证用户是否登录 
 | 
  const userInfo = router.app.$options.store.state.userInfo 
 | 
  if (userInfo != null) { 
 | 
    // 如果用户不存在权限 
 | 
    if (userInfo.permissions.length === 0) { 
 | 
      next({ name: 'no-permissions' }) 
 | 
      return 
 | 
    } 
 | 
    // 如果访问的是登录页面,则直接跳转至首页 
 | 
    // if (to.name === 'login') { 
 | 
    //   next({ name: 'index' }) 
 | 
    //   return 
 | 
    // } 
 | 
    next() 
 | 
    return 
 | 
  } 
 | 
  if (to.name === 'login') { 
 | 
    next() 
 | 
    return 
 | 
  } 
 | 
  getUserInfo() 
 | 
    .then(userInfo => { 
 | 
      // 如果用户不存在权限 
 | 
      if (userInfo.permissions.length === 0) { 
 | 
        next({ name: 'no-permissions' }) 
 | 
        return 
 | 
      } 
 | 
      // 已登录,存储userInfo 
 | 
      router.app.$store.commit('setUserInfo', userInfo) 
 | 
      // 如果访问的是登录页面,则直接跳转至首页 
 | 
      if (to.name === 'login') { 
 | 
        next({ name: 'index' }) 
 | 
        return 
 | 
      } 
 | 
      next() 
 | 
    }) 
 | 
    .catch(e => { 
 | 
      // 如果访问的是登录页面,则直接放行 
 | 
      if (to.name === 'login') { 
 | 
        next() 
 | 
        return 
 | 
      } 
 | 
      // 未登录,跳转至登录页 
 | 
      next({ name: 'login' }) 
 | 
    }) 
 | 
}) 
 | 
  
 | 
router.afterEach((to, from, failure) => { 
 | 
  setTimeout(function () { computeTableHeightIndex() }, 1000) 
 | 
  window.addEventListener('resize', computeTableHeightIndex()) 
 | 
}) 
 | 
function computeTableHeightIndex () { 
 | 
  const height = window.innerHeight 
 | 
  console.log('beforeEach========================:' + height) 
 | 
  const height13 = getEleHeghtByClassName('common-header', 0) 
 | 
  const height4 = getEleHeghtByClassName('table-pagination', 0,-20) 
 | 
  const height5 = document.getElementsByTagName('thead') && document.getElementsByTagName('thead')[0] ? document.getElementsByTagName('thead')[0].clientHeight : 0 
 | 
  if (document.getElementsByClassName('main_app') && document.getElementsByClassName('main_app')[0]) { 
 | 
    console.log('main_app========================') 
 | 
    // alert(height) 
 | 
    const height3 = getEleHeghtByClassName('main-header', 0) 
 | 
    const height2 = getEleHeghtByClassName('toolbar', 0) 
 | 
    const height6 = getEleHeghtByClassName('doumee-filter', 0, 16) 
 | 
    const height7 = getEleHeghtByClassName('pt16', 0, 0) 
 | 
    const height9 = getEleHeghtByClassName('static_wrap', 0) 
 | 
    const height10 = getEleHeghtByClassName('query_btns', 0) 
 | 
    const height11 = getEleHeghtByClassName('el-tabs-ele', 0) 
 | 
    const height12 = getEleHeghtByClassName('platgroup_tabs', 0,20) 
 | 
    router.app.$store.commit('setTableHeightNew', height -10 - height2 - height3 - height4 - height5 - height6 - height7 - height9 - height10 - height11 - height12 - height13) 
 | 
    console.log('gableHeightNew', router.app.$store.state.tableHeightNew) 
 | 
  } else { 
 | 
    console.log('tableLayout========================') 
 | 
    const height1 = getEleHeghtByClassName('table-search-form', 40, 16) 
 | 
    const height3 = getEleHeghtByClassName('main-header', 0) 
 | 
    // const height4 = getEleHeghtByClassName('table-pagination', 0,-20) 
 | 
    const height2 = getEleHeghtByClassName('toolbar', 0) 
 | 
    console.log('defualtlength', document.getElementsByClassName('table-search-form').length) 
 | 
    router.app.$store.commit('setTableHeightNew', height - height4 - height3 - height2 - height1 - height5 - height13) 
 | 
    console.log('gableHeightNew', router.app.$store.state.tableHeightNew) 
 | 
  } 
 | 
} 
 | 
  
 | 
function getEleHeghtByClassName (name, dv, margin) { 
 | 
  if ((document.getElementsByClassName(name) && document.getElementsByClassName(name)[0])) { 
 | 
    let t = 0 
 | 
    document.getElementsByClassName(name).forEach(e => { 
 | 
      console.log(name + '========================' + t + ':' + e.clientHeight) 
 | 
      t++ 
 | 
    }) 
 | 
    return document.getElementsByClassName(name)[document.getElementsByClassName(name).length - 1].clientHeight + (margin || 0) 
 | 
  } 
 | 
  return dv || 0 
 | 
} 
 | 
  
 | 
export default router 
 |