Commit ee8681db authored by XieZhiXiong's avatar XieZhiXiong

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

parent 68434b27
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* @Author: XieZhiXiong * @Author: XieZhiXiong
* @Date: 2021-06-04 15:51:19 * @Date: 2021-06-04 15:51:19
* @LastEditors: XieZhiXiong * @LastEditors: XieZhiXiong
* @LastEditTime: 2021-06-04 15:51:20 * @LastEditTime: 2021-07-03 17:19:58
* @Description: * @Description:
*/ */
import { ISchema } from '@formily/antd'; import { ISchema } from '@formily/antd';
...@@ -41,7 +41,7 @@ export const schema = (groups: GroupItem[]): ISchema => { ...@@ -41,7 +41,7 @@ export const schema = (groups: GroupItem[]): ISchema => {
wrapperCol: 8, wrapperCol: 8,
labelAlign: 'left', labelAlign: 'left',
}, },
properties: createMemberSchema(item.elements), properties: createMemberSchema(item.elements, false),
}, },
}, },
}; };
......
...@@ -104,12 +104,15 @@ const RULE_REG_MAP = { ...@@ -104,12 +104,15 @@ const RULE_REG_MAP = {
4: PATTERN_MAPS.tel, 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 } = { let description: { [key: string]: any } = {
'x-component-props': { 'x-component-props': {
placeholder: field.fieldRemark, placeholder: field.fieldRemark,
disabled: !!field.disabled, disabled: isDisabled,
}, },
}; };
// 公共的属性 // 公共的属性
...@@ -144,7 +147,7 @@ const getFieldType = (field: ElementType) => { ...@@ -144,7 +147,7 @@ const getFieldType = (field: ElementType) => {
'x-component': 'CustomUpload', 'x-component': 'CustomUpload',
'x-component-props': { 'x-component-props': {
showDesc: false, showDesc: false,
disabled: !!field.disabled, disabled: isDisabled,
}, },
}; };
break; break;
...@@ -154,7 +157,7 @@ const getFieldType = (field: ElementType) => { ...@@ -154,7 +157,7 @@ const getFieldType = (field: ElementType) => {
'x-component': 'RadioGroup', 'x-component': 'RadioGroup',
enum: field.fieldEnum, enum: field.fieldEnum,
'x-component-props': { 'x-component-props': {
disabled: !!field.disabled, disabled: isDisabled
}, },
}; };
break; break;
...@@ -163,7 +166,7 @@ const getFieldType = (field: ElementType) => { ...@@ -163,7 +166,7 @@ const getFieldType = (field: ElementType) => {
description = { description = {
enum: field.fieldEnum, enum: field.fieldEnum,
'x-component-props': { 'x-component-props': {
disabled: !!field.disabled, disabled: isDisabled,
}, },
}; };
break; break;
...@@ -173,7 +176,7 @@ const getFieldType = (field: ElementType) => { ...@@ -173,7 +176,7 @@ const getFieldType = (field: ElementType) => {
'x-component': 'CheckboxGroup', 'x-component': 'CheckboxGroup',
enum: field.fieldEnum, enum: field.fieldEnum,
'x-component-props': { 'x-component-props': {
disabled: !!field.disabled, disabled: isDisabled,
}, },
}; };
break; break;
...@@ -182,7 +185,7 @@ const getFieldType = (field: ElementType) => { ...@@ -182,7 +185,7 @@ const getFieldType = (field: ElementType) => {
description = { description = {
'x-component': 'AreaSelect', 'x-component': 'AreaSelect',
'x-component-props': { 'x-component-props': {
disabled: !!field.disabled, disabled: isDisabled,
}, },
}; };
break; break;
...@@ -193,15 +196,20 @@ const getFieldType = (field: ElementType) => { ...@@ -193,15 +196,20 @@ const getFieldType = (field: ElementType) => {
return Object.assign({}, description, common); 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 = {}; const components = {};
if (!Array.isArray(elements)) { if (!Array.isArray(elements)) {
return components; return components;
} }
for (let item of elements) { for (let item of elements) {
components[item.fieldName as string] = getFieldType(item); components[item.fieldName as string] = getFieldType(item, editable);
} }
return components; 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