From fa778b31af3b4becda625a81542ae3b046530572 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rairn?= <958414905@qq.com> Date: Fri, 26 May 2023 12:08:26 +0800 Subject: [PATCH] fix(data-template): fix title input prevented proper data switching (#1937) * fix(data-template): fix title input prevented proper data switching * fix: build error * fix: clear the previous data before switching --- .../src/schema-component/antd/form-v2/Templates.tsx | 3 +++ .../DataTemplates/components/DataTemplateTitle.tsx | 9 +++++---- 2 files changed, 8 insertions(+), 4 deletions(-) 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;