Commit f889c07f authored by 陈前坚's avatar 陈前坚

perf: dictionary

parent 61e4e69a
...@@ -18,13 +18,13 @@ import styles from './WebDic.less'; ...@@ -18,13 +18,13 @@ import styles from './WebDic.less';
const WebDic = () => { const WebDic = () => {
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [level, setLevel] = useState(0); // 设置基本,一级1,二级2 const [level, setLevel] = useState(0); // 设置级别,一级1,二级2
const [addVisible, setAddVisible] = useState(false); const [addVisible, setAddVisible] = useState(false);
const [editVisible, setEditVisible] = useState(false); const [editVisible, setEditVisible] = useState(false);
const [data, setData] = useState([]); // 一级条目 const [data, setData] = useState([]); // 一级条目
const [subData, setSubData] = useState([]); // 二级条目 const [subData, setSubData] = useState([]); // 二级条目
const [select, setSelect] = useState({}); // 当前选中一级条目,修改/删除时设置 const [select, setSelect] = useState({}); // 当前选中条目,可以是一级/二级,修改/删除时设置
const [subSelect, setSubSelect] = useState({}); // 当前选中二级条目,修改/删除时设置 const [selectColor, setSelectColor] = useState({}); // 当前选中一级条目颜色,修改/删除时设置
const [selectID, setSelectID] = useState('-1'); // 当前选中一级条目的ID,添加二级条目时使用 const [selectID, setSelectID] = useState('-1'); // 当前选中一级条目的ID,添加二级条目时使用
const [first, setFirst] = useState(true); // 是否第一次加载 const [first, setFirst] = useState(true); // 是否第一次加载
const [addForm] = Form.useForm(); const [addForm] = Form.useForm();
...@@ -59,10 +59,9 @@ const WebDic = () => { ...@@ -59,10 +59,9 @@ const WebDic = () => {
size="small" size="small"
onClick={e => { onClick={e => {
e.stopPropagation(); e.stopPropagation();
setSelect(record);
if (record.parentID === '-1') { if (record.parentID === '-1') {
setSelect(record); setSelectColor(record);
} else {
setSubSelect(record);
} }
setEditVisible(true); setEditVisible(true);
editForm.setFieldsValue({ editForm.setFieldsValue({
...@@ -84,10 +83,9 @@ const WebDic = () => { ...@@ -84,10 +83,9 @@ const WebDic = () => {
danger danger
onClick={e => { onClick={e => {
e.stopPropagation(); e.stopPropagation();
setSelect(record);
if (record.parentID === '-1') { if (record.parentID === '-1') {
setSelect(record); setSelectColor(record);
} else {
setSubSelect(record);
} }
}} }}
> >
...@@ -132,12 +130,6 @@ const WebDic = () => { ...@@ -132,12 +130,6 @@ const WebDic = () => {
getData(res[0].nodeID); getData(res[0].nodeID);
} }
} }
// if (level === 0) {
// setSelect(res[0]); // 默认当前选中一级条目第一条
// setSelectID(res[0].nodeID); // 设置选中的一级条目ID,用于添加二级条目
// } else if (level === 1) {
// setSelect({ nodeID: value2 });
// }
} else if (value) { } else if (value) {
setSubData(res); // 设置二级条目,res为空[]时也要设置 setSubData(res); // 设置二级条目,res为空[]时也要设置
} }
...@@ -155,7 +147,7 @@ const WebDic = () => { ...@@ -155,7 +147,7 @@ const WebDic = () => {
}); });
}; };
const setRowClassName = record => const setRowClassName = record =>
record.nodeID === select.nodeID ? styles.clickRowStyle : ''; record.nodeID === selectColor.nodeID ? styles.clickRowStyle : '';
// 提交-添加 // 提交-添加
const submitAdd = value => { const submitAdd = value => {
...@@ -174,8 +166,13 @@ const WebDic = () => { ...@@ -174,8 +166,13 @@ const WebDic = () => {
setAddVisible(false); setAddVisible(false);
if (level === 1) { if (level === 1) {
getData('-1'); getData('-1');
getData(res.message); // res.message为添加成功返回的一级条目ID
// 设置添加二级条目的父级ID及父级ID选中状态
setSelect({ nodeID: res.message, parentID: '-1' });
setSelectID(res.message);
setSelectColor({ nodeID: res.message });
} else { } else {
getData(selectID); getData(value);
} }
notification.success({ notification.success({
message: '提交成功', message: '提交成功',
...@@ -201,17 +198,11 @@ const WebDic = () => { ...@@ -201,17 +198,11 @@ const WebDic = () => {
const submitEdit = () => { const submitEdit = () => {
const nodeName1 = editForm.getFieldValue('nodeName1'); const nodeName1 = editForm.getFieldValue('nodeName1');
const nodeValue = editForm.getFieldValue('nodeValue'); const nodeValue = editForm.getFieldValue('nodeValue');
let nodeID = '';
if (select.parentID === '-1') {
nodeID = { ...select };
} else {
nodeID = { ...subSelect };
}
if (nodeName1) { if (nodeName1) {
get(`/Cityinterface/rest/services/OMS.svc/D_EditDataDictionary`, { get(`/Cityinterface/rest/services/OMS.svc/D_EditDataDictionary`, {
_version: 9999, _version: 9999,
_dc: new Date().getTime(), _dc: new Date().getTime(),
nodeID, nodeID: select.nodeID,
nodeName: nodeName1, nodeName: nodeName1,
nodeValue, nodeValue,
}) })
...@@ -248,6 +239,10 @@ const WebDic = () => { ...@@ -248,6 +239,10 @@ const WebDic = () => {
}) })
.then(res => { .then(res => {
if (res.success) { if (res.success) {
// 删除一级条目时要重新设置first为true,默认并选中一级条目第一条纪录
if (select.parentID === '-1') {
// setFirst(true);
}
getData(select.parentID); getData(select.parentID);
notification.success({ notification.success({
message: '删除成功', message: '删除成功',
...@@ -300,7 +295,7 @@ const WebDic = () => { ...@@ -300,7 +295,7 @@ const WebDic = () => {
onClick: () => { onClick: () => {
getData(record.nodeID); getData(record.nodeID);
setSelect(record); setSelect(record);
// setSelectColor(record); setSelectColor(record);
setSelectID(record.nodeID); setSelectID(record.nodeID);
}, },
})} })}
......
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