fix: improve the scroll bar flashing when the modal box is opened (#4438)

This commit is contained in:
Vben
2024-09-19 21:56:49 +08:00
committed by GitHub
parent 56bdb8f606
commit 161820dbc1
18 changed files with 530 additions and 42 deletions

View File

@@ -78,7 +78,8 @@
"query": "Query Form",
"rules": "Form Rules",
"dynamic": "Dynamic Form",
"custom": "Custom Component"
"custom": "Custom Component",
"api": "Api"
},
"captcha": {
"title": "Captcha",

View File

@@ -78,7 +78,8 @@
"query": "查询表单",
"rules": "表单校验",
"dynamic": "动态表单",
"custom": "自定义组件"
"custom": "自定义组件",
"api": "Api"
},
"captcha": {
"title": "验证码",

View File

@@ -99,6 +99,14 @@ const routes: RouteRecordRaw[] = [
title: $t('page.examples.form.custom'),
},
},
{
name: 'FormApiExample',
path: '/examples/form/api',
component: () => import('#/views/examples/form/api.vue'),
meta: {
title: $t('page.examples.form.api'),
},
},
],
},
],

View File

@@ -0,0 +1,208 @@
<script lang="ts" setup>
import { Page } from '@vben/common-ui';
import { Button, Card, message, Space } from 'ant-design-vue';
import { useVbenForm } from '#/adapter';
const [BaseForm, formApi] = useVbenForm({
// 所有表单项共用,可单独在表单内覆盖
commonConfig: {
// 所有表单项
componentProps: {
class: 'w-full',
},
},
// 使用 tailwindcss grid布局
// 提交函数
handleSubmit: onSubmit,
// 垂直布局label和input在不同行值为vertical
layout: 'horizontal',
// 水平布局label和input在同一行
schema: [
{
// 组件需要在 #/adapter.ts内注册并加上类型
component: 'Input',
// 对应组件的参数
componentProps: {
placeholder: '请输入用户名',
},
// 字段名
fieldName: 'field1',
// 界面显示的label
label: 'field1',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入',
},
fieldName: 'field2',
label: 'field2',
},
{
component: 'Input',
componentProps: {
placeholder: '请输入',
},
fieldName: 'field3',
label: 'field3',
},
],
// 大屏一行显示3个中屏一行显示2个小屏一行显示1个
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3',
});
function onSubmit(values: Record<string, any>) {
message.success({
content: `form values: ${JSON.stringify(values)}`,
});
}
function handleClick(
action:
| 'batchAddSchema'
| 'batchDeleteSchema'
| 'disabled'
| 'hiddenAction'
| 'hiddenResetButton'
| 'hiddenSubmitButton'
| 'labelWidth'
| 'resetDisabled'
| 'resetLabelWidth'
| 'showAction'
| 'showResetButton'
| 'showSubmitButton'
| 'updateActionAlign'
| 'updateResetButton'
| 'updateSubmitButton',
) {
switch (action) {
case 'labelWidth': {
formApi.setState({
commonConfig: {
labelWidth: 150,
},
});
break;
}
case 'resetLabelWidth': {
formApi.setState({
commonConfig: {
labelWidth: 100,
},
});
break;
}
case 'disabled': {
formApi.setState({ commonConfig: { disabled: true } });
break;
}
case 'resetDisabled': {
formApi.setState({ commonConfig: { disabled: false } });
break;
}
case 'hiddenAction': {
formApi.setState({ showDefaultActions: false });
break;
}
case 'showAction': {
formApi.setState({ showDefaultActions: true });
break;
}
case 'hiddenResetButton': {
formApi.setState({ resetButtonOptions: { show: false } });
break;
}
case 'showResetButton': {
formApi.setState({ resetButtonOptions: { show: true } });
break;
}
case 'hiddenSubmitButton': {
formApi.setState({ submitButtonOptions: { show: false } });
break;
}
case 'showSubmitButton': {
formApi.setState({ submitButtonOptions: { show: true } });
break;
}
case 'updateResetButton': {
formApi.setState({
resetButtonOptions: { disabled: true },
});
break;
}
case 'updateSubmitButton': {
formApi.setState({
submitButtonOptions: { loading: true },
});
break;
}
case 'updateActionAlign': {
formApi.setState({
// 可以自行调整class
actionWrapperClass: 'text-center',
});
break;
}
case 'batchAddSchema': {
formApi.setState((prev) => {
const currentSchema = prev?.schema ?? [];
const newSchema = [];
for (let i = 0; i < 3; i++) {
newSchema.push({
component: 'Input',
componentProps: {
placeholder: '请输入',
},
fieldName: `field${i}${Date.now()}`,
label: `field+`,
});
}
return {
schema: [...currentSchema, ...newSchema],
};
});
break;
}
case 'batchDeleteSchema': {
formApi.setState((prev) => {
const currentSchema = prev?.schema ?? [];
return {
schema: currentSchema.slice(0, -3),
};
});
break;
}
}
}
</script>
<template>
<Page description="表单组件api操作示例。" title="表单组件">
<Space class="mb-5 flex-wrap">
<Button @click="handleClick('labelWidth')">更改labelWidth</Button>
<Button @click="handleClick('resetLabelWidth')">还原labelWidth</Button>
<Button @click="handleClick('disabled')">禁用表单</Button>
<Button @click="handleClick('resetDisabled')">解除禁用</Button>
<Button @click="handleClick('hiddenAction')">隐藏操作按钮</Button>
<Button @click="handleClick('showAction')">显示操作按钮</Button>
<Button @click="handleClick('hiddenResetButton')">隐藏重置按钮</Button>
<Button @click="handleClick('showResetButton')">显示重置按钮</Button>
<Button @click="handleClick('hiddenSubmitButton')">隐藏提交按钮</Button>
<Button @click="handleClick('showSubmitButton')">显示提交按钮</Button>
<Button @click="handleClick('updateResetButton')">修改重置按钮</Button>
<Button @click="handleClick('updateSubmitButton')">修改提交按钮</Button>
<Button @click="handleClick('updateActionAlign')">
调整操作按钮位置
</Button>
<Button @click="handleClick('batchAddSchema')"> 批量添加表单项 </Button>
<Button @click="handleClick('batchDeleteSchema')">
批量删除表单项
</Button>
</Space>
<Card title="操作示例">
<BaseForm />
</Card>
</Page>
</template>

