62 lines
1.5 KiB
JavaScript
62 lines
1.5 KiB
JavaScript
/**
|
||
* 提示信息公共文件
|
||
*
|
||
* @author terrfly
|
||
* @site https://www.jeequan.com
|
||
* @date 2022/11/14 15:29
|
||
*/
|
||
|
||
const model = {
|
||
|
||
// uni.showToast的封装
|
||
// 参数: 标题、 显示时长(单位: 秒), 扩展参数
|
||
// 返回: promise对象, 当提示消失后调用 resolve()
|
||
showToast: (title, duration = 1.5, extObject) => {
|
||
return new Promise((resolve, reject) => {
|
||
uni.showToast(Object.assign({ title: title, icon: 'none', mask: false, duration: (duration * 1000) }, extObject))
|
||
setTimeout(resolve, (duration * 1000));
|
||
})
|
||
},
|
||
|
||
// success类型的提示
|
||
showSuccessToast: (title, duration) => {
|
||
return model.showToast(title, duration, {icon: 'success'})
|
||
},
|
||
|
||
// error类型的提示
|
||
showErrorToast: (title, duration) => {
|
||
return model.showToast(title, duration, {icon: 'error'})
|
||
},
|
||
|
||
showLoading: (title = '请稍后' ) => {
|
||
return uni.showLoading({ title: title, mask: true })
|
||
},
|
||
|
||
hideLoading: () => {
|
||
return uni.hideLoading()
|
||
},
|
||
|
||
// 返回 Promise 点击确定和取消
|
||
// APP安卓原生提示(比较丑), APP 不推荐使用该函数 。
|
||
showModal: (title, confirmText = '确定', cancalText = '取消', extObject) => {
|
||
return new Promise((resolve, reject) => {
|
||
uni.showModal( Object.assign({
|
||
title: title,
|
||
confirmText: confirmText,
|
||
showCancel: cancalText ? true : false,
|
||
cancelText: cancalText,
|
||
success: function(r) {
|
||
if (r.confirm) {
|
||
resolve()
|
||
}else if (r.cancel) {
|
||
reject()
|
||
}
|
||
}
|
||
}, extObject ));
|
||
});
|
||
},
|
||
|
||
|
||
}
|
||
|
||
export default model |