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 | 82 +++++++++++++++++++++++++++++++---------- 1 files changed, 62 insertions(+), 20 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index c8a621d..fc1607a 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -7,7 +7,6 @@ import options from '@/store/options.js' let mkDataBase = null -let storUsable = false if (window.openDatabase) { let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : '' @@ -15,7 +14,7 @@ mkDataBase = openDatabase(`mkdb${service}`, '1', 'mk-pc-database', 50 * 1024 * 1024) mkDataBase.transaction(tx => { tx.executeSql('CREATE TABLE IF NOT EXISTS VERSIONS (version varchar(50), createDate varchar(50), CDefine1 varchar(50), CDefine2 varchar(50), CDefine3 varchar(50))', [], () => { - + }, () => { // eslint-disable-next-line throw 'CREATE TABLE ERROR' @@ -57,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('#') @@ -65,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') { @@ -78,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) }) @@ -335,12 +335,14 @@ }) }) }, () => { - _reject() mkDataBase = null + _reject() return Promise.reject() }).then(() => { - storUsable = true _resolve(appVersion) + }, () => { + mkDataBase = null + _reject() }) } @@ -493,7 +495,7 @@ * @description 鑾峰彇鎴栦慨鏀规湰鍦伴厤缃紝澧炲姞appkey */ getLocalConfig (param) { - param.userid = sessionStorage.getItem('UserID') + param.userid = sessionStorage.getItem('UserID') || '' param.lang = localStorage.getItem('lang') || '' param.SessionUid = localStorage.getItem('SessionUid') || '' param.LoginUID = sessionStorage.getItem('LoginUID') || '' @@ -535,7 +537,7 @@ _param = JSON.stringify(_param) _param = md5(_param) - if (mkDataBase && storUsable) { + if (mkDataBase) { param = this.encryptParam(param) return new Promise(resolve => { @@ -565,6 +567,9 @@ }) } }, (tx, results) => { + mkDataBase = null + console.warn(results) + axios({ url: `/webapi/dostars${param.func ? '/' + param.func : ''}`, data: param @@ -574,9 +579,6 @@ } resolve(res) }) - mkDataBase = null - storUsable = false - console.warn(results) }) }) }) @@ -600,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