Commit 90910c18 authored by 武广's avatar 武广

feat: 添加loading状态

parent 030f2599
......@@ -9,6 +9,7 @@ const CustomTree = forwardRef(props => {
const [childrenList, setChildrenList] = useState([]);
const [initValue, setInitValue] = useState([]);
// 初始化数据状态
const initChildrenStatus = arr =>
arr.map(item => {
const obj = initValue.find(val => val.key === item.key) || {};
......@@ -155,6 +156,8 @@ const CustomTree = forwardRef(props => {
// 异步获取数据
const getSyncLoadChildrens = async (arr, ckey, parentChecked) => {
ChangeVal(arr, ckey, true, 'isLoading');
setTreeData(arr);
const res = await props.loadData({ key: ckey });
if (res && res.length) {
appendTreeData(arr, ckey, filterData(res, parentChecked), parentChecked);
......@@ -165,8 +168,6 @@ const CustomTree = forwardRef(props => {
const onVisibleChildren = async (ckey, visible, children, parentChecked) => {
const arr = [...treeData];
if (children && !children.length && typeof props.loadData === 'function') {
ChangeVal(arr, ckey, true, 'isLoading');
setTreeData(arr);
await getSyncLoadChildrens(arr, ckey, parentChecked);
}
updateVisible(arr, ckey, visible);
......@@ -188,9 +189,6 @@ const CustomTree = forwardRef(props => {
node.checked = false;
} else {
node.checked = node.children.every(item => item.checked);
// if (node.checked) {
// node.value = [];
// }
}
key = pkey;
}
......
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