Commit 02f1dc1d by 李伟康

commit 修复

1 parent 2f3e02ef
...@@ -14,13 +14,13 @@ const HOST = { ...@@ -14,13 +14,13 @@ const HOST = {
ip: 'http://192.168.9.119:8292' ip: 'http://192.168.9.119:8292'
}; };
class Request { class Request {
get(params, returnAll = false, hostType) { get (params, returnAll = false, hostType) {
return this.request("GET", params, returnAll, hostType); return this.request("GET", params, returnAll, hostType);
} }
post(params, returnAll = false, hostType) { post (params, returnAll = false, hostType) {
return this.request("POST", params, returnAll, hostType); return this.request("POST", params, returnAll, hostType);
} }
fetch(method, data, returnAll = true, hostType) { fetch (method, data, returnAll = true, hostType) {
return this.post( return this.post(
{ {
method, method,
...@@ -30,16 +30,16 @@ class Request { ...@@ -30,16 +30,16 @@ class Request {
hostType hostType
); );
} }
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 header =
RequestMethods === "POST" RequestMethods === "POST"
? { ? {
"content-type": "application/x-www-form-urlencoded", "content-type": "application/x-www-form-urlencoded",
} }
: { : {
"Cache-Control": "no-cache", "Cache-Control": "no-cache",
}; };
let projectName = params.projectName; let projectName = params.projectName;
if (!projectName) projectName = this.getRopProject(params.method); if (!projectName) projectName = this.getRopProject(params.method);
const path = pathEnum[projectName]; const path = pathEnum[projectName];
...@@ -51,7 +51,7 @@ class Request { ...@@ -51,7 +51,7 @@ class Request {
header, header,
dataType: "json", dataType: "json",
responseType: "text", responseType: "text",
success(response) { success (response) {
/**业务代码 */ /**业务代码 */
let { let {
data: { code, message }, data: { code, message },
...@@ -77,25 +77,25 @@ class Request { ...@@ -77,25 +77,25 @@ class Request {
} }
} }
}, },
fail(error) { fail (error) {
uni.hideLoading(); uni.hideLoading();
console.error(`${params.method}接口异常:`, error); console.error(`${params.method}接口异常:`, error);
uni.showToast({ uni.showToast({
title: title:
typeof error == "string" typeof error == "string"
? error ? error
: JSON.stringify(error) || "系统异常", : error.errMsg ? error.errMsg : JSON.stringify(error) || "系统异常",
icon: "error", icon: "error",
}); });
reject(error); reject(error);
}, },
complete() { complete () {
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
}, },
}); });
}); });
} }
getData(params, hostType = "scrm") { getData (params, hostType = "scrm") {
let projectName = params.projectName; let projectName = params.projectName;
if (!projectName) projectName = this.getRopProject(params.method); if (!projectName) projectName = this.getRopProject(params.method);
else delete params.projectName; else delete params.projectName;
...@@ -127,11 +127,11 @@ class Request { ...@@ -127,11 +127,11 @@ class Request {
params.appKey = appKey; params.appKey = appKey;
return sign(params, secret, noSignAttr); return sign(params, secret, noSignAttr);
} }
getRopProject(method) { getRopProject (method) {
const projectName = method.split(".")[2]; const projectName = method.split(".")[2];
return projectName; return projectName;
} }
uni_request({ uni_request ({
url, url,
method = "GET", method = "GET",
data = {}, data = {},
...@@ -147,7 +147,7 @@ class Request { ...@@ -147,7 +147,7 @@ class Request {
header, header,
dataType, dataType,
responseType, responseType,
success(response) { success (response) {
resolve(response.data); resolve(response.data);
}, },
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!