Commit b57146c3 by zhaochengxiang

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

parent 72a097a7
......@@ -36,7 +36,7 @@ const ModelTable = (props) => {
<Button icon={<EditOutlined />} size='small' />
</Tooltip>
<Tooltip placement='bottom' title={'详情'}>
<Button icon={<ReconciliationOutlined />} size='small' />
<Button icon={<ReconciliationOutlined />} size='small' onClick={() => { detailItem(record); }} />
</Tooltip>
<Tooltip placement='bottom' title={'提交审核'}>
<Button icon={<CheckOutlined />} size='small' />
......@@ -50,6 +50,10 @@ const ModelTable = (props) => {
}
];
const detailItem = (record) => {
}
const deleteItem = (record) => {
modal.confirm({
......
import React, { useState, useEffect } from "react";
import React, { useState, useEffect, useRef } from "react";
import { Tooltip, Tree, Button, Modal, Spin } from "antd";
import { PlusOutlined, EditOutlined, SyncOutlined, DeleteOutlined } from '@ant-design/icons';
......@@ -19,6 +19,9 @@ const ModelTree = (props) => {
const [modal, contextHolder] = Modal.useModal();
const itemRef = useRef();
itemRef.current = item;
useEffect(() => {
getTreeData();
//eslint-disable-next-line react-hooks/exhaustive-deps
......@@ -51,9 +54,15 @@ const ModelTree = (props) => {
setLoading(false);
setTreeData(data.subCatalogs||[]);
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||''):'');
}
......@@ -112,6 +121,8 @@ const ModelTree = (props) => {
},
callback: () => {
showMessage('success', '删除目录成功');
setItem(null);
itemRef.current = null;
getTreeData();
}
});
......@@ -120,8 +131,10 @@ const ModelTree = (props) => {
}
const onUpdateTreeItemModalOk = () => {
const onUpdateTreeItemModalOk = (updateItem) => {
setVisible(false);
setItem(updateItem);
itemRef.current = updateItem;
getTreeData();
}
......
......@@ -136,7 +136,7 @@ const UpdateTreeItemModal = (props) => {
setConfirmLoading(false);
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