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 ++++++++++++++++++++++++++++++-
 1 files changed, 60 insertions(+), 2 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

--
Gitblit v1.8.0