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..8690d722e 100644 --- a/src/components/Form/src/types/form.ts +++ b/src/components/Form/src/types/form.ts @@ -1,10 +1,10 @@ -import type { NamePath, RuleObject } from 'ant-design-vue/lib/form/interface' -import type { CSSProperties, VNode } from 'vue' -import type { RowProps } from 'ant-design-vue/lib/grid/Row' -import type { FormItem } from './formItem' -import type { ColEx, ComponentType } from './index' import type { ButtonProps as AntdButtonProps } from '@/components/Button' import type { TableActionType } from '@/components/Table/src/types/table' +import type { NamePath, RuleObject } from 'ant-design-vue/lib/form/interface' +import type { RowProps } from 'ant-design-vue/lib/grid/Row' +import type { CSSProperties, VNode } from 'vue' +import type { FormItem } from './formItem' +import type { ColEx, ComponentType } from './index' export type FieldMapToTime = [string, [string, string], (string | [string, string])?][] @@ -189,6 +189,12 @@ interface BaseFormSchema { isAdvanced?: boolean + // Input/InputTextArea是否显示字数 + showCount?: boolean + + // Input/InputTextArea是否字限制长度 + maxlength?: number + // Matching details components span?: number @@ -258,3 +264,10 @@ export interface HelpComponentProps { // Positioning position: any } + +export interface InputAttribute { + // 输入框默认输入的最大长度 + maxlength?: number | string, + // 是否显示输入的最大长度 + showCount?: boolean +} \ No newline at end of file