import XEUtils from 'xe-utils' interface ModalOptions { title?: string content?: string confirmButtonText?: string cancelButtonText?: string } const MaliModal = { alert (option: string | ModalOptions) { const opts = XEUtils.isString(option) ? { content: option } : (option || {}) return new Promise<'confirm' | 'cancel'>(resolve => { uni.showModal({ title: opts.title || '系统提示', content: opts.content || '', showCancel: false, confirmText: opts.confirmButtonText || '确认', success () { const type = 'confirm' resolve(type) } }) }) }, confirm (option: string | ModalOptions) { const opts = XEUtils.isString(option) ? { content: option } : (option || {}) return new Promise<'confirm' | 'cancel'>(resolve => { uni.showModal({ title: opts.title || '系统提示', content: opts.content || '', showCancel: true, confirmText: opts.confirmButtonText || '确认', cancelText: opts.cancelButtonText || '取消', success (res) { let type: any = '' if (res.confirm) { type = 'confirm' } else if (res.cancel) { type = 'cancel' } resolve(type) } }) }) } } export default MaliModal