38 lines
941 B
JavaScript
38 lines
941 B
JavaScript
|
"use strict";
|
||
|
const common_vendor = require("../common/vendor.js");
|
||
|
const utils_Auth = require("./Auth.js");
|
||
|
const baseUrl = "http://127.0.0.1:8085";
|
||
|
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;
|