爱简收旧衣按件回收前端代码仓库
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.
 
 
 
 

58 lines
1.8 KiB

"use strict";
const common_vendor = require("../common/vendor.js");
const utils_utils = require("../utils/utils.js");
const config = require("../config.js");
function http(uri, data, callback, method = "GET", showLoading, title) {
if (showLoading) {
common_vendor.index.showLoading({
title: title || "加载中..."
});
}
return new Promise((resolve, reject) => {
common_vendor.index.request({
url: config.ossConfig.baseUrl + uri,
// 使用 config.baseUrl
data,
method,
header: {
"X-Access-Token": common_vendor.index.getStorageSync("token"),
"Content-Type": "application/x-www-form-urlencoded"
},
success: (res) => {
if (showLoading) {
common_vendor.index.hideLoading();
}
if (res.statusCode == 401 || res.data.message == "操作失败,token非法无效!" || res.data.message == "操作失败,用户不存在!") {
common_vendor.index.__f__("error", "at api/http.js:30", "登录过期");
utils_utils.util.toLogin();
}
if (res.statusCode == 200 && res.data.code != 200 && res.data.code != 902) {
common_vendor.index.showToast({
mask: true,
duration: 1e3,
title: res.data.message,
icon: "none"
});
}
callback && callback(res.data);
resolve(res.data);
},
fail: () => {
reject("api fail");
common_vendor.index.showLoading({});
setTimeout(() => {
common_vendor.index.hideLoading();
common_vendor.index.showToast({ icon: "none", title: "网络异常" });
}, 3e3);
if (showLoading) {
common_vendor.index.hideLoading();
}
}
});
});
}
const http$1 = {
http
};
exports.http = http$1;
//# sourceMappingURL=../../.sourcemap/mp-weixin/api/http.js.map