@@ -17,10 +17,11 @@ import { safeJsonStringify, uuid } from '../../utils';
17
17
18
18
interface INodeEditorProps {
19
19
data : any ;
20
- onChange : ( data : any ) => void ;
20
+ onChange : ( data : any , id ?: string ) => void ;
21
21
nodeType : string ;
22
22
id : string ;
23
23
ref ?: React . Ref < any > ; // 添加 ref 属性
24
+ // activeNode?: any;
24
25
}
25
26
26
27
const NodeEditor : FC < INodeEditorProps > = forwardRef ( ( props , ref : any ) => {
@@ -35,6 +36,20 @@ const NodeEditor: FC<INodeEditorProps> = forwardRef((props, ref: any) => {
35
36
const getSettingSchema = nodeSetting [ 'getSettingSchema' ] ;
36
37
const [ asyncSchema , setAsyncSchema ] = useState < Schema > ( { } ) ;
37
38
const nodeWidgetRef = useRef ( null ) ;
39
+ const { nodes, setNodes } = useStore (
40
+ ( state : any ) => ( {
41
+ nodes : state . nodes ,
42
+ setNodes : state . setNodes ,
43
+ } ) ,
44
+ shallow
45
+ ) ;
46
+ const [ internalData , setInternalData ] = useState ( ) ;
47
+
48
+ useEffect ( ( ) => {
49
+ const activeNode = nodes . find ( node => node . id === id ) ;
50
+ const { _nodeType, _status, ...restData } = activeNode ?. data || { } ;
51
+ setInternalData ( restData ) ;
52
+ } , [ ] ) ;
38
53
39
54
useImperativeHandle ( ref , ( ) => ( {
40
55
validateForm : async ( ) => {
@@ -51,7 +66,10 @@ const NodeEditor: FC<INodeEditorProps> = forwardRef((props, ref: any) => {
51
66
. catch ( err => {
52
67
return false ;
53
68
} ) ;
54
- } else if ( nodeSetting ?. settingWidget && nodeWidgetRef . current ?. validateForm ) {
69
+ } else if (
70
+ nodeSetting ?. settingWidget &&
71
+ nodeWidgetRef . current ?. validateForm
72
+ ) {
55
73
result = await nodeWidgetRef . current . validateForm ( ) ;
56
74
}
57
75
return result ;
@@ -68,20 +86,13 @@ const NodeEditor: FC<INodeEditorProps> = forwardRef((props, ref: any) => {
68
86
) . catch ( ( ) => ( { } ) ) ;
69
87
setAsyncSchema ( shema ) ;
70
88
}
89
+
71
90
useEffect ( ( ) => {
72
91
if ( isFunction ( getSettingSchema ) ) {
73
92
getSchema ( ) ;
74
93
}
75
94
} , [ ] ) ;
76
95
77
- const { nodes, setNodes } = useStore (
78
- ( state : any ) => ( {
79
- nodes : state . nodes ,
80
- setNodes : state . setNodes ,
81
- } ) ,
82
- shallow
83
- ) ;
84
-
85
96
useEffect ( ( ) => {
86
97
if ( nodeSetting ?. settingSchema ) {
87
98
// 自定义Schema
@@ -115,14 +126,14 @@ const NodeEditor: FC<INodeEditorProps> = forwardRef((props, ref: any) => {
115
126
if ( item ?. _id ) {
116
127
return item ;
117
128
} else {
118
- if ( node ?. data ?. list ?. length && node ?. data ?. list [ index ] ?. _id ) {
119
- return {
120
- ...item ,
121
- _id : node ?. data ?. list [ index ] ?. _id ,
122
- } ;
123
- } else {
124
- return { ...item , _id : `id_${ uuid ( ) } ` } ;
125
- }
129
+ // if (node?.data?.list?.length && node?.data?.list[index]?._id) {
130
+ // return {
131
+ // ...item,
132
+ // _id: node?.data?.list[index]?._id,
133
+ // };
134
+ // } else {
135
+ return { ...item , _id : `id_${ uuid ( ) } ` } ;
136
+ // }
126
137
}
127
138
} ) ;
128
139
}
@@ -131,6 +142,11 @@ const NodeEditor: FC<INodeEditorProps> = forwardRef((props, ref: any) => {
131
142
}
132
143
} ) ;
133
144
setNodes ( newNodes , false ) ;
145
+
146
+ // if (onChange) {
147
+ // onChange(data, id);
148
+ // }
149
+ setInternalData ( data ) ;
134
150
} , 100 ) ;
135
151
136
152
const watch = {
@@ -193,7 +209,8 @@ const NodeEditor: FC<INodeEditorProps> = forwardRef((props, ref: any) => {
193
209
onChange = { val => {
194
210
handleNodeValueChange ( { ...val } ) ;
195
211
} }
196
- value = { data }
212
+ value = { internalData } // data
213
+ // value={data}
197
214
readOnly = { readOnly }
198
215
/>
199
216
) ;
0 commit comments