榆山
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.

45 lines
1.2 KiB

var global = require('./config.js')
export default function request ({method, url, options = {}}) {
return new Promise((resolve, reject) => {
wx.request({
// url: `${config.apiUrl}${url}`,
url: `${global.CLERKONLINE()}${url}`,
method: method,
data: method === 'GET' ? options : JSON.stringify(options),
header: {
'Content-Type': 'application/json; charset=UTF-8',
'Authorization': wx.getStorageSync('token')
},
success (response) {
if (response.statusCode === 200) {
if (response.data.code === 0) {
resolve(response.data)
} else {
wx.showToast({
title: response.data.msg,
icon: 'none',
duration: 2000
})
reject(response.data)
}
} else {
wx.showToast({
title: '网络问题,请稍后再试~',
icon: 'none',
duration: 2000
})
reject(false)
}
},
fail (err) {
wx.showToast({
title: '网络问题,请稍后再试~',
icon: 'none',
duration: 2000
})
reject(err)
}
})
})
}