From 0227c25e4ed573d3095ada3f9c9a4ba5f18b0de5 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期三, 20 一月 2021 10:53:01 +0800 Subject: [PATCH] 2021-01-20 --- src/api/index.js | 63 ++++++++++++++++++++++++++----- 1 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index 8d1b215..fc1607a 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -56,7 +56,7 @@ return Promise.reject(error) }) -const setCurrentUrl = () => { +const setCurrentUrl = (res) => { if (!!(window.history && window.history.pushState)) { if (window.location.href.indexOf('paramsmain') > -1) { let _href = window.location.href.split('#') @@ -64,12 +64,11 @@ } sessionStorage.clear() + sessionStorage.setItem('loginError', JSON.stringify({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() } } - -window.GLOB.CacheMap = new Map() axios.interceptors.response.use((response) => { if (response.data.ErrCode === 'LoginError') { @@ -77,19 +76,21 @@ response.data.ErrCode = 'E' return Promise.resolve(response.data) } else { - setCurrentUrl() + setCurrentUrl(response) } } else { return Promise.resolve(response.data) } }, (error) => { - notification.error({ - className: 'notification-custom-error', - bottom: 0, - message: '鐘舵�佺爜-' + error.response.status + '锛岃鑱旂郴绠$悊鍛�', - placement: 'bottomRight', - duration: 15 - }) + if (error && error.response) { + notification.error({ + className: 'notification-custom-error', + bottom: 0, + message: '鐘舵�佺爜-' + error.response.status + '锛岃鑱旂郴绠$悊鍛�', + placement: 'bottomRight', + duration: 15 + }) + } return Promise.reject(error) }) @@ -601,6 +602,46 @@ } /** + * @description 鑾峰彇鏈湴绯荤粺閰嶇疆 + * @param {Object} param 璇锋眰鍙傛暟 + */ + getLocalCacheConfig (param) { + param.userid = sessionStorage.getItem('UserID') || '' + param.lang = localStorage.getItem('lang') || '' + param.SessionUid = localStorage.getItem('SessionUid') || '' + param.LoginUID = sessionStorage.getItem('LoginUID') || '' + param.appkey = window.GLOB.appkey || '' + + if (window.GLOB.mainSystemApi) { + param.rduri = window.GLOB.mainSystemApi + } + + let _param = md5(JSON.stringify(param)) + + if (mkDataBase) { + return new Promise(resolve => { + mkDataBase.transaction(tx => { + tx.executeSql(`SELECT * FROM CONFIGS WHERE menuid='${param.MenuID}' and userid='${param.userid}'`, [], (tx, results) => { + let paramItem = results.rows[0] + if (paramItem) { + resolve({ ErrCode: 'S', ErrMesg: '', LongParam: paramItem.LongParam, message: '', status: true }) + } else { + resolve({ ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false }) + } + }, (tx, results) => { + mkDataBase = null + resolve({ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false}) + }) + }) + }) + } else if (window.GLOB.CacheMap.has(_param)) { + return Promise.resolve(window.GLOB.CacheMap.get(_param)) + } else { + return Promise.resolve({ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false}) + } + } + + /** * @description 灏嗘暟鎹啓鍏ebsql */ writeInWebSql (data) { -- Gitblit v1.8.0