// 基本域名
const Base_url = "/api";
// 查询字符串转换器
export const queryString = (params) =>
"?" +
Object.keys(params)
.map((key) => `${key}=${encodeURIComponent(params[key])}`)
.join("&");
// 封装核心请求函数
const request = (partialUrl, body, query, method = "GET") =>
new Promise((success, fail) =>
wx.request({
url: Base_url + partialUrl + (query ? queryString(query) : ""),
method,
data: body,
success,
fail,
})
);
export const get = (partialUrl, query) =>
request(partialUrl, undefined, query);
export const post = (partialUrl, body, query) =>
request(partialUrl, body, query, "POST");