king
2021-01-20 0227c25e4ed573d3095ada3f9c9a4ba5f18b0de5
src/api/index.js
@@ -7,7 +7,6 @@
import options from '@/store/options.js'
let mkDataBase = null
let storUsable = false
if (window.openDatabase) {
  let service = window.GLOB.service ? '-' + window.GLOB.service.replace('/', '') : ''
@@ -15,7 +14,7 @@
    mkDataBase = openDatabase(`mkdb${service}`, '1', 'mk-pc-database', 50 * 1024 * 1024)
    mkDataBase.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'
@@ -57,7 +56,7 @@
  return Promise.reject(error)
})
const setCurrentUrl = () => {
const setCurrentUrl = (res) => {
  if (!!(window.history && window.history.pushState)) {
    if (window.location.href.indexOf('paramsmain') > -1) {
      let _href = window.location.href.split('#')
@@ -65,12 +64,11 @@
    }
    sessionStorage.clear()
    sessionStorage.setItem('loginError', JSON.stringify({request: res.config ? res.config.data : '', response: JSON.stringify(res.data)}))
    window.history.replaceState(null, null, window.location.href.split('#')[0] + '#/login')
    window.location.reload()
  }
}
window.GLOB.CacheMap = new Map()
axios.interceptors.response.use((response) => {
  if (response.data.ErrCode === 'LoginError') {
@@ -78,19 +76,21 @@
      response.data.ErrCode = 'E'
      return Promise.resolve(response.data)
    } else {
      setCurrentUrl()
      setCurrentUrl(response)
    }
  } else {
    return Promise.resolve(response.data)
  }
}, (error) => {
  notification.error({
    className: 'notification-custom-error',
    bottom: 0,
    message: '状态码-' + error.response.status + ',请联系管理员',
    placement: 'bottomRight',
    duration: 15
  })
  if (error && error.response) {
    notification.error({
      className: 'notification-custom-error',
      bottom: 0,
      message: '状态码-' + error.response.status + ',请联系管理员',
      placement: 'bottomRight',
      duration: 15
    })
  }
  return Promise.reject(error)
})
@@ -335,12 +335,14 @@
        })
      }) 
    }, () => {
      _reject()
      mkDataBase = null
      _reject()
      return Promise.reject()
    }).then(() => {
      storUsable = true
      _resolve(appVersion)
    }, () => {
      mkDataBase = null
      _reject()
    })
  }
@@ -535,7 +537,7 @@
    _param = JSON.stringify(_param)
    _param  = md5(_param)
    
    if (mkDataBase && storUsable) {
    if (mkDataBase) {
      param = this.encryptParam(param)
      return new Promise(resolve => {
@@ -565,6 +567,9 @@
              })
            }
          }, (tx, results) => {
            mkDataBase = null
            console.warn(results)
            axios({
              url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
              data: param
@@ -574,9 +579,6 @@
              }
              resolve(res)
            })
            mkDataBase = null
            storUsable = false
            console.warn(results)
          })
        })
      })
@@ -600,6 +602,46 @@
  }
  /**
   * @description 获取本地系统配置
   * @param {Object}  param   请求参数
   */
  getLocalCacheConfig (param) {
    param.userid = sessionStorage.getItem('UserID') || ''
    param.lang = localStorage.getItem('lang') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = sessionStorage.getItem('LoginUID') || ''
    param.appkey = window.GLOB.appkey || ''
    if (window.GLOB.mainSystemApi) {
      param.rduri = window.GLOB.mainSystemApi
    }
    let _param  = md5(JSON.stringify(param))
    if (mkDataBase) {
      return new Promise(resolve => {
        mkDataBase.transaction(tx => {
          tx.executeSql(`SELECT * FROM CONFIGS WHERE menuid='${param.MenuID}' and userid='${param.userid}'`, [], (tx, results) => {
            let paramItem = results.rows[0]
            if (paramItem) {
              resolve({ ErrCode: 'S', ErrMesg: '', LongParam: paramItem.LongParam, message: '', status: true })
            } else {
              resolve({ ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false })
            }
          }, (tx, results) => {
            mkDataBase = null
            resolve({ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false})
          })
        })
      })
    } else if (window.GLOB.CacheMap.has(_param)) {
      return Promise.resolve(window.GLOB.CacheMap.get(_param))
    } else {
      return Promise.resolve({ErrCode: 'S', ErrMesg: '', LongParam: '', message: '', status: false})
    }
  }
  /**
   * @description 将数据写入websql
   */
  writeInWebSql (data) {