mirror of
https://gitee.com/ssssssss-team/magic-boot.git
synced 2025-03-15 19:43:36 +08:00
凭证过期,提示重新登录
This commit is contained in:
parent
ea9bf5b3bd
commit
1c4bfc10fd
@ -6,7 +6,6 @@ import NProgress from 'nprogress' // progress bar
|
|||||||
import 'nprogress/nprogress.css' // progress bar style
|
import 'nprogress/nprogress.css' // progress bar style
|
||||||
import { getToken } from '@/scripts/auth' // get token from cookie
|
import { getToken } from '@/scripts/auth' // get token from cookie
|
||||||
import getPageTitle from '@/scripts/get-page-title'
|
import getPageTitle from '@/scripts/get-page-title'
|
||||||
import axios from 'axios'
|
|
||||||
|
|
||||||
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
NProgress.configure({ showSpinner: false }) // NProgress Configuration
|
||||||
|
|
||||||
@ -23,24 +22,6 @@ router.beforeEach(async(to, from, next) => {
|
|||||||
const hasToken = getToken()
|
const hasToken = getToken()
|
||||||
|
|
||||||
if (hasToken) {
|
if (hasToken) {
|
||||||
var tokenIsOverdue
|
|
||||||
await axios({
|
|
||||||
baseURL: process.env.VUE_APP_BASE_API,
|
|
||||||
url: 'security/validateToken',
|
|
||||||
params: {
|
|
||||||
token: hasToken
|
|
||||||
}
|
|
||||||
}).then(res => {
|
|
||||||
const { data } = res
|
|
||||||
tokenIsOverdue = data.data
|
|
||||||
})
|
|
||||||
if (to.path !== '/login' && !tokenIsOverdue) {
|
|
||||||
// if (to.path !== '/login') {
|
|
||||||
store.dispatch('user/logout').then(() => {
|
|
||||||
next(`/login`)
|
|
||||||
NProgress.done()
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
if (to.path === '/login') {
|
if (to.path === '/login') {
|
||||||
// if is logged in, redirect to the home page
|
// if is logged in, redirect to the home page
|
||||||
next({ path: '/' })
|
next({ path: '/' })
|
||||||
@ -73,7 +54,6 @@ router.beforeEach(async(to, from, next) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
/* has no token*/
|
/* has no token*/
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { Message } from 'element-ui'
|
import { Message, MessageBox } from 'element-ui'
|
||||||
import store from '@/store'
|
import store from '@/store'
|
||||||
import { getToken } from '@/scripts/auth'
|
import { getToken } from '@/scripts/auth'
|
||||||
|
|
||||||
@ -51,6 +51,23 @@ service.interceptors.response.use(
|
|||||||
var duration = 5
|
var duration = 5
|
||||||
if (res.code === 402) {
|
if (res.code === 402) {
|
||||||
duration = 1
|
duration = 1
|
||||||
|
MessageBox.prompt('凭证已过期,请输入密码重新登录', '提示', {
|
||||||
|
confirmButtonText: '确定',
|
||||||
|
cancelButtonText: '退出',
|
||||||
|
inputType: 'password'
|
||||||
|
}).then(({ value }) => {
|
||||||
|
store.dispatch('user/login', {
|
||||||
|
username: store.getters.username,
|
||||||
|
password: value
|
||||||
|
}).then((res) => {
|
||||||
|
console.log(res)
|
||||||
|
})
|
||||||
|
}).catch(() => {
|
||||||
|
store.dispatch('user/logout').then(() => {
|
||||||
|
location.reload()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
return
|
||||||
}
|
}
|
||||||
if (isShowMsg === false) {
|
if (isShowMsg === false) {
|
||||||
Message({
|
Message({
|
||||||
|
@ -6,6 +6,7 @@ const getters = {
|
|||||||
token: state => state.user.token,
|
token: state => state.user.token,
|
||||||
avatar: state => state.user.avatar,
|
avatar: state => state.user.avatar,
|
||||||
name: state => state.user.name,
|
name: state => state.user.name,
|
||||||
|
username: state => state.user.username,
|
||||||
roles: state => state.user.roles,
|
roles: state => state.user.roles,
|
||||||
permission_routes: state => state.permission.routes,
|
permission_routes: state => state.permission.routes,
|
||||||
errorLogs: state => state.errorLog.logs
|
errorLogs: state => state.errorLog.logs
|
||||||
|
@ -6,7 +6,8 @@ import { resetRouter } from '@/router'
|
|||||||
const getDefaultState = () => {
|
const getDefaultState = () => {
|
||||||
return {
|
return {
|
||||||
token: getToken(),
|
token: getToken(),
|
||||||
name: ''
|
name: '',
|
||||||
|
username: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,6 +22,9 @@ const mutations = {
|
|||||||
},
|
},
|
||||||
SET_NAME: (state, name) => {
|
SET_NAME: (state, name) => {
|
||||||
state.name = name
|
state.name = name
|
||||||
|
},
|
||||||
|
SET_USERNAME: (state, username) => {
|
||||||
|
state.username = username
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +37,7 @@ const actions = {
|
|||||||
const { data } = response
|
const { data } = response
|
||||||
commit('SET_TOKEN', data)
|
commit('SET_TOKEN', data)
|
||||||
setToken(data)
|
setToken(data)
|
||||||
resolve()
|
resolve(data)
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error)
|
reject(error)
|
||||||
})
|
})
|
||||||
@ -54,6 +58,7 @@ const actions = {
|
|||||||
}
|
}
|
||||||
Vue.prototype.$authorities = authorities_
|
Vue.prototype.$authorities = authorities_
|
||||||
commit('SET_NAME', data.name)
|
commit('SET_NAME', data.name)
|
||||||
|
commit('SET_USERNAME', data.username)
|
||||||
resolve()
|
resolve()
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
reject(error)
|
reject(error)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user