From 24842b40de5cd60700bf69dfd38a0332f5431e36 Mon Sep 17 00:00:00 2001
From: king <18310653075@163.com>
Date: 星期五, 23 五月 2025 10:55:07 +0800
Subject: [PATCH] Merge branch 'master' into positec

---
 src/api/cacheutils.js |  346 ++-------------------------------------------------------
 1 files changed, 16 insertions(+), 330 deletions(-)

diff --git a/src/api/cacheutils.js b/src/api/cacheutils.js
index 1c174d9..b20d3f6 100644
--- a/src/api/cacheutils.js
+++ b/src/api/cacheutils.js
@@ -3,280 +3,11 @@
  */
 export default class CacheUtils {
   /**
-   * @description 鎵撳紑websql
-   */
-  static openWebSql (db) {
-    try {
-      window.GLOB.WebSql = openDatabase(db, '1', 'mk-pc-database', 50 * 1024 * 1024)
-      window.GLOB.WebSql.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'
-        })
-        tx.executeSql('CREATE TABLE IF NOT EXISTS CONFIGS (menuid varchar(50), userid varchar(50), openEdition varchar(50), webEdition varchar(50), LongParam text, LongParamUser text, CDefine1 varchar(50), CDefine2 varchar(50), CDefine3 varchar(50), CDefine4 varchar(50), CDefine5 varchar(50))', [], () => {
-
-        }, () => {
-          // eslint-disable-next-line
-          throw 'CREATE TABLE ERROR'
-        })
-
-        tx.executeSql('CREATE TABLE IF NOT EXISTS CACHES (menuid varchar(50), CreateDate varchar(50), LongParam text, CDefine1 varchar(50), CDefine2 varchar(50))', [], () => {
-
-        }, () => {
-          // eslint-disable-next-line
-          throw 'CREATE TABLE ERROR'
-        })
-
-        if (window.GLOB.systemType === '') {
-          tx.executeSql('CREATE TABLE IF NOT EXISTS FUNCS (func_code varchar(50), key_sql text, CDefine1 varchar(50), CDefine2 varchar(50), CDefine3 varchar(50))', [], () => {
-
-          }, () => {
-            // eslint-disable-next-line
-            throw 'CREATE TABLE ERROR'
-          })
-        }
-      })
-      // window.GLOB.WebSql.transaction(tx => {
-      //   tx.executeSql('DROP TABLE VERSIONS')
-      //   tx.executeSql('DROP TABLE CONFIGS')
-      // })
-    } catch (e) {
-      console.warn('WebSql 鍒濆鍖栧け璐ワ紒')
-      window.GLOB.WebSql = null
-
-      if (window.indexedDB) {
-        this.openIndexDB(db)
-      }
-    }
-  }
-
-  /**
-   * @description 娓呯┖鍑芥暟
-   */
-  static clearFuncs () {
-    if (window.GLOB.systemType !== '') return
-
-    if (window.GLOB.WebSql) {
-      window.GLOB.WebSql.transaction(tx => {
-        tx.executeSql('DELETE FROM FUNCS')
-
-        tx.executeSql(`UPDATE VERSIONS SET createDate='1970-01-01 14:59:09.000' where CDefine1='funcs'`)
-      })
-    } else if (window.GLOB.IndexDB) {
-      let objectStore = window.GLOB.IndexDB.transaction(['funcs'], 'readwrite').objectStore('funcs')
-      objectStore.clear()
-
-      window.GLOB.IndexDB.transaction(['version'], 'readwrite').objectStore('version').delete('funcs')
-    }
-  }
-
-  /**
-   * @description 鑾峰彇websql涓繚瀛樹俊鎭増鏈�
-   */
-  static getWebSqlVersion () {
-    if (!window.GLOB.WebSql) {
-      return Promise.reject()
-    }
-
-    let deffers = []
-
-    deffers.push(
-      new Promise((resolve) => {
-        window.GLOB.WebSql.transaction(tx => {
-          tx.executeSql("SELECT * FROM VERSIONS where CDefine1='LongParam'", [], (tx, results) => {
-            if (results.rows[0]) {
-              resolve(results.rows[0])
-            } else {
-              resolve({version: '', createDate: ''})
-            }
-          }, (tx, results) => {
-            console.warn(results)
-            resolve({version: '', createDate: ''})
-          })
-        })
-      })
-    )
-
-    deffers.push(
-      new Promise((resolve) => {
-        window.GLOB.WebSql.transaction(tx => {
-          tx.executeSql(`SELECT * FROM CONFIGS`, [], (tx, results) => {
-            let menus = []
-            for (let i = 0; i < results.rows.length; i++) {
-              menus.push(`'${results.rows[i].menuid}','${results.rows[i].openEdition || 'mk'}'`)
-            }
-            resolve(menus)
-          }, (tx, results) => {
-            console.warn(results)
-            resolve([])
-          })
-        })
-      })
-    )
-
-    return new Promise((resolve) => {
-      Promise.all(deffers).then(res => {
-        let result = res[0]
-
-        if (result.createDate && !/^\d{4}-\d{2}-\d{2}/.test(result.createDate)) {
-          result.createDate = ''
-        }
-
-        result.menuids = res[1].join(';')
-
-        resolve(result)
-      })
-    })
-  }
-
-  /**
-   * @description 鍒犻櫎websql涓繚瀛樼殑閰嶇疆淇℃伅
-   */
-  static delWebSqlConfig (keys) {
-    if (!window.GLOB.WebSql) return
-
-    if (!keys) {
-      window.GLOB.WebSql.transaction(tx => {
-        tx.executeSql(`DELETE FROM CONFIGS`, [], () => {}, (tx, results) => {
-          console.warn(results)
-        })
-      })
-    } else {
-      window.GLOB.WebSql.transaction(tx => {
-        tx.executeSql(`DELETE FROM CONFIGS where menuid in (${keys})`, [], () => {}, (tx, results) => {
-          console.warn(results)
-        })
-      })
-    }
-  }
-
-  /**
-   * @description 鍒犻櫎websql涓繚瀛樼殑閰嶇疆淇℃伅
-   */
-  static delMenuWebSqlConfig (menuId) {
-    if (!window.GLOB.WebSql || !menuId) return Promise.resolve()
-    return new Promise(resolve => {
-      window.GLOB.WebSql.transaction(tx => {
-        tx.executeSql(`DELETE FROM CONFIGS where menuid='${menuId}'`, [], () => {
-          resolve()
-        }, (tx, results) => {
-          console.warn(results)
-          resolve()
-        })
-      })
-    })
-  }
-
-  /**
-   * @description 鏇存柊websql涓厤缃俊鎭殑鐗堟湰
-   */
-  static updateWebSqlversion (version, curTime) {
-    if (!window.GLOB.WebSql) return
-
-    window.GLOB.WebSql.transaction(tx => {
-      tx.executeSql(`DELETE FROM VERSIONS where CDefine1='LongParam'`)
-
-      if (version) {
-        tx.executeSql('INSERT INTO VERSIONS (version, createDate, CDefine1) VALUES (?, ?, ?)', [version, curTime, 'LongParam'], () => {}, (tx, results) => {
-          console.warn(results)
-        })
-      }
-    })
-  }
-
-  /**
-   * @description 鑾峰彇websql涓殑閰嶇疆淇℃伅
-   */
-  static getWebSqlMenuConfig (MenuID, userid) {
-    if (!window.GLOB.WebSql || !MenuID || !userid) return Promise.reject()
-    return new Promise((resolve, reject) => {
-      window.GLOB.WebSql.transaction(tx => {
-        tx.executeSql(`SELECT * FROM CONFIGS WHERE menuid='${MenuID}' and userid='${userid}'`, [], (tx, results) => {
-          let paramItem = results.rows[0]
-          if (paramItem) {
-            resolve({
-              ErrCode: 'S',
-              ErrMesg: '',
-              LongParam: paramItem.LongParam,
-              LongParamUser: paramItem.LongParamUser,
-              message: '',
-              open_edition: paramItem.openEdition,
-              status: true,
-              web_edition: paramItem.webEdition
-            })
-          } else {
-            reject()
-          }
-        }, (tx, results) => {
-          console.warn(results)
-          reject()
-        })
-      })
-    })
-  }
-
-  /**
-   * @description 灏嗘暟鎹啓鍏ebsql
-   */
-  static writeInWebSql (data) {
-    if (!window.GLOB.WebSql || !data) return
-    window.GLOB.WebSql.transaction(tx => {
-      tx.executeSql('INSERT INTO CONFIGS (menuid, userid, openEdition, webEdition, LongParam, LongParamUser) VALUES (?, ?, ?, ?, ?, ?)', data)
-    })
-  }
-
-  /**
-   * @description 灏嗙紦瀛樻暟鎹啓鍏ebsql
-   */
-  static writeCacheInWebSql (data) {
-    if (!window.GLOB.WebSql) return
-    window.GLOB.WebSql.transaction(tx => {
-      tx.executeSql(`DELETE FROM CACHES where menuid='${data[0]}'`)
-      if (data[2]) {
-        tx.executeSql('INSERT INTO CACHES (menuid, CreateDate, LongParam) VALUES (?, ?, ?)', data)
-      }
-    })
-  }
-
-  /**
-   * @description 鑾峰彇websql涓殑閰嶇疆淇℃伅
-   */
-  static getWebSqlCacheConfig (MenuID) {
-    if (!window.GLOB.WebSql) return Promise.resolve()
-    return new Promise((resolve, reject) => {
-      window.GLOB.WebSql.transaction(tx => {
-        tx.executeSql(`SELECT * FROM CACHES WHERE menuid='${MenuID}'`, [], (tx, results) => {
-          resolve(results.rows[0])
-        }, (tx, results) => {
-          console.warn(results)
-          resolve()
-        })
-      })
-    })
-  }
-
-  /**
-   * @description 鍒犻櫎websql涓秴杩�7澶╃殑缂撳瓨淇℃伅
-   */
-  static delWebSqlCacheConfig (date, type) {
-    if (!window.GLOB.WebSql) return
-    window.GLOB.WebSql.transaction(tx => {
-      if (type === 'all') {
-        tx.executeSql('DELETE FROM CACHES')
-      } else {
-        tx.executeSql(`DELETE FROM CACHES where CreateDate<'${date}'`)
-      }
-    })
-  }
-
-  /**
    * @description 鎵撳紑IndexedDB
    */
   static openIndexDB (db) {
     try {
-      let request = window.indexedDB.open(db, 2)
+      let request = window.indexedDB.open(db, 3)
       request.onerror = () => {
         console.warn('IndexedDB 鍒濆鍖栧け璐ワ紒')
       }
@@ -296,9 +27,9 @@
         if (!window.GLOB.IndexDB.objectStoreNames.contains('caches')) {
           window.GLOB.IndexDB.createObjectStore('caches', { keyPath: 'menuid' })
         }
-        if (window.GLOB.systemType === '' && !window.GLOB.IndexDB.objectStoreNames.contains('funcs')) {
-          window.GLOB.IndexDB.createObjectStore('funcs', { keyPath: 'id' })
-        }
+        // if (!window.GLOB.IndexDB.objectStoreNames.contains('funcs')) {
+        //   window.GLOB.IndexDB.createObjectStore('funcs', { keyPath: 'id' })
+        // }
       }
     } catch (e) {
       console.warn('IndexedDB 鍒濆鍖栧け璐ワ紒')
@@ -323,7 +54,6 @@
           .get('mksoft')
 
         request.onerror = (event) => {
-          window.GLOB.IndexDB = null
           console.warn(event)
           resolve({version: '', createDate: ''})
         }
@@ -342,16 +72,19 @@
       new Promise((resolve) => {
         let request = window.GLOB.IndexDB.transaction(['configs']).objectStore('configs').openCursor()
         let menus = []
+        let ids = []
 
         request.onerror = () => {
-          window.GLOB.IndexDB = null
           resolve(menus)
         }
 
         request.onsuccess = (e) => {
           let cursor = e.target.result
           if (cursor) {
-            menus.push(`'${cursor.value.menuid}','${cursor.value.open_edition || 'mk'}'`)
+            if (cursor.value.menuid && !ids.includes(cursor.value.menuid)) {
+              menus.push(`'${cursor.value.menuid}','${cursor.value.open_edition || 'mk'}'`)
+              ids.push(cursor.value.menuid)
+            }
             cursor.continue()
           } else {
             resolve(menus)
@@ -382,58 +115,21 @@
     if (!window.GLOB.IndexDB || !version) return
 
     if (!version) {
-      let request = window.GLOB.IndexDB.transaction(['configs'], 'readwrite').objectStore('configs').delete('mksoft')
-  
-      request.onerror = () => {
-        window.GLOB.IndexDB = null
-      }
+      window.GLOB.IndexDB.transaction(['configs'], 'readwrite').objectStore('configs').delete('mksoft')
     } else {
       version.id = 'mksoft'
 
       let objectStore = window.GLOB.IndexDB.transaction(['version'], 'readwrite').objectStore('version')
       let request = objectStore.get('mksoft')
   
-      request.onerror = () => {
-        window.GLOB.IndexDB = null
-      }
-  
       request.onsuccess = () => {
         if (request.result) {
-          let put = objectStore.put(version)
-  
-          put.onerror = () => {
-            window.GLOB.IndexDB = null
-          }
+          objectStore.put(version)
         } else {
-          let add = objectStore.add(version)
-  
-          add.onerror = () => {
-            window.GLOB.IndexDB = null
-          }
+          objectStore.add(version)
         }
       }
     }
-  }
-
-  /**
-   * @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()
-      }
-    })
   }
 
   /**
@@ -443,17 +139,9 @@
     if (!window.GLOB.IndexDB) return
 
     if (!menuids) {
-      let request = window.GLOB.IndexDB.transaction(['configs'], 'readwrite').objectStore('configs').clear()
-  
-      request.onerror = () => {
-        window.GLOB.IndexDB = null
-      }
+      window.GLOB.IndexDB.transaction(['configs'], 'readwrite').objectStore('configs').clear()
     } else {
       let request = window.GLOB.IndexDB.transaction(['configs'], 'readwrite').objectStore('configs').openCursor()
-  
-      request.onerror = () => {
-        window.GLOB.IndexDB = null
-      }
 
       request.onsuccess = (e) => {
         let cursor = e.target.result
@@ -470,15 +158,13 @@
   /**
    * @description 鑾峰彇IndexedDB涓殑閰嶇疆淇℃伅
    */
-  static getIndexDBMenuConfig (MenuID, userid) {
-    if (!window.GLOB.IndexDB || !MenuID || !userid) return Promise.reject()
-    let key = MenuID + userid
+  static getIndexDBMenuConfig (key) {
+    if (!window.GLOB.IndexDB || !key) return Promise.reject()
     
     return new Promise((resolve, reject) => {
       let request = window.GLOB.IndexDB.transaction(['configs']).objectStore('configs').get(key)
 
       request.onerror = () => {
-        window.GLOB.IndexDB = null
         reject()
       }
 
@@ -548,7 +234,7 @@
       request.onsuccess = (e) => {
         let cursor = e.target.result
         if (cursor) {
-          if (cursor.value.CreateDate < date) {
+          if (cursor.value.CreateDate < date || cursor.value.CreateDate.length === 10) {
             cursor.delete()
           }
           cursor.continue()

--
Gitblit v1.8.0