增加jwt主动失效功能(next:多点登录限制
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import service from '@/utils/request'
|
||||
|
||||
// @Tags jwt
|
||||
// @Summary jwt加入黑名单
|
||||
// @Security ApiKeyAuth
|
||||
// @accept application/json
|
||||
// @Produce application/json
|
||||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"拉黑成功"}"
|
||||
// @Router /jwt/jsonInBlacklist [post]
|
||||
|
||||
export const jsonInBlacklist = () => {
|
||||
return service({
|
||||
url: "/jwt/jsonInBlacklist",
|
||||
method: 'post',
|
||||
})
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { login } from '@/api/user'
|
||||
import { jsonInBlacklist } from '@/api/jwt'
|
||||
import router from '@/router/index'
|
||||
export const user = {
|
||||
namespaced: true,
|
||||
@@ -52,6 +53,12 @@ export const user = {
|
||||
router.push({ path: '/layout/dashbord' })
|
||||
}
|
||||
}
|
||||
},
|
||||
async LoginOut({ commit }) {
|
||||
const res = await jsonInBlacklist()
|
||||
if (res.success) {
|
||||
commit("LoginOut")
|
||||
}
|
||||
}
|
||||
},
|
||||
getters: {
|
||||
|
||||
@@ -61,11 +61,13 @@ service.interceptors.response.use(
|
||||
Message({
|
||||
showClose: true,
|
||||
message: response.data.msg,
|
||||
type: 'error'
|
||||
type: 'error',
|
||||
onClose: () => {
|
||||
if (response.data.data && response.data.data.reload) {
|
||||
store.commit('user/LoginOut')
|
||||
}
|
||||
}
|
||||
})
|
||||
if (response.data.data && response.data.data.reload) {
|
||||
store.commit('user/LoginOut')
|
||||
}
|
||||
return Promise.reject(response.data.msg)
|
||||
}
|
||||
},
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
|
||||
<script>
|
||||
import Aside from '@/view/layout/aside'
|
||||
import { mapGetters, mapMutations } from 'vuex'
|
||||
import { mapGetters, mapActions } from 'vuex'
|
||||
export default {
|
||||
name: 'Layout',
|
||||
data() {
|
||||
@@ -63,7 +63,7 @@ export default {
|
||||
Aside
|
||||
},
|
||||
methods: {
|
||||
...mapMutations('user', ['LoginOut']),
|
||||
...mapActions('user', ['LoginOut']),
|
||||
totalCollapse() {
|
||||
this.isCollapse = !this.isCollapse
|
||||
this.$bus.emit('totalCollapse')
|
||||
|
||||
Reference in New Issue
Block a user