-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfirm.js
46 lines (39 loc) · 1.03 KB
/
confirm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import Vue from 'vue'
import ConfirmDialog from './ConfirmDialog'
export default function confirm (config) {
const div = document.createElement('div')
const el = document.createElement('div')
div.appendChild(el)
document.body.appendChild(div)
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) {
const confirmDialogProps = {
props,
}
return new Vue({
el: el,
render () {
return <ConfirmDialog {...confirmDialogProps} />
},
})
}
confirmDialogInstance = render({ ...config, visible: true, close })
return {
destroy: close,
}
}