From ce70be666bcd78a7e16e739040488cf7e7256cc2 Mon Sep 17 00:00:00 2001 From: king <18310653075@163.com> Date: 星期一, 31 五月 2021 15:49:43 +0800 Subject: [PATCH] 2021-05-31 --- src/api/cacheutils.js | 87 ++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/api/cacheutils.js b/src/api/cacheutils.js index 409b427..2aa5642 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,88 @@ } } + /** + * @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 delIndexDBConfig (keys) { + if (!window.GLOB.IndexDB || !keys) return + + let objectStore = window.GLOB.IndexDB.transaction(['configs'], 'readwrite').objectStore('configs') + + objectStore.openCursor().onsuccess = (event) => { + let cursor = event.target.result + + if (cursor) { + if (cursor.value && keys.includes(cursor.value.menuid)) { + let request = objectStore.delete(cursor.key) + + request.onerror = () => { + window.GLOB.IndexDB = null + } + } + + cursor.continue() + } + } + } + + /** + * @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 -- Gitblit v1.8.0