1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| import { baseUrl } from './http.js' module.exports = {
request : function(url, methodType, data){ let fullUrl = `${baseUrl}${url}` let token = wx.getStorageSync('token') ? wx.getStorageSync('token') : '' wx.showLoading({ title: "加载中" }); return new Promise((resolve,reject)=>{ wx.request({ url: fullUrl, method:methodType, data, header: { 'content-type': 'application/json', 'x-api-key': token, }, success: (res) => { if (res.data.status == 200) { resolve(res.data) }else{ wx.showToast({ title: res.data.msg, icon:'none' }) reject(res.data.message) } }, fail: () => { wx.showToast({ title: '接口请求错误', icon:'none' }) reject('接口请求错误') }, complete: () => { setTimeout(() => { wx.hideLoading() }, 100) } }) }) } }
|