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
This commit is contained in:
parent
644b6eccb3
commit
fa778b31af
@ -100,6 +100,9 @@ export const Templates = ({ style = {}, form }) => {
|
|||||||
fetchTemplateData(api, option, t)
|
fetchTemplateData(api, option, t)
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (form && data) {
|
if (form && data) {
|
||||||
|
// 切换之前先把之前的数据清空
|
||||||
|
form.reset();
|
||||||
|
|
||||||
forEach(data, (value, key) => {
|
forEach(data, (value, key) => {
|
||||||
if (value) {
|
if (value) {
|
||||||
form.values[key] = value;
|
form.values[key] = value;
|
||||||
|
@ -9,7 +9,7 @@ import { clone } from 'lodash';
|
|||||||
import React, { Fragment, useEffect, useState } from 'react';
|
import React, { Fragment, useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
const DataTemplateTitle = (props) => {
|
const DataTemplateTitle = observer<{ index: number; item: any }>((props) => {
|
||||||
const array = ArrayBase.useArray();
|
const array = ArrayBase.useArray();
|
||||||
const index = ArrayBase.useIndex(props.index);
|
const index = ArrayBase.useIndex(props.index);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@ -22,17 +22,18 @@ const DataTemplateTitle = (props) => {
|
|||||||
value.title = `${t('Template name')} ${array?.field?.value?.length}`;
|
value.title = `${t('Template name')} ${array?.field?.value?.length}`;
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Input.TextArea
|
<Input.TextArea
|
||||||
value={value.title}
|
value={value.title}
|
||||||
placeholder={t('Template name')}
|
placeholder={t('Template name')}
|
||||||
onChange={(ev) => {
|
onChange={(ev) => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
array.field.value.splice(index, 1, { ...value, title: ev.target.value });
|
value.title = ev.target.value;
|
||||||
}}
|
}}
|
||||||
onBlur={(ev) => {
|
onBlur={(ev) => {
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
array.field.value.splice(index, 1, { ...value, title: ev.target.value });
|
value.title = ev.target.value;
|
||||||
}}
|
}}
|
||||||
autoSize
|
autoSize
|
||||||
style={{ width: '70%', border: 'none' }}
|
style={{ width: '70%', border: 'none' }}
|
||||||
@ -41,7 +42,7 @@ const DataTemplateTitle = (props) => {
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
});
|
||||||
|
|
||||||
export interface IArrayCollapseProps extends CollapseProps {
|
export interface IArrayCollapseProps extends CollapseProps {
|
||||||
defaultOpenPanelCount?: number;
|
defaultOpenPanelCount?: number;
|
||||||
|
Loading…
Reference in New Issue
Block a user