1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- const isTest = true;
- const baseUrl = isTest ? 'http://app.rt/api/mini/' : 'http://t18.9026.com/api/mini/';
- const http = (data) => {
- var data = Object.assign({}, {
- url: '',
- method: 'POST',
- data: {},
- success: null,
- error: null,
- loadTitle: '加载中',
- showLoading: true
- }, data)
- if (data.showLoading) {
- wx.showLoading({
- title: data.loadTitle,
- })
- }
- var userinfo = wx.getStorageSync('sg-userinfo')
- var token = userinfo ? userinfo.token : ''
- wx.request({
- url: baseUrl + data.url,
- method: data.method,
- data: data.data,
- header: {
- 'X-Token': token
- },
- success: function (res) {
- if (data.showLoading) wx.hideLoading()
- if(res.statusCode != 200) {
- wx.showToast({
- title: res.data.message,
- icon: 'none'
- })
- return false
- }
- if (res.data.code != 0) {
- wx.showToast({
- title: res.data.msg,
- icon: 'none'
- })
- }
- typeof data.success === "function" && data.success(res.data)
- },
- fail: function (res) {
-
- typeof data.error === "function" && data.error(res.data)
- }
- })
- }
- module.exports = http
|