53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
const toastOptions = { duration: 2000, mask: false };
|
|
const confirmOptions = { title: '提示', cancelText: '取消', confirmText: '确定', showCancel: true };
|
|
|
|
export function toast(message, opts = {}) {
|
|
const options = { ...toastOptions, ...opts }
|
|
return new Promise((resolve) => {
|
|
uni.showToast({
|
|
title: message,
|
|
icon: 'none',
|
|
// mask: options.mask,
|
|
duration: options.duration,
|
|
})
|
|
if (options.duration > 0) {
|
|
setTimeout(resolve, options.duration)
|
|
} else {
|
|
resolve()
|
|
}
|
|
})
|
|
|
|
}
|
|
|
|
export function hideToast() {
|
|
uni.hideToast()
|
|
}
|
|
|
|
export function loading(title = '加载中...') {
|
|
uni.showLoading({ title, mask: true })
|
|
}
|
|
|
|
export function hideLoading() {
|
|
uni.hideLoading()
|
|
}
|
|
|
|
// 使用系统原生确认弹窗
|
|
export async function confirm(content, opt = {}) {
|
|
const options = { ...confirmOptions, ...opt }
|
|
return new Promise((resolve, reject) => {
|
|
uni.showModal({
|
|
title: options.title,
|
|
content,
|
|
showCancel: options.showCancel,
|
|
cancelText: options.cancelText,
|
|
confirmText: options.confirmText,
|
|
success: ({ confirm, cancel }) => {
|
|
if (confirm) {
|
|
resolve()
|
|
} else if (cancel) {
|
|
reject()
|
|
}
|
|
}
|
|
})
|
|
})
|
|
} |