ant-design-vue/components/modal/confirm.js

46 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-03-06 19:14:41 +08:00
import Vue from 'vue'
import ConfirmDialog from './ConfirmDialog'
export default function confirm (config) {
const div = document.createElement('div')
2018-03-07 21:36:15 +08:00
const el = document.createElement('div')
div.appendChild(el)
2018-03-06 19:14:41 +08:00
document.body.appendChild(div)
2018-03-07 21:36:15 +08:00
2018-03-06 19:14:41 +08:00
let confirmDialogInstance = null
function close (...args) {
destroy(...args)
}
function destroy (...args) {
if (confirmDialogInstance && div.parentNode) {
confirmDialogInstance.$destroy()
confirmDialogInstance = null
div.parentNode.removeChild(div)
}
const triggerCancel = args && args.length &&
args.some(param => param && param.triggerCancel)
if (config.onCancel && triggerCancel) {
config.onCancel(...args)
}
}
function render (props) {
2018-03-22 17:23:51 +08:00
const confirmDialogProps = {
props,
}
2018-03-06 19:14:41 +08:00
return new Vue({
2018-03-07 21:36:15 +08:00
el: el,
2018-03-06 19:14:41 +08:00
render () {
2018-03-22 17:23:51 +08:00
return <ConfirmDialog {...confirmDialogProps} />
2018-03-06 19:14:41 +08:00
},
})
}
confirmDialogInstance = render({ ...config, visible: true, close })
return {
destroy: close,
}
}