FormAction.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import type { ColEx } from './types/index';
  2. import { defineComponent, unref, computed, PropType } from 'vue';
  3. import { Form, Col } from 'ant-design-vue';
  4. import { Button } from '/@/components/Button';
  5. import { BasicArrow } from '/@/components/Basic/index';
  6. import { getSlot } from '/@/utils/helper/tsxHelper';
  7. import { useI18n } from '/@/hooks/web/useI18n';
  8. const { t } = useI18n('component.form');
  9. export default defineComponent({
  10. name: 'BasicFormAction',
  11. props: {
  12. show: {
  13. type: Boolean,
  14. default: true,
  15. },
  16. showResetButton: {
  17. type: Boolean,
  18. default: true,
  19. },
  20. showSubmitButton: {
  21. type: Boolean,
  22. default: true,
  23. },
  24. showAdvancedButton: {
  25. type: Boolean,
  26. default: true,
  27. },
  28. resetButtonOptions: {
  29. type: Object as PropType<any>,
  30. default: {},
  31. },
  32. submitButtonOptions: {
  33. type: Object as PropType<any>,
  34. default: {},
  35. },
  36. actionColOptions: {
  37. type: Object as PropType<any>,
  38. default: {},
  39. },
  40. actionSpan: {
  41. type: Number,
  42. default: 6,
  43. },
  44. isAdvanced: {
  45. type: Boolean,
  46. default: false,
  47. },
  48. hideAdvanceBtn: {
  49. type: Boolean,
  50. default: false,
  51. },
  52. },
  53. emits: ['toggle-advanced'],
  54. setup(props, { slots, emit }) {
  55. const getResetBtnOptionsRef = computed(() => {
  56. return {
  57. text: t('resetButton'),
  58. ...props.resetButtonOptions,
  59. };
  60. });
  61. const getSubmitBtnOptionsRef = computed(() => {
  62. return {
  63. text: t('submitButton'),
  64. // htmlType: 'submit',
  65. ...props.submitButtonOptions,
  66. };
  67. });
  68. const actionColOpt = computed(() => {
  69. const { showAdvancedButton, actionSpan: span, actionColOptions } = props;
  70. const actionSpan = 24 - span;
  71. const advancedSpanObj = showAdvancedButton ? { span: actionSpan < 6 ? 24 : actionSpan } : {};
  72. const actionColOpt: Partial<ColEx> = {
  73. span: showAdvancedButton ? 6 : 4,
  74. ...advancedSpanObj,
  75. ...actionColOptions,
  76. };
  77. return actionColOpt;
  78. });
  79. function toggleAdvanced() {
  80. emit('toggle-advanced');
  81. }
  82. return () => {
  83. if (!props.show) {
  84. return;
  85. }
  86. const {
  87. showAdvancedButton,
  88. hideAdvanceBtn,
  89. isAdvanced,
  90. showResetButton,
  91. showSubmitButton,
  92. } = props;
  93. return (
  94. <Col {...unref(actionColOpt)} style={{ textAlign: 'right' }}>
  95. {() => (
  96. <Form.Item>
  97. {() => (
  98. <>
  99. {getSlot(slots, 'advanceBefore')}
  100. {showAdvancedButton && !hideAdvanceBtn && (
  101. <Button type="default" class="mr-2" onClick={toggleAdvanced}>
  102. {() => (
  103. <>
  104. {isAdvanced ? t('putAway') : t('unfold')}
  105. <BasicArrow expand={!isAdvanced} top />
  106. </>
  107. )}
  108. </Button>
  109. )}
  110. {getSlot(slots, 'resetBefore')}
  111. {showResetButton && (
  112. <Button type="default" class="mr-2" {...unref(getResetBtnOptionsRef)}>
  113. {() => unref(getResetBtnOptionsRef).text}
  114. </Button>
  115. )}
  116. {getSlot(slots, 'submitBefore')}
  117. {showSubmitButton && (
  118. <Button type="primary" {...unref(getSubmitBtnOptionsRef)}>
  119. {() => unref(getSubmitBtnOptionsRef).text}
  120. </Button>
  121. )}
  122. {getSlot(slots, 'submitAfter')}
  123. </>
  124. )}
  125. </Form.Item>
  126. )}
  127. </Col>
  128. );
  129. };
  130. },
  131. });