feat(web): 输出节点增加输出类型
This commit is contained in:
@@ -1,22 +1,75 @@
|
|||||||
import type {NodeProps} from '@xyflow/react'
|
import type {NodeProps} from '@xyflow/react'
|
||||||
|
import {Tag} from 'antd'
|
||||||
import React, {useCallback} from 'react'
|
import React, {useCallback} from 'react'
|
||||||
import {useContextStore} from '../store/ContextStore.ts'
|
import {useContextStore} from '../store/ContextStore.ts'
|
||||||
import {useDataStore} from '../store/DataStore.ts'
|
import {useDataStore} from '../store/DataStore.ts'
|
||||||
import {useFlowStore} from '../store/FlowStore.ts'
|
import {useFlowStore} from '../store/FlowStore.ts'
|
||||||
import AmisNode, {EndNodeHandler, inputsFormColumns} from './AmisNode.tsx'
|
import AmisNode, {EndNodeHandler, inputsFormColumns} from './AmisNode.tsx'
|
||||||
|
|
||||||
|
const typeMap: Record<string, string> = {
|
||||||
|
markdown: 'Markdown',
|
||||||
|
json: 'JSON',
|
||||||
|
'template-markdown': 'Markdown 模板',
|
||||||
|
'template-rich-text': '富文本模板',
|
||||||
|
}
|
||||||
|
|
||||||
const OutputNode = (props: NodeProps) => {
|
const OutputNode = (props: NodeProps) => {
|
||||||
const {getNodes, getEdges} = useFlowStore()
|
const {getNodes, getEdges} = useFlowStore()
|
||||||
const {getData} = useDataStore()
|
const {getData, getDataById} = useDataStore()
|
||||||
const {getInputSchema} = useContextStore()
|
const {getInputSchema} = useContextStore()
|
||||||
|
|
||||||
|
const nodeData = getDataById(props.id)
|
||||||
|
|
||||||
const columnsSchema = useCallback(
|
const columnsSchema = useCallback(
|
||||||
() => inputsFormColumns(props.id, getInputSchema(), getNodes(), getEdges(), getData()),
|
() => [
|
||||||
|
...inputsFormColumns(props.id, getInputSchema(), getNodes(), getEdges(), getData()),
|
||||||
|
{
|
||||||
|
type: 'divider',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'select',
|
||||||
|
name: 'type',
|
||||||
|
label: '输出类型',
|
||||||
|
required: true,
|
||||||
|
selectFirst: true,
|
||||||
|
options: Object.keys(typeMap).map(key => ({label: typeMap[key], value: key})),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
visibleOn: 'type === \'template-markdown\'',
|
||||||
|
type: 'editor',
|
||||||
|
required: true,
|
||||||
|
label: '模板内容',
|
||||||
|
name: 'template',
|
||||||
|
language: 'markdown',
|
||||||
|
options: {
|
||||||
|
wordWrap: 'bounded',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
visibleOn: 'type === \'template-rich-text\'',
|
||||||
|
type: 'input-rich-text',
|
||||||
|
required: true,
|
||||||
|
name: 'template',
|
||||||
|
label: '模板内容',
|
||||||
|
options: {
|
||||||
|
min_height: 500,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
[props.id],
|
[props.id],
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AmisNode
|
<AmisNode
|
||||||
nodeProps={props}
|
nodeProps={props}
|
||||||
|
extraNodeDescription={
|
||||||
|
nodeData?.type
|
||||||
|
? <div className="mt-2 flex justify-between">
|
||||||
|
<span>输出类型</span>
|
||||||
|
<Tag className="m-0" color="blue">{typeMap[nodeData.type]}</Tag>
|
||||||
|
</div>
|
||||||
|
: <></>
|
||||||
|
}
|
||||||
columnSchema={columnsSchema}
|
columnSchema={columnsSchema}
|
||||||
handler={<EndNodeHandler/>}
|
handler={<EndNodeHandler/>}
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user