You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
1.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// const toast =(option = {} ) => {}
const toast =({title = '数据加载中...',icon='none',duration =500 , mask =true } = {}) => {
wx.showToast({
title,
icon,
duration,
mask
})
}
//其他js文件需要使用toast方法需要先导入
const modal = (options = {}) => {
//方法内部需要通过Promise 返回用户操作
//如果用户点了 确定 需要通过resolve返回 true
// 如果用户点了 取消 需要通过resolve 返回false
return new Promise((resolve) => {
//默认参数
const defaultOpt ={
title:'提示',
content:'您确定执行该操作么?',
confirmCol0or:'#f3514f'
}
//通过object.assign方法将参数进行合并
const opts = Object.assign({},defaultOpt,options) //options覆盖default传给第一个
wx.showModal({
//将合并以后的参数通过展开运算符 赋值给 wx.showModal对象
...opts,
complete({confirm, cancel}){
confirm && resolve(true)
cancel && resolve(false)
}
})
})
}
export { toast, modal}