From ecf4ef987e0275acdb6c9d84426c96453b7b072b Mon Sep 17 00:00:00 2001 From: ZhengJie <201507802@qq.com> Date: Thu, 4 Jun 2020 16:06:35 +0800 Subject: [PATCH] =?UTF-8?q?[=E4=BB=A3=E7=A0=81=E5=AE=8C=E5=96=84](v2.5):?= =?UTF-8?q?=20v2.5=20=E4=BF=AE=E6=94=B9Token=E8=BF=87=E6=9C=9F=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 由原来的弹窗提示改为登录界面消息提示 --- src/utils/request.js | 19 ++++++------------- src/views/login.vue | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/utils/request.js b/src/utils/request.js index f997d12..9cf0155 100644 --- a/src/utils/request.js +++ b/src/utils/request.js @@ -1,9 +1,10 @@ import axios from 'axios' import router from '@/router/routers' -import { Notification, MessageBox } from 'element-ui' +import { Notification } from 'element-ui' import store from '../store' import { getToken } from '@/utils/auth' import Config from '@/settings' +import Cookies from 'js-cookie' // 创建axios实例 const service = axios.create({ @@ -55,18 +56,10 @@ service.interceptors.response.use( } if (code) { if (code === 401) { - MessageBox.confirm( - '登录状态已过期,您可以继续留在该页面,或者重新登录', - '系统提示', - { - confirmButtonText: '重新登录', - cancelButtonText: '取消', - type: 'warning' - } - ).then(() => { - store.dispatch('LogOut').then(() => { - location.reload() // 为了重新实例化vue-router对象 避免bug - }) + store.dispatch('LogOut').then(() => { + // 用户登录界面提示 + Cookies.set('point', 401) + location.reload() }) } else if (code === 403) { router.push({ path: '/401' }) diff --git a/src/views/login.vue b/src/views/login.vue index 7cc70ae..837b5b5 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -79,8 +79,12 @@ export default { } }, created() { + // 获取验证码 this.getCode() + // 获取用户名密码等Cookie this.getCookie() + // token 过期提示 + this.point() }, methods: { getCode() { @@ -138,6 +142,18 @@ export default { return false } }) + }, + point() { + const point = Cookies.get('point') !== undefined + if (point) { + this.$notify({ + title: '提示', + message: '当前登录状态已过期,请重新登录!', + type: 'warning', + duration: 8000 + }) + Cookies.remove('point') + } } } }