diff --git a/package-lock.json b/package-lock.json index f38ecf8..9a505de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6917,6 +6917,11 @@ "resolved": "https://registry.npm.taobao.org/js-base64/download/js-base64-2.5.2.tgz", "integrity": "sha1-MTtidN2nGPcU0AszMLuubjjpAgk=" }, + "js-cookie": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.1.tgz", + "integrity": "sha512-+0rgsUXZu4ncpPxRL+lNEptWMOWl9etvPHc/koSRp6MPwpRYAhmk0dUG00J4bxVV3r9uUzfo24wW0knS07SKSw==" + }, "js-message": { "version": "1.0.7", "resolved": "https://registry.npmjs.org/js-message/-/js-message-1.0.7.tgz", diff --git a/package.json b/package.json index 5897dd4..6db4a8e 100644 --- a/package.json +++ b/package.json @@ -13,6 +13,7 @@ "core-js": "^3.19.3", "element-ui": "^2.15.6", "jquery": "^3.6.0", + "js-cookie": "^3.0.1", "lib-flexible": "^0.3.2", "postcss-px2rem": "^0.3.0", "postcss-pxtorem": "^5.1.1", diff --git a/src/api/http.js b/src/api/http.js index 685bd79..4f35222 100644 --- a/src/api/http.js +++ b/src/api/http.js @@ -3,7 +3,7 @@ import { Message } from 'element-ui' import router from '../router/index' -import util from '@/util' +import Cookie from 'js-cookie' import config from '@/config' const service = axios.create({ @@ -15,7 +15,7 @@ const service = axios.create({ service.defaults.headers.post['Content-Type'] = 'application/json;charset=UTF-8'; // 请求拦截器 service.interceptors.request.use(config => { - const token = util.getCookie('token') + const token = Cookie.get('admin-token') if (token) { config.headers.token = token } @@ -49,7 +49,10 @@ service.interceptors.response.use( switch (error.response.status) { // 401: 未登录 case 401: - history.back() + Message.error('登录过期,请重新登录') + setTimeout(() => { + history.back() + }, 1500) break; default: // Message.error(error.response.data.message) diff --git a/src/components/TestPanel.vue b/src/components/TestPanel.vue index dd83286..bbff075 100644 --- a/src/components/TestPanel.vue +++ b/src/components/TestPanel.vue @@ -127,21 +127,22 @@ + \ No newline at end of file diff --git a/src/components/codemirror.vue b/src/components/codemirror.vue index f90d49e..139a2dc 100644 --- a/src/components/codemirror.vue +++ b/src/components/codemirror.vue @@ -82,6 +82,7 @@