// 封装 模态对话框 showModal
const modal = ( options = {} ) => {
return new Promise((resolve) => {
// 默认参数
const optinsObj = {
title: "提示",
content: "您确定执行该操作吗?",
confirmColor: "#f3514f",
}
// 通过 object.assign 方法将参数进行合并
const opts = Object.assign({}, optinsObj, options)
wx.showModal({
...opts,
// 成功或失败都会执行回调函数
complete({ confirm, cancel }){
confirm && resolve(true)
cancel && resolve(false)
}
})
})
}
// 将封装的模块挂载到 wx 全局对象身上
wx.modal = modal
- 使用
import './utils/extendApi'
// 模态对话框
async showModal(){
await wx.modal({ showCancel: false })
}