Commit bf11d550 by zhaochengxiang

修改问题

parent 5271f1d3
......@@ -114,7 +114,6 @@ const UpdateField = (props) => {
const [data, setData] = useState([]);
const [keyword, setKeyword] = useState('');
const [editingKey, setEditingKey] = useState(null);
const [insertIndex, setInsertIndex] = useState(0);
const [supportedDatatypes, setSupportedDatatypes] = useState([]);
const [loading, setLoading] = useState(false);
const [form] = Form.useForm();
......@@ -315,8 +314,6 @@ const UpdateField = (props) => {
setData(newData);
dataRef.current = newData;
setInsertIndex(newData.length-1);
editItem(newData[newData.length-1]);
setTimeout(() => {
......@@ -400,15 +397,10 @@ const UpdateField = (props) => {
const newData = [...dataRef.current];
const index = newData.findIndex((item) => editingKeyRef.current === item.name);
//判断字段名称是否唯一
let _index;
if (index === -1) {
_index = (data||[]).findIndex(item => item.name === row.name);
} else {
const newDataExcludeSelf = [...data];
const newDataExcludeSelf = [...dataRef.current];
newDataExcludeSelf.splice(index, 1);
_index = (newDataExcludeSelf||[]).findIndex(item => item.name === row.name);
}
//判断字段名称是否唯一
let _index = (newDataExcludeSelf||[]).findIndex(item => item.name === row.name);
if (_index !== -1) {
form.setFields([{ name: 'name', errors: ['字段名称不能重复'] }]);
......@@ -417,15 +409,9 @@ const UpdateField = (props) => {
row.dataType = JSON.stringify(row.dataType);
let attribute = {};
if (index === -1) {
attribute = {...row};
newData.splice(insertIndex, 0, attribute);
} else {
const item = newData[index];
attribute = { ...item, ...row};
let attribute = { ...item, ...row};
newData.splice(index, 1, attribute);
}
setEditingKey(null);
editingKeyRef.current = null;
......@@ -445,8 +431,8 @@ const UpdateField = (props) => {
const moveRow = useCallback(
(dragIndex, hoverIndex) => {
const dragRow = dataRef.current[dragIndex];
const newData = update(dataRef.current, {
const dragRow = data[dragIndex];
const newData = update(data, {
$splice: [
[dragIndex, 1],
[hoverIndex, 0, dragRow],
......@@ -457,7 +443,7 @@ const UpdateField = (props) => {
dataRef.current = newData;
onChange && onChange(newData);
//eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [data]);
const onTableRow = (record, index) => {
let rowParams = {
......
......@@ -245,7 +245,7 @@ export const DragableBodyRow = ({ index, moveRow, className, style, ...restProps
}
},
}),
[index],
[index, moveRow],
);
const [, drag] = useDrag(
() => ({
......@@ -261,7 +261,7 @@ export const DragableBodyRow = ({ index, moveRow, className, style, ...restProps
isDragging: monitor.isDragging(),
}),
}),
[index],
[index, moveRow],
);
drop(drag(ref));
......
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