From 0519dcda8b6fb2914987f8d4d58e1d14bcf98dc3 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 30 六月 2023 14:33:06 +0800 Subject: [PATCH] 2023-06-30 --- src/api/index.js | 75 ++++++++++++++++++------------------- 1 files changed, 37 insertions(+), 38 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index 781daf3..1d2ed22 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -1,6 +1,6 @@ import axios from 'axios' import qs from 'qs' -import { notification } from 'antd' +import { notification, Modal } from 'antd' import md5 from 'md5' import CryptoJS from 'crypto-js' import jsSHA from 'jssha' @@ -11,6 +11,7 @@ window.GLOB.IndexDB = null window.GLOB.OuterToken = {} +window.GLOB.$error = false let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : '' let db = `mkdb${service}` @@ -23,55 +24,53 @@ axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' axios.defaults.withCredentials = false -// Modal.destroyAll() -// Modal.error({ -// title: response.data.message, -// onOk: () => { -// sessionStorage.clear() -// } -// }) - -const setCurrentUrl = (res) => { - if (!!(window.history && window.history.pushState)) { - sessionStorage.clear() - sessionStorage.setItem('loginError', JSON.stringify({url: res.config ? res.config.url : '', request: res.config ? res.config.data : '', response: JSON.stringify(res.data)})) - window.history.replaceState(null, null, window.location.href.split('#')[0] + '#/login') - window.location.reload() - } -} - axios.interceptors.response.use((response) => { if (response.data.ErrCode === 'LoginError') { - if (window.debugger === true) { - response.data.ErrCode = 'E' - return Promise.resolve(response.data) - } else if (window.GLOB.developing) { + if (window.GLOB.developing) { sessionStorage.setItem('devError', 'true') response.data.ErrCode = 'E' return Promise.resolve(response.data) - } else if (!sessionStorage.getItem('loginError')) { - setCurrentUrl(response) + } else if (response.config.url.indexOf('https://sso.mk9h.cn/webapi/dostars') > -1) { + return Promise.reject(response.data) + } else if (response.config.url.indexOf('https://epc.mk9h.cn/webapi/dostars') > -1) { + return Promise.reject(response.data) } + + if (!window.GLOB.$error) { + window.GLOB.$error = true + + Modal.destroyAll() + Modal.error({ + title: response.data.message, + onOk: () => { + window.GLOB.$error = false + sessionStorage.clear() + if (!!(window.history && window.history.pushState)) { + window.history.replaceState(null, null, window.location.href.split('#')[0] + '#/login') + window.location.reload() + } + } + }) + } + + return Promise.reject(response.data) } else { return Promise.resolve(response.data) } }, (error) => { - let response = error.response + let response = error.response || '' - if (response) { - if (!response.data || !response.data.errors) { // 杩囨护鏃疯鎶ラ敊淇℃伅 - notification.error({ - className: 'notification-custom-error', - bottom: 0, - message: '鐘舵�佺爜-' + response.status + '锛岃鑱旂郴绠$悊鍛�', - placement: 'bottomRight', - duration: 15 - }) - } - return Promise.reject(response) - } else { - return Promise.reject() + if (response && (!response.data || !response.data.errors)) { // 杩囨护鏃疯鎶ラ敊淇℃伅 + notification.error({ + className: 'notification-custom-error', + bottom: 0, + message: '鐘舵�佺爜-' + response.status + '锛岃鑱旂郴绠$悊鍛�', + placement: 'bottomRight', + duration: 15 + }) } + + return Promise.reject(response) }) class Api { -- Gitblit v1.8.0