mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-24 10:33:50 +08:00
feat: 新增表单只读功能 (#3335)
* fix(useFormEvents): 修复setFieldsValue 方法设置完值后,表单属性丢失formActionType 的bug * feat: 新增 sync 的action * feat(FormItem): 新增只读属性 * feat(FormItem): 新增表单只读属性 --------- Co-authored-by: gavin-james <meaganlindesy1258@gmail.com>
This commit is contained in:
parent
0f13758554
commit
342328ce5f
@ -116,6 +116,21 @@
|
|||||||
return disabled;
|
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 } {
|
function getShow(): { isShow: boolean; isIfShow: boolean } {
|
||||||
const { show, ifShow } = props.schema;
|
const { show, ifShow } = props.schema;
|
||||||
const { showAdvancedButton } = props.formProps;
|
const { showAdvancedButton } = props.formProps;
|
||||||
@ -280,6 +295,7 @@
|
|||||||
size,
|
size,
|
||||||
...unref(getComponentsProps),
|
...unref(getComponentsProps),
|
||||||
disabled: unref(getDisable),
|
disabled: unref(getDisable),
|
||||||
|
readonly: unref(getReadonly),
|
||||||
};
|
};
|
||||||
|
|
||||||
const isCreatePlaceholder = !propsData.disabled && autoSetPlaceHolder;
|
const isCreatePlaceholder = !propsData.disabled && autoSetPlaceHolder;
|
||||||
@ -305,7 +321,12 @@
|
|||||||
return <Comp {...compAttr} />;
|
return <Comp {...compAttr} />;
|
||||||
}
|
}
|
||||||
const compSlot = isFunction(renderComponentContent)
|
const compSlot = isFunction(renderComponentContent)
|
||||||
? { ...renderComponentContent(unref(getValues), { disabled: unref(getDisable) }) }
|
? {
|
||||||
|
...renderComponentContent(unref(getValues), {
|
||||||
|
disabled: unref(getDisable),
|
||||||
|
readonly: unref(getReadonly),
|
||||||
|
}),
|
||||||
|
}
|
||||||
: {
|
: {
|
||||||
default: () => renderComponentContent,
|
default: () => renderComponentContent,
|
||||||
};
|
};
|
||||||
@ -339,7 +360,7 @@
|
|||||||
const { itemProps, slot, render, field, suffix, component } = props.schema;
|
const { itemProps, slot, render, field, suffix, component } = props.schema;
|
||||||
const { labelCol, wrapperCol } = unref(itemLabelWidthProp);
|
const { labelCol, wrapperCol } = unref(itemLabelWidthProp);
|
||||||
const { colon } = props.formProps;
|
const { colon } = props.formProps;
|
||||||
const opts = { disabled: unref(getDisable) };
|
const opts = { disabled: unref(getDisable), readonly: unref(getReadonly) };
|
||||||
if (component === 'Divider') {
|
if (component === 'Divider') {
|
||||||
return (
|
return (
|
||||||
<Col span={24}>
|
<Col span={24}>
|
||||||
@ -397,7 +418,7 @@
|
|||||||
const realColProps = { ...baseColProps, ...colProps };
|
const realColProps = { ...baseColProps, ...colProps };
|
||||||
const { isIfShow, isShow } = getShow();
|
const { isIfShow, isShow } = getShow();
|
||||||
const values = unref(getValues);
|
const values = unref(getValues);
|
||||||
const opts = { disabled: unref(getDisable) };
|
const opts = { disabled: unref(getDisable), readonly: unref(getReadonly) };
|
||||||
|
|
||||||
const getContent = () => {
|
const getContent = () => {
|
||||||
return colSlot
|
return colSlot
|
||||||
|
@ -85,6 +85,8 @@ export interface FormProps {
|
|||||||
size?: 'default' | 'small' | 'large';
|
size?: 'default' | 'small' | 'large';
|
||||||
// Whether to disable
|
// Whether to disable
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
// Whether to readonly
|
||||||
|
readonly?: boolean;
|
||||||
// Time interval fields are mapped into multiple
|
// Time interval fields are mapped into multiple
|
||||||
fieldMapToTime?: FieldMapToTime;
|
fieldMapToTime?: FieldMapToTime;
|
||||||
// Placeholder is set automatically
|
// Placeholder is set automatically
|
||||||
@ -218,6 +220,8 @@ interface BaseFormSchema {
|
|||||||
|
|
||||||
dynamicDisabled?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
|
dynamicDisabled?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
|
||||||
|
|
||||||
|
dynamicReadonly?: boolean | ((renderCallbackParams: RenderCallbackParams) => boolean);
|
||||||
|
|
||||||
dynamicRules?: (renderCallbackParams: RenderCallbackParams) => Rule[];
|
dynamicRules?: (renderCallbackParams: RenderCallbackParams) => Rule[];
|
||||||
}
|
}
|
||||||
export interface ComponentFormSchema extends BaseFormSchema {
|
export interface ComponentFormSchema extends BaseFormSchema {
|
||||||
|
Loading…
Reference in New Issue
Block a user