| | |
| | | /** |
| | | * @description 打开websql |
| | | */ |
| | | static openWebSql () { |
| | | static openWebSql (sysType) { |
| | | let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : '' |
| | | try { |
| | | window.GLOB.WebSql = openDatabase(`mkdb${service}`, '1', 'mk-pc-database', 50 * 1024 * 1024) |
| | |
| | | // eslint-disable-next-line |
| | | throw 'CREATE TABLE ERROR' |
| | | }) |
| | | |
| | | if (sysType === 'local' && 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') |
| | |
| | | } |
| | | return new Promise((resolve, reject) => { |
| | | window.GLOB.WebSql.transaction(tx => { |
| | | tx.executeSql('SELECT * FROM VERSIONS', [], (tx, results) => { |
| | | tx.executeSql("SELECT * FROM VERSIONS where CDefine1='LongParam'", [], (tx, results) => { |
| | | if (results.rows.length === 0) { |
| | | tx.executeSql('DELETE FROM CONFIGS') |
| | | resolve({version: '', createDate: ''}) |
| | | } else if (results.rows.length === 1) { |
| | | resolve(results.rows[0]) |
| | | } else if (results.rows.length > 1) { |
| | | tx.executeSql('DELETE FROM VERSIONS') |
| | | tx.executeSql('DELETE FROM CONFIGS') |
| | | resolve({version: '', createDate: ''}) |
| | | } else { |
| | | resolve(results.rows[0]) |
| | | } |
| | | }, (tx, results) => { |
| | | window.GLOB.WebSql = null |
| | |
| | | static updateWebSqlTime (curTime) { |
| | | if (!window.GLOB.WebSql || !curTime) return |
| | | window.GLOB.WebSql.transaction(tx => { |
| | | tx.executeSql(`UPDATE VERSIONS SET createDate='${curTime}'`, [], () => {}, () => { |
| | | tx.executeSql(`UPDATE VERSIONS SET createDate='${curTime}' where CDefine1='LongParam'`, [], () => {}, () => { |
| | | window.GLOB.WebSql = null |
| | | }) |
| | | }) |
| | |
| | | static updateWebSqlversion (version, curTime) { |
| | | if (!window.GLOB.WebSql || !curTime || !version) return |
| | | window.GLOB.WebSql.transaction(tx => { |
| | | tx.executeSql(`UPDATE VERSIONS SET version='${version}', createDate='${curTime}'`, [], () => {}, () => { |
| | | tx.executeSql(`UPDATE VERSIONS SET version='${version}', createDate='${curTime}' where CDefine1='LongParam'`, [], () => {}, () => { |
| | | window.GLOB.WebSql = null |
| | | }) |
| | | }) |
| | |
| | | static createWebSqlversion (version, curTime) { |
| | | if (!window.GLOB.WebSql || !curTime || !version) return |
| | | window.GLOB.WebSql.transaction(tx => { |
| | | tx.executeSql('INSERT INTO VERSIONS (version, createDate) VALUES (?, ?)', [version, curTime], () => {}, () => { |
| | | tx.executeSql('INSERT INTO VERSIONS (version, createDate, CDefine1) VALUES (?, ?, ?)', [version, curTime, 'LongParam'], () => {}, () => { |
| | | window.GLOB.WebSql = null |
| | | }) |
| | | }) |
| | |
| | | /** |
| | | * @description 打开IndexedDB |
| | | */ |
| | | static openIndexDB () { |
| | | static openIndexDB (sysType) { |
| | | let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : '' |
| | | try { |
| | | let request = window.indexedDB.open(`mkdb${service}`, 1) |
| | |
| | | objectStore.createIndex('menuid', 'menuid', { unique: false }) |
| | | objectStore.createIndex('userid', 'userid', { unique: false }) |
| | | } |
| | | if (window.GLOB.systemType === '' && sysType === 'local' && !window.GLOB.IndexDB.objectStoreNames.contains('funcs')) { |
| | | window.GLOB.IndexDB.createObjectStore('funcs', { keyPath: 'id' }) |
| | | } |
| | | } |
| | | } catch (e) { |
| | | console.warn('IndexedDB 初始化失败!') |