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.

49 lines
1.3 KiB

"use strict";
const common_vendor = require("../common/vendor.js");
const baseUrl = "https://www.hzkjai.com";
const httpInterceptor = {
invoke(options) {
if (!options.url.startsWith("http")) {
options.url = (options.baseUrl ? options.baseUrl : baseUrl) + options.url;
}
options.timeout = 1e4;
options.header = {
...options.header,
"source-client": "miniapp",
"Content-Type": "application/x-www-form-urlencoded"
};
}
};
common_vendor.index.addInterceptor("request", httpInterceptor);
const http = (options) => {
return new Promise((resolve, reject) => {
common_vendor.index.request({
...options,
//请求成功
success(res) {
console.log("success:", res);
if (res.statusCode >= 200 && res.statusCode < 300) {
resolve(res.data);
} else if (res.statusCode === 401) {
reject(res);
} else {
common_vendor.index.showToast({
icon: "none",
title: res.data.msg || "请求错误"
});
reject(res);
}
},
//响应失败
fail(err) {
common_vendor.index.showToast({
icon: "none",
title: "网络错误,请更换网络试试~"
});
reject(err);
}
});
});
};
exports.http = http;