| | |
| | | /** |
| | | * @description 打开websql |
| | | */ |
| | | static openWebSql (sysType) { |
| | | let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : '' |
| | | static openWebSql (db) { |
| | | try { |
| | | window.GLOB.WebSql = openDatabase(`mkdb${service}`, '1', 'mk-pc-database', 50 * 1024 * 1024) |
| | | 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))', [], () => { |
| | | |
| | |
| | | throw 'CREATE TABLE ERROR' |
| | | }) |
| | | |
| | | if (sysType === 'local' && window.GLOB.systemType === '') { |
| | | 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 清空函数 |
| | | */ |
| | | static clearFuncs (sysType) { |
| | | if (sysType !== 'local' || window.GLOB.systemType !== '') return |
| | | static clearFuncs () { |
| | | if (window.GLOB.systemType !== '') return |
| | | |
| | | if (window.GLOB.WebSql) { |
| | | window.GLOB.WebSql.transaction(tx => { |
| | | tx.executeSql('DELETE FROM FUNCS') |
| | |
| | | let objectStore = window.GLOB.IndexDB.transaction(['funcs'], 'readwrite').objectStore('funcs') |
| | | objectStore.clear() |
| | | |
| | | let funcStore = window.GLOB.IndexDB.transaction(['version'], 'readwrite').objectStore('version') |
| | | funcStore.put({id: 'funcs', version: '1.0', createDate: '1970-01-01 14:59:09.000'}) |
| | | window.GLOB.IndexDB.transaction(['version'], 'readwrite').objectStore('version').delete('funcs') |
| | | } |
| | | } |
| | | |
| | |
| | | if (!window.GLOB.WebSql) { |
| | | return Promise.reject() |
| | | } |
| | | return new Promise((resolve, 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.length === 0) { |
| | | tx.executeSql('DELETE FROM VERSIONS') |
| | | tx.executeSql('DELETE FROM CONFIGS') |
| | | resolve({version: '', createDate: ''}) |
| | | } else { |
| | | if (results.rows[0]) { |
| | | resolve(results.rows[0]) |
| | | } else { |
| | | resolve({version: '', createDate: ''}) |
| | | } |
| | | }, (tx, results) => { |
| | | window.GLOB.WebSql = null |
| | | reject() |
| | | 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) => { |
| | | window.GLOB.WebSql = null |
| | | 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 = '' |
| | | } |
| | | |
| | | /** |
| | | * @description 清空websql中保存的配置信息 |
| | | */ |
| | | static clearWebSqlConfig () { |
| | | if (!window.GLOB.WebSql) return |
| | | window.GLOB.WebSql.transaction(tx => { |
| | | tx.executeSql(`DELETE FROM CONFIGS`, [], () => {}, () => { window.GLOB.WebSql = null }) |
| | | result.menuids = res[1].join(';') |
| | | |
| | | resolve(result) |
| | | }) |
| | | }) |
| | | } |
| | | |
| | |
| | | * @description 删除websql中保存的配置信息 |
| | | */ |
| | | static delWebSqlConfig (keys) { |
| | | if (!window.GLOB.WebSql || !keys) return |
| | | if (!window.GLOB.WebSql) return |
| | | |
| | | if (!keys) { |
| | | window.GLOB.WebSql.transaction(tx => { |
| | | tx.executeSql(`DELETE FROM CONFIGS`, [], () => {}, () => { window.GLOB.WebSql = null }) |
| | | }) |
| | | } else { |
| | | window.GLOB.WebSql.transaction(tx => { |
| | | tx.executeSql(`DELETE FROM CONFIGS where menuid in (${keys})`, [], () => {}, () => { |
| | | window.GLOB.WebSql = null |
| | | }) |
| | | }) |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * @description 更新websql中配置信息的保存时间 |
| | | */ |
| | | static updateWebSqlTime (curTime) { |
| | | if (!window.GLOB.WebSql || !curTime) return |
| | | window.GLOB.WebSql.transaction(tx => { |
| | | tx.executeSql(`UPDATE VERSIONS SET createDate='${curTime}' where CDefine1='LongParam'`, [], () => {}, () => { |
| | | window.GLOB.WebSql = null |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | /** |
| | | * @description 更新websql中配置信息的版本 |
| | | */ |
| | | 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}' where CDefine1='LongParam'`, [], () => {}, () => { |
| | | window.GLOB.WebSql = null |
| | | }) |
| | | }) |
| | | } |
| | | if (!window.GLOB.WebSql) return |
| | | |
| | | /** |
| | | * @description 创建websql中配置信息的版本 |
| | | */ |
| | | static createWebSqlversion (version, curTime) { |
| | | if (!window.GLOB.WebSql || !curTime || !version) 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'], () => {}, () => { |
| | | window.GLOB.WebSql = null |
| | | }) |
| | | } |
| | | }) |
| | | } |
| | | |
| | |
| | | /** |
| | | * @description 打开IndexedDB |
| | | */ |
| | | static openIndexDB (sysType) { |
| | | let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : '' |
| | | static openIndexDB (db) { |
| | | try { |
| | | let request = window.indexedDB.open(`mkdb${service}`, 1) |
| | | let request = window.indexedDB.open(db, 1) |
| | | request.onerror = () => { |
| | | console.warn('IndexedDB 初始化失败!') |
| | | } |
| | |
| | | objectStore.createIndex('menuid', 'menuid', { unique: false }) |
| | | objectStore.createIndex('userid', 'userid', { unique: false }) |
| | | } |
| | | if (window.GLOB.systemType === '' && sysType === 'local' && !window.GLOB.IndexDB.objectStoreNames.contains('funcs')) { |
| | | if (window.GLOB.systemType === '' && !window.GLOB.IndexDB.objectStoreNames.contains('funcs')) { |
| | | window.GLOB.IndexDB.createObjectStore('funcs', { keyPath: 'id' }) |
| | | } |
| | | } |
| | |
| | | if (!window.GLOB.IndexDB) { |
| | | return Promise.reject() |
| | | } |
| | | return new Promise((resolve, reject) => { |
| | | |
| | | let deffers = [] |
| | | |
| | | deffers.push( |
| | | new Promise((resolve) => { |
| | | let request = window.GLOB.IndexDB.transaction(['version']) |
| | | .objectStore('version') |
| | | .get('mksoft') |
| | |
| | | request.onerror = (event) => { |
| | | window.GLOB.IndexDB = null |
| | | console.warn(event) |
| | | reject() |
| | | resolve({version: '', createDate: ''}) |
| | | } |
| | | |
| | | request.onsuccess = () => { |
| | | if (request.result) { |
| | | resolve(request.result) |
| | | } else { |
| | | this.clearIndexDBConfig() |
| | | resolve({version: '', createDate: ''}) |
| | | } |
| | | } |
| | | }) |
| | | } |
| | | ) |
| | | |
| | | /** |
| | | * @description 清空IndexedDB中保存的配置信息 |
| | | */ |
| | | static clearIndexDBConfig () { |
| | | if (!window.GLOB.IndexDB) return |
| | | let request = window.GLOB.IndexDB.transaction(['configs'], 'readwrite').objectStore('configs').clear() |
| | | deffers.push( |
| | | new Promise((resolve) => { |
| | | let request = window.GLOB.IndexDB.transaction(['configs']).objectStore('configs').openCursor() |
| | | let menus = [] |
| | | |
| | | 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'}'`) |
| | | cursor.continue() |
| | | } else { |
| | | resolve(menus) |
| | | } |
| | | } |
| | | }) |
| | | ) |
| | | |
| | | 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) |
| | | }) |
| | | }) |
| | | } |
| | | |
| | | /** |
| | |
| | | static updateIndexDBversion (version) { |
| | | 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 |
| | | } |
| | | } else { |
| | | version.id = 'mksoft' |
| | | |
| | | let objectStore = window.GLOB.IndexDB.transaction(['version'], 'readwrite').objectStore('version') |
| | |
| | | window.GLOB.IndexDB = null |
| | | } |
| | | } else { |
| | | this.clearIndexDBConfig() |
| | | |
| | | let add = objectStore.add(version) |
| | | |
| | | add.onerror = () => { |
| | | window.GLOB.IndexDB = null |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | /** |
| | | * @description 删除IndexedDB中保存的配置信息-批量 |
| | | */ |
| | | static delIndexDBConfig (keys) { |
| | | if (!window.GLOB.IndexDB || !keys) return |
| | | static delIndexDBConfig (menuids) { |
| | | if (!window.GLOB.IndexDB) 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) |
| | | if (!menuids) { |
| | | let request = window.GLOB.IndexDB.transaction(['configs'], 'readwrite').objectStore('configs').clear() |
| | | |
| | | request.onerror = () => { |
| | | window.GLOB.IndexDB = null |
| | | } |
| | | } 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 |
| | | if (cursor) { |
| | | if (menuids.includes(cursor.value.menuid)) { |
| | | cursor.delete() |
| | | } |
| | | cursor.continue() |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | 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) |
| | | |