feat: 接口调试
This commit is contained in:
@@ -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)
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user