|
@@ -1,11 +1,61 @@
|
|
|
-import { PlusOutlined } from '@ant-design/icons'
|
|
|
-import { Button } from 'antd'
|
|
|
-import React from 'react'
|
|
|
+import { buildUUID } from '@/utils/uuid'
|
|
|
+import { ApartmentOutlined, ClusterOutlined, PlusOutlined } from '@ant-design/icons'
|
|
|
+import { Button, Dropdown, Menu, Popover } from 'antd'
|
|
|
+import React, { useState, useContext } from 'react'
|
|
|
import { getBezierPath, getEdgeCenter, getMarkerEnd } from 'react-flow-renderer'
|
|
|
+import { Actions, FlowContext } from '../../context'
|
|
|
import styles from './index.less'
|
|
|
|
|
|
const foreignObjectSize = 40
|
|
|
|
|
|
+const renderMenu = ({ dispatch, elements, togglePopver, ...node }) => {
|
|
|
+ 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 = () => {
|
|
|
+ const newNode = {
|
|
|
+ id: buildUUID(),
|
|
|
+ tpye: 'input',
|
|
|
+ position: { x: 400, y: 0 },
|
|
|
+ data: {}
|
|
|
+ }
|
|
|
+ setElements(elements.concat(newNode))
|
|
|
+ }
|
|
|
+
|
|
|
+ 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>
|
|
|
+ )
|
|
|
+}
|
|
|
+
|
|
|
export function ButtonEdge({
|
|
|
id,
|
|
|
sourceX,
|
|
@@ -15,10 +65,12 @@ export function ButtonEdge({
|
|
|
sourcePosition,
|
|
|
targetPosition,
|
|
|
style = {},
|
|
|
- data,
|
|
|
arrowHeadType,
|
|
|
markerEndId
|
|
|
}) {
|
|
|
+ const [visible, setVisible] = useState(false)
|
|
|
+ const { state, dispatch } = useContext(FlowContext)
|
|
|
+ const { elements } = state
|
|
|
const edgePath = getBezierPath({
|
|
|
sourceX,
|
|
|
sourceY,
|
|
@@ -35,9 +87,16 @@ export function ButtonEdge({
|
|
|
targetY
|
|
|
})
|
|
|
|
|
|
+ const togglePopver = (isShow: boolean) => {
|
|
|
+ console.log(isShow)
|
|
|
+
|
|
|
+ setVisible(isShow)
|
|
|
+ }
|
|
|
+
|
|
|
const onEdgeClick = (evt, id) => {
|
|
|
- evt.stopPropagation()
|
|
|
- alert(`remove ${id}`)
|
|
|
+ togglePopver(true)
|
|
|
+ // evt.stopPropagation()
|
|
|
+ // alert(`remove ${id}`)
|
|
|
}
|
|
|
|
|
|
return (
|
|
@@ -47,16 +106,23 @@ export function ButtonEdge({
|
|
|
width={foreignObjectSize}
|
|
|
height={foreignObjectSize}
|
|
|
x={edgeCenterX - foreignObjectSize / 2}
|
|
|
- y={edgeCenterY - foreignObjectSize / 2}
|
|
|
- className="edgebutton-foreignobject"
|
|
|
- requiredExtensions="http://www.w3.org/1999/xhtml">
|
|
|
+ y={edgeCenterY - foreignObjectSize / 2}>
|
|
|
<div className={styles.addIcon}>
|
|
|
- <Button
|
|
|
- icon={<PlusOutlined />}
|
|
|
- shape="circle"
|
|
|
- size="small"
|
|
|
- onClick={event => onEdgeClick(event, id)}
|
|
|
- />
|
|
|
+ <Popover
|
|
|
+ content={renderMenu({ elements, dispatch, togglePopver })}
|
|
|
+ trigger="click"
|
|
|
+ placement="right"
|
|
|
+ // visible={visible}
|
|
|
+ // destroyTooltipOnHide
|
|
|
+ // onVisibleChange={togglePopver}
|
|
|
+ overlayClassName="flow-popover">
|
|
|
+ <Button
|
|
|
+ icon={<PlusOutlined />}
|
|
|
+ shape="circle"
|
|
|
+ size="small"
|
|
|
+ onClick={event => onEdgeClick(event, id)}
|
|
|
+ />
|
|
|
+ </Popover>
|
|
|
</div>
|
|
|
</foreignObject>
|
|
|
</>
|