From ec7cc88fca8de4b3c56f8ebee074fb7ce71ebf1e Mon Sep 17 00:00:00 2001
From: jiangping <jp@doumee.com>
Date: 星期三, 02 七月 2025 10:39:12 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
admin/src/router/index.js | 130 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 130 insertions(+), 0 deletions(-)
diff --git a/admin/src/router/index.js b/admin/src/router/index.js
new file mode 100644
index 0000000..c8bf2a8
--- /dev/null
+++ b/admin/src/router/index.js
@@ -0,0 +1,130 @@
+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
--
Gitblit v1.9.3