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

feat: 添加loading状态

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