cczg-lottery-activity/util/request.js

45 lines
969 B
JavaScript
Raw Permalink 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.

import {authState,loginPage} from './auth.js'
//const baseUrL = "/api";
const baseUrl = "https://lottery.api.86698.cn"//"http://192.168.110.39:8090"//
// const baseUrl = "http://39.98.117.3"
const request = (url, method, param = {}, showLoading = false) => {
return new Promise((resolve, reject) => {
let token = undefined
const api = baseUrl + url
if(authState.isLogin())token = authState.state.token
if (showLoading) uni.showLoading({title: ""})
uni.request({
url: api,
data: param,
method: method,
header: {
// 'Content-Type': 'application/x-www-form-urlencoded'
'content-type': 'application/json',
'token': token
},
success: res => {
if (res.data.code == 401) {
authState.logout()
uni.reLaunch({
url: loginPage
})
} else {
resolve(res);
}
},
fail: (error) => {
reject(error);
},
complete() {
uni.hideLoading()
}
})
})
}
export default {
request
}