提交 14373d7a 作者: 郁骅焌

优化

上级 fda615ff
...@@ -19,13 +19,14 @@ const MenuTree = (props, ref) => { ...@@ -19,13 +19,14 @@ const MenuTree = (props, ref) => {
const [treeData, setTreeData] = useState([]) const [treeData, setTreeData] = useState([])
const [expandedKeys, setExpandedKeys] = useState([]); const [expandedKeys, setExpandedKeys] = useState([]);
const [checkedKeys, setCheckedKeys] = useState([]); const [checkedKeys, setCheckedKeys] = useState([]);
const [halfCheckedKeys, setHalfCheckedKeys] = useState([])
const [selectedKeys, setSelectedKeys] = useState([]); const [selectedKeys, setSelectedKeys] = useState([]);
const [autoExpandParent, setAutoExpandParent] = useState(true); const [autoExpandParent, setAutoExpandParent] = useState(true);
const queryMenu = async () => { const queryMenu = async () => {
const res = await getMenu() const res = await getMenu()
const { data } = res const { data } = res
const treeDataArr = data.slice() const treeDataArr = data ? data.slice() : []
loopTree(treeDataArr) loopTree(treeDataArr)
setTreeData(treeDataArr) setTreeData(treeDataArr)
} }
...@@ -38,9 +39,10 @@ const MenuTree = (props, ref) => { ...@@ -38,9 +39,10 @@ const MenuTree = (props, ref) => {
setAutoExpandParent(false); setAutoExpandParent(false);
}; };
const onCheck = checkedkeys => { const onCheck = (checkedkeys, e) => {
// console.log('onCheck', checkedkeys); // console.log('onCheck', checkedkeys);
setCheckedKeys(checkedkeys); setCheckedKeys(checkedkeys);
setHalfCheckedKeys(e.halfCheckedKeys)
}; };
const onSelect = (selectedkeys, info) => { const onSelect = (selectedkeys, info) => {
...@@ -52,6 +54,10 @@ const MenuTree = (props, ref) => { ...@@ -52,6 +54,10 @@ const MenuTree = (props, ref) => {
return checkedKeys return checkedKeys
} }
const getHalfCheckedKeys = () => {
return halfCheckedKeys
}
useEffect(() => { useEffect(() => {
queryMenu() queryMenu()
}, []) }, [])
...@@ -59,13 +65,14 @@ const MenuTree = (props, ref) => { ...@@ -59,13 +65,14 @@ const MenuTree = (props, ref) => {
// 暴露给外部的方法 // 暴露给外部的方法
useImperativeHandle(ref, () => ({ useImperativeHandle(ref, () => ({
setCheckedKeys, setCheckedKeys,
getCheckedKeys getCheckedKeys,
getHalfCheckedKeys
})) }))
return ( return (
<SageTree <SageTree
checkable checkable
checkStrictly // checkStrictly
onExpand={onExpand} onExpand={onExpand}
expandedKeys={expandedKeys} expandedKeys={expandedKeys}
autoExpandParent={autoExpandParent} autoExpandParent={autoExpandParent}
......
import { LogoutOutlined, SettingOutlined, UserOutlined } from '@ant-design/icons'; import { LogoutOutlined, SettingOutlined, UserOutlined, ExclamationCircleOutlined } from '@ant-design/icons';
import { Avatar, Menu, Spin } from 'antd'; import { Avatar, Menu, Spin, Modal } from 'antd';
import React from 'react'; import React from 'react';
import { history, connect } from 'umi'; import { history, connect } from 'umi';
import HeaderDropdown from '../HeaderDropdown'; import HeaderDropdown from '../HeaderDropdown';
...@@ -8,15 +8,25 @@ import styles from './index.less'; ...@@ -8,15 +8,25 @@ import styles from './index.less';
class AvatarDropdown extends React.Component { class AvatarDropdown extends React.Component {
onMenuClick = event => { onMenuClick = event => {
const { key } = event; const { key } = event;
const { confirm } = Modal;
const { dispatch } = this.props;
if (key === 'logout') { if (key === 'logout') {
const { dispatch } = this.props; confirm({
title: '退出登录',
if (dispatch) { icon: <ExclamationCircleOutlined />,
dispatch({ content: '您确认要退出吗?',
type: 'login/logout', okText: '确认',
}); cancelText: '取消',
} onOk() {
if (dispatch) {
dispatch({
type: 'login/logout',
});
}
},
onCancel() { },
})
return; return;
} }
...@@ -62,16 +72,16 @@ class AvatarDropdown extends React.Component { ...@@ -62,16 +72,16 @@ class AvatarDropdown extends React.Component {
</span> </span>
</HeaderDropdown> </HeaderDropdown>
) : ( ) : (
<span className={`${styles.action} ${styles.account}`}> <span className={`${styles.action} ${styles.account}`}>
<Spin <Spin
size="small" size="small"
style={{ style={{
marginLeft: 8, marginLeft: 8,
marginRight: 8, marginRight: 8,
}} }}
/> />
</span> </span>
); );
} }
} }
......
...@@ -250,10 +250,12 @@ const TableList = () => { ...@@ -250,10 +250,12 @@ const TableList = () => {
// 保存授权菜单 // 保存授权菜单
const onSaveMenuRole = async () => { const onSaveMenuRole = async () => {
const checkedKeys = menutreeRef.current.getCheckedKeys() const checkedKeys = menutreeRef.current.getCheckedKeys()
const halfCheckedKeys = menutreeRef.current.getHalfCheckedKeys()
const pp = { const pp = {
...role, ...role,
authList: checkedKeys.checked // authList: checkedKeys.checked // 非关联
authList: checkedKeys.concat(halfCheckedKeys) // 关联
} }
const res = await updateRule(pp) const res = await updateRule(pp)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论