diff --git a/packages/core/client/src/schema-component/antd/form-v2/Templates.tsx b/packages/core/client/src/schema-component/antd/form-v2/Templates.tsx index 590596cc1..9aca6f86a 100644 --- a/packages/core/client/src/schema-component/antd/form-v2/Templates.tsx +++ b/packages/core/client/src/schema-component/antd/form-v2/Templates.tsx @@ -100,6 +100,9 @@ export const Templates = ({ style = {}, form }) => { fetchTemplateData(api, option, t) .then((data) => { if (form && data) { + // 切换之前先把之前的数据清空 + form.reset(); + forEach(data, (value, key) => { if (value) { form.values[key] = value; diff --git a/packages/core/client/src/schema-settings/DataTemplates/components/DataTemplateTitle.tsx b/packages/core/client/src/schema-settings/DataTemplates/components/DataTemplateTitle.tsx index b95d4bb76..dcae98891 100644 --- a/packages/core/client/src/schema-settings/DataTemplates/components/DataTemplateTitle.tsx +++ b/packages/core/client/src/schema-settings/DataTemplates/components/DataTemplateTitle.tsx @@ -9,7 +9,7 @@ import { clone } from 'lodash'; import React, { Fragment, useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; -const DataTemplateTitle = (props) => { +const DataTemplateTitle = observer<{ index: number; item: any }>((props) => { const array = ArrayBase.useArray(); const index = ArrayBase.useIndex(props.index); const { t } = useTranslation(); @@ -22,17 +22,18 @@ const DataTemplateTitle = (props) => { value.title = `${t('Template name')} ${array?.field?.value?.length}`; } }, []); + return ( { ev.stopPropagation(); - array.field.value.splice(index, 1, { ...value, title: ev.target.value }); + value.title = ev.target.value; }} onBlur={(ev) => { ev.stopPropagation(); - array.field.value.splice(index, 1, { ...value, title: ev.target.value }); + value.title = ev.target.value; }} autoSize style={{ width: '70%', border: 'none' }} @@ -41,7 +42,7 @@ const DataTemplateTitle = (props) => { }} /> ); -}; +}); export interface IArrayCollapseProps extends CollapseProps { defaultOpenPanelCount?: number;