🐛 Fix: [前台]:修复将一个已加载文件夹拖拽到未加载文件夹,已加载文件夹的子节点不显示bug

This commit is contained in:
fanxb 2019-08-01 20:25:29 +08:00
parent af1d063709
commit 0ef049c994
4 changed files with 30 additions and 8 deletions

View File

@ -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) {

View File

@ -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 (
<MainLayout>
@ -105,6 +109,7 @@ class OverView extends React.Component {
</div>
<Tree
showIcon
loadedKeys={loadedKeys}
checkedKeys={checkedKeys}
onCheck={this.props.changeCheckedKeys}
expandedKeys={expandedKeys}

View File

@ -15,7 +15,9 @@ export function getInitData() {
expandedKeys: [],
isInit: false,
//右键菜单触发项
currentClickItem: null
currentClickItem: null,
//已经加载了的节点列表
loadedKeys: []
};
}
@ -109,6 +111,7 @@ export const changeIsInit = isInit => {
};
};
// 修改当前右键点击的节点
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 }
};
};

View File

@ -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;