Commit c4626648 by 李伟康

commit 无网络提示

1 parent 2b6bd914
...@@ -31,68 +31,82 @@ class Request { ...@@ -31,68 +31,82 @@ class Request {
); );
} }
request (RequestMethods, params, returnAll, hostType = "dj") { request (RequestMethods, params, returnAll, hostType = "dj") {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let header = let _this = this
RequestMethods === "POST" uni.getNetworkType({
? { success (res) {
"content-type": "application/x-www-form-urlencoded", if(res.networkType == 'none'){
}
: {
"Cache-Control": "no-cache",
};
let projectName = params.projectName;
if (!projectName) projectName = this.getRopProject(params.method);
const path = pathEnum[projectName];
params = this.getData(params, hostType);
uni.request({
url: `${HOST[hostType]}${path}router?method=${params.method}`,
data: params,
method: RequestMethods,
header,
dataType: "json",
responseType: "text",
success (response) {
/**业务代码 */
let {
data: { code, message },
data,
} = response;
if (returnAll) {
resolve(data);
return;
}
if (code == 20 || code == 21) {
uni.hideLoading(); uni.hideLoading();
uni.reLaunch({
url: "/pages/common/login",
});
} else {
if (code == "0") {
resolve(data.data);
} else {
uni.showToast({ uni.showToast({
title: message || "系统异常", title:'网络异常',
icon: "none", icon: "error",
}); });
} reject('网络异常');
return
} }
}, let header = RequestMethods === "POST"
fail (error) { ? {
uni.hideLoading(); "content-type": "application/x-www-form-urlencoded",
console.error(`${params.method}接口异常:`, error); }
uni.showToast({ : {
title: "Cache-Control": "no-cache",
typeof error == "string" };
? error let projectName = params.projectName;
: error.errMsg ? error.errMsg : JSON.stringify(error) || "系统异常", if (!projectName) projectName = _this.getRopProject(params.method);
icon: "error", const path = pathEnum[projectName];
params = _this.getData(params, hostType);
uni.request({
url: `${HOST[hostType]}${path}router?method=${params.method}`,
data: params,
method: RequestMethods,
header,
dataType: "json",
responseType: "text",
success (response) {
/**业务代码 */
let {
data: { code, message },
data,
} = response;
if (returnAll) {
resolve(data);
return;
}
if (code == 20 || code == 21) {
uni.hideLoading();
uni.reLaunch({
url: "/pages/common/login",
});
} else {
if (code == "0") {
resolve(data.data);
} else {
uni.showToast({
title: message || "系统异常",
icon: "none",
});
}
}
},
fail (error) {
uni.hideLoading();
console.error(`${params.method}接口异常:`, error);
uni.showToast({
title:
typeof error == "string"
? error
: error.errMsg ? error.errMsg : JSON.stringify(error) || "系统异常",
icon: "error",
});
reject(error);
},
complete () {
uni.stopPullDownRefresh();
},
}); });
reject(error); }
}, })
complete () {
uni.stopPullDownRefresh();
},
});
}); });
} }
getData (params, hostType = "scrm") { getData (params, hostType = "scrm") {
......
const target = ["ip", "dev", "uat", "prod", "beta"]; const target = ["ip", "dev", "uat", "prod", "beta"];
const index = 1; const index = 2;
/** /**
* *
0本地 0本地
...@@ -116,7 +116,6 @@ const CONFIG_ENV_MAP = { ...@@ -116,7 +116,6 @@ const CONFIG_ENV_MAP = {
3: "production", 3: "production",
4: "beta", 4: "beta",
}; };
console.log(secretKey, "===");
module.exports = { module.exports = {
index, index,
domain, domain,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!