|
@@ -1,10 +1,12 @@
|
|
-import React, { useContext, useState } from 'react'
|
|
|
|
|
|
+import React, { useContext, useMemo, useState } from 'react'
|
|
import { EdgeProps } from 'react-flow-renderer'
|
|
import { EdgeProps } from 'react-flow-renderer'
|
|
import { Button, Popover } from 'antd'
|
|
import { Button, Popover } from 'antd'
|
|
import { BranchesOutlined, PlusOutlined, SolutionOutlined } from '@ant-design/icons'
|
|
import { BranchesOutlined, PlusOutlined, SolutionOutlined } from '@ant-design/icons'
|
|
import styles from './index.less'
|
|
import styles from './index.less'
|
|
import { FlowContext } from '../../context'
|
|
import { FlowContext } from '../../context'
|
|
import { NodeType } from '@/components/Flow/src/enum'
|
|
import { NodeType } from '@/components/Flow/src/enum'
|
|
|
|
+import { addNodes } from './utils'
|
|
|
|
+import { createUid } from '@/utils/util'
|
|
export type BaseEdgeProps = Pick<EdgeProps, 'style' | 'markerEnd'> & {
|
|
export type BaseEdgeProps = Pick<EdgeProps, 'style' | 'markerEnd'> & {
|
|
centerX: number
|
|
centerX: number
|
|
centerY: number
|
|
centerY: number
|
|
@@ -12,11 +14,22 @@ export type BaseEdgeProps = Pick<EdgeProps, 'style' | 'markerEnd'> & {
|
|
}
|
|
}
|
|
const foreignObjectSize = 48
|
|
const foreignObjectSize = 48
|
|
|
|
|
|
-export default ({ id, source, path, centerX, centerY, style }: BaseEdgeProps) => {
|
|
|
|
|
|
+export default ({ id, source, target, path, centerX, centerY, style }: BaseEdgeProps) => {
|
|
const [open, setOpen] = useState(false)
|
|
const [open, setOpen] = useState(false)
|
|
- const { flowStore } = useContext(FlowContext)
|
|
|
|
|
|
+ const { flowStore, dispatch } = useContext(FlowContext)
|
|
|
|
+
|
|
|
|
+ const showForeignObject = ![NodeType.OPERATION, NodeType.OPERATION_BTN].includes(
|
|
|
|
+ flowStore.elements.find(item => item.id === source)?.type
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ const showConditionItem = useMemo(() => {
|
|
|
|
+ return (
|
|
|
|
+ flowStore.elements.find(item => item.id === source)?.type === NodeType.INPUT ||
|
|
|
|
+ flowStore.elements.find(item => item.id === target)?.type === NodeType.OPERATION ||
|
|
|
|
+ flowStore.elements.find(item => item.id === source)?.data?.parentId
|
|
|
|
+ )
|
|
|
|
+ }, [flowStore.elements])
|
|
|
|
|
|
- const showForeignObject = flowStore.elements.find(item => item.id === source)?.type !== NodeType.OPERATION
|
|
|
|
const togglePopver = (open: boolean) => {
|
|
const togglePopver = (open: boolean) => {
|
|
setOpen(open)
|
|
setOpen(open)
|
|
}
|
|
}
|
|
@@ -27,11 +40,59 @@ export default ({ id, source, path, centerX, centerY, style }: BaseEdgeProps) =>
|
|
// alert(`remove ${id}`)
|
|
// alert(`remove ${id}`)
|
|
}
|
|
}
|
|
|
|
|
|
- const addAuditor = async () => {
|
|
|
|
- togglePopver(false)
|
|
|
|
- setTimeout(() => {
|
|
|
|
- flowInstance?.fitView()
|
|
|
|
- }, 80)
|
|
|
|
|
|
+ const addAuditorOrCondition = async (mode: 'auditor' | 'condition') => {
|
|
|
|
+ let insertNodes = []
|
|
|
|
+ if (mode === 'auditor') {
|
|
|
|
+ insertNodes.push({ id: createUid(), type: NodeType.COMMON })
|
|
|
|
+ } else {
|
|
|
|
+ insertNodes = [
|
|
|
|
+ {
|
|
|
|
+ id: createUid(),
|
|
|
|
+ type: NodeType.OPERATION,
|
|
|
|
+ children: [
|
|
|
|
+ {
|
|
|
|
+ id: createUid(),
|
|
|
|
+ type: NodeType.BLOCK,
|
|
|
|
+ children: [
|
|
|
|
+ {
|
|
|
|
+ id: createUid(),
|
|
|
|
+ type: NodeType.CONDITION
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ id: createUid(),
|
|
|
|
+ type: NodeType.COMMON
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ id: createUid(),
|
|
|
|
+ type: NodeType.BLOCK,
|
|
|
|
+ children: [
|
|
|
|
+ {
|
|
|
|
+ id: createUid(),
|
|
|
|
+ type: NodeType.CONDITION
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ id: createUid(),
|
|
|
|
+ type: NodeType.COMMON
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ id: createUid(),
|
|
|
|
+ type: NodeType.OPERATION_BTN
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ dispatch({
|
|
|
|
+ type: 'set_flow_process',
|
|
|
|
+ payload: addNodes(flowStore.process, source, insertNodes)
|
|
|
|
+ })
|
|
|
|
+ // togglePopver(false)
|
|
|
|
+ flowStore.flowInstance?.fitView({ duration: 280 })
|
|
}
|
|
}
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
@@ -49,22 +110,30 @@ export default ({ id, source, path, centerX, centerY, style }: BaseEdgeProps) =>
|
|
onBlur={e => {
|
|
onBlur={e => {
|
|
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
if (!e.currentTarget.contains(e.relatedTarget)) {
|
|
// Not triggered when swapping focus between children
|
|
// Not triggered when swapping focus between children
|
|
- togglePopver(false)
|
|
|
|
|
|
+ // togglePopver(false)
|
|
}
|
|
}
|
|
}}>
|
|
}}>
|
|
<Popover
|
|
<Popover
|
|
content={
|
|
content={
|
|
<ul className="m-0 p-0">
|
|
<ul className="m-0 p-0">
|
|
<li>
|
|
<li>
|
|
- <Button type="dashed" onClick={addAuditor} icon={<SolutionOutlined />}>
|
|
|
|
|
|
+ <Button
|
|
|
|
+ type="dashed"
|
|
|
|
+ onClick={() => addAuditorOrCondition('auditor')}
|
|
|
|
+ icon={<SolutionOutlined />}>
|
|
审批人
|
|
审批人
|
|
</Button>
|
|
</Button>
|
|
</li>
|
|
</li>
|
|
- <li className="mt-2 condition">
|
|
|
|
- <Button type="dashed" onClick={addAuditor} icon={<BranchesOutlined />}>
|
|
|
|
- 条件分支
|
|
|
|
- </Button>
|
|
|
|
- </li>
|
|
|
|
|
|
+ {!showConditionItem && (
|
|
|
|
+ <li className="mt-2 condition">
|
|
|
|
+ <Button
|
|
|
|
+ type="dashed"
|
|
|
|
+ onClick={() => addAuditorOrCondition('condition')}
|
|
|
|
+ icon={<BranchesOutlined />}>
|
|
|
|
+ 条件分支
|
|
|
|
+ </Button>
|
|
|
|
+ </li>
|
|
|
|
+ )}
|
|
</ul>
|
|
</ul>
|
|
}
|
|
}
|
|
trigger="click"
|
|
trigger="click"
|