Commit bf11d550 by zhaochengxiang

修改问题

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