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.
36 lines
822 B
36 lines
822 B
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 {
|
|
params.error && params.error(res)
|
|
}
|
|
},
|
|
fail: function(res) {
|
|
params.fail && params.fail(res)
|
|
},
|
|
})
|
|
}
|
|
}
|
|
export {HTTP}
|
|
|