增加jwt主动失效功能(next:多点登录限制

This commit is contained in:
pixel
2019-12-28 18:32:47 +08:00
parent 22820d9983
commit 7e3870490f
11 changed files with 114 additions and 10 deletions
+16
View File
@@ -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',
})
}
+7
View File
@@ -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: {
+6 -4
View File
@@ -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)
}
},
+2 -2
View File
@@ -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')