Commit 6a3a8f8f authored by 邓超's avatar 邓超

fix: 重构web配置拖拽逻辑,修复表字段保存排序乱了问题

parent 050641e6
...@@ -59,7 +59,7 @@ const DragTable = props => { ...@@ -59,7 +59,7 @@ const DragTable = props => {
index, index,
ItemTypes, ItemTypes,
moveRow, moveRow,
onClick: () => props.onClick(record), onClick: () => props.onClick && props.onClick(record),
})} })}
{...props} {...props}
/> />
......
...@@ -28,7 +28,6 @@ const DraggableBodyRow = ({ ...@@ -28,7 +28,6 @@ const DraggableBodyRow = ({
}; };
}, },
drop: item => { drop: item => {
console.log(item, '3333');
moveRow(item.index, index, tableType); moveRow(item.index, index, tableType);
}, },
}); });
......
...@@ -80,6 +80,7 @@ const Order = props => { ...@@ -80,6 +80,7 @@ const Order = props => {
pagination={false} pagination={false}
size="small" size="small"
dragCallBack={dragCallBack} dragCallBack={dragCallBack}
ItemTypes="flowOrder"
/> />
</Modal> </Modal>
); );
......
...@@ -107,6 +107,7 @@ const AddModal = props => { ...@@ -107,6 +107,7 @@ const AddModal = props => {
const { Item } = Form; const { Item } = Form;
// 提交 // 提交
const onSubmit = () => { const onSubmit = () => {
console.log(itemData, 'itemData');
form.validateFields().then(validate => { form.validateFields().then(validate => {
if (validate) { if (validate) {
setLoading(true); setLoading(true);
...@@ -125,6 +126,7 @@ const AddModal = props => { ...@@ -125,6 +126,7 @@ const AddModal = props => {
ExceptionValue: pramData.ExceptionValue || '', ExceptionValue: pramData.ExceptionValue || '',
Preset: pramData.Preset || '', Preset: pramData.Preset || '',
ID: Number(itemData.ID), ID: Number(itemData.ID),
Order: Number(itemData.order),
Name: obj.Name, Name: obj.Name,
Alias: obj.Alias, Alias: obj.Alias,
SyncEvent: obj.SyncEvent, SyncEvent: obj.SyncEvent,
......
...@@ -22,8 +22,8 @@ import { ...@@ -22,8 +22,8 @@ import {
removeFields, removeFields,
loadUnattachedTables, loadUnattachedTables,
} from '@/services/platform/bs'; } from '@/services/platform/bs';
import FieldEditor from './fieldEditor';
import { useHistory } from 'react-router-dom'; import { useHistory } from 'react-router-dom';
import FieldEditor from './fieldEditor';
import styles from './index.less'; import styles from './index.less';
import AffiliateAdd from '../bsmanager/tablemanager/components/Field/affiliateAdd'; import AffiliateAdd from '../bsmanager/tablemanager/components/Field/affiliateAdd';
import LoadGroup from '../bsmanager/tablemanager/components/Field/loadGroupNew'; import LoadGroup from '../bsmanager/tablemanager/components/Field/loadGroupNew';
...@@ -187,18 +187,16 @@ const AddModal = props => { ...@@ -187,18 +187,16 @@ const AddModal = props => {
return ( return (
<Table <Table
columns={columns} columns={columns}
onRow={record => { onRow={record => ({
return { onDoubleClick: event => {
onDoubleClick: event => { event.stopPropagation();
event.stopPropagation(); editor(record);
editor(record); },
}, onClick: event => {
onClick: event => { event.stopPropagation();
event.stopPropagation(); setSelectTableName(record);
setSelectTableName(record); }, // 点击行
}, // 点击行 })}
};
}}
bordered bordered
rowClassName={setRowClassName} rowClassName={setRowClassName}
showHeader={false} showHeader={false}
...@@ -219,13 +217,11 @@ const AddModal = props => { ...@@ -219,13 +217,11 @@ const AddModal = props => {
key: 'type', key: 'type',
align: 'left', align: 'left',
width: 150, width: 150,
render: text => { render: text => (
return ( <a>
<a> {text}(共{allData[text] ? allData[text].length : ''}条)
{text}(共{allData[text] ? allData[text].length : ''}条) </a>
</a> ),
);
},
}, },
{ {
title: '别名', title: '别名',
...@@ -279,7 +275,7 @@ const AddModal = props => { ...@@ -279,7 +275,7 @@ const AddModal = props => {
}, },
]; ];
useEffect(() => { useEffect(() => {
console.log(props) console.log(props);
if (props.match.params.id) { if (props.match.params.id) {
setFormObj(props.match.params.id); setFormObj(props.match.params.id);
setTreeLoading(true); setTreeLoading(true);
...@@ -309,14 +305,15 @@ const AddModal = props => { ...@@ -309,14 +305,15 @@ const AddModal = props => {
if (!name) { if (!name) {
return '请传入对象属性'; return '请传入对象属性';
} }
//先获取一下这个数组中有多少个"name" // 先获取一下这个数组中有多少个"name"
let nameArr = []; let nameArr = [];
// eslint-disable-next-line no-restricted-syntax
for (let i in initialArr) { for (let i in initialArr) {
if (nameArr.indexOf(initialArr[i][`${name}`]) === -1) { if (nameArr.indexOf(initialArr[i][`${name}`]) === -1) {
nameArr.push(initialArr[i][`${name}`]); nameArr.push(initialArr[i][`${name}`]);
} }
} }
//新建一个包含多个list的结果对象 // 新建一个包含多个list的结果对象
let tempObj = {}; let tempObj = {};
// 根据不同的"name"生成多个数组 // 根据不同的"name"生成多个数组
for (let k in nameArr) { for (let k in nameArr) {
...@@ -378,13 +375,13 @@ const AddModal = props => { ...@@ -378,13 +375,13 @@ const AddModal = props => {
} }
setSelect(data); setSelect(data);
}; };
//附加 // 附加
const add = record => { const add = record => {
setPramFormObj(props.location.state.template); setPramFormObj(props.location.state.template);
setType('affiliateAdd'); setType('affiliateAdd');
setVisible(true); setVisible(true);
}; };
//分组与排序 // 分组与排序
const sort = record => { const sort = record => {
setPramFormObj(props.location.state.template); setPramFormObj(props.location.state.template);
setType('sort'); setType('sort');
...@@ -427,12 +424,11 @@ const AddModal = props => { ...@@ -427,12 +424,11 @@ const AddModal = props => {
expandable={{ expandedRowRender }} expandable={{ expandedRowRender }}
size="small" size="small"
rowKey="id" rowKey="id"
expandedRowKeys={select.map(item => item.key)} //展开的行 expandedRowKeys={select.map(item => item.key)} // 展开的行
expandRowByClick={true} expandRowByClick
defaultExpandAllRows={true} defaultExpandAllRows
pagination={false} pagination={false}
scroll={{ y: 'calc(100vh - 186px)' }} scroll={{ y: 'calc(100vh - 186px)' }}
size="small"
onExpand={onUnfold} onExpand={onUnfold}
/> />
</div> </div>
......
...@@ -383,60 +383,88 @@ const MiniMenu = props => { ...@@ -383,60 +383,88 @@ const MiniMenu = props => {
}); });
setRoleList(arr2); 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 => { const handleDrop = infos => {
const { pos } = infos.node.props; const dropKey = infos.node.key;
const dragKey = infos.dragNode.props.eventKey; const dragKey = infos.dragNode.key;
const dragPos = infos.dragNode.props.pos.split('-'); // 拖动的节点 const dropPos = infos.node.pos.split('-');
const dropKey = infos.node.props.eventKey;
const dropPos = infos.node.props.pos.split('-'); // 拖动结束的节点
const endIndex = Number(dropPos[dropPos.length - 1]);
const dropPosition = const dropPosition =
infos.dropPosition - Number(dropPos[dropPos.length - 1]); infos.dropPosition - Number(dropPos[dropPos.length - 1]);
// let obj = findNum(newTreeList, dragKey, getArrList); const data = [...menuList];
let obj; // 找到拖拽的元素
findNum(newTreeList, dragKey, (arr, id, parentId, index) => { let dragObj;
obj = { arr, id, parentId, index }; let dropObj;
return { arr, id, parentId, index }; let id;
let dragList;
loop(data, dropKey, -1, item => {
dropObj = item;
}); });
let arrList = []; loop(data, dragKey, -1, (item, index, arr) => {
if ( if (infos.dropToGap) {
dragPos.length !== dropPos.length || arr.splice(index, 1);
dragPos[dragPos.length - 2] !== dropPos[dropPos.length - 2] dragObj = item;
) { } else if (dropObj.menuType !== 'Web4Menu') {
notification.warning({ arr.splice(index, 1);
message: '提示', dragObj = item;
duration: 3,
description: '操作失败',
});
return null;
}
let idIndex;
obj.arr.map((item, index) => {
if (item.menuID === obj.id) {
idIndex = index;
return;
} }
arrList.push(item.menuID);
}); });
if (idIndex > endIndex) { if (!infos.dropToGap) {
if (dropPosition === -1) { // Drop on the content
arrList.splice(endIndex, 0, obj.id); loop(data, dropKey, -1, item => {
} else if (dropPosition === 1) { item.children = item.children || [];
arrList.splice(endIndex + 1, 0, obj.id); if (item.menuType !== 'Web4Menu') {
} // where to insert 示例添加到头部,可以是随意位置
} else if (idIndex < endIndex) { 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) { if (dropPosition === -1) {
arrList.splice(endIndex - 1, 0, obj.id); ar.splice(i, 0, dragObj);
} else if (dropPosition === 1) { } else {
arrList.splice(endIndex, 0, obj.id); ar.splice(i + 1, 0, dragObj);
} }
dragList = ar.map(val => val.menuID);
}
// 如果拖拽到菜单下不做任何处理
if (!dragList) {
return;
} }
dragMenu({ dragMenu({
menuID: obj.id, menuID: dragKey,
newParentID: obj.parentId || -1, newParentID: id || -1,
menuList: String(arrList) || '', menuList: String(dragList) || '',
_version: 9999, _version: 9999,
_dc: Date.now(), _dc: Date.now(),
}).then(res => { }).then(res => {
...@@ -452,21 +480,6 @@ const MiniMenu = props => { ...@@ -452,21 +480,6 @@ const MiniMenu = props => {
} }
}); });
}; };
const findNum = (array, id, callback, parentId = '') => {
let ptId = parentId;
let arrFlag = true;
array.map((item, index) => {
if (item.menuID === id) {
callback(array, id, parentId, index);
arrFlag = false;
return;
}
if (arrFlag && item.children && item.children.length > 0) {
ptId = item.menuID;
findNum(item.children, id, callback, ptId);
}
});
};
return ( return (
<Spin spinning={loading} tip="loading..."> <Spin spinning={loading} tip="loading...">
<div <div
......
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