Commit ee8681db authored by XieZhiXiong's avatar XieZhiXiong

feat: 添加 是否可编辑有值元素 参数

parent 68434b27
......@@ -2,7 +2,7 @@
* @Author: XieZhiXiong
* @Date: 2021-06-04 15:51:19
* @LastEditors: XieZhiXiong
* @LastEditTime: 2021-06-04 15:51:20
* @LastEditTime: 2021-07-03 17:19:58
* @Description:
*/
import { ISchema } from '@formily/antd';
......@@ -41,7 +41,7 @@ export const schema = (groups: GroupItem[]): ISchema => {
wrapperCol: 8,
labelAlign: 'left',
},
properties: createMemberSchema(item.elements),
properties: createMemberSchema(item.elements, false),
},
},
};
......
......@@ -104,12 +104,15 @@ const RULE_REG_MAP = {
4: PATTERN_MAPS.tel,
};
const getFieldType = (field: ElementType) => {
const getFieldType = (field: ElementType, editable: boolean = true) => {
const isDisabled = (!editable && field.fieldValue) || !!field.disabled;
// 默认是 输入框
let description: { [key: string]: any } = {
'x-component-props': {
placeholder: field.fieldRemark,
disabled: !!field.disabled,
disabled: isDisabled,
},
};
// 公共的属性
......@@ -144,7 +147,7 @@ const getFieldType = (field: ElementType) => {
'x-component': 'CustomUpload',
'x-component-props': {
showDesc: false,
disabled: !!field.disabled,
disabled: isDisabled,
},
};
break;
......@@ -154,7 +157,7 @@ const getFieldType = (field: ElementType) => {
'x-component': 'RadioGroup',
enum: field.fieldEnum,
'x-component-props': {
disabled: !!field.disabled,
disabled: isDisabled
},
};
break;
......@@ -163,7 +166,7 @@ const getFieldType = (field: ElementType) => {
description = {
enum: field.fieldEnum,
'x-component-props': {
disabled: !!field.disabled,
disabled: isDisabled,
},
};
break;
......@@ -173,7 +176,7 @@ const getFieldType = (field: ElementType) => {
'x-component': 'CheckboxGroup',
enum: field.fieldEnum,
'x-component-props': {
disabled: !!field.disabled,
disabled: isDisabled,
},
};
break;
......@@ -182,7 +185,7 @@ const getFieldType = (field: ElementType) => {
description = {
'x-component': 'AreaSelect',
'x-component-props': {
disabled: !!field.disabled,
disabled: isDisabled,
},
};
break;
......@@ -193,15 +196,20 @@ const getFieldType = (field: ElementType) => {
return Object.assign({}, description, common);
};
// 根据后台生成注册资料 schema
export function createMemberSchema(elements: ElementType[]) {
/**
* 根据后台生成注册资料 schema
* @param elements
* @param editable 有值的元素是否可编辑
* @returns
*/
export function createMemberSchema(elements: ElementType[], editable: boolean = true) {
const components = {};
if (!Array.isArray(elements)) {
return components;
}
for (let item of elements) {
components[item.fieldName as string] = getFieldType(item);
components[item.fieldName as string] = getFieldType(item, editable);
}
return components;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment