-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (72 loc) · 2.12 KB
/
index.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import vue from 'vue'
import Confirm from './components/Confirm'
const ConfirmConstructor = vue.extend(Confirm);
/**
* usage:
* import registryConfirm from '...'
* Vue.use(registryConfirm)
*
* this.$confirm(obj, callback)
*/
function showConfirm(data, callback, callback2) {
let title = data.title ? data.title : '溫馨提示';
let content = data.content ? data.content : '';
let confirmBtn = data.confirmBtn ? data.confirmBtn : '確定';
let cancelBtn = data.cancelBtn ? data.cancelBtn : null;
const confirmDom = new ConfirmConstructor({
el: document.createElement('div'),
data() {
return {
title,
content,
confirmBtn,
cancelBtn,
show: false
}
},
watch: {
show(val) {
if (val === true) {
document.getElementsByTagName('body')[0].style.overflow = 'hidden';
} else {
document.getElementsByTagName('body')[0].style.overflow = 'auto';
}
}
},
mounted() {
setTimeout(() => {
this.show = true;
}, 100);
},
methods: {
close() {
this.show = false;
// 避免dom一直疊加
setTimeout(() => {
document.body.removeChild(confirmDom.$el);
}, 100);
},
confirm() {
if (callback && typeof callback == 'function') {
callback();
this.close();
} else {
this.close();
}
},
preClose() {
if (callback2 && typeof callback2 == 'function') {
callback2();
this.close();
} else {
this.close();
}
}
}
});
document.body.appendChild(confirmDom.$el);
}
function registryConfirm() {
vue.prototype.$confirm = showConfirm;
}
export default registryConfirm