You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
102 lines
2.4 KiB
102 lines
2.4 KiB
|
|
const HOSTARR = {
|
|
'development': 'https://yunyubang.ali251.langye.net',
|
|
'production': 'https://yunyubang.ali251.langye.net'
|
|
};
|
|
|
|
const HOST = HOSTARR[process.env
|
|
.NODE_ENV]; //"https://tiantianxinye.365care.langye.net/";//HOSTARR[process.env.NODE_ENV];//
|
|
|
|
const request = options => {
|
|
if (!options.customLoading) {
|
|
//if(false){
|
|
uni.showLoading({
|
|
title: '正在加载'
|
|
});
|
|
} else {
|
|
// 当前页面请求数量+1
|
|
if (options.bindThis) {
|
|
//options.bindThis.loadingCount=options.bindThis.data.loadingCount + 1;
|
|
}
|
|
}
|
|
|
|
options.url = HOST + options.api;
|
|
options.header = {
|
|
...options.header,
|
|
//'Accept': 'application/json',
|
|
//'Connection': 'keep-alive'
|
|
//'content-type': 'application/json'
|
|
}; // 如果已登录,请求中拼openId
|
|
|
|
|
|
if (options.method == 'POST') {
|
|
// 拼时间戳
|
|
options.data.ts = new Date().getTime();
|
|
}
|
|
|
|
uni.request({
|
|
...options,
|
|
success: function(res) {
|
|
uni.hideLoading();
|
|
if (res.statusCode != 200) {
|
|
if (options.utilFail != undefined) {
|
|
if (res.statusCode == 401) {
|
|
uni.clearStorageSync();
|
|
uni.navigateTo({
|
|
url: '/pages/login/login'
|
|
});
|
|
} else {
|
|
options.utilFail('TODO: 特殊处理非200错误(' + res.statusCode + ')');
|
|
}
|
|
}
|
|
} else {
|
|
if (!isNull(res.data.errorcode) || res.data.errorcode == 0) {
|
|
if (options.utilFail != undefined) {
|
|
options.utilFail(res.data.errormsg || '接口发生未知错误');
|
|
} else {
|
|
options.utilFail(res.data.errormsg);
|
|
}
|
|
} else {
|
|
if (options.utilSuccess != undefined) {
|
|
options.utilSuccess(res.data);
|
|
}
|
|
}
|
|
}
|
|
},
|
|
fail: function(res) {
|
|
uni.hideLoading();
|
|
options.utilFail(res);
|
|
},
|
|
complete: function(res) {
|
|
if (!options.customLoading) {
|
|
uni.hideNavigationBarLoading();
|
|
|
|
} else {
|
|
// 当前页面请求数量-1
|
|
if (options.bindThis) {
|
|
//options.bindThis.setData({
|
|
//loadingCount: options.bindThis.data.loadingCount - 1
|
|
//});
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}; // 提交formID封装
|
|
const isNull = p => {
|
|
return p == '' || p == undefined || p == null || p == 'undefined' || p == 'null';
|
|
}; // 正则
|
|
|
|
const alert = msg => {
|
|
uni.showModal({
|
|
title: '',
|
|
content: msg,
|
|
showCancel: false
|
|
});
|
|
}; // 订单状态
|
|
module.exports = {
|
|
HOST: HOST,
|
|
request: request,
|
|
isNull:isNull,
|
|
alert:alert
|
|
};
|