当前位置:网站首页>开发环境和测试环境的发包(及uniapp的request封装)
开发环境和测试环境的发包(及uniapp的request封装)
2022-06-21 21:16:00 【wh20141212】
// created by wangyong for uni-app request 2019.11.22
const isDev = process.env.NODE_ENV === 'development'
let baseURL = null
if (process.env.NODE_ENV === 'development') {
// 这里就是本地跑的情况 就是本地运行 分安卓机和ios机 如果想在正式环境上运行将域名换为正式域名即可
baseURL = '/api';
// console.log('开发环境')
// #ifdef APP-PLUS
switch (uni.getSystemInfoSync().platform) {
case 'android':
console.log('运行Android上')
baseURL = 'http://www.ceshi.kewek.com.cn/'
break;
case 'ios':
// console.log('运行iOS上')
baseURL = 'http://www.ceshi.kewek.com.cn/'
break;
default:
// console.log('运行在开发者工具上')
break;
}
// #endif
} else {
// 这就是发包以后 所在的环境 第一个为测试环境 第二个为正式环境
console.log('生产环d境')
// baseURL = 'http://www.zhengshi.kewek.com.cn/';
baseURL = 'http://www.ceshi.kewek.com.cn/'
}
const http = (options) => {
return new Promise((resolve, reject) => {
// uni.showLoading({
// title: '加载中...',
// mask: options.load || false // 默认遮罩出现可以继续操作
// });
try {
uni.request({
url: (options.baseURL || baseURL) + options.url,
method: options.method || 'POST', // 默认为POST请求
data: options.data, //请求超时在manifest.json配置
header: {
'token': uni.getStorageSync('token'),
'Content-Type': options.header == 'form' ? 'application/x-www-form-urlencoded' : 'application/json'
},
// sslVerify:false,
success: res => {
if (res.data.code == 401) {
uni.clearStorage();
uni.showToast({
title: res.data.message,
icon: 'none',
mask: true
})
// setTimeout(function() {
// uni.reLaunch({
// url: '/pages/login/login',
// success: ress => {
// uni.showToast({
// title: res.data.message,
// icon: 'none',
// mask: true
// })
// }
// });
// }, 1000);
} else if (res.data.code == 405) {
// uni.reLaunch({
// url: '/pages/login/login',
// success: ress => {
// uni.showToast({
// title: "尚未登录,请先登录!",
// icon: 'none',
// mask: true
// })
// }
// });
uni.hideLoading();
}
resolve(res)
},
fail: (err) => {
reject(err.data);
console.log(err);
uni.showToast({
title: '请检查网络连接',
icon: 'none'
})
/*错误码处理
let code = err.data.code;
switch (code) {
case 1000:
break;
default:
break;
} */
},
complete: () => {
// uni.hideLoading();
}
});
} catch (e) {
console.log(e)
// uni.hideLoading();
uni.showToast({
title: '服务端异常',
icon: 'none'
})
}
})
}
export default http
边栏推荐
- 翻译软件Bob安装教程
- Flow cytometry flowjo 10 introduction and ultra detailed graphic installation activation tutorial
- 378. 有序矩阵中第 K 小的元素-常规法
- 语音信号处理之多阶MFCC提取(matlab)
- FPGA之道——FPGA开发流程之项目方案与FPGA设计方案
- Analysis of 43 cases of MATLAB neural network: Chapter 9 associative memory of discrete Hopfield Neural Network -- number recognition
- Flink real-time risk control rule engine
- Professional font design editor glyphs 3
- plt修改横纵坐标颜色
- 必讀書籍
猜你喜欢

使用云开发实现微信支付的具体方法

Translation software Bob installation tutorial

《MATLAB 神经网络43个案例分析》:第9章 离散Hopfield神经网络的联想记忆——数字识别

Matlab2020a使用App Designer如何导出exe

Professional font design editor glyphs 3

promise错误捕获处理——Promisifying技术

Multi order MFCC extraction for speech signal processing (matlab)

WPF routing

Resolve the invalidation of OpenCV code prompt in pycharm

About Eureka starting successfully but accessing 404
随机推荐
KVM虚拟机救援模式修改root密码 —— 筑梦之路
Flink实战之实时风控规则引擎
初识 vxe-table (一)
专业字体设计编辑Glyphs 3
在小程序的 wxml 文件中使用 js 函数
An error prone to appear when MATLAB is doing image processing: to improve the operation speed, use the pre declared zero matrix to store image data
WPF ListBox虚拟化
WPF x:ArrayExtension
Better manage all kinds of music, professional DJ music management software pioneer DJ rekordbox
Common options and commands of Synplify Pro
Qt滚动区域QScrollArea
花200W买流量,不如0成本起步做独立站私域运营收益高!
js 监听和移除监听事件
Design and implementation of spark offline development framework
企业微信内置应用h5开发记录-1
将字符串按长度截取成数组
Analysis of 43 cases of MATLAB neural network: Chapter 19 handwritten font recognition based on SVM
plt修改横纵坐标颜色
阿里出品!图形化的ant脚本——IDEA插件CloudToolkit
Text text associated with scroll scroll bar in Tkinter