king
2022-08-06 cbeffcc0902631909c0373f274752a97ddaf2d4e
src/api/index.js
@@ -29,7 +29,7 @@
axios.interceptors.request.use((config) => {
  if (config.url.includes('LoginAndRedirect') || config.url.includes('getjsonresult') || config.url.includes('wxNativePay')) {
    config.data = qs.stringify(config.data)
  } else if (config.url.includes('Upload') || config.url.includes('doupload') || config.url.includes('dopreload')) {
  } else if (config.url.includes('doupload') || config.url.includes('dopreload')) {
    config.headers = { 'Content-Type': 'multipart/form-data' }
  } else if (config.method === 'post' && config.data) {
    config.data = JSON.stringify(config.data)
@@ -48,7 +48,7 @@
    }
    sessionStorage.clear()
    sessionStorage.setItem('loginError', JSON.stringify({request: res.config ? res.config.data : '', response: JSON.stringify(res.data)}))
    sessionStorage.setItem('loginError', JSON.stringify({url: res.config ? res.config.url : '', 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()
  }
@@ -59,23 +59,29 @@
    if (window.debugger === true) {
      response.data.ErrCode = 'E'
      return Promise.resolve(response.data)
    } else {
    } else if (!sessionStorage.getItem('loginError')) {
      setCurrentUrl(response)
    }
  } else {
    return Promise.resolve(response.data)
  }
}, (error) => {
  if (error && error.response) {
    notification.error({
      className: 'notification-custom-error',
      bottom: 0,
      message: '状态码-' + error.response.status + ',请联系管理员',
      placement: 'bottomRight',
      duration: 15
    })
  let response = error.response
  if (response) {
    if (!response.data || !response.data.errors) { // 过滤旷视报错信息
      notification.error({
        className: 'notification-custom-error',
        bottom: 0,
        message: '状态码-' + response.status + ',请联系管理员',
        placement: 'bottomRight',
        duration: 15
      })
    }
    return Promise.reject(response)
  } else {
    return Promise.reject()
  }
  return Promise.reject(error.response)
})
class Api {
@@ -98,6 +104,69 @@
      url: '/webapi/dostar',
      method: 'post',
      data: param
    })
  }
  /**
   * @description 微信业务请求
   */
  wxAccessToken () {
    let _url = document.location.origin + '/' + window.GLOB.service + 'wxpay/getaccesstoken'
    if (process.env.NODE_ENV !== 'production') {
      _url = document.location.origin + '/wxpay/getaccesstoken'
    }
    return new Promise(resolve => {
      if (window.GLOB.accessToken.accessTime && (parseInt(new Date().getTime() / 1000) - window.GLOB.accessToken.accessTime < 30)) {
        resolve(window.GLOB.accessToken)
      } else {
        window.GLOB.accessToken = {}
        axios({
          url: _url,
          method: 'get'
        }).then(res => {
          if (res.oa_access_token || res.mini_access_token) {
            window.GLOB.accessToken.accessTime = parseInt(new Date().getTime() / 1000)
            window.GLOB.accessToken.oa_access_token = res.oa_access_token
            window.GLOB.accessToken.mini_access_token = res.mini_access_token
          }
          resolve(res)
        })
      }
    })
  }
  /**
   * @description 微信业务请求
   */
  wxNginxRequest (url, method, param) {
    let _url = window.GLOB.location + '/' + url
    if (process.env.NODE_ENV === 'production') {
      _url = document.location.origin + '/' + url
    }
    if (/^http:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
      _url = window.GLOB.location + ':8080/' + url
      if (process.env.NODE_ENV === 'production') {
        _url = document.location.origin + ':8080/' + url
      }
    } else if (/^https:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
      _url = window.GLOB.location + ':8443/' + url
      if (process.env.NODE_ENV === 'production') {
        _url = document.location.origin + ':8443/' + url
      }
    }
    if (param) {
      return axios({
        url: _url,
        method,
        data: param
      })
    }
    return axios({
      url: _url,
      method
    })
  }
@@ -153,7 +222,8 @@
      func: 's_visitor_login',
      timestamp: moment().format('YYYY-MM-DD HH:mm:ss'), 
      SessionUid: _SessionUid,
      TypeCharOne: 'pc'
      TypeCharOne: 'pc',
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host))
    }
    
    param.LText = md5(window.btoa(_SessionUid + param.timestamp))
