lanjianrong 3 سال پیش
والد
کامیت
8624ed9203

+ 1 - 1
src/components/Flow/src/components/Edge/index.tsx

@@ -1,6 +1,6 @@
 import { buildUUID } from '@/utils/uuid'
 import { ApartmentOutlined, ClusterOutlined, PlusOutlined } from '@ant-design/icons'
-import { Button, Dropdown, Menu, Popover } from 'antd'
+import { Button, Menu, Popover } from 'antd'
 import React, { useMemo, useState, useContext } from 'react'
 import { getBezierPath, getEdgeCenter, getMarkerEnd, useStoreState } from 'react-flow-renderer'
 import { Actions, FlowContext } from '../../context'

+ 3 - 1
src/components/Flow/src/components/Node/index.tsx

@@ -29,7 +29,8 @@ export const CommonNode = props => {
   // console.log(props)
   const { id, data } = props
 
-  const { dispatch } = useContext(FlowContext)
+  const { state, dispatch } = useContext(FlowContext)
+  const { flowInstance } = state
   const removeNode = () => {
     dispatch({
       type: Actions.REMOVE_FLOW_NODE,
@@ -38,6 +39,7 @@ export const CommonNode = props => {
         data
       }
     })
+    flowInstance?.fitView()
   }
   return (
     <>

+ 20 - 8
src/pages/Institutions/Company/Detail/components/Organization.tsx

@@ -1,4 +1,4 @@
-import { Button, Popconfirm, message, Tooltip } from 'antd'
+import { Button, Popconfirm, message, Table, Tooltip } from 'antd'
 import type { ActionType } from '@ant-design/pro-table'
 import ProTable from '@ant-design/pro-table'
 import React, { useState, useEffect, useRef } from 'react'
@@ -26,6 +26,7 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
   const [state, setState] = useState({
     organizationList: [],
     visible: false,
+    expandTreeIds: [],
     currentModalType: ModalType.ADD,
     defaultFormData: null,
     parentID: '',
@@ -34,7 +35,6 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
     down: 'down',
     accountTotal: null
   })
-  const [expandTree, setExpandTree] = useState([])
   const titleType = {
     ADD: 1,
     ADDITEM: 2,
@@ -52,17 +52,17 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
           let idArr: string[] = []
           data.forEach((item: OrganizationalStructureListItem) => {
             if (item.children?.length) {
-              idArr.push(item.id)
+              idArr.push(item.ID)
               const childIDs = expandTreeList(item.children)
               idArr = [...idArr, ...childIDs]
             }
           })
+          return idArr
         }
         setState({
           ...state,
           organizationList: result,
-          ...setExpandTree,
-          expandTree: expandTreeList
+          expandTreeIds: expandTreeList(result)
         })
       }
     }
@@ -222,13 +222,25 @@ const Organization: React.FC<OrganizationProps> = ({ dataID, structureType }) =>
 
   return (
     <div>
-      <ProTable<API.OrganizationalStructureListItem>
+      <Table<API.OrganizationalStructureListItem>
         rowKey="ID"
         actionRef={tRef}
         columns={columns}
         dataSource={state.organizationList}
-        defaultExpandAllRows={true}
-        expandable={{ defaultExpandedRowKeys: state.expandTree }}
+        // defaultExpandAllRows={true}
+        expandable={{
+          expandedRowKeys: state.expandTreeIds,
+          onExpand: (expanded, record) => {
+            if (expanded) {
+              if (state.expandTreeIds.includes(record.ID)) return
+              setState({ ...state, expandTreeIds: [...state.expandTreeIds, record.ID] })
+            }
+            setState({
+              ...state,
+              expandTreeIds: state.expandTreeIds.filter(item => item !== record.ID)
+            })
+          }
+        }}
         // expandedRowRender={expandedRowRender}
         indentSize={30}
         search={false}