提交 67328219 authored 作者: pengxiaohui's avatar pengxiaohui

修复退出登录bug

上级 09bdada6
......@@ -56,7 +56,6 @@ export default {
if (path.includes('error-page')) {
path = '/calendar'
}
console.log(path)
this.$router.push(path)
}
}
......
......@@ -3,13 +3,31 @@ import Router from 'vue-router'
import routes from './routes'
Vue.use(Router)
const originalPush = Router.prototype.push
Router.prototype.push = function push(location, onResolve, onReject) {
if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject)
return originalPush.call(this, location).catch(err => err)
}
export default new Router({
routes,
mode: 'history', // 还有一个 hash 默认
fallback: true // 浏览器不支持 history时,自动改成 hash方式
export const asyncRoutes = [...routes]
const createRouter = () => new Router({
mode: 'history', // require service support
scrollBehavior: () => ({ y: 0 }),
routes: routes
})
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
const newRouter = createRouter()
router.matcher = newRouter.matcher // reset router
}
export default router
// export default new Router({
// routes,
// mode: 'history', // 还有一个 hash 默认
// fallback: true // 浏览器不支持 history时,自动改成 hash方式
// })
......@@ -85,12 +85,12 @@ export default [
path: '/tencent',
component: Layout,
redirect: '/tencent/account',
name: 'System',
name: 'Tencent',
meta: { title: '腾讯会议管理', icon: 'el-icon-setting' },
children: [
{
path: 'account',
name: 'Account',
name: 'TencentAccount',
component: () => import('@/pages/tencent/account/index'),
meta: { title: '账号管理', icon: 'el-icon-key', roles: ['administrator'] }
}
......
import { getUser, logout } from '@/api/account'
import { getUserRoles } from '@/api/system'
import { resetRouter } from '@/router'
const user = {
state: {
user: {},
......@@ -8,7 +9,6 @@ const user = {
isSuperAdmin: false,
hasRoles: false
},
mutations: {
setUser(state, user) {
state.user = user
......@@ -38,6 +38,10 @@ const user = {
return logout().then(response => {
commit('setUser', {})
commit('setIsLogin', false)
commit('setRoles', [])
commit('setSuperAdmin', false)
commit('setHasRoles', false)
resetRouter()
return response
})
},
......@@ -50,9 +54,14 @@ const user = {
// .catch(() => {
// })
const isLogin = await getUser()
.then(response => {
commit('setUser', response.data)
.then(res => {
if (res.code === 0 && res.data && res.data.id) {
commit('setUser', res.data)
return true
} else {
commit('setUser', {})
return false
}
})
.catch(() => {
commit('setUser', {})
......
......@@ -38,7 +38,7 @@ httpRequest.interceptors.request.use(
httpRequest.interceptors.response.use(
function(response) {
const { data } = response
if (data.code === 1 && data.msg === '请先登录') {
if (data.code === 4001 && data.message === '请重新登录') {
// Message.error(data.msg || data.message)
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
return Promise.reject(data)
......@@ -46,7 +46,6 @@ httpRequest.interceptors.response.use(
return data
},
function(error) {
console.log(error)
if (error.response) {
const { status, message, code } = error.response.data
// 未登录
......@@ -55,8 +54,7 @@ httpRequest.interceptors.response.use(
} else if (status === 400 && code === 401) {
router.push('/role')
} else {
console.log(message)
// Message.error(message || error.response.data)
Message.error(message || error.response.data)
}
return Promise.reject(error.response)
} else if (typeof error === 'string') {
......
......@@ -19,9 +19,8 @@ export default class BeforeEnter {
async update(to, from, next) {
const isLogin = store.state.user.isLogin || (await store.dispatch('checkLogin'))
const loginUrl = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
if (!isLogin) {
window.location.href = loginUrl
window.location.href = this.getLoginUrl()
next()
} else {
const hasRoles = store.state.user.hasRoles || (await store.dispatch('checkRoles'))
......@@ -38,9 +37,19 @@ export default class BeforeEnter {
next()
}
} else {
window.location.href = loginUrl
window.location.href = this.getLoginUrl()
}
}
next()
}
getLoginUrl() {
const loginUrl = webConf.others.loginUrl
let rdUrl = window.location.href
if (rdUrl.includes('error-page')) {
rdUrl = window.location.protocol + '//' + window.location.host
}
console.log(rdUrl)
return `${loginUrl}?rd=${encodeURIComponent(rdUrl)}`
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论