提交 fe250b01 编写于 作者: F FateRiddle

Merge branch 'dev' of github.com:alibaba/form-render into dev

......@@ -32,6 +32,17 @@ const Demo = () => {
api: { title: 'api', type: 'string' },
},
},
{
text: '姓名',
name: 'name',
schema: {
title: '输入框',
type: 'string',
},
setting: {
maxLength: { title: '最长字数', type: 'number' },
},
},
{
text: 'object',
name: 'object',
......@@ -43,15 +54,17 @@ const Demo = () => {
setting: {},
},
{
text: '姓名',
name: 'name',
text: 'array',
name: 'array',
schema: {
title: '输入框',
type: 'string',
},
setting: {
maxLength: { title: '最长字数', type: 'number' },
title: '数组',
type: 'array',
items: {
type: 'object',
properties: {},
},
},
setting: {},
},
],
},
......
......@@ -55,7 +55,7 @@ const RenderList = ({
newItem,
...displayList.slice(idx),
];
onItemChange(dataPath, newList);
onItemChange(dataPath, JSON.parse(JSON.stringify(newList)));
};
const deleteItem = idx => {
......
{
"name": "fr-generator",
"version": "2.1.1",
"version": "2.1.2",
"scripts": {
"build": "father-build",
"prepare": "npm run build",
......
......@@ -5,6 +5,7 @@ import IdInput from '../widgets/antd/idInput';
import PercentSlider from '../widgets/antd/percentSlider';
import {
defaultSettings,
baseCommonSettings,
defaultCommonSettings,
elements,
advancedElements,
......@@ -38,14 +39,28 @@ export default function ItemSettings() {
const getWidgetList = (settings, commonSettings) => {
return settings.reduce((widgetList, setting) => {
if (!Array.isArray(setting.widgets)) return widgetList;
const basicWidgets = setting.widgets.map(item => ({
...item,
widget:
item.widget ||
item.schema.widget ||
getWidgetName(item.schema, defaultMapping),
setting: { ...commonSettings, ...item.setting },
}));
const basicWidgets = setting.widgets.map(item => {
const baseItemSettings = {};
if (item.schema.type === 'array') {
baseItemSettings.items = {
type: 'object',
hidden: '{{true}}',
};
}
return {
...item,
widget:
item.widget ||
item.schema.widget ||
getWidgetName(item.schema, defaultMapping),
setting: {
...baseCommonSettings,
...commonSettings,
...baseItemSettings,
...item.setting,
},
};
});
return [...widgetList, ...basicWidgets];
}, []);
};
......
// 只需写配置,方便可扩展
export const defaultCommonSettings = {
$id: {
title: 'ID',
description: '字段名称/英文',
type: 'string',
widget: 'idInput',
required: true,
},
export const baseCommonSettings = {
title: {
title: '标题',
type: 'string',
......@@ -26,6 +19,20 @@ export const defaultCommonSettings = {
type: 'string',
hidden: '{{true}}',
},
};
export const defaultCommonSettings = {
$id: {
title: 'ID',
description: '字段名称/英文',
type: 'string',
widget: 'idInput',
required: true,
},
title: {
title: '标题',
type: 'string',
},
description: {
title: '说明',
type: 'string',
......@@ -438,7 +445,7 @@ export const advancedElements = [
export const layouts = [
{
text: 'object',
text: '对象',
name: 'object',
schema: {
title: '对象',
......
......@@ -228,6 +228,12 @@ export function idToSchema(flatten, id = '#', final = false) {
if (final) {
schema.$id && delete schema.$id;
}
if (schema.type === 'array') {
if (!schema.items) schema.items = {}
if (!schema.items.type) {
schema.items.type = 'object'
}
}
if (item.children.length > 0) {
item.children.forEach(child => {
let childId = child;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册