class request {
    constructor() {
     this._baseUrl = 'https://xzjl-api.windymuse.cn';
     this._token = wx.getStorageSync('token');
     this._header = {'Authorization': this._token}
    }
    
    /**
     * GET类型的网络请求
     */
    getRequest(url, data, header = this._header) {
     return this.requestAll(url, data, header, 'GET')
    }
    
    /**
     * DELETE类型的网络请求
     */
    deleteRequest(url, data, header = this._header) {
     return this.requestAll(url, data, header, 'DELETE')
    }
    
    /**
     * PUT类型的网络请求
     */
    putRequest(url, data, header = this._header) {
     return this.requestAll(url, data, header, 'PUT')
    }
    
    /**
     * POST类型的网络请求
     */
    postRequest(url, data, header = this._header) {
     return this.requestAll(url, data, header, 'POST')
    }
    
    /**
     * 网络请求
     */
    requestAll(url, data, header, method) {
     return new Promise((resolve, reject) => {
      wx.request({
       url: this._baseUrl + url,
       data: data,
       header: {'Authorization': wx.getStorageSync('token')},
       method: method,
       success: (res => {
        if (res.statusCode === 200) {
         //200: 服务端业务处理正常结束
         resolve(res)
        } else {
         //其它错误，提示用户错误信息
         reject(res)
        }
       }),
       fail: (res => {
        reject(res)
       })
      })
     })
    }
   }
    
   export default request