
type IconType = "success" | "error" | "none" | "loading" | undefined

/**
 * @desc 公共弹窗简化
 * @author zhangshuwei
 * @time 2022年12月12日
 * @Email 2966211270@qq.com
 * @param {title}-提示内容
 * @param {type}-图标类型 1：成功 2：失败 3：无图标
 * @param {timer}-提示消失时间默认 2000 毫秒
*/
const toast = (title = '默认内容', type = 3, timer = 2000) => {
    let icon: IconType
    switch (type) {
        case 1:
            icon = 'success'
            break
        case 2:
            icon = 'error'
            break
        case 3:
            icon = 'none'
            break
    }

    if (icon == 'none') {
        uni.showToast({
            title: title,
            icon: icon,
            duration: timer,
        })
    } else if (icon == 'error') {
        uni.showToast({
            title: title,
            image: '/static/image/global/error.png',
            duration: timer,
        })
    } else {
        uni.showToast({
            title: title,
            icon: 'success',
            duration: timer,
        })
    }
}


export default toast