feat: 接口调试

This commit is contained in:
zoujing
2025-07-21 18:08:45 +08:00
parent eef75457c8
commit 8a040896a7
7 changed files with 28 additions and 18 deletions

View File

@@ -2,7 +2,7 @@ import { BASE_URL } from "../../constant/base";
const defaultConfig = {
header: {
Authorization: '', // 可在此动态设置 token
Authorization: 'Basic Y3VzdG9tOmN1c3RvbQ==', // 可在此动态设置 token
'Content-Type': 'application/x-www-form-urlencoded'
},
};
@@ -21,24 +21,34 @@ function request(url, args = {}, method = 'POST', customConfig = {}) {
// 判断是否需要 token
if (customConfig.noToken) {
delete header.Authorization;
} else if (token) {
header.Authorization = `Basic ${token}`;
} else {
delete header.Authorization;
}
if (token) {
header.Authorization = `Basic ${token}`;
}
}
const config = {
...defaultConfig,
...customConfig,
header
};
console.log("请求接口:" + url)
console.log("请求头:" + JSON.stringify(config))
console.log("请求参数:" + JSON.stringify(args))
return new Promise((resolve, reject) => {
uni.request({
url,
data: args,
method,
...config,
success: (res) => resolve(res.data),
fail: (err) => reject(err)
success: (res) => {
console.log("请求响应:" + JSON.stringify(res))
resolve(res.data)
},
fail: (err) => {
console.error("请求失败:", err);
reject(err)
}
});
});
}