1.18整合

This commit is contained in:
2026-01-18 16:06:37 +08:00
parent 10c3fbb0d7
commit a11d3cc2f8
138 changed files with 7241 additions and 856 deletions

View File

@@ -4,13 +4,12 @@ const request_luchRequest_core_Request = require("./luch-request/core/Request.js
const baseUrl = "http://192.168.1.168:5004";
new request_luchRequest_core_Request.Request({
baseURL: baseUrl,
timeout: 1e4,
header: {
// 'content-type': 'application/json',
"Authorization": "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImxvZ2luX3VzZXJfa2V5IjoiNzQ5NGU2MzAtNTRlYS00ZTM5LWIxYjUtNzc2MzY5NTRhYmJmIn0.7l5CMwFitlpXniZ6PTR5DqN8ASFTFZ1DCUZKjOtr5CpuXWiPHeSW19nY8XKfGdxMvB7j-OnXuSznLRjx-N7K9g"
}
timeout: 1e4
});
const AUTH_TOKEN = "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImxvZ2luX3VzZXJfa2V5IjoiNTQyMjJlODYtZDUyNS00ZTA0LWI3Y2QtMGU1ZWYzYmIwM2EwIn0.x8zPXafDGVjIDIcAdWsWT3F2fU20QHVLFR15b251LfwpfRt_UaDo1-bvHEyi8hxqVkiStOqi09TTUTPBgjPYkw";
const getToken = () => {
const token = common_vendor.index.getStorageSync("token");
return token ? `Bearer ${token}` : "";
};
const isEmptyObject = (obj) => {
return Object.keys(obj).length === 0;
};
@@ -31,21 +30,28 @@ function showToast(title) {
});
}
const requestAPI = (config) => {
let { url, method = "GET", data = {} } = typeof config === "object" && config.url ? config : { url: config, method: arguments[1] || "GET", data: arguments[2] || {} };
let { url, method = "GET", data = {}, noAuth = false } = typeof config === "object" && config.url ? config : { url: config, method: arguments[1] || "GET", data: arguments[2] || {} };
if (method == "GET" && !isEmptyObject(data)) {
url += "?" + objectToQueryString(data);
}
common_vendor.index.showLoading({
title: "加载中..."
});
const header = {
"Content-Type": "application/json"
};
if (!noAuth) {
const token = getToken();
if (token) {
header["Authorization"] = token;
}
}
return new Promise((resolve, reject) => {
common_vendor.index.request({
url: baseUrl + url,
method,
data,
header: {
"Authorization": AUTH_TOKEN
},
header,
success: (res) => {
common_vendor.index.hideLoading();
if (res.statusCode !== 200) {
@@ -57,8 +63,14 @@ const requestAPI = (config) => {
if (res.data.code === 200 || res.data.code === 0) {
resolve(res.data);
} else if (res.data.code === 401) {
common_vendor.index.removeStorageSync("_user_token_");
common_vendor.index.removeStorageSync("token");
common_vendor.index.removeStorageSync("userInfo");
showToast("登录已过期,请重新登录");
setTimeout(() => {
common_vendor.index.reLaunch({
url: "/pages/login/login"
});
}, 1500);
reject("401");
} else {
showToast(res.data.msg || "请求失败");
@@ -83,6 +95,6 @@ const requestAPI = (config) => {
});
});
};
exports.AUTH_TOKEN = AUTH_TOKEN;
exports.baseUrl = baseUrl;
exports.getToken = getToken;
exports.requestAPI = requestAPI;