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.
93 lines
2.5 KiB
93 lines
2.5 KiB
const app = getApp()
|
|
|
|
const service = (options) => {
|
|
return new Promise((resolve, reject) => {
|
|
wx.showLoading({
|
|
title: '加载中',
|
|
})
|
|
wx.request({
|
|
url: `${app.globalData.baseurl}${options.url}`,
|
|
method: options.method,
|
|
data: options.data,
|
|
header: {
|
|
'content-type': options.isJson ? 'application/json' : 'application/x-www-form-urlencoded',
|
|
'M-Token': wx.getStorageSync('token') ? wx.getStorageSync('token') : '' // 看自己是否需要
|
|
},
|
|
success(request) {
|
|
// console.log('success:', request);
|
|
if(request.data.code == 1) {
|
|
resolve(request.data)
|
|
// }else if(request.data.code == 508) {
|
|
// wx.showModal({
|
|
// title: '提示',
|
|
// content: '当前暂未登录',
|
|
// showCancel: false,
|
|
// confirmText: '立即登录',
|
|
// success: res => {
|
|
// if (res.confirm) {
|
|
// wx.navigateTo({
|
|
// url: '/pages/login/login'
|
|
// })
|
|
// }
|
|
// }
|
|
// })
|
|
}
|
|
// if (request.data.code == 0) {
|
|
// resolve(request)
|
|
// } else {
|
|
// reject(request)
|
|
// }
|
|
},
|
|
fail(error) {
|
|
console.log('error:', error);
|
|
reject(error.data)
|
|
},
|
|
complete: () => {
|
|
setTimeout(() => {
|
|
wx.hideLoading();
|
|
}, 100);
|
|
}
|
|
})
|
|
})
|
|
}
|
|
|
|
export default service
|
|
|
|
/*
|
|
// 示例get请求
|
|
const demoGetApi = (options) => {
|
|
return service({
|
|
url: '',
|
|
method: 'GET',
|
|
data: options
|
|
})
|
|
}
|
|
|
|
// 示例post参数请求
|
|
const demoPostApi = (options) => {
|
|
return service({
|
|
url: '',
|
|
method: 'POST',
|
|
data: options,
|
|
})
|
|
}
|
|
|
|
|
|
// 示例put请求
|
|
const demoPutApi = (options) => {
|
|
return service({
|
|
url: '',
|
|
method: 'PUT',
|
|
data: options
|
|
})
|
|
}
|
|
|
|
// 示例DELETE
|
|
const demoRemoveApi = (options) => {
|
|
return service({
|
|
url: '',
|
|
method: 'DELETE',
|
|
data: options
|
|
})
|
|
}
|
|
*/
|