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'; ...@@ -3,9 +3,7 @@ import { Checkbox, Empty } from 'antd';
import styles from './checkBox.less'; import styles from './checkBox.less';
const CheckList = props => { const CheckList = props => {
const { info, valueCallback, nodeType } = props; const { info, valueCallback, nodeType } = props;
console.log(info, 'info');
const [list, setList] = useState([]); const [list, setList] = useState([]);
const [checkList, setCheckList] = useState([]);
const [flag, setFlag] = useState(false); const [flag, setFlag] = useState(false);
const a = 'a'; const a = 'a';
useEffect(() => { useEffect(() => {
...@@ -17,20 +15,15 @@ const CheckList = props => { ...@@ -17,20 +15,15 @@ const CheckList = props => {
arr2.push(item.relatedRoleCode); arr2.push(item.relatedRoleCode);
} }
}); });
console.log(arr2, 'arr2');
setCheckList(arr2);
setList(arr); setList(arr);
setFlag(true); setFlag(true);
} }
return () => { return () => {
setFlag(false); setFlag(false);
setCheckList([]);
}; };
}, [info]); }, [info]);
const handleSelect = (e, val) => { const handleSelect = (e, val) => {
console.log(e.target, 'e', val);
let arr = []; let arr = [];
list.forEach(item => { list.forEach(item => {
if (item.relatedRoleCode === val) { if (item.relatedRoleCode === val) {
......
...@@ -9,7 +9,6 @@ const EditForm = props => { ...@@ -9,7 +9,6 @@ const EditForm = props => {
const { submitCallback, nodeType, info, configFiles } = props; const { submitCallback, nodeType, info, configFiles } = props;
const [form] = Form.useForm(); const [form] = Form.useForm();
const [otherForm] = Form.useForm(); const [otherForm] = Form.useForm();
console.log(info);
const layout = { const layout = {
layout: 'horizontal', layout: 'horizontal',
labelCol: { span: 4, offset: 1 }, labelCol: { span: 4, offset: 1 },
......
import React, { useEffect, useState } from 'react'; 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 { import {
FileAddTwoTone, FileAddTwoTone,
FolderAddTwoTone, FolderAddTwoTone,
...@@ -79,13 +80,10 @@ const MiniMenu = props => { ...@@ -79,13 +80,10 @@ const MiniMenu = props => {
}; };
// 树的点击事件 // 树的点击事件
const handleSelect = (prop, treeNode) => { const handleSelect = (prop, treeNode) => {
console.log(prop, treeNode);
if (treeNode) { if (treeNode) {
const { const {
node,
node: { menuType }, node: { menuType },
} = treeNode; } = treeNode;
console.log(menuType);
setCurMenuType(menuType); setCurMenuType(menuType);
switch (menuType) { switch (menuType) {
case 'Web4MenuGroup': case 'Web4MenuGroup':
...@@ -123,7 +121,6 @@ const MiniMenu = props => { ...@@ -123,7 +121,6 @@ const MiniMenu = props => {
description: res.message || '获取失败', description: res.message || '获取失败',
}); });
} }
console.log(res, 'resss');
}) })
.catch(err => { .catch(err => {
setLoading(false); setLoading(false);
...@@ -133,7 +130,6 @@ const MiniMenu = props => { ...@@ -133,7 +130,6 @@ const MiniMenu = props => {
// 删除的回调 // 删除的回调
const deleteMenuTip = (val, e) => { const deleteMenuTip = (val, e) => {
e.stopPropagation(); e.stopPropagation();
console.log(val, 'val');
setModalTitle(val.text); setModalTitle(val.text);
setNodeObj(val); setNodeObj(val);
setDelVisible(true); setDelVisible(true);
...@@ -167,7 +163,7 @@ const MiniMenu = props => { ...@@ -167,7 +163,7 @@ const MiniMenu = props => {
}) })
.catch(err => { .catch(err => {
setModalLoading(false); setModalLoading(false);
console.log(err); console.error(err);
}); });
}; };
// 新增菜单组 // 新增菜单组
...@@ -228,7 +224,6 @@ const MiniMenu = props => { ...@@ -228,7 +224,6 @@ const MiniMenu = props => {
duration: 10, duration: 10,
}); });
} }
console.log(res, 'resadd');
}) })
.catch(err => { .catch(err => {
setSubmitLoading(false); 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