DialogWrap.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { createVNode as _createVNode, resolveDirective as _resolveDirective } from "vue";
  3. import Dialog from './Dialog';
  4. import getDialogPropTypes from './IDialogPropTypes';
  5. import Portal from '../_util/PortalWrapper';
  6. import { defineComponent, ref, watch } from 'vue';
  7. import { useProvidePortal } from '../vc-trigger/context';
  8. import { initDefaultProps } from '../_util/props-util';
  9. var IDialogPropTypes = getDialogPropTypes();
  10. var DialogWrap = defineComponent({
  11. compatConfig: {
  12. MODE: 3
  13. },
  14. name: 'DialogWrap',
  15. inheritAttrs: false,
  16. props: initDefaultProps(IDialogPropTypes, {
  17. visible: false
  18. }),
  19. setup: function setup(props, _ref) {
  20. var attrs = _ref.attrs,
  21. slots = _ref.slots;
  22. var animatedVisible = ref(props.visible);
  23. useProvidePortal({}, {
  24. inTriggerContext: false
  25. });
  26. watch(function () {
  27. return props.visible;
  28. }, function () {
  29. if (props.visible) {
  30. animatedVisible.value = true;
  31. }
  32. }, {
  33. flush: 'post'
  34. });
  35. return function () {
  36. var visible = props.visible,
  37. getContainer = props.getContainer,
  38. forceRender = props.forceRender,
  39. _props$destroyOnClose = props.destroyOnClose,
  40. destroyOnClose = _props$destroyOnClose === void 0 ? false : _props$destroyOnClose,
  41. _afterClose = props.afterClose;
  42. var dialogProps = _objectSpread(_objectSpread(_objectSpread({}, props), attrs), {}, {
  43. ref: '_component',
  44. key: 'dialog'
  45. });
  46. // 渲染在当前 dom 里;
  47. if (getContainer === false) {
  48. return _createVNode(Dialog, _objectSpread(_objectSpread({}, dialogProps), {}, {
  49. "getOpenCount": function getOpenCount() {
  50. return 2;
  51. }
  52. }), slots);
  53. }
  54. // Destroy on close will remove wrapped div
  55. if (!forceRender && destroyOnClose && !animatedVisible.value) {
  56. return null;
  57. }
  58. return _createVNode(Portal, {
  59. "visible": visible,
  60. "forceRender": forceRender,
  61. "getContainer": getContainer
  62. }, {
  63. default: function _default(childProps) {
  64. dialogProps = _objectSpread(_objectSpread(_objectSpread({}, dialogProps), childProps), {}, {
  65. afterClose: function afterClose() {
  66. _afterClose === null || _afterClose === void 0 ? void 0 : _afterClose();
  67. animatedVisible.value = false;
  68. }
  69. });
  70. return _createVNode(Dialog, dialogProps, slots);
  71. }
  72. });
  73. };
  74. }
  75. });
  76. export default DialogWrap;