2024-06-16 01:04:56 +00:00
|
|
|
"use strict";
|
|
|
|
const common_vendor = require("../common/vendor.js");
|
|
|
|
const utils_Auth = require("./Auth.js");
|
2024-06-22 07:31:44 +00:00
|
|
|
const baseUrl = "https://9miao.fun/prod-api";
|
2024-06-16 01:04:56 +00:00
|
|
|
const http = (option) => {
|
|
|
|
if (!option instanceof Object) {
|
|
|
|
throw "参数非法";
|
|
|
|
}
|
2024-06-16 15:32:15 +00:00
|
|
|
const {
|
|
|
|
url,
|
|
|
|
data
|
|
|
|
} = option;
|
2024-06-16 01:04:56 +00:00
|
|
|
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) {
|
2024-06-20 15:36:19 +00:00
|
|
|
console.log("结果1", res);
|
2024-06-16 01:04:56 +00:00
|
|
|
if (res.data.code == 401) {
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
icon: "none",
|
|
|
|
title: "请登录后使用该功能"
|
|
|
|
});
|
|
|
|
common_vendor.index.removeStorageSync("token");
|
|
|
|
}
|
2024-06-20 15:36:19 +00:00
|
|
|
resolve(res.data);
|
2024-06-16 01:04:56 +00:00
|
|
|
},
|
|
|
|
fail(err) {
|
|
|
|
console.log(err);
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2024-06-20 15:36:19 +00:00
|
|
|
function uploadFile(file) {
|
|
|
|
const token = common_vendor.index.getStorageSync("token");
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
common_vendor.index.uploadFile({
|
|
|
|
url: `${baseUrl}/api/upload`,
|
|
|
|
filePath: file,
|
|
|
|
name: "file",
|
|
|
|
header: {
|
|
|
|
Authorization: token
|
|
|
|
},
|
|
|
|
success: (res) => {
|
|
|
|
setTimeout(() => {
|
|
|
|
resolve(res.data);
|
|
|
|
}, 1e3);
|
|
|
|
},
|
|
|
|
fail: (err) => {
|
|
|
|
console.log(err);
|
|
|
|
reject(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2024-06-16 01:04:56 +00:00
|
|
|
exports.http = http;
|
2024-06-20 15:36:19 +00:00
|
|
|
exports.uploadFile = uploadFile;
|