feat: supports filling in the collection name and field name

This commit is contained in:
chenos 2021-10-21 12:18:21 +08:00
parent 58d89068af
commit 4b586148b1
2 changed files with 24 additions and 5 deletions

View File

@ -46,8 +46,6 @@ const useResource = () => {
};
const useCollectionsResource = () => {
const descriptionsContext = useContext(DescriptionsContext);
console.log('descriptionsContext.service', descriptionsContext.service);
const resource = useResourceRequest('collections');
return {
resource,
@ -335,6 +333,15 @@ function FieldConfigTitle() {
return <>{`配置「${ctx.record.title}」表字段`}</>;
}
function useCollectionResource({ onSuccess }) {
const visible = useContext(VisibleContext);
const resource = useResourceRequest('collections');
useEffect(() => {
visible && onSuccess({ name: `t_${uid()}` });
}, [visible]);
return { resource };
}
const schema: ISchema = {
type: 'void',
name: 'action',
@ -409,6 +416,9 @@ const schema: ISchema = {
type: 'void',
title: '创建数据表',
'x-decorator': 'Form',
'x-decorator-props': {
useResource: useCollectionResource,
},
'x-component': 'Action.Drawer',
'x-component-props': {
useOkAction: '{{ Table.useTableCreateAction }}',
@ -420,6 +430,14 @@ const schema: ISchema = {
'x-component': 'Input',
'x-decorator': 'FormilyFormItem',
},
name: {
type: 'string',
title: '数据表标识',
'x-component': 'Input',
'x-decorator': 'FormilyFormItem',
description:
'随机生成,可修改。支持英文、数字和下划线,必须以英文字母开头',
},
},
},
},
@ -581,10 +599,10 @@ function CreateFieldButton() {
console.log('click', info.key);
const schema = interfaces.get(info.key);
form.setValues({
...schema.default,
...clone(schema.default),
collection_name: ctx.record.name,
key: uid(),
name: uid(),
name: `f_${uid()}`,
interface: info.key,
});
setProperties(clone(schema.properties));

View File

@ -188,9 +188,10 @@ export const defaultProps = {
type: 'string',
title: '字段标识',
required: true,
'x-disabled': true,
// 'x-disabled': true,
'x-decorator': 'FormItem',
'x-component': 'Input',
description: '随机生成,可修改。支持英文、数字和下划线,必须以英文字母开头',
},
dataType,
// 'uiSchema.required': {