feat(web): 优化流程界面显示
This commit is contained in:
@@ -16,7 +16,7 @@ import {arrToMap, find, findIdx, isEqual, isNil, randomId} from 'licia'
|
|||||||
import {type JSX, useState} from 'react'
|
import {type JSX, useState} from 'react'
|
||||||
import styled from 'styled-components'
|
import styled from 'styled-components'
|
||||||
import '@xyflow/react/dist/style.css'
|
import '@xyflow/react/dist/style.css'
|
||||||
import {amisRender, commonInfo} from '../../../util/amis.tsx'
|
import {amisRender, commonInfo, horizontalFormOptions} from '../../../util/amis.tsx'
|
||||||
import StartNode from './node/StartNode.tsx'
|
import StartNode from './node/StartNode.tsx'
|
||||||
import EndNode from './node/EndNode.tsx'
|
import EndNode from './node/EndNode.tsx'
|
||||||
import LlmNode from './node/LlmNode.tsx'
|
import LlmNode from './node/LlmNode.tsx'
|
||||||
@@ -103,15 +103,10 @@ function FlowEditor() {
|
|||||||
type: 'wrapper',
|
type: 'wrapper',
|
||||||
size: 'none',
|
size: 'none',
|
||||||
body: [
|
body: [
|
||||||
{
|
|
||||||
type: 'tpl',
|
|
||||||
className: 'text-secondary',
|
|
||||||
tpl: description,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
debug: commonInfo.debug,
|
debug: commonInfo.debug,
|
||||||
title: name,
|
|
||||||
type: 'form',
|
type: 'form',
|
||||||
|
...horizontalFormOptions(),
|
||||||
wrapWithPanel: false,
|
wrapWithPanel: false,
|
||||||
onEvent: {
|
onEvent: {
|
||||||
submitSucc: {
|
submitSucc: {
|
||||||
@@ -229,6 +224,7 @@ function FlowEditor() {
|
|||||||
closeIcon={false}
|
closeIcon={false}
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
destroyOnHidden
|
destroyOnHidden
|
||||||
|
size="large"
|
||||||
>
|
>
|
||||||
{currentNodeForm}
|
{currentNodeForm}
|
||||||
</Drawer>
|
</Drawer>
|
||||||
|
|||||||
@@ -2,24 +2,30 @@ import {Handle, type NodeProps, Position} from '@xyflow/react'
|
|||||||
import type {Schema} from 'amis'
|
import type {Schema} from 'amis'
|
||||||
import {Card, Dropdown} from 'antd'
|
import {Card, Dropdown} from 'antd'
|
||||||
import {DeleteFilled, EditFilled} from '@ant-design/icons'
|
import {DeleteFilled, EditFilled} from '@ant-design/icons'
|
||||||
import {isEqual} from 'licia'
|
import {isEmpty, isEqual} from 'licia'
|
||||||
|
import type {JSX} from 'react'
|
||||||
|
|
||||||
export type AmisNodeType = 'normal' | 'start' | 'end'
|
export type AmisNodeType = 'normal' | 'start' | 'end'
|
||||||
|
|
||||||
const AmisNode = (
|
const AmisNode = (
|
||||||
props: NodeProps,
|
props: NodeProps,
|
||||||
type: AmisNodeType,
|
type: AmisNodeType,
|
||||||
name: String,
|
defaultNodeName: String,
|
||||||
description?: String,
|
defaultNodeDescription?: String,
|
||||||
|
extraNodeDescription?: (nodeData: any) => JSX.Element,
|
||||||
columnSchema?: Schema[],
|
columnSchema?: Schema[],
|
||||||
) => {
|
) => {
|
||||||
const {id, data} = props
|
const {id, data} = props
|
||||||
const {getDataById, removeNode, editNode} = data
|
const {getDataById, removeNode, editNode} = data
|
||||||
|
// @ts-ignore
|
||||||
|
const nodeData = getDataById(id)
|
||||||
|
const nodeName = isEmpty(nodeData?.node?.name) ? defaultNodeName : nodeData.node.name
|
||||||
|
const nodeDescription = isEmpty(nodeData?.node?.description) ? defaultNodeDescription : nodeData.node?.description
|
||||||
return (
|
return (
|
||||||
<div className="p-1 w-64">
|
<div className="p-1 w-64">
|
||||||
<Card
|
<Card
|
||||||
className="node-card"
|
className="node-card"
|
||||||
title={name}
|
title={nodeName}
|
||||||
size="small"
|
size="small"
|
||||||
hoverable
|
hoverable
|
||||||
>
|
>
|
||||||
@@ -43,7 +49,29 @@ const AmisNode = (
|
|||||||
switch (menu.key) {
|
switch (menu.key) {
|
||||||
case 'edit':
|
case 'edit':
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
editNode(id, name, description, columnSchema)
|
editNode(
|
||||||
|
id,
|
||||||
|
defaultNodeName,
|
||||||
|
defaultNodeDescription,
|
||||||
|
[
|
||||||
|
{
|
||||||
|
type: 'input-text',
|
||||||
|
name: 'node.name',
|
||||||
|
label: '节点名称',
|
||||||
|
placeholder: nodeName,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'textarea',
|
||||||
|
name: 'node.description',
|
||||||
|
label: '节点描述',
|
||||||
|
placeholder: nodeDescription,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'divider'
|
||||||
|
},
|
||||||
|
...(columnSchema ?? [])
|
||||||
|
]
|
||||||
|
)
|
||||||
break
|
break
|
||||||
case 'remove':
|
case 'remove':
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -54,7 +82,8 @@ const AmisNode = (
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div className="card-description p-2 text-secondary text-sm">
|
<div className="card-description p-2 text-secondary text-sm">
|
||||||
{description}
|
{nodeDescription}
|
||||||
|
{extraNodeDescription?.(nodeData)}
|
||||||
</div>
|
</div>
|
||||||
</Dropdown>
|
</Dropdown>
|
||||||
</Card>
|
</Card>
|
||||||
|
|||||||
@@ -1,22 +1,27 @@
|
|||||||
import type {NodeProps} from '@xyflow/react'
|
import type {NodeProps} from '@xyflow/react'
|
||||||
import AmisNode from './AmisNode.tsx'
|
import AmisNode from './AmisNode.tsx'
|
||||||
|
import {horizontalFormOptions} from '../../../../util/amis.tsx'
|
||||||
|
|
||||||
const EndNode = (props: NodeProps) => AmisNode(
|
const EndNode = (props: NodeProps) => AmisNode(
|
||||||
props,
|
props,
|
||||||
'end',
|
'end',
|
||||||
'结束节点',
|
'结束节点',
|
||||||
'定义输出变量',
|
'定义输出变量',
|
||||||
|
undefined,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: 'input-kvs',
|
type: 'input-kvs',
|
||||||
name: 'fields',
|
name: 'outputVariables',
|
||||||
|
label: '输出变量',
|
||||||
addButtonText: '新增输出',
|
addButtonText: '新增输出',
|
||||||
draggable: false,
|
draggable: false,
|
||||||
keyItem: {
|
keyItem: {
|
||||||
|
...horizontalFormOptions(),
|
||||||
label: '参数名称',
|
label: '参数名称',
|
||||||
},
|
},
|
||||||
valueItems: [
|
valueItems: [
|
||||||
{
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
type: 'select',
|
type: 'select',
|
||||||
name: 'type',
|
name: 'type',
|
||||||
label: '参数',
|
label: '参数',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ const LlmNode = (props: NodeProps) => AmisNode(
|
|||||||
'normal',
|
'normal',
|
||||||
'大模型节点',
|
'大模型节点',
|
||||||
'使用大模型对话',
|
'使用大模型对话',
|
||||||
|
undefined,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: 'select',
|
type: 'select',
|
||||||
|
|||||||
@@ -1,27 +1,33 @@
|
|||||||
import type {NodeProps} from '@xyflow/react'
|
import type {NodeProps} from '@xyflow/react'
|
||||||
import AmisNode from './AmisNode.tsx'
|
import AmisNode from './AmisNode.tsx'
|
||||||
|
import {horizontalFormOptions} from '../../../../util/amis.tsx'
|
||||||
|
|
||||||
const StartNode = (props: NodeProps) => AmisNode(
|
const StartNode = (props: NodeProps) => AmisNode(
|
||||||
props,
|
props,
|
||||||
'start',
|
'start',
|
||||||
'开始节点',
|
'开始节点',
|
||||||
'定义输入变量',
|
'定义输入变量',
|
||||||
|
undefined,
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
type: 'input-kvs',
|
type: 'input-kvs',
|
||||||
name: 'fields',
|
name: 'inputVariables',
|
||||||
|
label: '输入变量',
|
||||||
addButtonText: '新增入参',
|
addButtonText: '新增入参',
|
||||||
draggable: false,
|
draggable: false,
|
||||||
keyItem: {
|
keyItem: {
|
||||||
label: '参数名称',
|
label: '参数名称',
|
||||||
|
...horizontalFormOptions(),
|
||||||
},
|
},
|
||||||
valueItems: [
|
valueItems: [
|
||||||
{
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
type: 'input-text',
|
type: 'input-text',
|
||||||
name: 'description',
|
name: 'description',
|
||||||
label: '参数描述',
|
label: '参数描述',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
...horizontalFormOptions(),
|
||||||
type: 'select',
|
type: 'select',
|
||||||
name: 'type',
|
name: 'type',
|
||||||
label: '参数类型',
|
label: '参数类型',
|
||||||
|
|||||||
@@ -274,6 +274,15 @@ export function serviceLogByAppNameAndHost(name: string, host: string) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function horizontalFormOptions() {
|
||||||
|
return {
|
||||||
|
mode: 'horizontal',
|
||||||
|
horizontal: {
|
||||||
|
leftFixed: 'sm'
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function crudCommonOptions() {
|
export function crudCommonOptions() {
|
||||||
return {
|
return {
|
||||||
affixHeader: false,
|
affixHeader: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user