|  | @@ -5,11 +5,12 @@ import {
 | 
	
		
			
				|  |  |    QuestionCircleOutlined
 | 
	
		
			
				|  |  |  } from '@ant-design/icons'
 | 
	
		
			
				|  |  |  import { ModalForm, ProFormText } from '@ant-design/pro-form'
 | 
	
		
			
				|  |  | -
 | 
	
		
			
				|  |  | -import { Button, Input, Popconfirm, Tree } from 'antd'
 | 
	
		
			
				|  |  | +import { useRequest } from 'umi'
 | 
	
		
			
				|  |  | +import { Button, Input, message, Popconfirm, Tree } from 'antd'
 | 
	
		
			
				|  |  |  import type { DirectoryTreeProps } from 'antd/lib/tree'
 | 
	
		
			
				|  |  |  import '@/pages/Permission/Role/components/RoleLeftMenu/index.less'
 | 
	
		
			
				|  |  | -import { addDataSource } from '@/services/api/schema'
 | 
	
		
			
				|  |  | +import { addDataSource, delDataSourceID, updateDataSourceItem } from '@/services/api/schema'
 | 
	
		
			
				|  |  | +import { useRef, useState } from 'react'
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  const { DirectoryTree } = Tree
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -19,10 +20,50 @@ type LeftMenuProps = {
 | 
	
		
			
				|  |  |    initFn: () => Promise<void>
 | 
	
		
			
				|  |  |  }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, options }) => {
 | 
	
		
			
				|  |  | -  const handleOnSelect: DirectoryTreeProps['onSelect'] = keys => {
 | 
	
		
			
				|  |  | -    console.log('Trigger Select', keys, info)
 | 
	
		
			
				|  |  | -    onSelect?.(keys[0])
 | 
	
		
			
				|  |  | +const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, options, showDelIcon, initFn }) => {
 | 
	
		
			
				|  |  | +  const [activeID, setActiveID] = useState<Nullable<string>>(null)
 | 
	
		
			
				|  |  | +  const formRef = useRef<ProFormInstance>(null)
 | 
	
		
			
				|  |  | +  const handleOnSelect: DirectoryTreeProps['onSelect'] = (keys, node) => {
 | 
	
		
			
				|  |  | +    // console.log('Trigger Select', keys)
 | 
	
		
			
				|  |  | +    onSelect?.(keys[0], node)
 | 
	
		
			
				|  |  | +  }
 | 
	
		
			
				|  |  | +  const { run: tryUpdateDataSourceItem } = useRequest(
 | 
	
		
			
				|  |  | +    (params: Partial<API.UpdateRoleParams>) => updateDataSourceItem(params),
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      manual: true,
 | 
	
		
			
				|  |  | +      onSuccess: () => {
 | 
	
		
			
				|  |  | +        message.success('修改成功')
 | 
	
		
			
				|  |  | +        initFn()
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  )
 | 
	
		
			
				|  |  | +  const { run: tryAddDataSource } = useRequest(
 | 
	
		
			
				|  |  | +    (params: API.CreateRoleParams) => addDataSource(params),
 | 
	
		
			
				|  |  | +    {
 | 
	
		
			
				|  |  | +      manual: true,
 | 
	
		
			
				|  |  | +      onSuccess: () => {
 | 
	
		
			
				|  |  | +        initFn()
 | 
	
		
			
				|  |  | +      }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  )
 | 
	
		
			
				|  |  | +  const { run: tryDelRole } = useRequest((ID: string) => delDataSourceID({ ID }), {
 | 
	
		
			
				|  |  | +    manual: true,
 | 
	
		
			
				|  |  | +    onSuccess: () => {
 | 
	
		
			
				|  |  | +      message.success('删除成功')
 | 
	
		
			
				|  |  | +      initFn()
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +  })
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +  const handleOnFocus = async (
 | 
	
		
			
				|  |  | +    e: React.FocusEvent<HTMLInputElement> | React.KeyboardEvent<HTMLElement>,
 | 
	
		
			
				|  |  | +    oldTitle: string,
 | 
	
		
			
				|  |  | +    ID: string
 | 
	
		
			
				|  |  | +  ) => {
 | 
	
		
			
				|  |  | +    const val = e.currentTarget.value || e.currentTarget.nodeValue
 | 
	
		
			
				|  |  | +    if (val !== oldTitle) {
 | 
	
		
			
				|  |  | +      await tryUpdateDataSourceItem({ ID, name: val })
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +    setActiveID(null)
 | 
	
		
			
				|  |  |    }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |    const renderTreeNode = tree => {
 | 
	
	
		
			
				|  | @@ -77,6 +118,7 @@ const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, options }) => {
 | 
	
		
			
				|  |  |            layout="horizontal"
 | 
	
		
			
				|  |  |            title="新增数据源"
 | 
	
		
			
				|  |  |            width="30%"
 | 
	
		
			
				|  |  | +          onVisibleChange={visible => !visible && formRef.current?.resetFields()}
 | 
	
		
			
				|  |  |            isKeyPressSubmit
 | 
	
		
			
				|  |  |            labelCol={{ span: 5 }}
 | 
	
		
			
				|  |  |            trigger={
 | 
	
	
		
			
				|  | @@ -86,8 +128,9 @@ const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, options }) => {
 | 
	
		
			
				|  |  |              </Button>
 | 
	
		
			
				|  |  |            }
 | 
	
		
			
				|  |  |            onFinish={async values => {
 | 
	
		
			
				|  |  | -            const { code = -1 } = await addDataSource(values)
 | 
	
		
			
				|  |  | -            return code === consts.RET_CODE.SUCCESS
 | 
	
		
			
				|  |  | +            await tryAddDataSource(values)
 | 
	
		
			
				|  |  | +            message.success('添加成功')
 | 
	
		
			
				|  |  | +            return true
 | 
	
		
			
				|  |  |            }}>
 | 
	
		
			
				|  |  |            <ProFormText
 | 
	
		
			
				|  |  |              label="数据源名称"
 | 
	
	
		
			
				|  | @@ -103,6 +146,7 @@ const LeftMenu: React.FC<LeftMenuProps> = ({ onSelect, options }) => {
 | 
	
		
			
				|  |  |              options.map(item => ({ title: item.name, key: item.ID, ...item }))
 | 
	
		
			
				|  |  |            )}
 | 
	
		
			
				|  |  |            onSelect={handleOnSelect}
 | 
	
		
			
				|  |  | +          showIcon={false}
 | 
	
		
			
				|  |  |            defaultExpandAll
 | 
	
		
			
				|  |  |          />
 | 
	
		
			
				|  |  |        </div>
 |