lottery-flip-card/util/request.js

56 lines
1.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// const BASE_URL = "/api";
const BASE_URL = "https://lottery.api.86698.cn"//"http://192.168.110.39:8000"//
export const baseUrl = BASE_URL
const request = (url, method, data = {}, showLoading = false) => {
return new Promise((resolve, reject) => {
const token = getApp().globalData.token
if (token == "") {
uni.reLaunch({
url: "/pages/index/index"
})
return false
}
if (showLoading) {
uni.showLoading({
title: ""
})
}
let api = baseUrl + url
let tempData = data
uni.request({
url: api,
data: tempData,
method: method,
header: {
// 'Content-Type': 'application/x-www-form-urlencoded'
'content-type': 'application/json',
'token': token
},
success: res => {
uni.hideLoading()
if (res.data.code == 401) {
uni.removeStorageSync('token')
uni.reLaunch({
url: "/pages/index/index"
})
} else {
resolve(res);
}
},
fail: (error) => {
uni.hideLoading()
console.log('接口异常api', api)
console.log('接口异常入参', tempData)
console.log('接口异常返参', error)
reject(error);
},
complete() {
uni.hideLoading()
}
})
})
}
export default {
request
}