import tools from "@/service/tools"; let BASE_URL ='' //#ifndef H5 BASE_URL ='https://' + process.uniEnv.baseUrl; //#endif /** * post请求封装 */ export const request = (url, method, data, show = false) => { let token = uni.getStorageSync('token') // data.token = token; // data.m_id = uni.getStorageSync('m_id') if (show) { tools.showLoading(); } if (data === undefined) { data = {}; } 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(); } }) }) }