let baseUrl = 'https://broadcast.waityou24.cn/st/api';
const $get = (uri, data) => {
    return new Promise((resolve, reject) => {
        wx.request({
            url: `${baseUrl}${uri}`,
            method: "get",
            data,
            success: (res) => toResolve(resolve, res),
            error: (e) => toReject(reject, e),
        });
    });
};
const $post = (uri, data) => {
    return new Promise((resolve, reject) => {
        wx.request({
            url: `${baseUrl}${uri}`,
            method: "post",
            data,
            success: (res) => toResolve(resolve, res),
            error: (e) => toReject(reject, e),
        });
    });
};
const $delete = (uri, data) => {
    return new Promise((resolve, reject) => {
        wx.request({
            url: `${baseUrl}${uri}`,
            method: "delete",
            data,
            success: (res) => toResolve(resolve, res),
            error: (e) => toReject(reject, e),
        });
    });
};

const toResolve = (resolve, result) => {
    if (result.statusCode === 200) resolve(result.data);
    else {
        console.error("请求失败");
    }
};

const toReject = (reject, result) => {
    console.error(result);
    reject(result);
};

module.exports = { $get, $post, $delete };
