feat(web): 增加编辑侧边栏关闭时保存节点数据

This commit is contained in:
2025-06-23 20:15:32 +08:00
parent 73e6ff3c54
commit df6f1eb548

View File

@@ -1,4 +1,4 @@
import {DeleteFilled, EditFilled, FolderFilled, PlusCircleFilled, SaveFilled} from '@ant-design/icons' import {DeleteFilled, EditFilled, PlusCircleFilled, SaveFilled} from '@ant-design/icons'
import { import {
addEdge, addEdge,
applyEdgeChanges, applyEdgeChanges,
@@ -34,6 +34,14 @@ const FlowableDiv = styled.div`
z-index: 999; z-index: 999;
position: absolute; position: absolute;
} }
.node-card {
cursor: grab;
.card-container {
cursor: default;
}
}
` `
type AmisNodeType = 'normal' | 'start' | 'end' type AmisNodeType = 'normal' | 'start' | 'end'
@@ -46,15 +54,17 @@ const AmisNode = (
columnSchema?: Schema[], columnSchema?: Schema[],
) => { ) => {
const {id, data} = props const {id, data} = props
const {removeNode, editNode} = data const {getDataById, removeNode, editNode} = data
return ( return (
<div className="p-1 w-64"> <div className="p-1 w-64">
<Card <Card
className="node-card"
title={name} title={name}
size="small" size="small"
hoverable hoverable
> >
<Dropdown <Dropdown
className="card-container"
trigger={['contextMenu']} trigger={['contextMenu']}
menu={{ menu={{
items: [ items: [
@@ -80,7 +90,7 @@ const AmisNode = (
removeNode(id) removeNode(id)
break break
} }
} },
}} }}
> >
<div className="card-description p-2 text-secondary text-sm"> <div className="card-description p-2 text-secondary text-sm">
@@ -258,7 +268,7 @@ const useFlowStore = create<{
addNode: node => set({nodes: get().nodes.concat(node)}), addNode: node => set({nodes: get().nodes.concat(node)}),
removeNode: id => { removeNode: id => {
set({ set({
nodes: filter(get().nodes, node => !isEqual(node.id, id)) nodes: filter(get().nodes, node => !isEqual(node.id, id)),
}) })
}, },
setNodes: nodes => set({nodes}), setNodes: nodes => set({nodes}),
@@ -302,7 +312,6 @@ function Test() {
}, },
]) ])
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const onClose = () => setOpen(false)
const {getData, getDataById, setDataById} = useStore() const {getData, getDataById, setDataById} = useStore()
const { const {
@@ -323,28 +332,70 @@ function Test() {
setCurrentNodeForm( setCurrentNodeForm(
amisRender( amisRender(
{ {
debug: commonInfo.debug, type: 'wrapper',
title: name, size: 'none',
type: 'form', body: [
wrapWithPanel: false, {
onEvent: { type: 'tpl',
change: { className: 'text-secondary',
actions: [ tpl: description,
},
{
debug: commonInfo.debug,
title: name,
type: 'form',
wrapWithPanel: false,
onEvent: {
submitSucc: {
actions: [
{
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
setDataById(id, context.props.data)
setOpen(false)
},
},
],
},
},
body: [
...(columnSchema ?? []),
{ {
actionType: 'custom', type: 'wrapper',
// @ts-ignore size: 'none',
script: (context, action, event) => { className: 'space-x-1 float-right',
console.log(id, context.props.data) body: [
setDataById(id, context.props.data) {
}, type: 'action',
} label: '取消',
] onEvent: {
} click: {
}, actions: [
body: columnSchema, {
actionType: 'custom',
// @ts-ignore
script: (context, action, event) => {
setOpen(false)
},
},
],
},
},
},
{
type: 'submit',
label: '保存',
level: 'primary',
},
],
},
],
},
]
}, },
getDataById(id), getDataById(id),
) ),
) )
setOpen(true) setOpen(true)
} }
@@ -407,7 +458,8 @@ function Test() {
<Drawer <Drawer
title="节点编辑" title="节点编辑"
open={open} open={open}
onClose={onClose} closeIcon={false}
maskClosable={false}
destroyOnHidden destroyOnHidden
> >
{currentNodeForm} {currentNodeForm}