ny
昨天 282fbc6488f4e8ceb5fda759f963ee88fbf7b999
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<script lang="ts">
import type { ButtonProps } from '@jnpf/ui';
 
import type { PropType } from 'vue';
 
import type { ColEx } from '../types/index';
 
import { computed, defineComponent } from 'vue';
 
import { AButton, BasicArrow } from '@jnpf/ui';
import { propTypes } from '@jnpf/utils';
 
import { $t } from '@vben/locales';
 
import { Col as ACol, Form } from 'ant-design-vue';
 
import { useFormContext } from '../hooks/useFormContext';
 
type ButtonOptions = Partial<ButtonProps> & { text: string };
 
export default defineComponent({
  components: {
    AButton,
    ACol,
    BasicArrow,
    FormItem: Form.Item,
  },
  emits: ['toggleAdvanced'],
  name: 'BasicFormAction',
  props: {
    actionColOptions: {
      default: () => ({}),
      type: Object as PropType<Partial<ColEx>>,
    },
    actionSpan: propTypes.number.def(6),
    hideAdvanceBtn: propTypes.bool,
    isAdvanced: propTypes.bool,
    resetButtonOptions: {
      default: () => ({}),
      type: Object as PropType<ButtonOptions>,
    },
    showActionButtonGroup: propTypes.bool.def(true),
    showAdvancedButton: propTypes.bool.def(true),
    showResetButton: propTypes.bool.def(true),
    showSubmitButton: propTypes.bool.def(true),
    submitButtonOptions: {
      default: () => ({}),
      type: Object as PropType<ButtonOptions>,
    },
  },
  setup(props, { emit }) {
    const actionColOpt = computed(() => {
      const { actionColOptions, actionSpan: span, showAdvancedButton } = props;
      const actionSpan = 24 - span;
      const advancedSpanObj = showAdvancedButton ? { span: actionSpan < 6 ? 24 : actionSpan } : {};
      const actionColOpt: Partial<ColEx> = {
        span: showAdvancedButton ? 6 : 4,
        style: { textAlign: 'left' },
        ...advancedSpanObj,
        ...actionColOptions,
      };
      return actionColOpt;
    });
 
    const getResetBtnOptions = computed((): ButtonOptions => {
      return Object.assign(
        {
          text: $t('common.resetText'),
        },
        props.resetButtonOptions,
      );
    });
 
    const getSubmitBtnOptions = computed(() => {
      return Object.assign(
        {
          text: $t('common.queryText'),
        },
        props.submitButtonOptions,
      );
    });
 
    function toggleAdvanced() {
      emit('toggleAdvanced');
    }
 
    return {
      actionColOpt,
      getResetBtnOptions,
      getSubmitBtnOptions,
      t: $t,
      toggleAdvanced,
      ...useFormContext(),
    };
  },
});
</script>
<template>
  <ACol v-bind="actionColOpt" v-if="showActionButtonGroup">
    <div :style="{ textAlign: actionColOpt.style.textAlign }" class="w-full">
      <FormItem>
        <slot name="submitBefore"></slot>
        <AButton class="mr-2" type="primary" v-bind="getSubmitBtnOptions" v-if="showSubmitButton" @click="submitAction">
          {{ getSubmitBtnOptions.text }}
        </AButton>
        <slot name="resetBefore"></slot>
        <AButton class="mr-2" type="default" v-bind="getResetBtnOptions" v-if="showResetButton" @click="resetAction">
          {{ getResetBtnOptions.text }}
        </AButton>
        <slot name="advanceBefore"></slot>
        <AButton v-if="showAdvancedButton && !hideAdvanceBtn" size="small" type="link" @click="toggleAdvanced">
          {{ isAdvanced ? t('component.form.fold') : t('component.form.unfold') }}
          <BasicArrow :expand="!isAdvanced" class="ml-1" up />
        </AButton>
        <slot name="advanceAfter"></slot>
      </FormItem>
    </div>
  </ACol>
</template>