Commit c4626648 by 李伟康

commit 无网络提示

1 parent 2b6bd914
......@@ -31,68 +31,82 @@ class Request {
);
}
request (RequestMethods, params, returnAll, hostType = "dj") {
return new Promise((resolve, reject) => {
let header =
RequestMethods === "POST"
? {
"content-type": "application/x-www-form-urlencoded",
}
: {
"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) {
let _this = this
uni.getNetworkType({
success (res) {
if(res.networkType == 'none'){
uni.hideLoading();
uni.reLaunch({
url: "/pages/common/login",
});
} else {
if (code == "0") {
resolve(data.data);
} else {
uni.showToast({
title: message || "系统异常",
icon: "none",
title:'网络异常',
icon: "error",
});
}
reject('网络异常');
return
}
},
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",
let header = RequestMethods === "POST"
? {
"content-type": "application/x-www-form-urlencoded",
}
: {
"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.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") {
......
const target = ["ip", "dev", "uat", "prod", "beta"];
const index = 1;
const index = 2;
/**
*
0本地
......@@ -116,7 +116,6 @@ const CONFIG_ENV_MAP = {
3: "production",
4: "beta",
};
console.log(secretKey, "===");
module.exports = {
index,
domain,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!