View File

@@ -14,12 +14,11 @@ const [BaseForm, baseFormApi] = useVbenForm({
class: 'w-full',
},
},
// 使用 tailwindcss grid布局
// 提交函数
handleSubmit: onSubmit,
// 垂直布局label和input在不同行值为vertical
layout: 'horizontal',
// 水平布局label和input在同一行
layout: 'horizontal',
schema: [
{
// 组件需要在 #/adapter.ts内注册并加上类型

View File

@@ -16,12 +16,11 @@ const [BaseForm] = useVbenForm({
},
labelClass: 'w-2/6',
},
// 使用 tailwindcss grid布局
// 提交函数
handleSubmit: onSubmit,
// 垂直布局label和input在不同行值为vertical
layout: 'horizontal',
// 水平布局label和input在同一行
layout: 'horizontal',
schema: [
{
// 组件需要在 #/adapter.ts内注册并加上类型
@@ -31,7 +30,6 @@ const [BaseForm] = useVbenForm({
suffix: () => h('span', { class: 'text-red-600' }, '元'),
},
{
// 组件需要在 #/adapter.ts内注册并加上类型
component: 'Input',
fieldName: 'field1',
label: '自定义组件slot',
@@ -41,14 +39,12 @@ const [BaseForm] = useVbenForm({
}),
},
{
// 组件需要在 #/adapter.ts内注册并加上类型
component: h(Input, { placeholder: '请输入' }),
fieldName: 'field2',
label: '自定义组件',
rules: 'required',
},
{
// 组件需要在 #/adapter.ts内注册并加上类型
component: 'Input',
fieldName: 'field3',
label: '自定义组件(slot)',

View File

@@ -6,10 +6,8 @@ import { Button, Card, message } from 'ant-design-vue';
import { useVbenForm } from '#/adapter';
const [Form, formApi] = useVbenForm({
// 使用 tailwindcss grid布局
// 提交函数
handleSubmit: onSubmit,
// 水平布局label和input在同一行
schema: [
{
component: 'Switch',
@@ -55,12 +53,9 @@ const [Form, formApi] = useVbenForm({
show(values) {
return !!values.field2Switch;
},
// 只有指定的字段改变时,才会触发
triggerFields: ['field2Switch'],
},
// 字段名
fieldName: 'field2',
// 界面显示的label
label: '字段2',
},
{
@@ -69,12 +64,9 @@ const [Form, formApi] = useVbenForm({
disabled(values) {
return !!values.field3Switch;
},
// 只有指定的字段改变时,才会触发
triggerFields: ['field3Switch'],
},
// 字段名
fieldName: 'field3',
// 界面显示的label
label: '字段3',
},
{
@@ -83,12 +75,9 @@ const [Form, formApi] = useVbenForm({
required(values) {
return !!values.field4Switch;
},
// 只有指定的字段改变时,才会触发
triggerFields: ['field4Switch'],
},
// 字段名
fieldName: 'field4',
// 界面显示的label
label: '字段4',
},
{
@@ -100,13 +89,10 @@ const [Form, formApi] = useVbenForm({
}
return null;
},
// 只有指定的字段改变时,才会触发
triggerFields: ['field1'],
},
// 字段名
fieldName: 'field5',
help: '当字段1的值为`123`时,必填',
// 界面显示的label
label: '动态rules',
},
{
@@ -150,13 +136,10 @@ const [Form, formApi] = useVbenForm({
}
return {};
},
// 只有指定的字段改变时,才会触发
triggerFields: ['field2'],
},
// 字段名
fieldName: 'field6',
help: '当字段2的值为`123`时,更改下拉选项',
// 界面显示的label
label: '动态配置',
},
{

View File

@@ -18,9 +18,8 @@ const [QueryForm] = useVbenForm({
// 提交函数
handleSubmit: onSubmit,
// 垂直布局label和input在不同行值为vertical
layout: 'horizontal',
// 使用 tailwindcss grid布局
// 水平布局label和input在同一行
layout: 'horizontal',
schema: [
{
// 组件需要在 #/adapter.ts内注册并加上类型
@@ -101,9 +100,8 @@ const [QueryForm1] = useVbenForm({
// 提交函数
handleSubmit: onSubmit,
// 垂直布局label和input在不同行值为vertical
layout: 'horizontal',
// 使用 tailwindcss grid布局
// 水平布局label和input在同一行
layout: 'horizontal',
schema: (() => {
const schema = [];
for (let index = 0; index < 14; index++) {

View File

@@ -13,12 +13,11 @@ const [Form, formApi] = useVbenForm({
class: 'w-full',
},
},
// 使用 tailwindcss grid布局
// 提交函数
handleSubmit: onSubmit,
// 垂直布局label和input在不同行值为vertical
layout: 'horizontal',
// 水平布局label和input在同一行
layout: 'horizontal',
schema: [
{
// 组件需要在 #/adapter.ts内注册并加上类型
@@ -80,7 +79,6 @@ const [Form, formApi] = useVbenForm({
},
fieldName: 'number',
label: '数字',
// 预处理函数将空字符串或null转换为undefined
rules: 'required',
},
{