Commit d4434f8f authored by 张烨's avatar 张烨

feat: 封装树

parent 6039d9c8
import { Tree } from 'antd';
import { uniq, remove } from 'lodash';
import React, { useState, useEffect } from 'react';
const getChildKeys = tree => {
let childKeys = tree.children?.map(c => getChildKeys(c)).flat(Infinity) || [];
return [tree.key, ...childKeys];
};
export default props => {
const { expandedKeys, onExpand, onSelect, selectedKeys, ...rest } = props;
const [epKeys, setEpKeys] = useState([expandedKeys]);
const handleExpand = (keys, { expanded, node }) => {
if (!expanded) {
let childKeys = getChildKeys(node);
remove(keys, k => childKeys.includes(k));
}
setEpKeys(keys);
};
const handleSelect = (keys, e) => {
let result = [];
if (keys.length > 0 && epKeys.includes(keys[0])) {
remove(epKeys, k => keys.includes(k));
result = [...epKeys];
} else if (keys[0]) {
result = [...epKeys, keys[0]];
} else {
if (epKeys.includes(e.node.key)) {
remove(epKeys, k => k === e.node.key);
} else {
epKeys.push(e.node.key);
}
result = [...epKeys];
}
// eslint-disable-next-line no-unused-expressions
onSelect && onSelect(keys, e);
setEpKeys(result);
};
return (
<Tree
onSelect={handleSelect}
onExpand={handleExpand}
expandedKeys={epKeys}
selectedKeys={selectedKeys}
{...rest}
/>
);
};
......@@ -3,9 +3,7 @@ import { Checkbox, Empty } from 'antd';
import styles from './checkBox.less';
const CheckList = props => {
const { info, valueCallback, nodeType } = props;
console.log(info, 'info');
const [list, setList] = useState([]);
const [checkList, setCheckList] = useState([]);
const [flag, setFlag] = useState(false);
const a = 'a';
useEffect(() => {
......@@ -17,20 +15,15 @@ const CheckList = props => {
arr2.push(item.relatedRoleCode);
}
});
console.log(arr2, 'arr2');
setCheckList(arr2);
setList(arr);
setFlag(true);
}
return () => {
setFlag(false);
setCheckList([]);
};
}, [info]);
const handleSelect = (e, val) => {
console.log(e.target, 'e', val);
let arr = [];
list.forEach(item => {
if (item.relatedRoleCode === val) {
......
......@@ -9,7 +9,6 @@ const EditForm = props => {
const { submitCallback, nodeType, info, configFiles } = props;
const [form] = Form.useForm();
const [otherForm] = Form.useForm();
console.log(info);
const layout = {
layout: 'horizontal',
labelCol: { span: 4, offset: 1 },
......
import React, { useEffect, useState } from 'react';
import { notification, Tree, Tooltip, Modal, Spin, Empty } from 'antd';
import { notification, Tooltip, Modal, Spin, Empty } from 'antd';
import Tree from '@/components/ExpendableTree';
import {
FileAddTwoTone,
FolderAddTwoTone,
......@@ -79,13 +80,10 @@ const MiniMenu = props => {
};
// 树的点击事件
const handleSelect = (prop, treeNode) => {
console.log(prop, treeNode);
if (treeNode) {
const {
node,
node: { menuType },
} = treeNode;
console.log(menuType);
setCurMenuType(menuType);
switch (menuType) {
case 'Web4MenuGroup':
......@@ -123,7 +121,6 @@ const MiniMenu = props => {
description: res.message || '获取失败',
});
}
console.log(res, 'resss');
})
.catch(err => {
setLoading(false);
......@@ -133,7 +130,6 @@ const MiniMenu = props => {
// 删除的回调
const deleteMenuTip = (val, e) => {
e.stopPropagation();
console.log(val, 'val');
setModalTitle(val.text);
setNodeObj(val);
setDelVisible(true);
......@@ -167,7 +163,7 @@ const MiniMenu = props => {
})
.catch(err => {
setModalLoading(false);
console.log(err);
console.error(err);
});
};
// 新增菜单组
......@@ -228,7 +224,6 @@ const MiniMenu = props => {
duration: 10,
});
}
console.log(res, 'resadd');
})
.catch(err => {
setSubmitLoading(false);
......
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