diff --git a/src/pages/editor/SourceBox.js b/src/pages/editor/SourceBox.js index 4d7d39f..4f86b4e 100644 --- a/src/pages/editor/SourceBox.js +++ b/src/pages/editor/SourceBox.js @@ -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; diff --git a/src/pages/editor/preview.js b/src/pages/editor/preview.js index 7c23155..4d496c8 100644 --- a/src/pages/editor/preview.js +++ b/src/pages/editor/preview.js @@ -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); }; }, []); diff --git a/src/utils/req.ts b/src/utils/req.ts index 0c268a2..a8fd997 100644 --- a/src/utils/req.ts +++ b/src/utils/req.ts @@ -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 + // 服务器地址需要自己配置和开发 + baseURL: isDev ? 'http://localhost:3000/xxx' : 'http://xxxxx', + timeout: 10000, + 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') || '' - } + 'x-requested-with': localStorage.getItem('user') || '', + 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); + 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.status === 404) { + if (response) { + if (response.status === 404) { message.error('请求资源未发现'); - }else if(response.status === 403) { + } else if (response.status === 403) { message.error(response.data.msg, () => { - window.location.href = '/admin/login' + window.location.href = '/admin/login'; }); - }else { + } else { message.error(response.data.msg); + } } + return Promise.reject(error); - }); + }, +); - - -export default instance \ No newline at end of file +export default instance;