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