//确认框
export const showModal = async ({title, content, confirmText, cancelText}) => {
    return new Promise((resolve) => {
        uni.showModal({
            title: title,
            content: content,
            confirmText: confirmText ?? '确定',
            cancelText: cancelText ?? '取消',
            success: function (res) {
                if (res.confirm) {
                    resolve(true)
                } else if (res.cancel) {
                    resolve(false)
                }
            }
        });
    })
}

//成功提示
export const successToast = (title = '成功', duration= 2000) => {
    uni.showToast({
        title: title,
        duration: duration,
        mask: true
    });
}

//失败提示
export const errorToast = (title = '失败', duration= 1500) => {
    uni.showToast({
        title: title,
        duration: duration,
        icon: 'none'
    });
}

//表单验证
export const formValidate = async (formRef) => {
    return new Promise( (resolve) => {
        formRef.validate().then((res) => {
            resolve(true)
        }).catch(err => {
            resolve(false)
        })
    });
}