You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { config } from '../config.js'
|
|
|
|
|
|
|
|
class HTTP {
|
|
|
|
constructor() {
|
|
|
|
this.baseUrl = config.api_url
|
|
|
|
}
|
|
|
|
request = (params) => {
|
|
|
|
let url = this.baseUrl + params.url
|
|
|
|
if (!params.method) {
|
|
|
|
params.method = 'GET'
|
|
|
|
}
|
|
|
|
wx.request({
|
|
|
|
url: url,
|
|
|
|
data: params.data,
|
|
|
|
header: {
|
|
|
|
'content-type': 'application/json',
|
|
|
|
},
|
|
|
|
method: params.method,
|
|
|
|
dataType: 'json',
|
|
|
|
success: function (res) {
|
|
|
|
console.log(res)
|
|
|
|
let code = res.statusCode.toString()
|
|
|
|
let startCode = code.charAt(0)
|
|
|
|
if (startCode == '2') {
|
|
|
|
params.success && params.success(res.data)
|
|
|
|
} else {
|
|
|
|
console.log('请求错误')
|
|
|
|
params.error && params.error(res)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
fail: function (res) {
|
|
|
|
console.log('服务器错误')
|
|
|
|
params.fail && params.fail(res)
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
export { HTTP }
|