提交 696726ea 编写于 作者: F FateRiddle

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

{ {
"name": "fr-generator", "name": "fr-generator",
"version": "2.0.3", "version": "2.1.1",
"scripts": { "scripts": {
"build": "father-build", "build": "father-build",
"prepare": "npm run build", "prepare": "npm run build",
......
...@@ -73,8 +73,9 @@ const RenderField = ({ ...@@ -73,8 +73,9 @@ const RenderField = ({
const usefulWidgetProps = transformProps({ const usefulWidgetProps = transformProps({
value: data || schema.default, value: data || schema.default,
checked: data, checked: data,
disabled: schema['disabled'], disabled: schema.disabled,
readOnly: schema['readOnly'], readOnly: schema.readOnly,
format: schema.format,
onChange, onChange,
schema, schema,
...schema['props'], ...schema['props'],
......
...@@ -11,8 +11,8 @@ import { ...@@ -11,8 +11,8 @@ import {
flattenToData, flattenToData,
looseJsonParse, looseJsonParse,
isObject, isObject,
oldSchemaToNew,
newSchemaToOld, newSchemaToOld,
schemaToState,
} from './utils'; } from './utils';
import { Ctx, StoreCtx } from './context'; import { Ctx, StoreCtx } from './context';
import FR from './FR'; import FR from './FR';
...@@ -90,28 +90,12 @@ function Wrapper( ...@@ -90,28 +90,12 @@ function Wrapper(
setState({ schemaForImport: e.target.value }); setState({ schemaForImport: e.target.value });
}; };
// 收口点 propsSchema 到 schema 的转换(一共就3个入口:defaultValue,importSchema,setValue)
// TODO: 3个入口可能还是太多了,是不是考虑在外面裹一层
// TODO2: 导入这边看看会不会传一个乱写的schema就crash
const importSchema = () => { const importSchema = () => {
try { try {
const value = transformFrom(looseJsonParse(local.schemaForImport)); const value = transformFrom(looseJsonParse(local.schemaForImport));
let _isNewVersion = true; setGlobal(() => ({
if (value && value.propsSchema) {
_isNewVersion = false;
}
const schema = oldSchemaToNew(value);
setGlobal(state => ({
schema,
formData: {},
selected: undefined, selected: undefined,
isNewVersion: _isNewVersion, ...schemaToState(value),
frProps: {
...state.frProps,
column: schema.column,
displayType: schema.displayType,
labelWidth: schema.labelWidth,
},
})); }));
} catch (error) { } catch (error) {
message.info('格式不对哦,请重新尝试'); // 可以加个格式哪里不对的提示 message.info('格式不对哦,请重新尝试'); // 可以加个格式哪里不对的提示
...@@ -141,29 +125,12 @@ function Wrapper( ...@@ -141,29 +125,12 @@ function Wrapper(
const getValue = () => displaySchema; const getValue = () => displaySchema;
// 收口点 propsSchema 到 schema
// setValue 外部用于修改大schema,叫setSchema比较合适
// TODO: 这次顶层的props传递改动和整理后,确保这个api还是正确的
const setValue = value => { const setValue = value => {
try { try {
// TODO: 这里默认使用setValue的同学不使用ui:Schema
let _isNewVersion = true;
if (value && value.propsSchema) {
_isNewVersion = false;
}
const schema = oldSchemaToNew(value);
setGlobal(state => ({ setGlobal(state => ({
...state, ...state,
schema,
formData: {},
selected: undefined, selected: undefined,
isNewVersion: _isNewVersion, ...schemaToState(value),
frProps: {
...state.frProps,
column: schema.column,
displayType: schema.displayType,
labelWidth: schema.labelWidth,
},
})); }));
} catch (error) { } catch (error) {
console.error(error); console.error(error);
......
...@@ -10,7 +10,7 @@ import list from './widgets/antd/list'; ...@@ -10,7 +10,7 @@ import list from './widgets/antd/list';
import './atom.less'; import './atom.less';
import './Main.less'; import './Main.less';
import 'antd/dist/antd.less'; import 'antd/dist/antd.less';
import { oldSchemaToNew } from './utils'; import { schemaToState } from './utils';
const DEFAULT_SCHEMA = { const DEFAULT_SCHEMA = {
type: 'object', type: 'object',
...@@ -48,9 +48,7 @@ function App(props, ref) { ...@@ -48,9 +48,7 @@ function App(props, ref) {
const frwRef = ref || useRef(); const frwRef = ref || useRef();
const [state, setState] = useSet({ const [state, setState] = useSet({
formData: {}, formData: {},
frProps: { frProps: {}, // form-render 的全局 props 等
displayType: 'row',
}, // form-render 的全局props等
hovering: undefined, // 目前没有用到 hovering: undefined, // 目前没有用到
isNewVersion: true, // 用schema字段,还是用propsSchema字段,这是一个问题 isNewVersion: true, // 用schema字段,还是用propsSchema字段,这是一个问题
preview: false, // preview = false 是编辑模式 preview: false, // preview = false 是编辑模式
...@@ -61,21 +59,7 @@ function App(props, ref) { ...@@ -61,21 +59,7 @@ function App(props, ref) {
// 收口点 propsSchema 到 schema 的转换 (一共3处,其他两个是 importSchema 和 setValue,在 FRWrapper 文件) // 收口点 propsSchema 到 schema 的转换 (一共3处,其他两个是 importSchema 和 setValue,在 FRWrapper 文件)
useEffect(() => { useEffect(() => {
const schema = defaultValue ? transformFrom(defaultValue) : DEFAULT_SCHEMA; const schema = defaultValue ? transformFrom(defaultValue) : DEFAULT_SCHEMA;
if (!schema) return; if (schema) setState(schemaToState(schema));
if (schema.propsSchema) {
setState({ isNewVersion: false });
} else {
setState({ isNewVersion: true });
}
setState({
schema: oldSchemaToNew(schema), // 旧的转新的,新的不变
formData: schema.formData || {},
frProps: {
column: schema.column,
displayType: schema.displayType,
labelWidth: schema.labelWidth,
},
});
}, [defaultValue]); }, [defaultValue]);
const { const {
......
...@@ -6,12 +6,9 @@ import { useStore, useGlobal } from '../hooks'; ...@@ -6,12 +6,9 @@ import { useStore, useGlobal } from '../hooks';
export default function GlobalSettings() { export default function GlobalSettings() {
const form = useForm(); const form = useForm();
const [innerUpdate, setInnerUpdate] = useState(false); const [innerUpdate, setInnerUpdate] = useState(false);
const { widgets, frProps, userProps } = useStore(); const { widgets, frProps, userProps = {} } = useStore();
const setGlobal = useGlobal(); const setGlobal = useGlobal();
const globalSettings = const globalSettings = userProps.globalSettings || defaultGlobalSettings;
userProps && userProps.globalSettings
? userProps.globalSettings
: defaultGlobalSettings;
const onDataChange = value => { const onDataChange = value => {
setInnerUpdate(true); setInnerUpdate(true);
......
...@@ -69,7 +69,7 @@ export default function ItemSettings() { ...@@ -69,7 +69,7 @@ export default function ItemSettings() {
// setting 该显示什么的计算,要把选中组件的 schema 和它对应的 widgets 的整体 schema 进行拼接 // setting 该显示什么的计算,要把选中组件的 schema 和它对应的 widgets 的整体 schema 进行拼接
try { try {
const item = flatten[selected]; const item = flatten[selected];
if (!item) return; if (!item || selected === '#') return;
setReady(false); setReady(false);
// 算 widgetList // 算 widgetList
const _settings = Array.isArray(settings) const _settings = Array.isArray(settings)
...@@ -88,13 +88,16 @@ export default function ItemSettings() { ...@@ -88,13 +88,16 @@ export default function ItemSettings() {
if (hideId) delete properties.$id; if (hideId) delete properties.$id;
form.setValues(item.schema);
setSettingSchema({ setSettingSchema({
type: 'object', type: 'object',
displayType: 'column', displayType: 'column',
properties, properties,
}); });
setTimeout(() => setReady(true), 0); form.setValues(item.schema);
setTimeout(() => {
setReady(true);
onDataChange(form.getValues());
}, 0);
} catch (error) { } catch (error) {
console.log(error); console.log(error);
} }
......
...@@ -11,6 +11,21 @@ export const defaultCommonSettings = { ...@@ -11,6 +11,21 @@ export const defaultCommonSettings = {
title: '标题', title: '标题',
type: 'string', type: 'string',
}, },
type: {
title: '类型',
type: 'string',
hidden: '{{true}}',
},
widget: {
title: '组件',
type: 'string',
hidden: '{{true}}',
},
format: {
title: '格式',
type: 'string',
hidden: '{{true}}',
},
description: { description: {
title: '说明', title: '说明',
type: 'string', type: 'string',
...@@ -322,7 +337,6 @@ export const elements = [ ...@@ -322,7 +337,6 @@ export const elements = [
name: 'checkboxes', name: 'checkboxes',
schema: { schema: {
title: '多选', title: '多选',
description: '点击多选',
type: 'array', type: 'array',
widget: 'checkboxes', widget: 'checkboxes',
items: { items: {
...@@ -445,6 +459,10 @@ export const layouts = [ ...@@ -445,6 +459,10 @@ export const layouts = [
}, },
}, },
setting: { setting: {
items: {
type: 'object',
hidden: '{{true}}',
},
min: { min: {
title: '最小长度', title: '最小长度',
type: 'number', type: 'number',
...@@ -486,6 +504,10 @@ export const layouts = [ ...@@ -486,6 +504,10 @@ export const layouts = [
}, },
}, },
setting: { setting: {
items: {
type: 'object',
hidden: '{{true}}',
},
min: { min: {
title: '最小长度', title: '最小长度',
type: 'number', type: 'number',
...@@ -531,6 +553,10 @@ export const layouts = [ ...@@ -531,6 +553,10 @@ export const layouts = [
}, },
}, },
setting: { setting: {
items: {
type: 'object',
hidden: '{{true}}',
},
min: { min: {
title: '最小长度', title: '最小长度',
type: 'number', type: 'number',
...@@ -572,6 +598,10 @@ export const layouts = [ ...@@ -572,6 +598,10 @@ export const layouts = [
}, },
}, },
setting: { setting: {
items: {
type: 'object',
hidden: '{{true}}',
},
min: { min: {
title: '最小长度', title: '最小长度',
type: 'number', type: 'number',
...@@ -694,6 +724,7 @@ export const defaultGlobalSettings = { ...@@ -694,6 +724,7 @@ export const defaultGlobalSettings = {
displayType: { displayType: {
title: '标签展示模式', title: '标签展示模式',
type: 'string', type: 'string',
default: 'row',
enum: ['row', 'column'], enum: ['row', 'column'],
enumNames: ['同行', '单独一行'], enumNames: ['同行', '单独一行'],
widget: 'radio', widget: 'radio',
......
...@@ -588,6 +588,22 @@ export const newSchemaToOld = setting => { ...@@ -588,6 +588,22 @@ export const newSchemaToOld = setting => {
return setting; return setting;
}; };
export const schemaToState = value => {
const schema = oldSchemaToNew(value);
const frProps = Object.keys(schema).reduce((rst, cur) => {
if (['type', 'properties'].includes(cur)) return rst;
return { ...rst, [cur]: schema[cur] };
}, {});
const isNewVersion = !(value && value.propsSchema);
return {
schema,
frProps,
formData: schema.formData || {},
isNewVersion,
};
};
export function defaultGetValueFromEvent(valuePropName, ...args) { export function defaultGetValueFromEvent(valuePropName, ...args) {
const event = args[0]; const event = args[0];
if (event && event.target && valuePropName in event.target) { if (event && event.target && valuePropName in event.target) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册