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` | - | | handleReset | 表单重置回调 | `(values: Record<string, any>,) => Promise<void> \| void` | - |
| handleSubmit | 表单提交回调 | `(values: Record<string, any>,) => Promise<void> \| void` | - | | handleSubmit | 表单提交回调 | `(values: Record<string, any>,) => Promise<void> \| void` | - |
| handleValuesChange | 表单值变化回调 | `(values: Record<string, any>,) => void` | - | | handleValuesChange | 表单值变化回调 | `(values: Record<string, any>,) => void` | - |
| actionButtonsReverse | 调换操作按钮位置 | `boolean` | `false` |
| resetButtonOptions | 重置按钮组件参数 | `ActionButtonOptions` | - | | resetButtonOptions | 重置按钮组件参数 | `ActionButtonOptions` | - |
| submitButtonOptions | 提交按钮组件参数 | `ActionButtonOptions` | - | | submitButtonOptions | 提交按钮组件参数 | `ActionButtonOptions` | - |
| showDefaultActions | 是否显示默认操作按钮 | `boolean` | `true` | | showDefaultActions | 是否显示默认操作按钮 | `boolean` | `true` |

View File

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

View File

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

View File

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