|  | @@ -11,21 +11,30 @@ import {
 | 
	
		
			
				|  |  |    QuestionCircleOutlined
 | 
	
		
			
				|  |  |  } from '@ant-design/icons'
 | 
	
		
			
				|  |  |  import { ModalForm, ProFormText } from '@ant-design/pro-form'
 | 
	
		
			
				|  |  | -import { Button, Input, message, Popconfirm, Popover } from 'antd'
 | 
	
		
			
				|  |  | +import { Button, Input, Tree, message, Popconfirm, Popover } from 'antd'
 | 
	
		
			
				|  |  |  import React, { useEffect, useState } from 'react'
 | 
	
		
			
				|  |  |  import { useRequest } from 'umi'
 | 
	
		
			
				|  |  |  import './index.less'
 | 
	
		
			
				|  |  | +const { DirectoryTree } = Tree
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  const RoleLeftMenu = ({ onSelect }) => {
 | 
	
		
			
				|  |  |    const [state, setState] = useState({
 | 
	
		
			
				|  |  |      value: ''
 | 
	
		
			
				|  |  |    })
 | 
	
		
			
				|  |  | -  const [activeId, setActiveId] = useState('')
 | 
	
		
			
				|  |  | +  // const [activeId, setActiveId] = useState('')
 | 
	
		
			
				|  |  |    const [menuRoles, setMenuRoles] = useState<API.MenuRoleItem[]>([])
 | 
	
		
			
				|  |  | +  console.log(menuRoles)
 | 
	
		
			
				|  |  |    const { run: tryFetchRoleListByMenu } = useRequest(() => fetchRoleListByMenu(), {
 | 
	
		
			
				|  |  |      manual: true,
 | 
	
		
			
				|  |  |      onSuccess: result => {
 | 
	
		
			
				|  |  | -      setMenuRoles(result)
 | 
	
		
			
				|  |  | +      setMenuRoles(
 | 
	
		
			
				|  |  | +        result.map(item => ({
 | 
	
		
			
				|  |  | +          id: item.ID,
 | 
	
		
			
				|  |  | +          key: item.ID,
 | 
	
		
			
				|  |  | +          title: item.name,
 | 
	
		
			
				|  |  | +          children: []
 | 
	
		
			
				|  |  | +        }))
 | 
	
		
			
				|  |  | +      )
 | 
	
		
			
				|  |  |        // setActiveId(result[0]['ID'])
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    })
 | 
	
	
		
			
				|  | @@ -55,11 +64,51 @@ const RoleLeftMenu = ({ onSelect }) => {
 | 
	
		
			
				|  |  |        tryFetchRoleListByMenu()
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |    })
 | 
	
		
			
				|  |  | +  function renderTreeNode(tree) {
 | 
	
		
			
				|  |  | +    return tree.map(item => {
 | 
	
		
			
				|  |  | +      const newItem = {
 | 
	
		
			
				|  |  | +        ...item,
 | 
	
		
			
				|  |  | +        title: (
 | 
	
		
			
				|  |  | +          <div className="department-node">
 | 
	
		
			
				|  |  | +            <div>{item.title}</div>
 | 
	
		
			
				|  |  | +            <div className="extra">
 | 
	
		
			
				|  |  | +              <Popconfirm
 | 
	
		
			
				|  |  | +                title={
 | 
	
		
			
				|  |  | +                  <Input
 | 
	
		
			
				|  |  | +                    placeholder="角色名称"
 | 
	
		
			
				|  |  | +                    name="name"
 | 
	
		
			
				|  |  | +                    onChange={e => onChangeName(e.currentTarget.value)}
 | 
	
		
			
				|  |  | +                  />
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +                okText="确认"
 | 
	
		
			
				|  |  | +                cancelText="取消"
 | 
	
		
			
				|  |  | +                onConfirm={() => tryUpdateRole(item.ID, state.name)}
 | 
	
		
			
				|  |  | +                icon="">
 | 
	
		
			
				|  |  | +                <FormOutlined className="pr-2" />
 | 
	
		
			
				|  |  | +              </Popconfirm>
 | 
	
		
			
				|  |  | +              <Popconfirm
 | 
	
		
			
				|  |  | +                title="确认删除吗?"
 | 
	
		
			
				|  |  | +                onText="确认"
 | 
	
		
			
				|  |  | +                cancelText="取消"
 | 
	
		
			
				|  |  | +                onConfirm={() => tryDelRole(item.ID)}
 | 
	
		
			
				|  |  | +                icon={<QuestionCircleOutlined style={{ color: 'red' }} />}>
 | 
	
		
			
				|  |  | +                <DeleteOutlined />
 | 
	
		
			
				|  |  | +              </Popconfirm>
 | 
	
		
			
				|  |  | +            </div>
 | 
	
		
			
				|  |  | +          </div>
 | 
	
		
			
				|  |  | +        )
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +      if (newItem.children?.length) {
 | 
	
		
			
				|  |  | +        newItem.children = renderTreeNode(newItem.children)
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +      return newItem
 | 
	
		
			
				|  |  | +    })
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  |    useEffect(() => {
 | 
	
		
			
				|  |  |      tryFetchRoleListByMenu()
 | 
	
		
			
				|  |  |    }, [])
 | 
	
		
			
				|  |  | -  const handleItemClick = (id: string) => {
 | 
	
		
			
				|  |  | -    setActiveId(id)
 | 
	
		
			
				|  |  | +  const saveActiveId = (id: string) => {
 | 
	
		
			
				|  |  | +    // setActiveId(id)
 | 
	
		
			
				|  |  |      if (onSelect) {
 | 
	
		
			
				|  |  |        onSelect(id)
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -97,7 +146,17 @@ const RoleLeftMenu = ({ onSelect }) => {
 | 
	
		
			
				|  |  |        </div>
 | 
	
		
			
				|  |  |        <div className="p-4 bg-white" style={{ height: 'calc(100% - 1rem*2 - 20px)' }}>
 | 
	
		
			
				|  |  |          <ul className="p-0 m-0 list-none text-primary flex flex-col flex-1">
 | 
	
		
			
				|  |  | -          {menuRoles.map(item => (
 | 
	
		
			
				|  |  | +          {menuRoles.length ? (
 | 
	
		
			
				|  |  | +            <DirectoryTree
 | 
	
		
			
				|  |  | +              multiple
 | 
	
		
			
				|  |  | +              defaultExpandAll
 | 
	
		
			
				|  |  | +              defaultSelectedKeys={['0']}
 | 
	
		
			
				|  |  | +              onSelect={keys => saveActiveId(keys[0])}
 | 
	
		
			
				|  |  | +              showIcon={false}
 | 
	
		
			
				|  |  | +              treeData={renderTreeNode()}
 | 
	
		
			
				|  |  | +            />
 | 
	
		
			
				|  |  | +          ) : null}
 | 
	
		
			
				|  |  | +          {/* {menuRoles.map(item => (
 | 
	
		
			
				|  |  |              <Popover
 | 
	
		
			
				|  |  |                key={item.id}
 | 
	
		
			
				|  |  |                placement="right"
 | 
	
	
		
			
				|  | @@ -141,7 +200,7 @@ const RoleLeftMenu = ({ onSelect }) => {
 | 
	
		
			
				|  |  |                  <span>{item.name}</span>
 | 
	
		
			
				|  |  |                </li>
 | 
	
		
			
				|  |  |              </Popover>
 | 
	
		
			
				|  |  | -          ))}
 | 
	
		
			
				|  |  | +          ))} */}
 | 
	
		
			
				|  |  |          </ul>
 | 
	
		
			
				|  |  |        </div>
 | 
	
		
			
				|  |  |      </div>
 |