index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import Vue from "vue";
  2. import VpPopupQuick from "./PopupQuick.vue";
  3. import { hexToRgba } from "@vci/helper/src/color";
  4. import { getElementBody } from "@vci/helper/src/element";
  5. import { mergeDeep } from "@vci/helper/src/object";
  6. const PopupQuickExt = Vue.extend({
  7. data() {
  8. return {
  9. props: {
  10. visible: false,
  11. zIndex: null,
  12. popupStyle: {},
  13. maskStyle: {
  14. backgroundColor: hexToRgba("#000", 0.6),
  15. backdropFilter: "blur(6px)"
  16. },
  17. enableMask: true,
  18. enableMaskClose: false,
  19. enableLockScroll: true,
  20. animation: "fade-up",
  21. overflow: "visible"
  22. },
  23. on: {
  24. beforeOpen: null,
  25. afterOpen: null,
  26. beforeClose: null,
  27. afterClose: null
  28. },
  29. component: null,
  30. propsComponent: {}
  31. };
  32. },
  33. methods: {
  34. open(option) {
  35. const { props, on, component, propsComponent } = option;
  36. this.props = mergeDeep(this.props, props);
  37. this.on = mergeDeep(this.on, on);
  38. this.component = component;
  39. this.propsComponent = mergeDeep(this.propsComponent, propsComponent);
  40. this.props.visible = true;
  41. },
  42. close() {
  43. this.props.visible = false;
  44. getElementBody().removeChild(this.$el);
  45. this.$destroy();
  46. },
  47. closeAmt() {
  48. if(this._isClosing) return false;
  49. this._isClosing = true;
  50. const targetVm = this.$children[0];
  51. if(!targetVm) return false;
  52. targetVm["close"]();
  53. }
  54. },
  55. render(h) {
  56. const on = {
  57. afterClose: vm => {
  58. this.on.afterClose && this.on.afterClose(vm);
  59. this.close();
  60. }
  61. };
  62. if(this.on.beforeOpen) on.beforeOpen = this.on.beforeOpen;
  63. if(this.on.afterOpen) on.afterOpen = this.on.afterOpen;
  64. if(this.on.beforeClose) on.beforeClose = this.on.beforeClose;
  65. return h(
  66. VpPopupQuick,
  67. {
  68. props: this.props,
  69. on,
  70. scopedSlots: {
  71. default: props => {
  72. const component = this.component || "div";
  73. return h(
  74. component,
  75. {
  76. props: {
  77. ...this.propsComponent,
  78. ...props
  79. }
  80. }
  81. );
  82. }
  83. }
  84. }
  85. );
  86. }
  87. });
  88. function open(option) {
  89. const popupQuick = new PopupQuickExt();
  90. popupQuick.$mount();
  91. getElementBody().appendChild(popupQuick.$el);
  92. popupQuick.open(option || {});
  93. return popupQuick;
  94. }
  95. function close(popupQuick) {
  96. popupQuick && popupQuick.close();
  97. }
  98. const PluginPopupQuick = {
  99. open,
  100. close,
  101. install: Vue => {
  102. Vue.prototype.$popupQuick = { open, close };
  103. }
  104. };
  105. export {
  106. PluginPopupQuick
  107. };