fix: FormItem配置新增输入框字数展示及长度限制

pull/39/head
郑伟彬 2023-11-03 14:59:33 +08:00
parent 1902b0e98b
commit 9c63ad8279
2 changed files with 21 additions and 1 deletions

View File

@ -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<any> = {
allowClear: true,
@ -293,6 +305,7 @@ export default defineComponent({
...propsData,
...on,
...bindValue,
...inputAttr
}
if (!renderComponentContent)

View File

@ -258,3 +258,10 @@ export interface HelpComponentProps {
// Positioning
position: any
}
export interface InputAttribute {
// 输入框默认输入的最大长度
maxlength?: number | string,
// 是否显示输入的最大长度
showCount?: boolean
}