|
|
|
|
@ -6,7 +6,7 @@ import { updateCanvasDataMap } from '@/store/ideContainer';
|
|
|
|
|
|
|
|
|
|
import { Dispatch } from 'redux';
|
|
|
|
|
|
|
|
|
|
export const useFlowEditorState = (initialData?: any) => {
|
|
|
|
|
export const useFlowEditorState = (initialData?: any, readOnly?: boolean) => {
|
|
|
|
|
const [nodes, setNodes] = useState<Node[]>([]);
|
|
|
|
|
const [edges, setEdges] = useState<Edge[]>([]);
|
|
|
|
|
|
|
|
|
|
@ -63,22 +63,33 @@ export const useFlowEditorState = (initialData?: any) => {
|
|
|
|
|
|
|
|
|
|
setNodes(prevNodes =>{
|
|
|
|
|
return prevNodes.map(node => {
|
|
|
|
|
// 优先使用运行时状态,其次使用节点自身的状态(历史实例),最后默认为 waiting
|
|
|
|
|
const nodeStatus = currentNodeStatusMap[node.id] || node.data.status || 'waiting';
|
|
|
|
|
// 如果是只读模式(历史实例查看),优先使用节点自身的历史状态
|
|
|
|
|
// 如果是正常运行模式,只使用运行时状态
|
|
|
|
|
let nodeStatus = 'waiting';
|
|
|
|
|
let showStatus = false;
|
|
|
|
|
|
|
|
|
|
if (readOnly) {
|
|
|
|
|
// 只读模式:使用历史状态
|
|
|
|
|
nodeStatus = node.data.status as string || 'waiting';
|
|
|
|
|
showStatus = hasInitialDataStatus as boolean || node.data.isStatusVisible as boolean || false;
|
|
|
|
|
} else {
|
|
|
|
|
// 正常模式:只使用运行时状态
|
|
|
|
|
nodeStatus = currentNodeStatusMap[node.id] || 'waiting';
|
|
|
|
|
showStatus = currentAppIsRunning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...node,
|
|
|
|
|
data: {
|
|
|
|
|
...node.data,
|
|
|
|
|
status: nodeStatus,
|
|
|
|
|
// 在运行时或有历史状态时显示状态指示器
|
|
|
|
|
isStatusVisible: currentAppIsRunning || hasInitialDataStatus || node.data.isStatusVisible
|
|
|
|
|
isStatusVisible: showStatus
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}, [appRuntimeData, currentAppKey, currentAppIsRunning, initialData?.id, initialData?.components, nodes.length]);
|
|
|
|
|
}, [appRuntimeData, currentAppKey, currentAppIsRunning, initialData?.id, initialData?.components, nodes.length, readOnly]);
|
|
|
|
|
|
|
|
|
|
const updateCanvasDataMapDebounced = useRef(
|
|
|
|
|
debounce((dispatch: Dispatch<any>, canvasDataMap: any, id: string, nodes: Node[], edges: Edge[]) => {
|
|
|
|
|
|