king
2021-01-04 c986f2f56bb153a9b6cebc74b4d9334c85ddfdda
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,6 +64,7 @@
    }
    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()
  }
@@ -78,19 +78,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 +337,14 @@
        })
      }) 
    }, () => {
      _reject()
      mkDataBase = null
      _reject()
      return Promise.reject()
    }).then(() => {
      storUsable = true
      _resolve(appVersion)
    }, () => {
      mkDataBase = null
      _reject()
    })
  }
@@ -535,7 +539,7 @@
    _param = JSON.stringify(_param)
    _param  = md5(_param)
    
    if (mkDataBase && storUsable) {
    if (mkDataBase) {
      param = this.encryptParam(param)
      return new Promise(resolve => {
@@ -565,6 +569,9 @@
              })
            }
          }, (tx, results) => {
            mkDataBase = null
            console.warn(results)
            axios({
              url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
              data: param
@@ -574,9 +581,6 @@
              }
              resolve(res)
            })
            mkDataBase = null
            storUsable = false
            console.warn(results)
          })
        })
      })