HookModal.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
  2. import { createVNode as _createVNode } from "vue";
  3. import { computed, defineComponent } from 'vue';
  4. import { useConfigContextInject } from '../../config-provider/context';
  5. import { useLocaleReceiver } from '../../locale-provider/LocaleReceiver';
  6. import defaultLocale from '../../locale/en_US';
  7. import ConfirmDialog from '../ConfirmDialog';
  8. import initDefaultProps from '../../_util/props-util/initDefaultProps';
  9. const comfirmFuncProps = () => ({
  10. config: Object,
  11. afterClose: Function,
  12. destroyAction: Function,
  13. open: Boolean
  14. });
  15. export default defineComponent({
  16. name: 'HookModal',
  17. inheritAttrs: false,
  18. props: initDefaultProps(comfirmFuncProps(), {
  19. config: {
  20. width: 520,
  21. okType: 'primary'
  22. }
  23. }),
  24. setup(props, _ref) {
  25. let {
  26. expose
  27. } = _ref;
  28. var _a;
  29. const open = computed(() => props.open);
  30. const innerConfig = computed(() => props.config);
  31. const {
  32. direction,
  33. getPrefixCls
  34. } = useConfigContextInject();
  35. const prefixCls = getPrefixCls('modal');
  36. const rootPrefixCls = getPrefixCls();
  37. const afterClose = () => {
  38. var _a, _b;
  39. props === null || props === void 0 ? void 0 : props.afterClose();
  40. (_b = (_a = innerConfig.value).afterClose) === null || _b === void 0 ? void 0 : _b.call(_a);
  41. };
  42. const close = function () {
  43. props.destroyAction(...arguments);
  44. };
  45. expose({
  46. destroy: close
  47. });
  48. const mergedOkCancel = (_a = innerConfig.value.okCancel) !== null && _a !== void 0 ? _a : innerConfig.value.type === 'confirm';
  49. const [contextLocale] = useLocaleReceiver('Modal', defaultLocale.Modal);
  50. return () => _createVNode(ConfirmDialog, _objectSpread(_objectSpread({
  51. "prefixCls": prefixCls,
  52. "rootPrefixCls": rootPrefixCls
  53. }, innerConfig.value), {}, {
  54. "close": close,
  55. "open": open.value,
  56. "afterClose": afterClose,
  57. "okText": innerConfig.value.okText || (mergedOkCancel ? contextLocale === null || contextLocale === void 0 ? void 0 : contextLocale.value.okText : contextLocale === null || contextLocale === void 0 ? void 0 : contextLocale.value.justOkText),
  58. "direction": innerConfig.value.direction || direction.value,
  59. "cancelText": innerConfig.value.cancelText || (contextLocale === null || contextLocale === void 0 ? void 0 : contextLocale.value.cancelText)
  60. }), null);
  61. }
  62. });