| ¶Ô±ÈÐÂÎļþ |
| | |
| | | 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({ |
| | | base: process.env.VUE_APP_CONTEXT_PATH + (process.env.VUE_APP_ROUTER_MODE === 'hash' ? '#' : ''), |
| | | 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 |
| | | } |
| | | 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() |
| | | window.addEventListener('resize', function(){ |
| | | computeTableHeightIndex()} |
| | | ) |
| | | }, 1000) |
| | | }) |
| | | 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 |
| | | // 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 |