king
2021-02-02 316877c1d9e5b6d92334f30b03d97d7e833cd934
src/api/index.js
@@ -41,13 +41,11 @@
axios.defaults.withCredentials = true
axios.interceptors.request.use((config) => {
  config.method = 'post'
  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')) {
    config.headers = { 'Content-Type': 'multipart/form-data' }
  } else {
    // config.headers.token = sessionStorage.getItem('TOKEN') || ''
  } else if (config.method === 'post') {
    config.data = JSON.stringify(config.data)
  }
@@ -101,7 +99,7 @@
      duration: 15
    })
  }
  return Promise.reject(error)
  return Promise.reject(error.response)
})
class Api {
@@ -122,6 +120,7 @@
    return axios({
      url: '/webapi/dostar',
      method: 'post',
      data: param
    })
  }
@@ -144,6 +143,30 @@
    })
  }
  /* @description 直接请求
   * @param {Object} param 查询及提交参数
   */
  directRequest (url, method = 'post', param) {
    let params = { method: 'post' }
    let _url = url
    if (method === 'get' && param) {
      let keys = Object.keys(param).map(key => `${key}=${param[key]}`)
      keys = keys.join('&')
      if (keys) {
        _url = _url + '?' + keys
      }
    } else if (method === 'post' && param) {
      params.data = param
    }
    _url = _url.replace(/&/ig, '%26')
    // _url = window.btoa(_url)
    params.url = '/trans/redirect?rd=' + _url + '&method=' + method
    return axios(params)
  }
  /**
   * @description 使用dostar接口,跳转至dostars
   * @param {Object} param 查询及提交参数
@@ -156,6 +179,7 @@
    return axios({
      url: '/webapi/dostar',
      method: 'post',
      data: param
    })
  }
@@ -189,6 +213,7 @@
    return axios({
      url: '/webapi/dologon',
      method: 'post',
      data: param
    })
  }
@@ -220,6 +245,7 @@
    return axios({
      url: '/webapi/dologon',
      method: 'post',
      data: param
    })
  }
@@ -250,6 +276,7 @@
    return axios({
      url: '/webapi/dologon',
      method: 'post',
      data: param
    })
  }
@@ -312,6 +339,7 @@
      return new Promise((resolve, reject) => {
        axios({
          url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
          method: 'post',
          data: param
        }).then(res => {
          if (!res.status) {
@@ -442,6 +470,7 @@
    return axios({
      url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
      method: 'post',
      data: param
    })
  }
@@ -482,6 +511,7 @@
      return new Promise(resolve => {
        axios({
          url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
          method: 'post',
          data: param
        }).then(res => {
          if (res.status) {
@@ -515,6 +545,7 @@
    return axios({
      url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
      method: 'post',
      data: param
    })
  }
@@ -533,6 +564,7 @@
    return axios({
      url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
      method: 'post',
      data: param
    })
  }
@@ -586,6 +618,7 @@
            } else {
              axios({
                url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
                method: 'post',
                data: param
              }).then(res => {
                if (res.status) {
@@ -600,6 +633,7 @@
            axios({
              url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
              method: 'post',
              data: param
            }).then(res => {
              if (res.status) {
@@ -618,6 +652,7 @@
      return new Promise(resolve => {
        axios({
          url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
          method: 'post',
          data: param
        }).then(res => {
          if (res.status) {
@@ -730,6 +765,7 @@
      return new Promise(resolve => {
        axios({
          url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
          method: 'post',
          data: param
        }).then(res => {
          if (res.status) {
@@ -751,8 +787,8 @@
    param.LoginUID = sessionStorage.getItem('LoginUID') || ''
    param.appkey = window.GLOB.appkey || ''
    if (sessionStorage.getItem('isEditState') === 'true') { // HS下菜单
      param.userid = sessionStorage.getItem('CloudUserID')
    if (options.cloudServiceApi && param.rduri === options.cloudServiceApi) { // HS下菜单
      param.userid = sessionStorage.getItem('CloudUserID') || ''
      param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
    }
@@ -760,6 +796,7 @@
    return axios({
      url: `/webapi/dostars${param.func ? '/' + param.func : ''}`,
      method: 'post',
      data: param
    })
  }
@@ -778,6 +815,7 @@
      axios({
        url: '/webapi/doexcel',
        responseType: 'blob',
        method: 'post',
        data: param
      }).then(res => {
@@ -819,28 +857,15 @@
   * @description 上传base64
   * @param {String} base64 base64图片编码
   */
  fileuploadbase64 (base64, service = 'local') {
    let param = {
      func: '',
      BasePath: 'Content/Upload',
      lang: localStorage.getItem('lang') || '',
      appkey: window.GLOB.appkey || '',
      Base64Img: base64
    }
  fileuploadbase64 (param) {
    param.func = ''
    param.BasePath = 'Content/Upload'
    param.lang = localStorage.getItem('lang') || ''
    param.appkey = window.GLOB.appkey || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    if (service === 'sso' && window.GLOB.mainSystemApi) {
      param.rduri = window.GLOB.mainSystemApi
      param.userid = sessionStorage.getItem('UserID')
      param.LoginUID = sessionStorage.getItem('LoginUID') || ''
    } else if (service === 'cloud' && options.cloudServiceApi) {
      param.rduri = options.cloudServiceApi
      param.userid = sessionStorage.getItem('CloudUserID')
      param.LoginUID = sessionStorage.getItem('CloudLoginUID') || ''
    } else {
      param.userid = sessionStorage.getItem('UserID')
      param.LoginUID = sessionStorage.getItem('LoginUID') || ''
    }
    param.userid = param.userid || sessionStorage.getItem('UserID') || ''
    param.LoginUID = param.LoginUID || sessionStorage.getItem('LoginUID') || ''
    param = this.encryptParam(param)
@@ -849,11 +874,13 @@
      return axios({
        url: '/webapi/dostars',
        method: 'post',
        data: param
      })
    } else {
      return axios({
        url: '/webapi/SaveBase64Image',
        method: 'post',
        data: param
      })
    }
@@ -865,6 +892,7 @@
  getLargeFileUpload (param) {
    return axios({
      url: '/webapi/doupload',
      method: 'post',
      data: param
    })
  }
@@ -875,6 +903,7 @@
  getFilePreUpload (param) {
    return axios({
      url: '/webapi/dopreload',
      method: 'post',
      data: param
    })
  }
@@ -885,53 +914,21 @@
  getWxNativePay (param) {
    return axios({
      url: '/wxpay/wxNativePay',
      method: 'post',
      data: param
    })
  }
  /**
   * @description 文件上传
   */
  getFileUpload (param) {
    return axios({
      url: '/zh-CN/Home/Upload',
      data: param
    })
  }
  /**
   * @description 通用接口(数据管理)
   * @param {Object} param 查询及提交参数
   */
  commonInterface (param) {
    param.userid = sessionStorage.getItem('UserID')
    param.lang = localStorage.getItem('lang') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = sessionStorage.getItem('LoginUID') || ''
    param.BID = param.BID || ''
    param.debug = param.debug || ''
    return axios({
      url: '/webapi/dostar',
      data: param
    })
  }
  /**
   * @description 通用接口(提交)(数据管理)
   * @param {Object} param 查询及提交参数
   */
  submitInterface (param) {
    param.userid = sessionStorage.getItem('UserID')
    param.lang = localStorage.getItem('lang') || ''
    param.SessionUid = localStorage.getItem('SessionUid') || ''
    param.LoginUID = sessionStorage.getItem('LoginUID') || ''
    return axios({
      url: '/webapi/dostar',
      data: param
    })
  }
  // /**
  //  * @description 文件上传
  //  */
  // getFileUpload (param) {
  //   return axios({
  //     url: '/zh-CN/Home/Upload',
  //     method: 'post',
  //     data: param
  //   })
  // }
}
export default new Api()