import {showToast} from "./uils.js";

const request = (options) => {
    return new Promise((resolve, reject) => {
        const {url, method, data, params} = options;

        uni.request({
            method: method,
            data: data,
            params: params,
            url: `${import.meta.env.VITE_API_URL}${url}`,
            success: ({data}) => {
                if (data.code !== 0) {
                    showToast(data.msg);
                    reject(data.msg);
                }
                resolve(data);
            },
            fail: (err) => {
                reject(err);
            }
        });
    });
}

export default request;
