| | |
| | | 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))', [], () => { |
| | | |
| | |
| | | } |
| | | |
| | | /** |
| | | * @description 将缓存数据写入websql |
| | | */ |
| | | 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, 1) |
| | | let request = window.indexedDB.open(db, 2) |
| | | request.onerror = () => { |
| | | console.warn('IndexedDB 初始化失败!') |
| | | } |
| | |
| | | let objectStore = window.GLOB.IndexDB.createObjectStore('configs', { keyPath: 'id' }) |
| | | objectStore.createIndex('menuid', 'menuid', { unique: false }) |
| | | objectStore.createIndex('userid', 'userid', { unique: false }) |
| | | } |
| | | 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' }) |
| | |
| | | static writeInIndexDB (data) { |
| | | if (!window.GLOB.IndexDB || !data) return |
| | | |
| | | let request = window.GLOB.IndexDB.transaction(['configs'], 'readwrite') |
| | | .objectStore('configs') |
| | | .add(data) |
| | | window.GLOB.IndexDB.transaction(['configs'], 'readwrite').objectStore('configs').add(data) |
| | | } |
| | | |
| | | request.onerror = () => { |
| | | window.GLOB.IndexDB = null |
| | | /** |
| | | * @description 将数据写入IndexedDB |
| | | */ |
| | | static writeCacheInIndexDB (data) { |
| | | if (!window.GLOB.IndexDB) return |
| | | |
| | | let objectStore = window.GLOB.IndexDB.transaction(['caches'], 'readwrite').objectStore('caches') |
| | | objectStore.delete(data.menuid) |
| | | |
| | | if (data.LongParam) { |
| | | objectStore.add(data) |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * @description 获取IndexedDB中的配置信息 |
| | | */ |
| | | static getIndexDBCacheConfig (MenuID) { |
| | | if (!window.GLOB.IndexDB) return Promise.resolve() |
| | | |
| | | return new Promise((resolve, reject) => { |
| | | let request = window.GLOB.IndexDB.transaction(['caches']).objectStore('caches').get(MenuID) |
| | | |
| | | request.onerror = () => { |
| | | resolve() |
| | | } |
| | | |
| | | request.onsuccess = () => { |
| | | resolve(request.result) |
| | | } |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description 删除IndexedDB中超过7天的缓存信息 |
| | | */ |
| | | static delIndexDBCacheConfig (date, type) { |
| | | if (!window.GLOB.IndexDB) return |
| | | |
| | | if (type === 'all') { |
| | | window.GLOB.IndexDB.transaction(['caches'], 'readwrite').objectStore('caches').clear() |
| | | } else { |
| | | let request = window.GLOB.IndexDB.transaction(['caches'], 'readwrite').objectStore('caches').openCursor() |
| | | |
| | | request.onsuccess = (e) => { |
| | | let cursor = e.target.result |
| | | if (cursor) { |
| | | if (cursor.value.CreateDate < date) { |
| | | cursor.delete() |
| | | } |
| | | cursor.continue() |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |