From a8ec1d4136507d54580c2599fbfbc70a9a38ee62 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期五, 05 二月 2021 00:35:17 +0800 Subject: [PATCH] 2021-02-05 --- src/api/cacheutils.js | 62 ++++++++++++++++++++++++++++++- src/api/index.js | 40 +++++++++++++++++++- 2 files changed, 98 insertions(+), 4 deletions(-) diff --git a/src/api/cacheutils.js b/src/api/cacheutils.js index 409b427..71983c5 100644 --- a/src/api/cacheutils.js +++ b/src/api/cacheutils.js @@ -138,7 +138,7 @@ } /** - * @description 鍒涘缓websql涓厤缃俊鎭殑淇濆瓨鏃堕棿 + * @description 鑾峰彇websql涓殑閰嶇疆淇℃伅 */ static getWebSqlMenuConfig (MenuID, userid) { if (!window.GLOB.WebSql || !MenuID || !userid) return Promise.reject() @@ -199,7 +199,6 @@ } if (!window.GLOB.IndexDB.objectStoreNames.contains('configs')) { let objectStore = window.GLOB.IndexDB.createObjectStore('configs', { keyPath: 'id' }) - objectStore.createIndex('type', 'type', { unique: false }) objectStore.createIndex('menuid', 'menuid', { unique: false }) objectStore.createIndex('userid', 'userid', { unique: false }) } @@ -285,4 +284,63 @@ } } + /** + * @description 鍒犻櫎IndexedDB涓繚瀛樼殑閰嶇疆淇℃伅 + */ + static delMenuIndexDBConfig (key) { + if (!window.GLOB.IndexDB || !key) return Promise.resolve() + + return new Promise(resolve => { + let request = window.GLOB.IndexDB.transaction(['configs'], 'readwrite') + .objectStore('configs') + .delete(key) + + request.onsuccess = () => { + resolve() + } + request.onerror = () => { + window.GLOB.IndexDB = null + resolve() + } + }) + } + + /** + * @description 鑾峰彇IndexedDB涓殑閰嶇疆淇℃伅 + */ + static getIndexDBMenuConfig (MenuID, userid) { + if (!window.GLOB.IndexDB || !MenuID || !userid) return Promise.reject() + let key = MenuID + userid + return new Promise((resolve, reject) => { + let request = window.GLOB.IndexDB.transaction(['configs']).objectStore('configs').get(key) + + request.onerror = () => { + window.GLOB.IndexDB = null + reject() + } + + request.onsuccess = () => { + if (request.result) { + resolve(request.result) + } else { + reject() + } + } + }) + } + + /** + * @description 灏嗘暟鎹啓鍏ndexedDB + */ + static writeInIndexDB (data) { + if (!window.GLOB.IndexDB || !data) return + + let request = window.GLOB.IndexDB.transaction(['configs'], 'readwrite') + .objectStore('configs') + .add(data) + + request.onerror = () => { + window.GLOB.IndexDB = null + } + } } \ No newline at end of file diff --git a/src/api/index.js b/src/api/index.js index 587fafd..67a1ccb 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -15,7 +15,7 @@ 1589782279158ngr675kk3oksin35sul,1589788042787ffdt9hle4s45k9r1nvs,15900310928174dro07ihfckghpb5h13,1594095599055qicg2eb642v5qglhnuo,1599613340050c8nu6rbst9d4emnnbsq,1577972969199lei1g0qkvlh4tkc908m, 1578479100252lfbp29v1kafk4s4q4ig,1577971621421tg4v0i1ur8873k7e0ob,1577929944419lgc5h3hepum765e2k7u,1588493493409k9guqp067d31lu7blsv` -if (window.openDatabase) { +if (!window.openDatabase) { CacheUtils.openWebSql() } else if (window.indexedDB) { CacheUtils.openIndexDB() @@ -343,7 +343,17 @@ * @description 鍒犻櫎鏌愪釜鑿滃崟閰嶇疆淇℃伅 */ deleteMenuStorage (menuId) { - return CacheUtils.delMenuWebSqlConfig(menuId) + if (window.GLOB.IndexDB) { + let key = menuId + (sessionStorage.getItem('UserID') || '') + + if (sessionStorage.getItem('isEditState') === 'true' && options.cloudServiceApi) { + key = menuId + (sessionStorage.getItem('CloudUserID') || '') + } + + return CacheUtils.delMenuIndexDBConfig(key) + } else { + return CacheUtils.delMenuWebSqlConfig(menuId) + } } /** @@ -518,6 +528,32 @@ }) }) }) + } else if (window.GLOB.IndexDB) { + return new Promise(resolve => { + CacheUtils.getIndexDBMenuConfig(param.MenuID, param.userid).then(res => { + resolve(res) + }, () => { + param = this.encryptParam(param) + axios({ + url: `/webapi/dostars${param.func ? '/' + param.func : ''}`, + method: 'post', + data: param + }).then(res => { + if (res.status && window.GLOB.IndexDB) { + let msg = { + ...res, + userid: param.userid, + menuid: param.MenuID, + id: param.MenuID + param.userid + } + CacheUtils.writeInIndexDB(msg) + } else if (res.status) { + window.GLOB.CacheMap.set(_param, res) + } + resolve(res) + }) + }) + }) } else if (window.GLOB.CacheMap.has(_param)) { return Promise.resolve(window.GLOB.CacheMap.get(_param)) } else { -- Gitblit v1.8.0