/* wx.request */ const BASE_API = 'https://worker.itthealth.com/api' // const BASE_API = 'https://itt-worker.chl6zk.store/api' const BASE_VERSION = '/v1' import itt from '../utils/util' const app = getApp() export const wxRequest = (url,data) => { return new Promise((resolve, reject) => { wx.request({ url: BASE_API + url + BASE_VERSION, data: data, header: { systemData:JSON.stringify({ requestId: itt.getUUID(), loginToken: wx.getStorageSync('accessToken') || '', timestamp: new Date().getTime() }) }, method: 'POST', success (response) { console.log('当前请求地址:', BASE_API + url); console.log('当前请求参数:', data); console.log('当前请求返回:', response.data); if (response.statusCode !== 200) { reject(response.data || '请求错误') } else { if (response.data.code !== '000' && response.data.code !== '102') { reject(response.data || '请求错误') } else if (response.data.code == '102') { wx.hideLoading() // 重新登录 wx.showModal({ content: response.data.msg, confirmColor: '#333', showCancel: false, success (res) { if (res.confirm) { wx.clearStorageSync() app.globalData.accessToken = '' app.globalData.userName = '' app.globalData.headImg = '' app.globalData.workerId = '' app.globalData.device = null wx.reLaunch({ url: '/pages/login/login' }) } } }) } else { resolve(response.data) } } }, fail (e) { reject('网络错误') } }) }) }