diff --git a/packages/core/client/src/schema-initializer/buttons/TabPaneInitializers.tsx b/packages/core/client/src/schema-initializer/buttons/TabPaneInitializers.tsx index 6e753c4e6..5e99536ae 100644 --- a/packages/core/client/src/schema-initializer/buttons/TabPaneInitializers.tsx +++ b/packages/core/client/src/schema-initializer/buttons/TabPaneInitializers.tsx @@ -1,8 +1,8 @@ import { useForm } from '@formily/react'; import React from 'react'; -import { SchemaComponent, useActionContext, useDesignable } from '../..'; +import { SchemaComponent, useActionContext, useDesignable, useRecordIndex } from '../..'; -export const TabPaneInitializers = () => { +export const TabPaneInitializers = (props?: any) => { const { designable, insertBeforeEnd } = useDesignable(); if (!designable) { return null; @@ -10,6 +10,7 @@ export const TabPaneInitializers = () => { const useSubmitAction = () => { const form = useForm(); const ctx = useActionContext(); + const index = useRecordIndex(); return { async run() { await form.submit(); @@ -26,7 +27,8 @@ export const TabPaneInitializers = () => { grid: { type: 'void', 'x-component': 'Grid', - 'x-initializer': 'RecordBlockInitializers', + 'x-initializer': + props.isCreate || index === null ? 'CreateFormBlockInitializers' : 'RecordBlockInitializers', properties: {}, }, }, @@ -111,3 +113,7 @@ export const TabPaneInitializers = () => { /> ); }; + +export const TabPaneInitializersForCreateFormBlock = () => { + return ; +}; diff --git a/packages/core/client/src/schema-initializer/buttons/index.ts b/packages/core/client/src/schema-initializer/buttons/index.ts index 1dd66cda4..4b4926020 100644 --- a/packages/core/client/src/schema-initializer/buttons/index.ts +++ b/packages/core/client/src/schema-initializer/buttons/index.ts @@ -16,3 +16,4 @@ export * from './TableActionInitializers'; export * from './TableColumnInitializers'; export * from './TableSelectorInitializers'; export * from './TabPaneInitializers'; + diff --git a/packages/core/client/src/schema-initializer/items/CreateActionInitializer.tsx b/packages/core/client/src/schema-initializer/items/CreateActionInitializer.tsx index 697ace75b..4778b5e63 100644 --- a/packages/core/client/src/schema-initializer/items/CreateActionInitializer.tsx +++ b/packages/core/client/src/schema-initializer/items/CreateActionInitializer.tsx @@ -1,46 +1,45 @@ -import React from "react"; -import { ActionInitializer } from "./ActionInitializer"; +import React from 'react'; +import { ActionInitializer } from './ActionInitializer'; export const CreateActionInitializer = (props) => { - const schema = { - type: 'void', - title: '{{ t("Add new") }}', - 'x-action': 'create', - 'x-designer': 'Action.Designer', - 'x-component': 'Action', - 'x-component-props': { - icon: 'PlusOutlined', - openMode: 'drawer', - type: 'primary', - }, - properties: { - drawer: { - type: 'void', - title: '{{ t("Add record") }}', - 'x-component': 'Action.Container', - 'x-component-props': { - className: 'nb-action-popup', - }, - properties: { - tabs: { - type: 'void', - 'x-component': 'Tabs', - 'x-component-props': {}, - 'x-initializer': 'TabPaneInitializers', - properties: { - tab1: { - type: 'void', - title: '{{t("Add new")}}', - 'x-component': 'Tabs.TabPane', - 'x-designer': 'Tabs.Designer', - 'x-component-props': {}, - properties: { - grid: { - type: 'void', - 'x-component': 'Grid', - 'x-initializer': 'CreateFormBlockInitializers', - properties: {}, - }, + const schema = { + type: 'void', + title: '{{ t("Add new") }}', + 'x-action': 'create', + 'x-designer': 'Action.Designer', + 'x-component': 'Action', + 'x-component-props': { + icon: 'PlusOutlined', + openMode: 'drawer', + type: 'primary', + }, + properties: { + drawer: { + type: 'void', + title: '{{ t("Add record") }}', + 'x-component': 'Action.Container', + 'x-component-props': { + className: 'nb-action-popup', + }, + properties: { + tabs: { + type: 'void', + 'x-component': 'Tabs', + 'x-component-props': {}, + 'x-initializer': 'TabPaneInitializersForCreateFormBlock', + properties: { + tab1: { + type: 'void', + title: '{{t("Add new")}}', + 'x-component': 'Tabs.TabPane', + 'x-designer': 'Tabs.Designer', + 'x-component-props': {}, + properties: { + grid: { + type: 'void', + 'x-component': 'Grid', + 'x-initializer': 'CreateFormBlockInitializers', + properties: {}, }, }, }, @@ -48,6 +47,7 @@ export const CreateActionInitializer = (props) => { }, }, }, - }; - return ; + }, }; + return ; +};