Commit 2dbbe0ca by zhaochengxiang

主数据定义

parent 704f99db
......@@ -120,6 +120,8 @@ const UpdateField = (props) => {
const [loading, setLoading] = useState(false);
const [form] = Form.useForm();
const tableRef = useRef(null);
const dataRef = useRef([]);
const editingKeyRef = useRef(null);
const { attrIsEditingFunction } = useContext(EditTemplateContext);
const cols = [
......@@ -235,8 +237,10 @@ const UpdateField = (props) => {
useEffect(() => {
if (visible) {
setEditingKey(null);
editingKeyRef.current = null;
if (!template) {
setData([]);
dataRef.current = [];
} else {
getFileds();
}
......@@ -301,6 +305,7 @@ const UpdateField = (props) => {
(data||[]).sort(compare);
setData(data||[]);
dataRef.current = data||[];
onChange && onChange(data||[]);
},
error: () => {
......@@ -316,9 +321,10 @@ const UpdateField = (props) => {
if (result) {
setKeyword('');
const newData = [...data, {name: ''}];
const newData = [...dataRef.current, {name: ''}];
setData(newData);
dataRef.current = newData;
setInsertIndex(newData.length-1);
editItem(newData[newData.length-1]);
......@@ -335,7 +341,7 @@ const UpdateField = (props) => {
if (result) {
setKeyword('');
let newData = [...data];
let newData = [...dataRef.current];
const index = newData.findIndex((item) => record.name === item.name);
if (index === 0) {
......@@ -349,6 +355,7 @@ const UpdateField = (props) => {
}
setData(newData);
dataRef.current = newData;
setTimeout(() => {
document.getElementById(`field-`)?.scrollIntoView();
......@@ -366,6 +373,7 @@ const UpdateField = (props) => {
}
setData(newData);
dataRef.current = newData;
onChange && onChange(newData);
}
......@@ -374,6 +382,7 @@ const UpdateField = (props) => {
removeItemLogic(record);
} else {
setEditingKey(null);
editingKeyRef.current = null;
removeItemLogic(record);
}
}
......@@ -394,9 +403,11 @@ const UpdateField = (props) => {
form.setFieldsValue({...record, dataType: dataTypeJson});
setEditingKey(record?.name);
editingKeyRef.current = record?.name;
} catch {
form.setFieldsValue({...record, dataType: {}});
setEditingKey(record?.name);
editingKeyRef.current = record?.name;
}
}
......@@ -410,7 +421,7 @@ const UpdateField = (props) => {
const save = async() => {
try {
if (editingKey !== null) {
if (editingKeyRef.current !== null) {
const row = await form.validateFields();
if ((row.dataType.name||'')==='') {
......@@ -425,7 +436,7 @@ const UpdateField = (props) => {
})
const newData = [...data];
const index = newData.findIndex((item) => editingKey === item.name);
const index = newData.findIndex((item) => editingKeyRef.current === item.name);
//判断字段名称是否唯一
let _index;
......@@ -455,7 +466,11 @@ const UpdateField = (props) => {
}
setEditingKey(null);
editingKeyRef.current = null;
setData(newData);
dataRef.current = newData;
onChange && onChange(newData);
}
......@@ -477,6 +492,7 @@ const UpdateField = (props) => {
});
setData(newData);
dataRef.current = newData;
onChange && onChange(newData);
},
[data],
......
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