index.js
1.41 KB
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
/*
* @Description:
* @Autor: renchao
* @LastEditTime: 2023-09-21 09:27:14
*/
import Vue from 'vue'
import Popup from './index.vue'
const PopupBox = Vue.extend(Popup)
let popuping = undefined
/**
* @description: close
* @author: renchao
*/
PopupBox.prototype.close = function () {
// 如果Popup 有引用,则去掉引用
if (popuping) {
popuping = undefined
}
// 先将组件隐藏
this.isShow = false
// 延迟300毫秒,等待Popup关闭动画执行完之后销毁组件
setTimeout(() => {
// 移除挂载的dom元素
if (this.$el && this.$el.parentNode) {
this.$el.parentNode.removeChild(this.$el)
}
}, 300)
}
/**
* @description: Popup1
* @param {*} title
* @param {*} editItem
* @param {*} data
* @param {*} formData
* @author: renchao
*/
const Popup1 = (title, editItem, data, formData) => {
// 如果组件已渲染,则返回即可
if (popuping) {
return popuping
}
data.title = title
data.editItem = editItem
if (formData) {
data.formData = formData
}
// 通过构造函数初始化组件 相当于 new Vue()
let instance = new PopupBox({
data
}).$mount()
// 设置 z-index 并递增层级计数器
instance.zIndex = data.zIndexCounter++
document.body.appendChild(instance.$el)
Vue.nextTick(() => {
instance.isShow = true
// 将组件实例赋值给loading
popuping = instance
})
return instance
}
export default Popup1