Commit 704f99db by zhaochengxiang

主数据定义

parent 2b87db54
...@@ -43,4 +43,24 @@ export function* getColumns(payload) { ...@@ -43,4 +43,24 @@ export function* getColumns(payload) {
export function* saveColumns(payload) { export function* saveColumns(payload) {
return yield call(service.saveColumns, payload); return yield call(service.saveColumns, payload);
}
export function* getMgrTreeNodes(payload) {
return yield call(service.getMgrTreeNodes, payload);
}
export function* getDatas(payload) {
return yield call(service.getDatas, payload);
}
export function* addData(payload) {
return yield call(service.addData, payload);
}
export function* updateData(payload) {
return yield call(service.updateData, payload);
}
export function* deleteDatas(payload) {
return yield call(service.deleteDatas, payload);
} }
\ No newline at end of file
...@@ -42,4 +42,24 @@ export function getColumns(payload) { ...@@ -42,4 +42,24 @@ export function getColumns(payload) {
export function saveColumns(payload) { export function saveColumns(payload) {
return PostJSON("/metadatarepo/rest/msdDefinition/batchSaveColumn", payload); return PostJSON("/metadatarepo/rest/msdDefinition/batchSaveColumn", payload);
}
export function getMgrTreeNodes() {
return GetJSON("/metadatarepo/rest/msdMgr/getTreeNode");
}
export function getDatas(payload) {
return PostJSON("/metadatarepo/rest/msdMgr/getDataByModel", payload);
}
export function addData(payload) {
return PostJSON("/metadatarepo/rest/msdMgr/addData", payload);
}
export function updateData(payload) {
return PostJSON("/metadatarepo/rest/msdMgr/updateData", payload);
}
export function deleteDatas(payload) {
return PostJSON("/metadatarepo/rest/msdMgr/deleteData", payload);
} }
\ No newline at end of file
...@@ -251,7 +251,7 @@ const UpdateField = (props) => { ...@@ -251,7 +251,7 @@ const UpdateField = (props) => {
} }
return newColumns; return newColumns;
}, [editable]); }, [editable, data, editingKey]);
useClickAway(() => { useClickAway(() => {
save(); save();
......
import {useEffect, useMemo, useState} from 'react'; import {useEffect, useMemo, useState, useRef} from 'react';
import {Tooltip, Spin, AutoComplete, Tree} from 'antd'; import {Tooltip, Spin, AutoComplete, Tree, Modal} from 'antd';
import {PlusOutlined, ReloadOutlined} from '@ant-design/icons'; import {PlusOutlined, ReloadOutlined} from '@ant-design/icons';
import {highlightSearchContentByTerms} from '../../../../../util'; import { dispatch } from '../../../../../model';
import {treeData1} from '../../Define/Component/Mock'; import {highlightSearchContentByTerms, showMessage} from '../../../../../util';
import '../../Define/Component/DefineTree.less'; import '../../Define/Component/DefineTree.less';
...@@ -12,46 +12,107 @@ const {Option} = AutoComplete; ...@@ -12,46 +12,107 @@ const {Option} = AutoComplete;
const ManageTree = (props) => { const ManageTree = (props) => {
const {onClick} = props; const {onClick} = props;
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
const [data, setData] = useState();
const [options, setOptions] = useState([]); const [options, setOptions] = useState([]);
const [keyword, setKeyword] = useState(''); const [keyword, setKeyword] = useState('');
const [expandedKeys, setExpandedKeys] = useState(['0-0']); const [expandedKeys, setExpandedKeys] = useState([]);
const [selectedKeys, setSelectedKeys] = useState(['0-0']); const [selectedKeys, setSelectedKeys] = useState([]);
const [autoExpandParent, setAutoExpandParent] = useState(false); const [autoExpandParent, setAutoExpandParent] = useState(false);
const selectedKeysRef = useRef([]);
useEffect(() => { useEffect(() => {
setLoading(false); getTreeNodes();
onTreeSelect(['0-0']);
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, []) }, [])
const treeData = useMemo(() => {
const loop = (data) =>
(data||[]).map((item) => {
if (item.children) {
return {
title: item.name||'',
key: item._id||'',
origin: item,
children: loop(item.children),
};
}
return {
title: item.name||'',
key: item._id||'',
};
});
return loop(data);
}, [data])
const treeList = useMemo(() => { const treeList = useMemo(() => {
const generateList = (data, list, path = null) => { const generateList = (data, list, path = null) => {
for (let i = 0; i < data.length; i++) { (data||[]).forEach(node => {
const node = data[i]; const {_id, name} = node;
const { key, title } = node;
const currentPath = path ? `${path}/${title}` : title; const currentPath = path ? `${path}/${name}` : name;
list.push({ key, title: currentPath }); list.push({key: _id, title: currentPath});
if (node.children) { if (node.children) {
generateList(node.children, list, currentPath); generateList(node.children, list, currentPath);
} }
} });
}; };
const newTreeList = []; const newTreeList = [];
generateList(treeData1, newTreeList); generateList(data, newTreeList);
return newTreeList; return newTreeList;
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, [treeData1]) }, [data])
const onAddClick = () => { const selectNode = useMemo(() => {
const generateList = (data, list) => {
(data||[]).forEach(node => {
list.push({...node});
if (node.children) {
generateList(node.children, list);
}
});
};
const newTreeList = [];
generateList(data, newTreeList);
const filterNodes = newTreeList.filter(item => selectedKeys.indexOf(item._id)!==-1);
return (filterNodes||[]).length>0 ? filterNodes[0]:{};
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [data, selectedKeys])
const getTreeNodes = () => {
setLoading(true);
dispatch({
type: 'msd.getMgrTreeNodes',
callback: (data) => {
setLoading(false);
setData(data||[]);
if ((selectedKeysRef.current||[]).length===0 && (data||[]).length>0) {
onTreeSelect([data[0]._id]);
}
if ((expandedKeys||[]).length===0 && (data||[]).length>0) {
setExpandedKeys([data[0]._id]);
} else {
setExpandedKeys(Array.from(new Set([...expandedKeys, ...selectedKeysRef.current])));
setAutoExpandParent(true);
}
},
error: () => {
setLoading(false);
}
})
} }
const onRefreshClick = () => { const onRefreshClick = () => {
getTreeNodes();
} }
const onAutoCompleteSearch = (searchText) => { const onAutoCompleteSearch = (searchText) => {
...@@ -83,23 +144,13 @@ const ManageTree = (props) => { ...@@ -83,23 +144,13 @@ const ManageTree = (props) => {
} }
setSelectedKeys(selectedKeys); setSelectedKeys(selectedKeys);
selectedKeysRef.current = selectedKeys;
onClick && onClick(selectedKeys[0]); onClick && onClick(selectedKeys[0]);
} }
return ( return (
<div className='data-master-tree'> <div className='data-master-tree'>
<div className='header p-3'> <div className='header p-3'>
<Tooltip title="新增目录">
<PlusOutlined
className='default'
onClick={onAddClick}
style={{
fontSize:16,
cursor:'pointer',
flex: 1
}}
/>
</Tooltip>
<Tooltip title="刷新目录" className='ml-2'> <Tooltip title="刷新目录" className='ml-2'>
<ReloadOutlined <ReloadOutlined
className='default' className='default'
...@@ -140,14 +191,14 @@ const ManageTree = (props) => { ...@@ -140,14 +191,14 @@ const ManageTree = (props) => {
showLine showLine
showIcon={false} showIcon={false}
autoExpandParent={autoExpandParent} autoExpandParent={autoExpandParent}
treeData={treeData1} treeData={treeData}
onExpand={onTreeExpand} onExpand={onTreeExpand}
onSelect={onTreeSelect} onSelect={onTreeSelect}
expandedKeys={expandedKeys} expandedKeys={expandedKeys}
selectedKeys={selectedKeys} selectedKeys={selectedKeys}
/> />
</Spin> </Spin>
</div> </div>
</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