From 9c63ad827905a59e632fc51278e9504c414ecd20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=83=91=E4=BC=9F=E5=BD=AC?= Date: Fri, 3 Nov 2023 14:59:33 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20FormItem=E9=85=8D=E7=BD=AE=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E8=BE=93=E5=85=A5=E6=A1=86=E5=AD=97=E6=95=B0=E5=B1=95?= =?UTF-8?q?=E7=A4=BA=E5=8F=8A=E9=95=BF=E5=BA=A6=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Form/src/components/FormItem.vue | 15 ++++++++++++++- src/components/Form/src/types/form.ts | 7 +++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/components/Form/src/components/FormItem.vue b/src/components/Form/src/components/FormItem.vue index fcd1d792f..2c9cc658d 100644 --- a/src/components/Form/src/components/FormItem.vue +++ b/src/components/Form/src/components/FormItem.vue @@ -5,7 +5,7 @@ import type { Rule as ValidationRule } from 'ant-design-vue/lib/form' import { Col, Divider, Form } from 'ant-design-vue' import { cloneDeep, upperFirst } from 'lodash-es' import type { FormActionType, FormProps, FormSchemaInner as FormSchema } from '../types/form' -import { isComponentFormSchema } from '../types/form' +import { isComponentFormSchema, InputAttribute } from '../types/form' import { componentMap } from '../componentMap' import { NO_AUTO_LINK_COMPONENTS, createPlaceholderMessage, setComponentRuleType } from '../helper' import { useItemLabelWidth } from '../hooks/useLabelWidth' @@ -255,6 +255,18 @@ export default defineComponent({ const eventKey = `on${upperFirst(changeEvent)}` + // Input/InputTextArea输入限制 + const inputAttr: InputAttribute = {} + if (component && ['Input', 'InputTextArea'.includes(component)]) { + const { maxlength, showCount } = props.schema + if (maxlength) { + inputAttr.maxlength = maxlength + } + if (showCount) { + inputAttr.showCount = showCount + } + } + const { autoSetPlaceHolder, size } = props.formProps const propsData: Recordable = { allowClear: true, @@ -293,6 +305,7 @@ export default defineComponent({ ...propsData, ...on, ...bindValue, + ...inputAttr } if (!renderComponentContent) diff --git a/src/components/Form/src/types/form.ts b/src/components/Form/src/types/form.ts index 6dfecbbe8..05ab90505 100644 --- a/src/components/Form/src/types/form.ts +++ b/src/components/Form/src/types/form.ts @@ -258,3 +258,10 @@ export interface HelpComponentProps { // Positioning position: any } + +export interface InputAttribute { + // 输入框默认输入的最大长度 + maxlength?: number | string, + // 是否显示输入的最大长度 + showCount?: boolean +} \ No newline at end of file