146 lines
4.4 KiB
JavaScript
146 lines
4.4 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../common/vendor.js");
|
|
let baseURL = "";
|
|
{
|
|
baseURL = "https://api.valuefrontier.cn:5002";
|
|
}
|
|
function getBaseURL1() {
|
|
return "https://valuefrontier.cn";
|
|
}
|
|
function get(url, params, isNotPort) {
|
|
return new Promise((resolve, reject) => {
|
|
let token = common_vendor.index.getStorageSync("token");
|
|
common_vendor.index.showLoading({
|
|
title: "加载中"
|
|
});
|
|
let baseUrl = baseURL;
|
|
if (isNotPort) {
|
|
baseUrl = "https://api.valuefrontier.cn";
|
|
}
|
|
common_vendor.index.request({
|
|
url: baseUrl + url,
|
|
data: params,
|
|
header: {
|
|
"Accept": "application/json",
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
"Authorization": token ? "Bearer " + token : ""
|
|
},
|
|
method: "GET",
|
|
success: (response) => {
|
|
common_vendor.index.__f__("log", "at request/http.js:47", response);
|
|
common_vendor.index.hideLoading();
|
|
if (response.data.code == 401) {
|
|
common_vendor.index.removeStorageSync("token");
|
|
common_vendor.index.navigateTo({
|
|
url: "/pages/login/login"
|
|
});
|
|
} else {
|
|
resolve(response.data);
|
|
}
|
|
},
|
|
fail: (error) => {
|
|
common_vendor.index.hideLoading();
|
|
common_vendor.index.showToast({
|
|
title: "请求失败",
|
|
icon: "error"
|
|
});
|
|
reject(error.response);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
function post(url, params, isNotPort) {
|
|
return new Promise((resolve, reject) => {
|
|
let token = common_vendor.index.getStorageSync("token");
|
|
let isJson = 0;
|
|
let isFile = 0;
|
|
if (params) {
|
|
isJson = params.isJson;
|
|
}
|
|
if (params) {
|
|
isFile = params.isFile;
|
|
}
|
|
common_vendor.index.showLoading({
|
|
title: "加载中"
|
|
});
|
|
if (isFile) {
|
|
let token2 = common_vendor.index.getStorageSync("token");
|
|
common_vendor.index.uploadFile({
|
|
url: baseURL + url,
|
|
filePath: params.avatar,
|
|
name: "avatar",
|
|
header: {
|
|
"Authorization": token2 ? "Bearer " + token2 : ""
|
|
},
|
|
formData: params,
|
|
success: (response) => {
|
|
common_vendor.index.__f__("log", "at request/http.js:103", response);
|
|
common_vendor.index.hideLoading();
|
|
if (response.data.code == 401) {
|
|
common_vendor.index.removeStorageSync("token");
|
|
common_vendor.index.navigateTo({
|
|
url: "/pages/login/login"
|
|
});
|
|
reject(response.data);
|
|
} else {
|
|
resolve(response.data);
|
|
}
|
|
},
|
|
fail: (error) => {
|
|
common_vendor.index.__f__("log", "at request/http.js:116", "上传失败" + error.errMsg);
|
|
common_vendor.index.hideLoading();
|
|
common_vendor.index.showToast({
|
|
title: "请求失败",
|
|
icon: "error"
|
|
});
|
|
reject();
|
|
}
|
|
});
|
|
} else {
|
|
let baseUrl = baseURL;
|
|
if (url.indexOf("concept-api") > -1 || url.indexOf("api/market/trade/batch") > -1) {
|
|
baseUrl = "https://api.valuefrontier.cn";
|
|
}
|
|
common_vendor.index.request({
|
|
url: baseUrl + url,
|
|
data: params,
|
|
header: {
|
|
"Accept": "application/json",
|
|
"Content-Type": isJson ? "application/json" : isFile ? "multipart/form-data" : "application/x-www-form-urlencoded",
|
|
"Authorization": token ? "Bearer " + token : ""
|
|
},
|
|
method: "POST",
|
|
success: (response) => {
|
|
common_vendor.index.hideLoading();
|
|
if (params && params.isNotNeedLogin)
|
|
;
|
|
else {
|
|
common_vendor.index.__f__("log", "at request/http.js:147", response.data);
|
|
if (response.data.code == 401) {
|
|
common_vendor.index.removeStorageSync("token");
|
|
common_vendor.index.navigateTo({
|
|
url: "/pages/login/login"
|
|
});
|
|
reject(response.data);
|
|
} else {
|
|
resolve(response.data);
|
|
}
|
|
}
|
|
},
|
|
fail: (error) => {
|
|
common_vendor.index.hideLoading();
|
|
common_vendor.index.showToast({
|
|
title: "请求失败",
|
|
icon: "error"
|
|
});
|
|
reject(error.response);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
}
|
|
exports.get = get;
|
|
exports.getBaseURL1 = getBaseURL1;
|
|
exports.post = post;
|
|
//# sourceMappingURL=../../.sourcemap/mp-weixin/request/http.js.map
|