Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
util.checkStatus = function checkStatus (response) {
// loading
// 如果http状态码正常,则直接返回数据
// console.log(response)
if (response && (response.status === 200 || response.status === 304 || response.status === 400)) {
return response;
// 如果不需要除了data之外的数据,可以直接 return response.data
}
Message.warning('网络异常');
// 异常状态下,把错误信息返回去
return {
status: -404,
msg: '网络异常'
};
};
util.checkStatus = function checkStatus (response) {
// loading
// 如果http状态码正常,则直接返回数据
// console.log(response)
if (response && (response.status === 200 || response.status === 304 || response.status === 400)) {
return response;
// 如果不需要除了data之外的数据,可以直接 return response.data
}
Message.warning('网络异常');
// 异常状态下,把错误信息返回去
return {
status: -404,
msg: '网络异常'
};
};
}, err => {
if (err && err.code == 0) {
Message.warning('您没有权限');
} else {
//正则判断超时
let rg = /8000/g
iView.LoadingBar.error();
if (rg.test(err)) {
Message.error('您的网络不给力喔,请刷新重试');
} else {
Message.error('服务器错误');
}
}
store.state.loadErr = true
return Promise.reject(err);
})
axios.post(obj.url, obj.data).then(data => {
if(data.data.code === 0) {
Message.success(data.data.msg)
resolve(data.data)
} else if (data.data.code === 1) {
Message.warning(data.data.msg)
resolve(data.data)
} else if (data.data.code === 2) {
Message.error(data.data.msg)
resolve(data.data)
} else {
Message.error(data.data.msg)
resolve(data.data)
}
}).catch(data => {
reject(data)
http.interceptors.response.use(res => {
iView.LoadingBar.finish();
if (res.data.code == 300) { //token过期
Message.warning('您的会话已过期,请重新登录');
localStorage.removeItem('token')
app.$router.replace('/login')
return Promise.reject();
} else if (res.data.code != 200) {
Message.error(res.data.msg);
return Promise.reject();
} else {
if (res.data.token) {
localStorage.setItem('token', res.data.token)
accessToken = res.data.token
}
return res.data.data
}
}, err => {
if (err && err.code == 0) {
this.on('dataError', ({ data, execute }) => {
execute.run = false;
if (data.data.status === -1) {
router.push('/login');
Message.warning(data.message);
} else {
this.trigger('notice', {
type: 'warning',
msg: data.message,
autoJoin: false,
});
}
});
}