const pathJoinPrefix = (url, prefix) => prefix + url;

export const doPost = (url, params, prefix, callback, error) => {
    return $.ajax({
        url: pathJoinPrefix(url, prefix),
        type: "post",
        data: JSON.stringify(params),
        headers: {
            "Content-Type": "application/json;charset=utf-8"
        },
        success: function (res) {
            if (res.httpCode === 200) {
                callback && callback(res.data)
            } else {
                //1 成功 2错误 7警告
                layer.msg(`<div>${res.msg}</div>`, {
                    icon: 2,
                    time: 3000,
                    offset: 't',
                });
                error && error(res)
            }
        },
        contentType: false
    })
}

export const doGet = (url, params, prefix, callback, error) => {
    return $.get(pathJoinPrefix(url, prefix), params, function (res) {
        if (res.httpCode === 200) {
            callback && callback(res.data)
        } else {
            //1 成功 2错误 7警告
            layer.msg(`<div>${res.msg}</div>`, {
                icon: 2,
                time: 3000,
                offset: 't',
            });
            error && error(res)
        }
    })
}