Blame view

src/components/ywPopup/index.js 1.32 KB
1
/*
yuanbo committed
2
 * @Description:
3 4 5 6 7 8 9 10
 * @Autor: renchao
 * @LastEditTime: 2023-06-14 15:05:38
 */
import Vue from 'vue'
import Popup from './index.vue'
const PopupBox = Vue.extend(Popup)
let popuping = undefined

yuanbo committed
11 12 13 14
/**
 * @description: close
 * @author: renchao
 */
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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)
}

yuanbo committed
31 32 33 34 35 36 37 38
/**
 * @description: Popup1
 * @param {*} title
 * @param {*} editItem
 * @param {*} data
 * @param {*} formData
 * @author: renchao
 */
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
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()
  document.body.appendChild(instance.$el)
  Vue.nextTick(() => {
    instance.isShow = true
    // 将组件实例赋值给loading
    popuping = instance
  })
  return instance
}
export default Popup1