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 }