This commit is contained in:
ronger 2021-02-01 18:12:35 +08:00
parent 8e91b539f0
commit eb8844e32a

View File

@ -1,6 +1,6 @@
import {Message} from 'element-ui' import {Message} from 'element-ui'
const Cookie = require('js-cookie') const Cookie = process.client ? require('js-cookie') : undefined
export default function ({app, $axios, store, redirect}) { export default function ({app, $axios, store, redirect}) {
$axios.onRequest(config => { $axios.onRequest(config => {
let token = store.state.oauth?.accessToken; let token = store.state.oauth?.accessToken;
@ -25,15 +25,17 @@ export default function ({app, $axios, store, redirect}) {
if (response.data.code === 0) { if (response.data.code === 0) {
Message.error(message ? message : '服务异常') Message.error(message ? message : '服务异常')
} else if (response.data.code === 401) { } else if (response.data.code === 401) {
Cookie.remove('auth') Cookie.remove('auth');
store.commit('setAuth', null); store.commit('setAuth', null);
} else if (response.data.code === 402) { } else if (response.data.code === 402) {
Cookie.remove('auth') Cookie.remove('auth');
store.commit('setAuth', null); store.commit('setAuth', null);
} else if (response.data.code === 404) { } else if (response.data.code === 404) {
Message.error('操作失败,请稍后再试......') Message.error('操作失败,请稍后再试......')
} else if (response.data.code === 500) { } else if (response.data.code === 500) {
Message.error('服务器正在开小差,请稍后再试......') Message.error('服务器正在开小差,请稍后再试......')
} else {
Message.error(response.data.message);
} }
} }
reject(response); reject(response);