first commit
This commit is contained in:
71
src/utils/message.js
Normal file
71
src/utils/message.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* 弹出 toast
|
||||
*
|
||||
* @param msg
|
||||
* @param icon
|
||||
* @param mask
|
||||
* @returns
|
||||
*/
|
||||
export const showToast = (msg, icon = 'none', mask = false) => {
|
||||
return uni.showToast({
|
||||
title: msg,
|
||||
icon: icon,
|
||||
mask
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出 alert
|
||||
* @param content
|
||||
* @param title
|
||||
* @returns
|
||||
*/
|
||||
export const showAlert = (content, title = '提示',showCancel=true,succFun) => {
|
||||
return uni.showModal({
|
||||
title: title,
|
||||
content: content,
|
||||
showCancel,
|
||||
success: function (res) {
|
||||
if (res.confirm) {
|
||||
// console.log('用户点击确定');
|
||||
succFun();
|
||||
} else if (res.cancel) {
|
||||
// console.log('用户点击取消');
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹出加载动画
|
||||
*
|
||||
* @param text
|
||||
* @param mask
|
||||
* @returns
|
||||
*/
|
||||
export const showLoading = (text = null, mask = true) => {
|
||||
return uni.showLoading({
|
||||
title: text,
|
||||
mask: mask
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏加载动画
|
||||
*/
|
||||
export const hideLoading = () => uni.hideLoading()
|
||||
|
||||
|
||||
/**
|
||||
* 组合式API
|
||||
*/
|
||||
export const useMessage = () => {
|
||||
return {
|
||||
toast: showToast,
|
||||
success: (msg, mask = true) => showToast(msg, 'success', mask),
|
||||
error: (msg, mask = true) => showToast(msg, 'error', mask),
|
||||
alert: showAlert,
|
||||
showLoading,
|
||||
hideLoading
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user