From cc87fc060c30597ec2efe38d0c3efe62f4957fd5 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 14 七月 2023 11:20:02 +0800 Subject: [PATCH] 2023-07-14 --- src/api/index.js | 90 ++++++++++++++++++++++++--------------------- 1 files changed, 48 insertions(+), 42 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index 54cf1dc..d2d5304 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,53 +24,54 @@ axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8' axios.defaults.withCredentials = false -// axios.interceptors.request.use((config) => { -// return config -// }, (error) => { -// return Promise.reject(error) -// }) - -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, + okText: '鐭ラ亾浜�', + 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 { @@ -197,16 +199,20 @@ param.thd_party_openid = openid param.thd_party_appid = appid param.id = scanId - } else if (binding_type === 'login_check') { // appid 姝ゆ椂涓虹洰鏍� + } else if (binding_type === 'login_check') { // appid 姝ゆ椂涓虹洰鏍囧湴鍧� param.v_type = 'login_check' param.LoginUID = sessionStorage.getItem('LoginUID') || '' - url = appid.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login') - + if (!param.rduri) { param.rduri = window.GLOB.baseurl + 'webapi/dologon/s_visitor_login' } - - param.linkurl = appid.replace(/\/webapi(.*)/, '/index.html') + + if (appid) { + url = appid.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login') + param.linkurl = appid.replace(/\/webapi(.*)/, '/index.html') + } else { + param.linkurl = window.GLOB.linkurl + } } param.LText = md5(window.btoa(_SessionUid + param.timestamp + (param.linkurl || ''))) @@ -538,7 +544,7 @@ param.lang = param.lang || sessionStorage.getItem('lang') || '' param.SessionUid = localStorage.getItem('SessionUid') || '' param.LoginUID = sessionStorage.getItem('LoginUID') || '' - param.appkey = window.GLOB.appkey || '' + param.appkey = param.appkey || window.GLOB.appkey || '' let url = '/webapi/dostars' if (sessionStorage.getItem('isEditState') === 'true') { // 缂栬緫鐘舵�侊紝鍗曠偣鐧诲綍鏈嶅姟鍣ㄤ负浜戠 -- Gitblit v1.8.0