fix Login页面相关的问题

This commit is contained in:
lb 2023-05-26 11:10:45 +08:00
parent 66efe8c476
commit ef9f36c75d
3 changed files with 41 additions and 24 deletions

View File

@ -38,8 +38,8 @@
<% if (process.env.VUE_APP_NODE_ENV === 'dev') { %> <% if (process.env.VUE_APP_NODE_ENV === 'dev') { %>
<script> <script>
// window.SITE_CONFIG['apiURL'] = 'http://192.168.1.103:8080/pms-am'; // window.SITE_CONFIG['apiURL'] = 'http://192.168.1.103:8080/pms-am';
// window.SITE_CONFIG['apiURL'] = 'http://192.168.1.49:8080/pms-am'; // tengyun window.SITE_CONFIG['apiURL'] = 'http://192.168.1.49:8080/pms-am'; // tengyun
window.SITE_CONFIG['apiURL'] = 'http://192.168.1.62:8080/pms-am'; // tao // window.SITE_CONFIG['apiURL'] = 'http://192.168.1.62:8080/pms-am'; // tao
// window.SITE_CONFIG['apiURL'] = 'http://192.168.1.21:8080/pms-am'; // xv // window.SITE_CONFIG['apiURL'] = 'http://192.168.1.21:8080/pms-am'; // xv
// window.SITE_CONFIG['apiURL'] = 'http://localhost:3000/p//////ms-am'; // xv // window.SITE_CONFIG['apiURL'] = 'http://localhost:3000/p//////ms-am'; // xv
</script> </script>

View File

@ -9,6 +9,7 @@ import Vue from 'vue'
import Router from 'vue-router' import Router from 'vue-router'
import http from '@/utils/request' import http from '@/utils/request'
import { isURL } from '@/utils/validate' import { isURL } from '@/utils/validate'
import { isAuthentcated } from '../utils'
Vue.use(Router) Vue.use(Router)
@ -19,7 +20,7 @@ export const pageRoutes = [
component: () => import('@/views/pages/404'), component: () => import('@/views/pages/404'),
name: '404', name: '404',
meta: { title: '404未找到' }, meta: { title: '404未找到' },
beforeEnter (to, from, next) { beforeEnter(to, from, next) {
// 拦截处理特殊业务场景 // 拦截处理特殊业务场景
// 如果, 重定向路由包含__双下划线, 为临时添加路由 // 如果, 重定向路由包含__双下划线, 为临时添加路由
if (/__.*/.test(to.redirectedFrom)) { if (/__.*/.test(to.redirectedFrom)) {
@ -43,7 +44,7 @@ export const moduleRoutes = {
] ]
} }
export function addDynamicRoute (routeParams, router) { export function addDynamicRoute(routeParams, router) {
// 组装路由名称, 并判断是否已添加, 如是: 则直接跳转 // 组装路由名称, 并判断是否已添加, 如是: 则直接跳转
var routeName = routeParams.routeName var routeName = routeParams.routeName
var dynamicRoute = window.SITE_CONFIG['dynamicRoutes'].filter(item => item.name === routeName)[0] var dynamicRoute = window.SITE_CONFIG['dynamicRoutes'].filter(item => item.name === routeName)[0]
@ -82,15 +83,22 @@ router.beforeEach((to, from, next) => {
// 添加动态(菜单)路由 // 添加动态(菜单)路由
// 已添加或者当前路由为页面路由, 可直接访问 // 已添加或者当前路由为页面路由, 可直接访问
if (window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] || fnCurrentRouteIsPageRoute(to, pageRoutes)) { if (window.SITE_CONFIG['dynamicMenuRoutesHasAdded'] || fnCurrentRouteIsPageRoute(to, pageRoutes)) {
// 如果是在已认证的情况下直接访问登录界面
if (to.name === 'login') {
return next('/')
}
return next() return next()
} }
if (isAuthentcated()) {
// 获取字典列表, 添加并全局变量保存 // 获取字典列表, 添加并全局变量保存
http.get('/sys/dict/type/all').then(({ data: res }) => { http.get('/sys/dict/type/all').then(({ data: res }) => {
if (res.code !== 0) { if (res.code !== 0) {
return return
} }
window.SITE_CONFIG['dictList'] = res.data window.SITE_CONFIG['dictList'] = res.data
}).catch(() => {}) }).catch(() => { })
// 获取菜单列表, 添加并全局变量保存 // 获取菜单列表, 添加并全局变量保存
http.get('/sys/menu/nav').then(({ data: res }) => { http.get('/sys/menu/nav').then(({ data: res }) => {
if (res.code !== 0) { if (res.code !== 0) {
@ -103,6 +111,11 @@ router.beforeEach((to, from, next) => {
}).catch(() => { }).catch(() => {
next({ name: 'login' }) next({ name: 'login' })
}) })
} else {
next({ name: 'login' })
}
}) })
/** /**
@ -110,7 +123,7 @@ router.beforeEach((to, from, next) => {
* @param {*} route 当前路由 * @param {*} route 当前路由
* @param {*} pageRoutes 页面路由 * @param {*} pageRoutes 页面路由
*/ */
function fnCurrentRouteIsPageRoute (route, pageRoutes = []) { function fnCurrentRouteIsPageRoute(route, pageRoutes = []) {
var temp = [] var temp = []
for (var i = 0; i < pageRoutes.length; i++) { for (var i = 0; i < pageRoutes.length; i++) {
if (route.path === pageRoutes[i].path) { if (route.path === pageRoutes[i].path) {
@ -128,7 +141,7 @@ function fnCurrentRouteIsPageRoute (route, pageRoutes = []) {
* @param {*} menuList 菜单列表 * @param {*} menuList 菜单列表
* @param {*} routes 递归创建的动态(菜单)路由 * @param {*} routes 递归创建的动态(菜单)路由
*/ */
function fnAddDynamicMenuRoutes (menuList = [], routes = []) { function fnAddDynamicMenuRoutes(menuList = [], routes = []) {
var temp = [] var temp = []
for (var i = 0; i < menuList.length; i++) { for (var i = 0; i < menuList.length; i++) {
if (menuList[i].children && menuList[i].children.length >= 1) { if (menuList[i].children && menuList[i].children.length >= 1) {

View File

@ -97,3 +97,7 @@ export function treeDataTranslate (data, id = 'id', pid = 'pid') {
} }
return res return res
} }
export function isAuthentcated() {
return Cookies.get('token')
}