12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- //设置域名
- const dev_baseUrl = 'http://192.168.11.17:8800/hanghui-warehouse'; //测试
- const pro_baseUrl = 'https://noise.hz-hanghui.com:8088/hanghui-warehouse'; //正式
- //是否是正式环境
- const wx_rlxf = true
- const baseUrl = wx_rlxf ? pro_baseUrl : dev_baseUrl;
- // https请求
- const request = e => {
- let token = uni.getStorageSync('token');
- return new Promise((resolve, reject) => {
- uni.request({
- url: wx_rlxf ? (pro_baseUrl + e.url) : (dev_baseUrl + e.url),
- method: e.method,
- data: e.data,
- header: {
- 'Content-Type': e.type,
- 'Authorization': token ? token : null,
- },
- success: res => {
- if (res.data.code == 200) {
- resolve(res.data)
- uni.hideLoading(); //关闭loading
- } else {
- wx.showToast({
- icon: 'none',
- title: res.data.msg,
- })
- reject(res.data)
- uni.hideLoading(); //关闭loading
- };
- },
- fail: error => {
- reject(error);
- uni.hideLoading(); //关闭loading
- },
- complete: () => {
- uni.hideLoading(); //关闭loading
- }
- })
- })
- }
- export default request;
|