king
2022-09-13 b8cde0c39d7b6d58ceff3adf6dea3cb3118ea602
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 (/\/doupload|\/dopreload|\/upload/.test(config.url)) {
    config.headers = { 'Content-Type': 'multipart/form-data' }
  } else if (config.method === 'post' && config.data) {
    config.data = JSON.stringify(config.data)
@@ -42,13 +42,8 @@
const setCurrentUrl = (res) => {
  if (!!(window.history && window.history.pushState)) {
    if (window.location.href.indexOf('paramsmain') > -1) {
      let _href = window.location.href.split('#')
      localStorage.setItem(_href[0] + 'paramsmain', _href[1])
    }
    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 +54,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 +99,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
    })
  }
@@ -172,7 +236,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')
    }
@@ -207,14 +270,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')
    }
@@ -265,6 +326,11 @@
    // Type: 'X' 时
    // param.Password = Utils.formatOptions(password)
    // positecgroup
    if (window.GLOB.appkey === '202011021844144334E823A3011414082AD77') {
      param.svccode = 'oms'
    }
    param.appkey = window.GLOB.appkey || ''
    let url = '/webapi/dologon'
@@ -281,6 +347,36 @@
      // url = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
      param.rduri = window.GLOB.mainSystemApi.replace(/\/webapi(.*)/, '/webapi/dologon')
    }
    return axios({
      url,
      method: 'post',
      data: param
    })
  }
  /**
   * @description 登录二次验证 // positecgroup
   */
  verifycode (verify) {
    let param = {
      certificate: 'certificate',
      captcha: verify.code,
      token: verify.token,
      ati: verify.ati,
      vid: verify.vid,
      uid: verify.uid,
      shopId: verify.shopId,
      loginId: verify.loginId,
      phone: verify.phone,
      sellerNick: verify.sellerNick,
      isRisk: verify.isRisk,
      requestId: verify.requestId,
      riskNum: verify.riskNum,
      username: verify.username
    }
    let url = '/webapi/dologon'
    return axios({
      url,
@@ -505,33 +601,7 @@
  }
  /**
   * @description 获取或修改本地配置,增加appkey
   */
  getLocalConfig (param) {
    param.userid = param.userid || sessionStorage.getItem('UserID') || ''
    param.lang = param.lang || sessionStorage.getItem('lang') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || ''
    param.appkey = window.GLOB.appkey || ''
    let url = '/webapi/dostars'
    if (param.rduri) {
      url = param.rduri
      delete param.rduri
    }
    param = this.encryptParam(param)
    return axios({
      url: `${url}${param.func ? '/' + param.func : ''}`,
      method: 'post',
      data: param
    })
  }
  /**
   * @description 获取系统配置,取值优先等级websql、缓存、服务器
   * @param {Object}  param   请求参数
   */
  getCacheConfig (param) {
    param.userid = sessionStorage.getItem('UserID') || ''
@@ -626,11 +696,10 @@
  /**
   * @description 获取本地系统配置
   * @param {Object}  param   请求参数
   */
  getLocalCacheConfig (param) {
    param.userid = sessionStorage.getItem('UserID') || ''
    param.lang = param.lang || sessionStorage.getItem('lang') || ''
    param.lang = sessionStorage.getItem('lang') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = sessionStorage.getItem('LoginUID') || ''
    param.appkey = window.GLOB.appkey || ''
@@ -671,7 +740,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
  }
@@ -689,10 +766,10 @@
    param.appkey = window.GLOB.appkey || ''
    let url = '/webapi/dostars'
    if (param.rduri) {
      url = param.rduri
      delete param.rduri
    }
    // if (param.rduri) { // positecgroup
    //   url = param.rduri
    //   delete param.rduri
    // }
    let _param = JSON.parse(JSON.stringify(param)) // 缓存校验,去除时间和加密字符
    delete _param.timestamp
@@ -723,22 +800,18 @@
  /**
   * @description 获取业务通用接口
   * 访问 'https://sso.mk9h.cn/webapi/dostars'或云端时,传入userid、LoginUID
   */
  genericInterface (param) {
    param.userid = sessionStorage.getItem('UserID') || ''
    param.lang = sessionStorage.getItem('lang') || ''
    param.userid = param.userid || sessionStorage.getItem('UserID') || ''
    param.lang = param.lang || sessionStorage.getItem('lang') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = sessionStorage.getItem('LoginUID') || ''
    param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || ''
    param.appkey = window.GLOB.appkey || ''
    if (options.cloudServiceApi && param.rduri === options.cloudServiceApi) { // HS下菜单
      param.userid = sessionStorage.getItem('CloudUserID') || param.userid || ''
      param.LoginUID = sessionStorage.getItem('CloudLoginUID') || param.LoginUID || ''
    }
    // 待优化,增加是否支持跨域请求
    // let url = '/webapi/dostars'
    // if (param.rduri) {
    let url = '/webapi/dostars'
    // positecgroup
    // if (param.rduri && /\/dostars/.test(param.rduri) && param.func !== 'webapi_ChangeUser') { // 切换用户需要通过本地
    //   url = param.rduri
    //   delete param.rduri
    // }
@@ -746,62 +819,62 @@
    param = this.encryptParam(param)
    return axios({
      url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
      url: `${url}${param.func ? '/' + param.func : ''}`,
      method: 'post',
      data: param
    })
  }
  /**
   * @description 导出Excel
   * @description 导出Excel,后台生成文件
   */
  getExcelOut (param, name) {
    param.userid = sessionStorage.getItem('UserID')
    param.lang = sessionStorage.getItem('lang') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = sessionStorage.getItem('LoginUID') || ''
    param.appkey = window.GLOB.appkey || ''
  // getExcelOut (param, name) {
  //   param.userid = sessionStorage.getItem('UserID')
  //   param.lang = sessionStorage.getItem('lang') || ''
  //   param.SessionUid = localStorage.getItem('SessionUid') || ''
  //   param.LoginUID = sessionStorage.getItem('LoginUID') || ''
  //   param.appkey = window.GLOB.appkey || ''
    
    return new Promise(resolve => {
      axios({
        url: '/webapi/doexcel',
        responseType: 'blob',
        method: 'post',
        data: param
      }).then(res => {
        try {
          const blob = new Blob([res])
  //   return new Promise(resolve => {
  //     axios({
  //       url: '/webapi/doexcel',
  //       responseType: 'blob',
  //       method: 'post',
  //       data: param
  //     }).then(res => {
  //       try {
  //         const blob = new Blob([res])
          
          if (res.type === 'application/json') {
            const reader = new FileReader()
            reader.onload = e => resolve(JSON.parse(e.target.result))
            reader.readAsText(blob)
          } else {
            if ('download' in document.createElement('a')) { // 非IE下载
              const elink = document.createElement('a')
              elink.download = name
              elink.style.display = 'none'
              elink.href = URL.createObjectURL(blob)
              document.body.appendChild(elink)
              elink.click()
              URL.revokeObjectURL(elink.href) // 释放URL 对象
              document.body.removeChild(elink)
            } else { // IE10+下载
              navigator.msSaveBlob(blob, name)
            }
            resolve()
          }
        } catch (e) {
          resolve({
            ErrCode: 'E',
            ErrMesg: '文件解析错误',
            message: '',
            status: false
          })
        }
      })
    })
  }
  //         if (res.type === 'application/json') {
  //           const reader = new FileReader()
  //           reader.onload = e => resolve(JSON.parse(e.target.result))
  //           reader.readAsText(blob)
  //         } else {
  //           if ('download' in document.createElement('a')) { // 非IE下载
  //             const elink = document.createElement('a')
  //             elink.download = name
  //             elink.style.display = 'none'
  //             elink.href = URL.createObjectURL(blob)
  //             document.body.appendChild(elink)
  //             elink.click()
  //             URL.revokeObjectURL(elink.href) // 释放URL 对象
  //             document.body.removeChild(elink)
  //           } else { // IE10+下载
  //             navigator.msSaveBlob(blob, name)
  //           }
  //           resolve()
  //         }
  //       } catch (e) {
  //         resolve({
  //           ErrCode: 'E',
  //           ErrMesg: '文件解析错误',
  //           message: '',
  //           status: false
  //         })
  //       }
  //     })
  //   })
  // }
  /**
   * @description 上传base64
@@ -855,11 +928,43 @@
  }
  /**
   * @description oss文件上传
   */
  fileOssUpload (param) {
    let _url = window.GLOB.location + '/file/oss/upload'
    if (process.env.NODE_ENV === 'production') {
      _url = document.location.origin + '/file/oss/upload'
    }
    if (/^http:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
      _url = window.GLOB.location + ':8080/file/oss/upload'
      if (process.env.NODE_ENV === 'production') {
        _url = document.location.origin + ':8080/file/oss/upload'
      }
    } else if (/^https:\/\/(qingqiumarket.cn|cloud.mk9h.cn|sso.mk9h.cn)/.test(_url)) {
      _url = window.GLOB.location + ':8443/file/oss/upload'
      if (process.env.NODE_ENV === 'production') {
        _url = document.location.origin + ':8443/file/oss/upload'
      }
    }
    return axios({
      url: _url,
      method: 'post',
      data: param
    })
  }
  /**
   * @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
    })