import tools from "./tools"; let BASE_URL ='' //#ifndef H5 // BASE_URL ='https://demoapi.jhcs888.com/' BASE_URL ='https://api.jhcs888.com/' //#endif export const request = (url, method, data,isFinance = false,show = false) => { let token = uni.getStorageSync('token') let u_id = uni.getStorageSync('u_id') if(token&&u_id){ data.token = token; data.u_id = u_id } if (show) { tools.showLoading(); } if (data === undefined) { data = {}; } //#ifndef H5 if(isFinance){ BASE_URL = 'https://adopted.jhcs888.com/' }else{ // BASE_URL ='https://demoapi.jhcs888.com/' BASE_URL ='https://api.jhcs888.com/' } //#endif return new Promise((resolve, reject) => { uni.request({ url:BASE_URL+ url, data: data, method: method || 'post', header: { 'content-type': 'application/json', 'hversion': '1.0', 'Authorization': token }, success: (res) => { if (res.statusCode === 200) { tools.hideLoading(); if (res.data.code * 1 === 401) { uni.clearStorageSync() uni.reLaunch({ url: '/pages/login/index' }); } else { resolve(res.data) } }else if(res.statusCode === 401){ uni.clearStorageSync() uni.reLaunch({ url: '/pages/login/index' }); } else{ tools.error('网络错误!!') } }, fail: (err) => { tools.error('网络错误!!') reject(err) tools.hideLoading(); } }) }) }