mirror of
https://github.com/MrXujiang/h5-Dooring.git
synced 2025-12-12 18:22:51 +00:00
fix response and timer error
This commit is contained in:
parent
01cf4c1614
commit
58e001dd6d
@ -69,9 +69,12 @@ const SourceBox = memo(props => {
|
||||
}, [canvasId]);
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => {
|
||||
let timer = window.setTimeout(() => {
|
||||
setIsShowTip(false);
|
||||
}, 3000);
|
||||
return () => {
|
||||
window.clearTimeout(timer);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const opacity = isOver ? 0.7 : 1;
|
||||
|
||||
@ -38,7 +38,7 @@ const PreviewPage = memo(props => {
|
||||
|
||||
useEffect(() => {
|
||||
const { tid } = props.location.query;
|
||||
const timer = null;
|
||||
let timer = null;
|
||||
req
|
||||
.get('/visible/preview/get', { params: { tid } })
|
||||
.then(res => {
|
||||
@ -55,7 +55,7 @@ const PreviewPage = memo(props => {
|
||||
}, 3000);
|
||||
});
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
window.clearTimeout(timer);
|
||||
};
|
||||
}, []);
|
||||
|
||||
|
||||
@ -1,50 +1,57 @@
|
||||
import axios from 'axios'
|
||||
import { message } from 'antd'
|
||||
import axios from 'axios';
|
||||
import { message } from 'antd';
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development'
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
|
||||
const instance = axios.create({
|
||||
// 服务器地址需要自己配置和开发
|
||||
baseURL: isDev ? 'http://localhost:3000/xxx' : 'http://xxxxx',
|
||||
timeout: 10000,
|
||||
withCredentials: true
|
||||
withCredentials: true,
|
||||
});
|
||||
|
||||
// 添加请求拦截器
|
||||
instance.interceptors.request.use(function (config) {
|
||||
instance.interceptors.request.use(
|
||||
function(config) {
|
||||
// 在发送请求之前做些什么
|
||||
config.headers = {
|
||||
'x-requested-with': localStorage.getItem('user') || '',
|
||||
'authorization': localStorage.getItem('token') || ''
|
||||
}
|
||||
authorization: localStorage.getItem('token') || '',
|
||||
};
|
||||
return config;
|
||||
}, function (error) {
|
||||
},
|
||||
function(error) {
|
||||
// 对请求错误做些什么
|
||||
return Promise.reject(error);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
// 添加响应拦截器
|
||||
instance.interceptors.response.use(function (response) {
|
||||
instance.interceptors.response.use(
|
||||
function(response) {
|
||||
// 对响应数据做点什么
|
||||
if (response.headers['x-show-msg'] === 'zxzk_msg_200') {
|
||||
message.success(response.data.msg);
|
||||
}
|
||||
return response.data.result;
|
||||
}, function (error) {
|
||||
},
|
||||
function(error) {
|
||||
// 对响应错误做点什么
|
||||
const { response } = error;
|
||||
if (response) {
|
||||
if (response.status === 404) {
|
||||
message.error('请求资源未发现');
|
||||
} else if (response.status === 403) {
|
||||
message.error(response.data.msg, () => {
|
||||
window.location.href = '/admin/login'
|
||||
window.location.href = '/admin/login';
|
||||
});
|
||||
} else {
|
||||
message.error(response.data.msg);
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
|
||||
export default instance
|
||||
export default instance;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user