Commit b57146c3 by zhaochengxiang

目录树新增编辑刷新节点不重置选中节点

parent 72a097a7
...@@ -36,7 +36,7 @@ const ModelTable = (props) => { ...@@ -36,7 +36,7 @@ const ModelTable = (props) => {
<Button icon={<EditOutlined />} size='small' /> <Button icon={<EditOutlined />} size='small' />
</Tooltip> </Tooltip>
<Tooltip placement='bottom' title={'详情'}> <Tooltip placement='bottom' title={'详情'}>
<Button icon={<ReconciliationOutlined />} size='small' /> <Button icon={<ReconciliationOutlined />} size='small' onClick={() => { detailItem(record); }} />
</Tooltip> </Tooltip>
<Tooltip placement='bottom' title={'提交审核'}> <Tooltip placement='bottom' title={'提交审核'}>
<Button icon={<CheckOutlined />} size='small' /> <Button icon={<CheckOutlined />} size='small' />
...@@ -50,6 +50,10 @@ const ModelTable = (props) => { ...@@ -50,6 +50,10 @@ const ModelTable = (props) => {
} }
]; ];
const detailItem = (record) => {
}
const deleteItem = (record) => { const deleteItem = (record) => {
modal.confirm({ modal.confirm({
......
import React, { useState, useEffect } from "react"; import React, { useState, useEffect, useRef } from "react";
import { Tooltip, Tree, Button, Modal, Spin } from "antd"; import { Tooltip, Tree, Button, Modal, Spin } from "antd";
import { PlusOutlined, EditOutlined, SyncOutlined, DeleteOutlined } from '@ant-design/icons'; import { PlusOutlined, EditOutlined, SyncOutlined, DeleteOutlined } from '@ant-design/icons';
...@@ -19,6 +19,9 @@ const ModelTree = (props) => { ...@@ -19,6 +19,9 @@ const ModelTree = (props) => {
const [modal, contextHolder] = Modal.useModal(); const [modal, contextHolder] = Modal.useModal();
const itemRef = useRef();
itemRef.current = item;
useEffect(() => { useEffect(() => {
getTreeData(); getTreeData();
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
...@@ -51,9 +54,15 @@ const ModelTree = (props) => { ...@@ -51,9 +54,15 @@ const ModelTree = (props) => {
setLoading(false); setLoading(false);
setTreeData(data.subCatalogs||[]); setTreeData(data.subCatalogs||[]);
setRootId(data.id||''); setRootId(data.id||'');
const firstItem = (data.subCatalogs||[]).length>0?data.subCatalogs[0]: null;
setItem(firstItem); let firstItem = itemRef.current;
if (firstItem === null) {
firstItem = (data.subCatalogs||[]).length>0?data.subCatalogs[0]: null;
setItem(firstItem);
}
itemRef.current = firstItem;
onSelect && onSelect(firstItem?(firstItem.key||''):''); onSelect && onSelect(firstItem?(firstItem.key||''):'');
} }
...@@ -112,6 +121,8 @@ const ModelTree = (props) => { ...@@ -112,6 +121,8 @@ const ModelTree = (props) => {
}, },
callback: () => { callback: () => {
showMessage('success', '删除目录成功'); showMessage('success', '删除目录成功');
setItem(null);
itemRef.current = null;
getTreeData(); getTreeData();
} }
}); });
...@@ -120,8 +131,10 @@ const ModelTree = (props) => { ...@@ -120,8 +131,10 @@ const ModelTree = (props) => {
} }
const onUpdateTreeItemModalOk = () => { const onUpdateTreeItemModalOk = (updateItem) => {
setVisible(false); setVisible(false);
setItem(updateItem);
itemRef.current = updateItem;
getTreeData(); getTreeData();
} }
......
...@@ -136,7 +136,7 @@ const UpdateTreeItemModal = (props) => { ...@@ -136,7 +136,7 @@ const UpdateTreeItemModal = (props) => {
setConfirmLoading(false); setConfirmLoading(false);
if (onOk) { if (onOk) {
onOk(); onOk(type==='add'?item:payload);
} }
} }
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment