import globalStore from '../config/store' import XEUtils from 'xe-utils' interface ToastOptions { content?: string } const MaliToast = { success (option: string | ToastOptions) { const opts = XEUtils.isString(option) ? { content: option } : (option || {}) return new Promise(resolve => { if (globalStore.toast && globalStore.toast.successMethod) { resolve(globalStore.toast.successMethod(opts)) return } uni.showToast({ title: opts.content || '操作成功', icon: 'success', success () { setTimeout(() => resolve(), 2000) } }) }) }, error (option: string | ToastOptions) { const opts = XEUtils.isString(option) ? { content: option } : (option || {}) return new Promise(resolve => { if (globalStore.toast && globalStore.toast.errorMethod) { resolve(globalStore.toast.errorMethod(opts)) return } uni.showToast({ title: opts.content || '操作失败', icon: 'error', success () { setTimeout(() => resolve(), 2000) } }) }) }, warning (option: string | ToastOptions) { const opts = XEUtils.isString(option) ? { content: option } : (option || {}) return new Promise(resolve => { if (globalStore.toast && globalStore.toast.warningMethod) { resolve(globalStore.toast.warningMethod(opts)) return } uni.showToast({ title: opts.content || '操作失败', icon: 'error', success () { setTimeout(() => resolve(), 2000) } }) }) }, hide () { return new Promise(resolve => { if (globalStore.toast && globalStore.toast.hideMethod) { resolve(globalStore.toast.hideMethod()) return } uni.hideToast() setTimeout(() => resolve(), 1500) }) } } export default MaliToast