From 4b586148b12ac76de5979f30e7126698e84a98e5 Mon Sep 17 00:00:00 2001 From: chenos Date: Thu, 21 Oct 2021 12:18:21 +0800 Subject: [PATCH] feat: supports filling in the collection name and field name --- .../admin-layout/Collections/index.tsx | 26 ++++++++++++++++--- .../interfaces/properties/index.ts | 3 ++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/packages/client/src/components/admin-layout/Collections/index.tsx b/packages/client/src/components/admin-layout/Collections/index.tsx index 6be24e218..e161982ff 100644 --- a/packages/client/src/components/admin-layout/Collections/index.tsx +++ b/packages/client/src/components/admin-layout/Collections/index.tsx @@ -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)); diff --git a/packages/client/src/schemas/database-field/interfaces/properties/index.ts b/packages/client/src/schemas/database-field/interfaces/properties/index.ts index 82324103c..d6b360f12 100644 --- a/packages/client/src/schemas/database-field/interfaces/properties/index.ts +++ b/packages/client/src/schemas/database-field/interfaces/properties/index.ts @@ -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': {