@@ -171,7 +241,6 @@
    let url = '/webapi/dologon/s_visitor_login'
    if (window.GLOB.mainSystemApi) {
      // url = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login')
      param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon/s_visitor_login')
    }
@@ -195,7 +264,9 @@
      way_no: 'sms_vcode',
      systemType: options.sysType,
      login_city: city,
      login_id_address: ipAddress
      login_id_address: ipAddress,
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
      device_id: localStorage.getItem('SessionUid')
    }
    param.appkey = window.GLOB.appkey || ''
@@ -204,14 +275,12 @@
    if (isCloud) {
      param.debug = 'Y'
      if (options.cloudServiceApi) {
        // url = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
        param.rduri = options.cloudServiceApi.replace(/\/webapi(.*)/, '/webapi/dologon')
      }
    } else if (window.GLOB.mainSystemApi) {
      if (options.sysType !== 'cloud' && window.GLOB.systemType !== 'production') {
        param.linkurl = window.GLOB.linkurl
      }
      // url = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
      param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
    }
@@ -232,7 +301,9 @@
      systemType: options.sysType,
      Type: 'S',
      login_city: city,
      login_id_address: ipAddress
      login_id_address: ipAddress,
      kei_id: window.btoa(window.encodeURIComponent(window.GLOB.host)),
      device_id: localStorage.getItem('SessionUid')
    }
    param.timestamp = moment().format('YYYY-MM-DD HH:mm:ss')
@@ -403,6 +474,7 @@
    CacheUtils.updateWebSqlversion('1.00', curTime)
    CacheUtils.clearIndexDBConfig()
    CacheUtils.updateIndexDBversion({version: '1.00', createDate: curTime})
    CacheUtils.clearFuncs(options.sysType)
  }
  /**
@@ -478,7 +550,7 @@
    param.lang = param.lang || sessionStorage.getItem('lang') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || ''
    param.appkey = window.GLOB.appkey || ''
    param.appkey = param.appkey || window.GLOB.appkey
    let url = '/webapi/dostars'
    if (sessionStorage.getItem('isEditState') === 'true' && options.cloudServiceApi) { // 编辑状态,且存在云端地址
@@ -665,7 +737,15 @@
      }
    })
    param.sign = md5(values)
    param.t = new Date().getTime()
    param.t = new Date().getTime();
    ['arr_field', 'LText_field', 'custom_script', 'LText1', 'LText', 'LText2', 'DateCount'].forEach(key => {
      if (param[key]) {
        let val = param[key]
        delete param[key]
        param[key] = val
      }
    })
    return param
  }
@@ -675,7 +755,7 @@
   * @param {Object}  param   请求参数
   * @param {Boolean} SSO     是否为单点登录地址
   */
  getSystemCacheConfig (param) {
  getSystemCacheConfig (param, cache = true) {
    param.userid = param.userid || sessionStorage.getItem('UserID') || ''
    param.lang = param.lang || sessionStorage.getItem('lang') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
@@ -695,7 +775,7 @@
    _param = JSON.stringify(_param)
    _param  = md5(_param)
    if (window.GLOB.CacheMap.has(_param)) {
    if (cache && window.GLOB.CacheMap.has(_param)) {
      return Promise.resolve(window.GLOB.CacheMap.get(_param))
    } else {
      param = this.encryptParam(param)
@@ -730,17 +810,16 @@
      param.LoginUID = sessionStorage.getItem('CloudLoginUID') || param.LoginUID || ''
    }
    // 待优化,增加是否支持跨域请求
    // let url = '/webapi/dostars'
    // if (param.rduri) {
    //   url = param.rduri
    //   delete param.rduri
    // }
    let url = '/webapi/dostars'
    if (param.rduri && /\/dostars/.test(param.rduri)) {
      url = param.rduri
      delete param.rduri
    }
    param = this.encryptParam(param)
    return axios({
      url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
      url: `${url}${param.func ? '/' + param.func : ''}`,
      method: 'post',
      data: param
    })
@@ -852,8 +931,13 @@
   * @description 获取微信支付二维码
   */
  getWxNativePay (param) {
    let _url = document.location.origin + '/' + window.GLOB.service + 'wxpay/wxNativePay'
    if (process.env.NODE_ENV !== 'production') {
      _url = document.location.origin + '/wxpay/wxNativePay'
    }
    return axios({
      url: '/wxpay/wxNativePay',
      url: _url,
      method: 'post',
      data: param
    })