refractor(web): 优化节点和流程图显示效果
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
import {PlusCircleFilled, RollbackOutlined, SaveFilled} from '@ant-design/icons'
|
import {PlusCircleFilled, RollbackOutlined, SaveFilled} from '@ant-design/icons'
|
||||||
import {Background, BackgroundVariant, Controls, MiniMap, ReactFlow} from '@xyflow/react'
|
import {Background, BackgroundVariant, Controls, MiniMap, Panel, ReactFlow} from '@xyflow/react'
|
||||||
import {Button, Dropdown, message, Popconfirm, Space} from 'antd'
|
import {Button, Dropdown, message, Popconfirm, Space} from 'antd'
|
||||||
import {arrToMap, isEqual, randomId, unique} from 'licia'
|
import {arrToMap, isEqual, randomId, unique} from 'licia'
|
||||||
import {useEffect} from 'react'
|
import {useEffect} from 'react'
|
||||||
@@ -34,13 +34,6 @@ const FlowableDiv = styled.div`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.toolbar {
|
|
||||||
position: absolute;
|
|
||||||
right: 20px;
|
|
||||||
top: 20px;
|
|
||||||
z-index: 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
.node-card {
|
.node-card {
|
||||||
cursor: default;
|
cursor: default;
|
||||||
|
|
||||||
@@ -85,6 +78,27 @@ function FlowEditor(props: FlowEditorProps) {
|
|||||||
return (
|
return (
|
||||||
<FlowableDiv className="h-full w-full">
|
<FlowableDiv className="h-full w-full">
|
||||||
{contextHolder}
|
{contextHolder}
|
||||||
|
<ReactFlow
|
||||||
|
nodes={nodes}
|
||||||
|
edges={edges}
|
||||||
|
onNodesChange={onNodesChange}
|
||||||
|
onEdgesChange={onEdgesChange}
|
||||||
|
onConnect={(connection) => {
|
||||||
|
try {
|
||||||
|
if (commonInfo.debug) {
|
||||||
|
console.info('Connection', JSON.stringify(connection), JSON.stringify({nodes, edges, data}))
|
||||||
|
}
|
||||||
|
checkAddConnection(connection, nodes, edges)
|
||||||
|
onConnect(connection)
|
||||||
|
} catch (e) {
|
||||||
|
// @ts-ignore
|
||||||
|
messageApi.error(e.toString())
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
// @ts-ignore
|
||||||
|
nodeTypes={arrToMap(Object.keys(NodeRegistryMap), key => NodeRegistryMap[key]!.component)}
|
||||||
|
>
|
||||||
|
<Panel position="top-right">
|
||||||
<Space className="toolbar">
|
<Space className="toolbar">
|
||||||
<Dropdown
|
<Dropdown
|
||||||
menu={{
|
menu={{
|
||||||
@@ -159,26 +173,7 @@ function FlowEditor(props: FlowEditorProps) {
|
|||||||
保存
|
保存
|
||||||
</Button>
|
</Button>
|
||||||
</Space>
|
</Space>
|
||||||
<ReactFlow
|
</Panel>
|
||||||
nodes={nodes}
|
|
||||||
edges={edges}
|
|
||||||
onNodesChange={onNodesChange}
|
|
||||||
onEdgesChange={onEdgesChange}
|
|
||||||
onConnect={(connection) => {
|
|
||||||
try {
|
|
||||||
if (commonInfo.debug) {
|
|
||||||
console.info('Connection', JSON.stringify(connection), JSON.stringify({nodes, edges, data}))
|
|
||||||
}
|
|
||||||
checkAddConnection(connection, nodes, edges)
|
|
||||||
onConnect(connection)
|
|
||||||
} catch (e) {
|
|
||||||
// @ts-ignore
|
|
||||||
messageApi.error(e.toString())
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
// @ts-ignore
|
|
||||||
nodeTypes={arrToMap(Object.keys(NodeRegistryMap), key => NodeRegistryMap[key]!.component)}
|
|
||||||
>
|
|
||||||
<Controls/>
|
<Controls/>
|
||||||
<MiniMap/>
|
<MiniMap/>
|
||||||
<Background variant={BackgroundVariant.Cross} gap={20} size={3}/>
|
<Background variant={BackgroundVariant.Cross} gap={20} size={3}/>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import {CopyFilled, DeleteFilled, EditFilled} from '@ant-design/icons'
|
import {CopyFilled, DeleteFilled, EditFilled} from '@ant-design/icons'
|
||||||
import {type Edge, Handle, type Node, type NodeProps, Position} from '@xyflow/react'
|
import {type Edge, Handle, type Node, type NodeProps, NodeToolbar, Position} from '@xyflow/react'
|
||||||
import type {Schema} from 'amis'
|
import type {Schema} from 'amis'
|
||||||
import {Button, Card, Drawer} from 'antd'
|
import {Button, Card, Drawer, Space, Tooltip} from 'antd'
|
||||||
import {type JSX, useCallback, useState} from 'react'
|
import {type JSX, useCallback, useState} from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import {amisRender, commonInfo, horizontalFormOptions} from '../../../util/amis.tsx'
|
import {amisRender, commonInfo, horizontalFormOptions} from '../../../util/amis.tsx'
|
||||||
@@ -247,37 +247,42 @@ const AmisNode: (props: AmisNodeProps) => JSX.Element = ({
|
|||||||
>
|
>
|
||||||
{editDrawerForm}
|
{editDrawerForm}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
<Card
|
<NodeToolbar>
|
||||||
className="node-card"
|
<Space>
|
||||||
title={nodeName}
|
<Tooltip title="复制节点">
|
||||||
extra={<span className="text-gray-300 text-xs">{id}</span>}
|
|
||||||
size="small"
|
|
||||||
actions={[
|
|
||||||
<Button
|
<Button
|
||||||
className="text-secondary"
|
className="text-secondary"
|
||||||
disabled
|
disabled
|
||||||
type="text"
|
type="text"
|
||||||
size="small"
|
size="small"
|
||||||
icon={<CopyFilled/>}
|
icon={<CopyFilled/>}
|
||||||
block
|
/>
|
||||||
/>,
|
</Tooltip>
|
||||||
|
<Tooltip title="编辑节点">
|
||||||
<Button
|
<Button
|
||||||
className="text-secondary"
|
className="text-secondary"
|
||||||
type="text"
|
type="text"
|
||||||
size="small"
|
size="small"
|
||||||
icon={<EditFilled/>}
|
icon={<EditFilled/>}
|
||||||
block
|
|
||||||
onClick={() => onOpenEditDrawerClick()}
|
onClick={() => onOpenEditDrawerClick()}
|
||||||
/>,
|
/>
|
||||||
|
</Tooltip>
|
||||||
|
<Tooltip title="删除节点">
|
||||||
<Button
|
<Button
|
||||||
className="text-secondary"
|
className="text-secondary"
|
||||||
type="text"
|
type="text"
|
||||||
size="small"
|
size="small"
|
||||||
icon={<DeleteFilled/>}
|
icon={<DeleteFilled/>}
|
||||||
block
|
|
||||||
onClick={() => onRemoveClick()}
|
onClick={() => onRemoveClick()}
|
||||||
/>,
|
/>
|
||||||
]}
|
</Tooltip>
|
||||||
|
</Space>
|
||||||
|
</NodeToolbar>
|
||||||
|
<Card
|
||||||
|
className="node-card"
|
||||||
|
title={nodeName}
|
||||||
|
extra={<span className="text-gray-300 text-xs">{id}</span>}
|
||||||
|
size="small"
|
||||||
>
|
>
|
||||||
<div className="card-description p-2 text-secondary text-sm">
|
<div className="card-description p-2 text-secondary text-sm">
|
||||||
{nodeDescription}
|
{nodeDescription}
|
||||||
|
|||||||
Reference in New Issue
Block a user