From 0ef049c9946c2d1f9b0f54573ae2fce2247c50de Mon Sep 17 00:00:00 2001 From: fanxb Date: Thu, 1 Aug 2019 20:25:29 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20[=E5=89=8D=E5=8F=B0]:?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=B0=86=E4=B8=80=E4=B8=AA=E5=B7=B2=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E6=96=87=E4=BB=B6=E5=A4=B9=E6=8B=96=E6=8B=BD=E5=88=B0?= =?UTF-8?q?=E6=9C=AA=E5=8A=A0=E8=BD=BD=E6=96=87=E4=BB=B6=E5=A4=B9=EF=BC=8C?= =?UTF-8?q?=E5=B7=B2=E5=8A=A0=E8=BD=BD=E6=96=87=E4=BB=B6=E5=A4=B9=E7=9A=84?= =?UTF-8?q?=E5=AD=90=E8=8A=82=E7=82=B9=E4=B8=8D=E6=98=BE=E7=A4=BAbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/pages/manage/OverView/function.js | 6 +++++- front/src/pages/manage/OverView/index.jsx | 17 +++++++++++------ front/src/redux/action/BookmarkTreeOverview.js | 14 +++++++++++++- front/src/redux/reducer/BookmarkTreeOverview.js | 1 + 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/front/src/pages/manage/OverView/function.js b/front/src/pages/manage/OverView/function.js index ed9da35..5b82e4e 100644 --- a/front/src/pages/manage/OverView/function.js +++ b/front/src/pages/manage/OverView/function.js @@ -187,7 +187,7 @@ function deleteTreeData(treeData, set) { * @param {*} info */ export function onDrop(info) { - const { treeData, updateTreeData } = this.props; + const { treeData, updateTreeData, loadedKeys, changeLoadedKeys } = this.props; const target = info.node.props.dataRef; if (!info.dropToGap && target.type === 0) { message.error("无法移动到书签内部"); @@ -222,6 +222,10 @@ export function onDrop(info) { const length = target.children.length; body.sort = length > 0 ? target.children[length - 1].sort + 1 : 1; target.children.push(current); + } else if (current.type === 1 && current.children) { + //目标未加载且当前节点为已经展开的目录情况下需要把当前节点从已加载列表中移除,否则在目标节点中展开时会不显示当前节点的子节点 + loadedKeys.splice(loadedKeys.indexOf(current.bookmarkId.toString()), 1); + changeLoadedKeys(loadedKeys); } } if (body.sort !== -1) { diff --git a/front/src/pages/manage/OverView/index.jsx b/front/src/pages/manage/OverView/index.jsx index f6960ad..d20bbc1 100644 --- a/front/src/pages/manage/OverView/index.jsx +++ b/front/src/pages/manage/OverView/index.jsx @@ -23,7 +23,8 @@ function mapDispatchToProps(dispatch) { changeIsInit: value => dispatch(action.changeIsInit(value)), changeCheckedKeys: (keys, nodes) => dispatch(action.changeCheckedKeys(keys, nodes)), changeExpandedKeys: keys => dispatch(action.changeExpandedKeys(keys)), - changeCurrentClickItem: item => dispatch(action.changeCurrentClickItem(item)) + changeCurrentClickItem: item => dispatch(action.changeCurrentClickItem(item)), + changeLoadedKeys: keys => dispatch(action.changeLoadedKeys(keys)) }; } @@ -44,17 +45,20 @@ class OverView extends React.Component { /** * 异步加载 */ - loadData = e => - new Promise(resolve => { + loadData = e => { + const { loadedKeys, treeData } = this.props; + return new Promise(resolve => { const item = e.props.dataRef; const newPath = item.path + "." + item.bookmarkId; httpUtil.get("/bookmark/currentUser/path?path=" + newPath).then(res => { item.children = res; - this.props.updateTreeData([...this.props.treeData]); + this.props.updateTreeData([...treeData]); + loadedKeys.push(item.bookmarkId.toString()); + this.props.changeLoadedKeys(loadedKeys); resolve(); }); }); - + }; /** * 节点选择 * @param {*} key @@ -74,7 +78,7 @@ class OverView extends React.Component { } render() { - const { isEdit, setIsEdit, treeData, addNode, isInit, expandedKeys, checkedKeys } = this.props; + const { isEdit, setIsEdit, treeData, addNode, isInit, expandedKeys, checkedKeys, loadedKeys } = this.props; const { changeExpandedKeys } = this.props; return ( @@ -105,6 +109,7 @@ class OverView extends React.Component { { }; }; +// 修改当前右键点击的节点 export const CHANGE_CURRENT_CLICK_ITEM = "changeCurrentClickItem"; export const changeCurrentClickItem = currentClickItem => { return { @@ -116,3 +119,12 @@ export const changeCurrentClickItem = currentClickItem => { data: { currentClickItem } }; }; + +// 修改已经加载的节点 +export const CHANGE_LOADED_KEYS = "changeLoadedKeys"; +export const changeLoadedKeys = loadedKeys => { + return { + type: CHANGE_LOADED_KEYS, + data: { loadedKeys } + }; +}; diff --git a/front/src/redux/reducer/BookmarkTreeOverview.js b/front/src/redux/reducer/BookmarkTreeOverview.js index 791b577..e6f7cda 100644 --- a/front/src/redux/reducer/BookmarkTreeOverview.js +++ b/front/src/redux/reducer/BookmarkTreeOverview.js @@ -10,6 +10,7 @@ const BookmarkTreeOverviewReducer = (state = info.getInitData(), action) => { case info.CHANGE_CURRENT_CLICK_ITEM: case info.ADD_NODE: case info.EDIT_NODE: + case info.CHANGE_LOADED_KEYS: return { ...state, ...action.data }; default: return state;