123456789101112131415161718192021222324252627282930313233 |
- const { baseUrl } = require('./env').prod
- module.exports = {
- request : function(url, type , data = {}){
- let fullUrl = `${baseUrl}${url}`
- var token = wx.getStorageSync('token') || ''
- return new Promise((resolve,reject)=>{
- wx.request({url: fullUrl,method:type,data,header: {'content-type': 'application/json','Authorization': token},
- success(res){
- if(res.data.code == 0){
- resolve(res)
- }else if(res.data.code == 401){
- wx.navigateTo({
- url: '/pages/sign/sign',
- })
- }else{
- wx.showModal({
- title: '错误',
- content: res.data.msg,
- showCancel:false
- })
- }
- },
- fail(){
- wx.showToast({
- title: '接口请求错误',
- icon:'none'
- })
- reject('接口请求错误')
- }
- })
- })
- },
- }
|