Commit 0e033d8d authored by 邓超's avatar 邓超

fix: 重构app菜单拖拽逻辑

parent cf398fb9
Pipeline #38841 passed with stages
in 22 minutes 19 seconds
......@@ -377,62 +377,94 @@ const MiniMenu = props => {
});
setRoleList(arr2);
};
const loop = (data, key, parentID, callback) => {
for (let i = 0; i < data.length; i++) {
if (data[i].menuID === key) {
return callback(data[i], i, data, parentID);
}
if (data[i].children) {
loop(data[i].children, key, data[i].menuID, callback);
}
}
};
// 树的拖动
const handleDrop = infos => {
console.log(infos, 'newTree');
const { pos } = infos.node.props;
const dragKey = infos.dragNode.props.eventKey;
const dragPos = infos.dragNode.props.pos.split('-'); // 拖动的节点
const dropKey = infos.node.props.eventKey;
const dropPos = infos.node.props.pos.split('-'); // 拖动结束的节点
const endIndex = Number(dropPos[dropPos.length - 1]);
const dropKey = infos.node.key;
const dragKey = infos.dragNode.key;
const dropPos = infos.node.pos.split('-');
const dropPosition =
infos.dropPosition - Number(dropPos[dropPos.length - 1]);
// let obj = findNum(newTreeList, dragKey, getArrList);
let obj;
findNum(newTreeList, dragKey, (arr, id, parentId, index) => {
obj = { arr, id, parentId, index };
return { arr, id, parentId, index };
const data = [...treeData];
// 找到拖拽的元素
let dragObj;
let dropObj;
let id;
let dragList;
loop(data, dropKey, -1, item => {
dropObj = item;
});
console.log(obj, 'obj');
let arrList = [];
if (
dragPos.length !== dropPos.length ||
dragPos[dragPos.length - 2] !== dropPos[dropPos.length - 2]
) {
notification.warning({
message: '提示',
duration: 3,
description: '操作失败',
});
return null;
}
let idIndex;
obj.arr.map((item, index) => {
if (item.menuID === obj.id) {
idIndex = index;
return;
loop(data, dragKey, -1, (item, index, arr) => {
if (infos.dropToGap) {
arr.splice(index, 1);
dragObj = item;
} else if (
dropObj.menuType !== 'MiniAppMenuThree' &&
dropObj.menuType !== 'MiniAppMenu'
) {
arr.splice(index, 1);
dragObj = item;
}
arrList.push(item.menuID);
});
if (idIndex > endIndex) {
if (dropPosition === -1) {
arrList.splice(endIndex, 0, obj.id);
} else if (dropPosition === 1) {
arrList.splice(endIndex + 1, 0, obj.id);
}
} else if (idIndex < endIndex) {
if (!infos.dropToGap) {
// Drop on the content
loop(data, dropKey, -1, item => {
item.children = item.children || [];
if (
item.menuType !== 'MiniAppMenuThree' &&
dropObj.menuType !== 'MiniAppMenu'
) {
// where to insert 示例添加到头部,可以是随意位置
item.children.unshift(dragObj);
id = item.menuID;
dragList = item.children.map(val => val.menuID);
}
});
} else if (
(infos.node.props.children || []).length > 0 && // Has children
infos.node.props.expanded && // Is expanded
dropPosition === 1 // On the bottom gap
) {
loop(data, dropKey, -1, item => {
item.children = item.children || [];
// where to insert 示例添加到头部,可以是随意位置
item.children.unshift(dragObj);
id = item.menuID;
dragList = item.children.map(val => val.menuID);
});
} else {
let ar;
let i;
loop(data, dropKey, -1, (item, index, arr, parentID) => {
ar = arr;
i = index;
id = parentID;
});
if (dropPosition === -1) {
arrList.splice(endIndex - 1, 0, obj.id);
} else if (dropPosition === 1) {
arrList.splice(endIndex, 0, obj.id);
ar.splice(i, 0, dragObj);
} else {
ar.splice(i + 1, 0, dragObj);
}
dragList = ar.map(val => val.menuID);
}
// 如果拖拽到菜单下不做任何处理
if (!dragList) {
return;
}
dragMenu({
menuID: obj.id,
newParentID: obj.parentId.toString() || '-1',
menuList: String(arrList) || '',
menuID: dragKey,
newParentID: id.toString() || '-1',
menuList: String(dragList) || '',
_version: 9999,
_dc: Date.now(),
}).then(res => {
......
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