From 87a5b88d3a9d72ac49ef2ba607e2c555aeff68c1 Mon Sep 17 00:00:00 2001 From: catchonme Date: Thu, 12 Sep 2019 16:42:07 +0800 Subject: [PATCH] =?UTF-8?q?tree=E4=B8=8B=E4=BC=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E7=BB=99dialog?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Tree.tsx | 6 +++--- src/renderers/Form/Tree.tsx | 20 +++++++++++++++----- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/components/Tree.tsx b/src/components/Tree.tsx index a0a12047..d76626eb 100644 --- a/src/components/Tree.tsx +++ b/src/components/Tree.tsx @@ -62,7 +62,7 @@ interface TreeSelectorProps { onEdit?: Function; editable?: boolean; openEditDialog?: Function; - deletable?: boolean; + removable?: boolean; onRemove?: Function; } @@ -439,7 +439,7 @@ export class TreeSelector extends React.Component {addable ? this.handleAdd(item, !isLeaf)}/> : null} - {deletable ? this.handleRemove(item)}/> : null} + {removable ? this.handleRemove(item)}/> : null} {editable ? this.handleEdit(item)}/> : null} ) : null} diff --git a/src/renderers/Form/Tree.tsx b/src/renderers/Form/Tree.tsx index 37eeec84..cb5fd4ca 100644 --- a/src/renderers/Form/Tree.tsx +++ b/src/renderers/Form/Tree.tsx @@ -31,7 +31,8 @@ export interface TreeState { isAddModalOpened: boolean, isEditModalOpened: boolean, parent: Option | null, - prev: Option | null + prev: Option | null, + data: any } export default class TreeControl extends React.Component { @@ -48,7 +49,8 @@ export default class TreeControl extends React.Component { isAddModalOpened: false, isEditModalOpened: false, parent: null, - prev: null + prev: null, + data: null } reload() { @@ -121,7 +123,7 @@ export default class TreeControl extends React.Component { const result = await env.fetcher(deleteApi, ctx); if (!result.ok) { - env.notify('error', '删除失败'); + env.notify('error', result.msg || '删除失败'); return; } @@ -131,8 +133,10 @@ export default class TreeControl extends React.Component { @autobind openAddDialog(parent: Option | null) { + const {data} = this.props; this.setState({ isAddModalOpened: true, + data: createObject(data, parent ? parent : {}), parent }); } @@ -147,10 +151,12 @@ export default class TreeControl extends React.Component { @autobind openEditDialog(prev: Option) { + const {data} = this.props; this.setState({ isEditModalOpened: true, + data: createObject(data, prev), prev - }) + }); } @autobind @@ -197,6 +203,8 @@ export default class TreeControl extends React.Component { deleteApi } = this.props; + const {data} = this.state; + return (
{loading ? ( @@ -238,7 +246,7 @@ export default class TreeControl extends React.Component { onEdit={this.handleEdit} openEditDialog={this.openEditDialog} onRemove={this.handleRemove} - deletable={isEffectiveApi(deleteApi)} + removable={isEffectiveApi(deleteApi)} /> )} @@ -250,6 +258,7 @@ export default class TreeControl extends React.Component { }, { key: 'addModal', + data: data, onConfirm: this.handleAddModalConfirm, onClose: this.closeAddDialog, show: this.state.isAddModalOpened @@ -264,6 +273,7 @@ export default class TreeControl extends React.Component { }, { key: 'editModal', + data: data, onConfirm: this.handleEditModalConfirm, onClose: this.closeEditDialog, show: this.state.isEditModalOpened