const apiCode = require('../config/code.js').apiCode;
const $api = require('../config/api.js').$api;
const $HttpSever = function () { }

$HttpSever.prototype = {
  /**
   *  通用请求方法
   * 
   * @param {any} [config={}] 
   * @returns 
   */
  Ajax(config = {}) {
    return new Promise((resolve, reject) => {
      wx.request({
        url: config.url,
        method: config.method,
        data: {
          ...config.data
        },
        success(res) {
          if (res.statusCode && res.statusCode === apiCode.common.successCode) {
            resolve(res.data)
          } else {
            resolve(res.data.message + "失败")
          }
        },
        error(msg) {
          reject(msg)
        }
      })
    })
  },
}
module.exports = {
  HttpSever: new $HttpSever()
}