gree_leran/unpackage/dist/dev/mp-weixin/utils/http.js

41 lines
956 B
JavaScript

"use strict";
const common_vendor = require("../common/vendor.js");
const utils_Auth = require("./Auth.js");
const baseUrl = "https://9miao.fun/prod-api";
const http = (option) => {
if (!option instanceof Object) {
throw "参数非法";
}
const {
url,
data
} = option;
const token = utils_Auth.getToken();
return new Promise((resolve, reject) => {
common_vendor.index.request({
header: {
Authorization: token,
...option.header
},
url: baseUrl + url,
data,
method: option.method,
success(res) {
resolve(res.data);
if (res.data.code == 401) {
common_vendor.index.showToast({
icon: "none",
title: "请登录后使用该功能"
});
common_vendor.index.removeStorageSync("token");
}
},
fail(err) {
console.log(err);
reject(err);
}
});
});
};
exports.http = http;