feat: form support reverse action buttons (#5108)

* feat: form support reverse action buttons

* fix: submit button class
pull/58/MERGE
Netfan 2024-12-11 15:29:25 +08:00 committed by GitHub
parent 991ada31ba
commit 7c4dfdc1c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 52 additions and 12 deletions

View File

@ -307,6 +307,7 @@ useVbenForm 返回的第二个参数,是一个对象,包含了一些表单
| handleReset | 表单重置回调 | `(values: Record<string, any>,) => Promise<void> \| void` | - |
| handleSubmit | 表单提交回调 | `(values: Record<string, any>,) => Promise<void> \| void` | - |
| handleValuesChange | 表单值变化回调 | `(values: Record<string, any>,) => void` | - |
| actionButtonsReverse | 调换操作按钮位置 | `boolean` | `false` |
| resetButtonOptions | 重置按钮组件参数 | `ActionButtonOptions` | - |
| submitButtonOptions | 提交按钮组件参数 | `ActionButtonOptions` | - |
| showDefaultActions | 是否显示默认操作按钮 | `boolean` | `true` |

View File

@ -142,13 +142,29 @@ defineExpose({
"
:style="queryFormStyle"
>
<template v-if="rootProps.actionButtonsReverse">
<!-- 提交按钮前 -->
<slot name="submit-before"></slot>
<component
:is="COMPONENT_MAP.PrimaryButton"
v-if="submitButtonOptions.show"
class="ml-3"
type="button"
@click="handleSubmit"
v-bind="submitButtonOptions"
>
{{ submitButtonOptions.content }}
</component>
</template>
<!-- 重置按钮前 -->
<slot name="reset-before"></slot>
<component
:is="COMPONENT_MAP.DefaultButton"
v-if="resetButtonOptions.show"
class="mr-3"
class="ml-3"
type="button"
@click="handleReset"
v-bind="resetButtonOptions"
@ -156,18 +172,21 @@ defineExpose({
{{ resetButtonOptions.content }}
</component>
<!-- 提交按钮前 -->
<slot name="submit-before"></slot>
<template v-if="!rootProps.actionButtonsReverse">
<!-- 提交按钮前 -->
<slot name="submit-before"></slot>
<component
:is="COMPONENT_MAP.PrimaryButton"
v-if="submitButtonOptions.show"
type="button"
@click="handleSubmit"
v-bind="submitButtonOptions"
>
{{ submitButtonOptions.content }}
</component>
<component
:is="COMPONENT_MAP.PrimaryButton"
v-if="submitButtonOptions.show"
class="ml-3"
type="button"
@click="handleSubmit"
v-bind="submitButtonOptions"
>
{{ submitButtonOptions.content }}
</component>
</template>
<!-- 展开按钮前 -->
<slot name="expand-before"></slot>

View File

@ -307,6 +307,10 @@ export interface VbenFormProps<
FormRenderProps<T>,
'componentBindEventMap' | 'componentMap' | 'form'
> {
/**
*
*/
actionButtonsReverse?: boolean;
/**
* class
*/

View File

@ -1,11 +1,17 @@
<script lang="ts" setup>
import { ref } from 'vue';
import { Page } from '@vben/common-ui';
import { Button, Card, message, Space } from 'ant-design-vue';
import { useVbenForm } from '#/adapter/form';
const isReverseActionButtons = ref(false);
const [BaseForm, formApi] = useVbenForm({
//
actionButtonsReverse: isReverseActionButtons.value,
//
commonConfig: {
//
@ -83,6 +89,7 @@ function handleClick(
| 'labelWidth'
| 'resetDisabled'
| 'resetLabelWidth'
| 'reverseActionButtons'
| 'showAction'
| 'showResetButton'
| 'showSubmitButton'
@ -158,6 +165,11 @@ function handleClick(
});
break;
}
case 'reverseActionButtons': {
isReverseActionButtons.value = !isReverseActionButtons.value;
formApi.setState({ actionButtonsReverse: isReverseActionButtons.value });
break;
}
case 'showAction': {
formApi.setState({ showDefaultActions: true });
break;
@ -177,6 +189,7 @@ function handleClick(
});
break;
}
case 'updateResetButton': {
formApi.setState({
resetButtonOptions: { disabled: true },
@ -226,6 +239,9 @@ function handleClick(
<Button @click="handleClick('resetLabelWidth')">labelWidth</Button>
<Button @click="handleClick('disabled')"></Button>
<Button @click="handleClick('resetDisabled')"></Button>
<Button @click="handleClick('reverseActionButtons')">
翻转操作按钮位置
</Button>
<Button @click="handleClick('hiddenAction')"></Button>
<Button @click="handleClick('showAction')"></Button>
<Button @click="handleClick('hiddenResetButton')"></Button>