mirror of
http://112.124.100.131/ebiz-ai/ebiz-ai-knowledge-manage.git
synced 2025-12-06 17:36:48 +08:00
fix(store): 修复获取路由信息失败时的处理逻辑
- 添加了对路由信息请求失败时的错误处理 - 在路由信息请求失败时显示错误消息并移除 token - 优化了代码格式,调整了部分缩进和换行
This commit is contained in:
@@ -2,7 +2,7 @@ import router from '@/router'
|
||||
import store from '@/store'
|
||||
import NProgress from 'nprogress' // progress bar
|
||||
import 'nprogress/nprogress.css' // progress bar style
|
||||
import { getToken } from '@/assets/js/utils/auth' // get token from cookie
|
||||
import { getToken, removeToken } from '@/assets/js/utils/auth' // get token from cookie
|
||||
import getPageTitle from '@/assets/js/utils/get-page-title'
|
||||
import { Message } from 'element-ui'
|
||||
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
||||
@@ -16,6 +16,7 @@ router.beforeEach((to, from, next) => {
|
||||
console.log(getToken())
|
||||
/* has token*/
|
||||
if (to.path === '/login') {
|
||||
removeToken()
|
||||
next({ path: '/login' })
|
||||
NProgress.done()
|
||||
} else {
|
||||
|
||||
@@ -363,7 +363,8 @@ h3 {
|
||||
}
|
||||
|
||||
#app .sidebar-container .horizontal-collapse-transition {
|
||||
transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out;
|
||||
transition: 0s width ease-in-out, 0s padding-left ease-in-out,
|
||||
0s padding-right ease-in-out;
|
||||
}
|
||||
|
||||
#app .sidebar-container .scrollbar-wrapper {
|
||||
@@ -423,7 +424,7 @@ h3 {
|
||||
}
|
||||
|
||||
#app .hideSidebar .sidebar-container {
|
||||
width: 54px !important;
|
||||
/*width: 54px !important;*/
|
||||
}
|
||||
|
||||
#app .hideSidebar .main-container {
|
||||
@@ -676,7 +677,8 @@ body {
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
text-rendering: optimizeLegibility;
|
||||
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB, Microsoft YaHei, Arial, sans-serif;
|
||||
font-family: Helvetica Neue, Helvetica, PingFang SC, Hiragino Sans GB,
|
||||
Microsoft YaHei, Arial, sans-serif;
|
||||
}
|
||||
|
||||
label {
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
|
||||
// reset element-ui css
|
||||
.horizontal-collapse-transition {
|
||||
transition: 0s width ease-in-out, 0s padding-left ease-in-out, 0s padding-right ease-in-out;
|
||||
transition: 0s width ease-in-out, 0s padding-left ease-in-out,
|
||||
0s padding-right ease-in-out;
|
||||
}
|
||||
|
||||
.scrollbar-wrapper {
|
||||
@@ -89,7 +90,7 @@
|
||||
|
||||
.hideSidebar {
|
||||
.sidebar-container {
|
||||
width: 54px !important;
|
||||
//width: 54px !important;
|
||||
}
|
||||
|
||||
.main-container {
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
import Cookies from 'js-cookie'
|
||||
import { getRouters } from '@/api/app/user'
|
||||
import { Message } from 'element-ui'
|
||||
import { removeToken } from '@/assets/js/utils/auth'
|
||||
|
||||
const state = {
|
||||
sidebar: {
|
||||
opened: Cookies.get('sidebarStatus') ? !!+Cookies.get('sidebarStatus') : true,
|
||||
opened: Cookies.get('sidebarStatus')
|
||||
? !!+Cookies.get('sidebarStatus')
|
||||
: true,
|
||||
withoutAnimation: false
|
||||
},
|
||||
device: 'desktop',
|
||||
@@ -51,6 +55,18 @@ const actions = {
|
||||
return new Promise(resolve => {
|
||||
// 向后端请求路由数据
|
||||
getRouters().then(res => {
|
||||
console.log(res)
|
||||
if (res) {
|
||||
if (res.content.result === '0') {
|
||||
commit('SET_SIDEBAR_LIST', res.content.content)
|
||||
} else {
|
||||
Message.error(res.content.message)
|
||||
removeToken()
|
||||
}
|
||||
} else {
|
||||
Message.error('请求失败')
|
||||
}
|
||||
|
||||
// const sdata = JSON.parse(JSON.stringify(res.data))
|
||||
// const rdata = JSON.parse(JSON.stringify(res.data))
|
||||
// const sidebarRoutes = filterAsyncRouter(sdata)
|
||||
@@ -62,7 +78,7 @@ const actions = {
|
||||
// commit('SET_SIDEBAR_ROUTERS', constantRoutes.concat(sidebarRoutes))
|
||||
// commit('SET_DEFAULT_ROUTES', sidebarRoutes)
|
||||
// commit('SET_TOPBAR_ROUTES', sidebarRoutes)
|
||||
commit('SET_SIDEBAR_LIST', res.content.content)
|
||||
|
||||
resolve()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user