From 342328ce5f06b33dabdbd4a3bdd2c846f011eb03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9E=97=E9=A3=9E?= <62117658+gavin-james@users.noreply.github.com> Date: Sun, 26 Nov 2023 14:04:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=A1=A8=E5=8D=95?= =?UTF-8?q?=E5=8F=AA=E8=AF=BB=E5=8A=9F=E8=83=BD=20(#3335)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix(useFormEvents): 修复setFieldsValue 方法设置完值后,表单属性丢失formActionType 的bug * feat: 新增 sync 的action * feat(FormItem): 新增只读属性 * feat(FormItem): 新增表单只读属性 --------- Co-authored-by: gavin-james --- .../Form/src/components/FormItem.vue | 27 ++++++++++++++++--- src/components/Form/src/types/form.ts | 4 +++ 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/components/Form/src/components/FormItem.vue b/src/components/Form/src/components/FormItem.vue index e6fc845f3..7198a9119 100644 --- a/src/components/Form/src/components/FormItem.vue +++ b/src/components/Form/src/components/FormItem.vue @@ -116,6 +116,21 @@ return disabled; }); + const getReadonly = computed(() => { + const { readonly: globReadonly } = props.formProps; + const { dynamicReadonly } = props.schema; + const { readonly: itemReadonly = false } = unref(getComponentsProps); + + let readonly = globReadonly || itemReadonly; + if (isBoolean(dynamicReadonly)) { + readonly = dynamicReadonly; + } + if (isFunction(dynamicReadonly)) { + readonly = dynamicReadonly(unref(getValues)); + } + return readonly; + }); + function getShow(): { isShow: boolean; isIfShow: boolean } { const { show, ifShow } = props.schema; const { showAdvancedButton } = props.formProps; @@ -280,6 +295,7 @@ size, ...unref(getComponentsProps), disabled: unref(getDisable), + readonly: unref(getReadonly), }; const isCreatePlaceholder = !propsData.disabled && autoSetPlaceHolder; @@ -305,7 +321,12 @@ return ; } const compSlot = isFunction(renderComponentContent) - ? { ...renderComponentContent(unref(getValues), { disabled: unref(getDisable) }) } + ? { + ...renderComponentContent(unref(getValues), { + disabled: unref(getDisable), + readonly: unref(getReadonly), + }), + } : { default: () => renderComponentContent, }; @@ -339,7 +360,7 @@ const { itemProps, slot, render, field, suffix, component } = props.schema; const { labelCol, wrapperCol } = unref(itemLabelWidthProp); const { colon } = props.formProps; - const opts = { disabled: unref(getDisable) }; + const opts = { disabled: unref(getDisable), readonly: unref(getReadonly) }; if (component === 'Divider') { return ( @@ -397,7 +418,7 @@ const realColProps = { ...baseColProps, ...colProps }; const { isIfShow, isShow } = getShow(); const values = unref(getValues); - const opts = { disabled: unref(getDisable) }; + const opts = { disabled: unref(getDisable), readonly: unref(getReadonly) }; const getContent = () => { return colSlot diff --git a/src/components/Form/src/types/form.ts b/src/components/Form/src/types/form.ts index 3f9fe157d..0838de8b7 100644 --- a/src/components/Form/src/types/form.ts +++ b/src/components/Form/src/types/form.ts @@ -85,6 +85,8 @@ export interface FormProps { size?: 'default' | 'small' | 'large'; // Whether to disable disabled?: boolean; + // Whether to readonly + readonly?: boolean; // Time interval fields are mapped into multiple fieldMapToTime?: FieldMapToTime; // Placeholder is set automatically @@ -218,6 +220,8 @@ interface BaseFormSchema { dynamicDisabled?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean); + dynamicReadonly?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean); + dynamicRules?: (renderCallbackParams: RenderCallbackParams) => Rule[]; } export interface ComponentFormSchema extends BaseFormSchema {