|
@@ -1,9 +1,11 @@
|
|
|
import { buildUUID } from '@/utils/uuid'
|
|
|
-import { PlusOutlined, SolutionOutlined } from '@ant-design/icons'
|
|
|
+import { SolutionOutlined } from '@ant-design/icons'
|
|
|
import { Button, Popover } from 'antd'
|
|
|
import React, { useMemo, useState, useContext } from 'react'
|
|
|
+import type { EdgeProps } from 'react-flow-renderer'
|
|
|
+import { isNode } from 'react-flow-renderer'
|
|
|
import { getBezierPath, getEdgeCenter, getMarkerEnd, useStoreState } from 'react-flow-renderer'
|
|
|
-import { Actions, FlowContext } from '../../context'
|
|
|
+import { Actions, eId, FlowContext } from '../../context'
|
|
|
import { generateElements, genreateElementEnum, getEdgeParams } from '../../utils'
|
|
|
import { addApprovalNode } from '@/services/api/project'
|
|
|
import styles from './index.less'
|
|
@@ -11,6 +13,7 @@ import 'antd/lib/button/style/css'
|
|
|
import consts from '@/utils/consts'
|
|
|
import useLoading from '../../hooks/useLoading'
|
|
|
import IconFont from '@/components/IconFont'
|
|
|
+import { ConfigureType } from '../../enum'
|
|
|
const foreignObjectSize = 50
|
|
|
|
|
|
export enum SectorType {
|
|
@@ -18,105 +21,7 @@ export enum SectorType {
|
|
|
CONDITION = 'condition'
|
|
|
}
|
|
|
|
|
|
-const RenderMenu = ({ dataID, source, dispatch, elements, togglePopver, id, flowInstance }) => {
|
|
|
- const { run: showLoading } = useLoading()
|
|
|
- const setElements = els => {
|
|
|
- dispatch({
|
|
|
- type: Actions.SET_ELEMENTS,
|
|
|
- payload: els
|
|
|
- })
|
|
|
- }
|
|
|
- // const edit = () => {
|
|
|
- // togglePopver(false)
|
|
|
- // dispatch({
|
|
|
- // type: Actions.OPEN_MODAL,
|
|
|
- // payload: {
|
|
|
- // id: node.id,
|
|
|
- // type: 'relation'
|
|
|
- // }
|
|
|
- // })
|
|
|
- // }
|
|
|
- // const remove = () => {
|
|
|
- // dispatch({
|
|
|
- // type: Actions.REMOVE_FLOW_NODE,
|
|
|
- // payload: node
|
|
|
- // })
|
|
|
- // }
|
|
|
-
|
|
|
- const addAuditor = async () => {
|
|
|
- const uid = buildUUID()
|
|
|
- const newNode = {
|
|
|
- id: uid,
|
|
|
- type: 'input',
|
|
|
- data: {}
|
|
|
- }
|
|
|
- const currentEdge = elements.find(item => item.id === id)
|
|
|
- const newElements = generateElements(genreateElementEnum.ADD, elements)(newNode, currentEdge)
|
|
|
-
|
|
|
- const { code = -1 } = await addApprovalNode({
|
|
|
- ID: dataID,
|
|
|
- segmentBrotherID: source,
|
|
|
- flowProcess: newElements,
|
|
|
- segment: {
|
|
|
- ID: uid,
|
|
|
- name: '审批人',
|
|
|
- sectorType: SectorType.APPROVAL
|
|
|
- }
|
|
|
- })
|
|
|
- if (code === consts.RET_CODE.SUCCESS) {
|
|
|
- setElements(newElements)
|
|
|
- dispatch({
|
|
|
- type: Actions.SET_FLOW_NODE,
|
|
|
- payload: {
|
|
|
- id: uid,
|
|
|
- node: null
|
|
|
- }
|
|
|
- })
|
|
|
- togglePopver(false)
|
|
|
- setTimeout(() => {
|
|
|
- showLoading()
|
|
|
- flowInstance?.fitView()
|
|
|
- }, 80)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- return (
|
|
|
- // <Menu>
|
|
|
- // <Menu.Item key="1" onClick={addAuditor}>
|
|
|
- // <ClusterOutlined />
|
|
|
- // <span className="ml-1">审批人</span>
|
|
|
- // </Menu.Item>
|
|
|
- // {/* <Menu.Item key="2" onClick={remove}>
|
|
|
- // <ApartmentOutlined />
|
|
|
- // <span className="ml-1">条件分支</span>
|
|
|
- // </Menu.Item> */}
|
|
|
- // </Menu>
|
|
|
- <ul className="m-0 p-0 ">
|
|
|
- <li>
|
|
|
- <Button type="dashed" onClick={addAuditor} icon={<SolutionOutlined />}>
|
|
|
- 审批人
|
|
|
- </Button>
|
|
|
- </li>
|
|
|
- {/* <li className="mt-2 condition">
|
|
|
- <Button type="dashed" onClick={addAuditor} icon={<BranchesOutlined />}>
|
|
|
- 条件分支
|
|
|
- </Button>
|
|
|
- </li> */}
|
|
|
- </ul>
|
|
|
- // <ul className="m-0 p-0">
|
|
|
- // <li className="rounded-2px border border-hex-d9d9d9 border-dashed text-hex-1890ff px-17px py-9px cursor-pointer">
|
|
|
- // <SolutionOutlined />
|
|
|
- // <span className="ml-9px">审批人</span>
|
|
|
- // </li>
|
|
|
- // <li className="mt-2 rounded-2px border border-hex-d9d9d9 border-dashed text-hex-52c41a px-17px py-9px cursor-pointer">
|
|
|
- // <BranchesOutlined />
|
|
|
- // <span className="ml-9px">条件分支</span>
|
|
|
- // </li>
|
|
|
- // </ul>
|
|
|
- )
|
|
|
-}
|
|
|
-
|
|
|
-export function CommonEdge(props) {
|
|
|
+export function CommonEdge(props: EdgeProps) {
|
|
|
const {
|
|
|
id,
|
|
|
sourceX,
|
|
@@ -132,7 +37,21 @@ export function CommonEdge(props) {
|
|
|
|
|
|
const [visible, setVisible] = useState(false)
|
|
|
const { flowState, dispatch } = useContext(FlowContext)
|
|
|
- const { elements, flowInstance, dataID, readPretty } = flowState
|
|
|
+ const { elements, flowInstance, flowData, dataID, readPretty } = flowState
|
|
|
+ const { run: showLoading } = useLoading()
|
|
|
+ const setElements = els => {
|
|
|
+ dispatch({
|
|
|
+ type: Actions.SET_ELEMENTS,
|
|
|
+ payload: els
|
|
|
+ })
|
|
|
+ }
|
|
|
+ const showBtn =
|
|
|
+ flowData.get(source) && target === eId
|
|
|
+ ? flowData
|
|
|
+ .get(source)
|
|
|
+ ?.accounts.every(item => !item.configure.includes(ConfigureType.NEXTSECTOR))
|
|
|
+ : true
|
|
|
+
|
|
|
const nodes = useStoreState(store => store.nodes)
|
|
|
const markerEnd = getMarkerEnd(arrowHeadType, markerEndId)
|
|
|
|
|
@@ -170,26 +89,68 @@ export function CommonEdge(props) {
|
|
|
// alert(`remove ${id}`)
|
|
|
}
|
|
|
|
|
|
+ const addAuditor = async () => {
|
|
|
+ const uid = buildUUID()
|
|
|
+ const newNode = {
|
|
|
+ id: uid,
|
|
|
+ type: 'input',
|
|
|
+ data: {}
|
|
|
+ }
|
|
|
+ const currentEdge = elements.find(item => item.id === id)
|
|
|
+ const newElements = generateElements(genreateElementEnum.ADD, elements)(newNode, currentEdge)
|
|
|
+
|
|
|
+ const { code = -1 } = await addApprovalNode({
|
|
|
+ ID: dataID,
|
|
|
+ segmentBrotherID: source,
|
|
|
+ flowProcess: newElements,
|
|
|
+ segment: {
|
|
|
+ ID: uid,
|
|
|
+ name: '审批人',
|
|
|
+ sectorType: SectorType.APPROVAL
|
|
|
+ }
|
|
|
+ })
|
|
|
+ if (code === consts.RET_CODE.SUCCESS) {
|
|
|
+ setElements(newElements)
|
|
|
+ dispatch({
|
|
|
+ type: Actions.SET_FLOW_NODE,
|
|
|
+ payload: {
|
|
|
+ id: uid,
|
|
|
+ node: null
|
|
|
+ }
|
|
|
+ })
|
|
|
+ togglePopver(false)
|
|
|
+ setTimeout(() => {
|
|
|
+ showLoading()
|
|
|
+ flowInstance?.fitView()
|
|
|
+ }, 80)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<>
|
|
|
<path id={id} style={style} className={styles.flowPath} d={d} markerEnd={markerEnd} />
|
|
|
- <foreignObject
|
|
|
- width={foreignObjectSize}
|
|
|
- height={foreignObjectSize}
|
|
|
- x={edgeCenterX - foreignObjectSize / 2}
|
|
|
- y={edgeCenterY - foreignObjectSize / 2}>
|
|
|
- <div className={styles.addIcon}>
|
|
|
- {!readPretty ? (
|
|
|
+ {showBtn && !readPretty && (
|
|
|
+ <foreignObject
|
|
|
+ width={foreignObjectSize}
|
|
|
+ height={foreignObjectSize}
|
|
|
+ x={edgeCenterX - foreignObjectSize / 2}
|
|
|
+ y={edgeCenterY - foreignObjectSize / 2}>
|
|
|
+ <div className={styles.addIcon}>
|
|
|
<Popover
|
|
|
- content={RenderMenu({
|
|
|
- elements,
|
|
|
- dispatch,
|
|
|
- source,
|
|
|
- togglePopver,
|
|
|
- id,
|
|
|
- flowInstance,
|
|
|
- dataID
|
|
|
- })}
|
|
|
+ content={
|
|
|
+ <ul className="m-0 p-0">
|
|
|
+ <li>
|
|
|
+ <Button type="dashed" onClick={addAuditor} icon={<SolutionOutlined />}>
|
|
|
+ 审批人
|
|
|
+ </Button>
|
|
|
+ </li>
|
|
|
+ {/* <li className="mt-2 condition">
|
|
|
+ <Button type="dashed" onClick={addAuditor} icon={<BranchesOutlined />}>
|
|
|
+ 条件分支
|
|
|
+ </Button>
|
|
|
+ </li> */}
|
|
|
+ </ul>
|
|
|
+ }
|
|
|
trigger="click"
|
|
|
placement="right"
|
|
|
visible={visible}
|
|
@@ -203,9 +164,9 @@ export function CommonEdge(props) {
|
|
|
onClick={event => onEdgeClick(event, id)}
|
|
|
/>
|
|
|
</Popover>
|
|
|
- ) : null}
|
|
|
- </div>
|
|
|
- </foreignObject>
|
|
|
+ </div>
|
|
|
+ </foreignObject>
|
|
|
+ )}
|
|
|
</>
|
|
|
)
|
|
|
}
|