优化工作流组件,增强节点数据处理的可选性和安全性,修复潜在的空值引用问题。

This commit is contained in:
2026-05-29 10:19:53 +08:00
parent 032f258912
commit 78d1fd93c8
3 changed files with 92 additions and 81 deletions

View File

@@ -55,9 +55,9 @@ import { ref, computed } from 'vue';
import type { Node } from '@vue-flow/core';
interface NodeData {
label: string;
nodeCode: string;
inputSource: Array<{ nodeId: string; field: string[]; quoteOutput?: boolean }> | null;
label?: string;
nodeCode?: string;
inputSource?: Array<{ nodeId: string; field: string[]; quoteOutput?: boolean }> | null;
formConfig?: any[];
modelConfig?: any;
skillName?: string;
@@ -74,8 +74,8 @@ interface ParamOption {
}
const props = defineProps<{
selectedNode: Node<NodeData> | null;
nodes: Node<NodeData>[];
selectedNode: Node<NodeData, any, string> | null;
nodes: Node<NodeData, any, string>[];
edges: any[];
}>();
@@ -89,19 +89,19 @@ const selectedParam = ref('');
// 当前节点的 inputSource
const currentInputSource = computed(() => {
if (!props.selectedNode?.data.inputSource) return [];
if (!props.selectedNode?.data?.inputSource) return [];
return props.selectedNode.data.inputSource.filter((item) => item.field && item.field.length > 0);
});
// 获取节点名称
const getNodeName = (nodeId: string) => {
const node = props.nodes.find((n) => n.id === nodeId);
return node?.data.label || nodeId;
return node?.data?.label || nodeId;
};
// 获取所有上级节点(用于显示输出引用选项)
const availableParentNodes = computed(() => {
if (!props.selectedNode) return [];
if (!props.selectedNode?.data) return [];
// 获取已经引用了字段的节点ID列表
const inputSource = props.selectedNode.data.inputSource;
@@ -134,7 +134,7 @@ const availableParentNodes = computed(() => {
const parentNodes = allParentIds
.map((parentId) => {
const parentNode = props.nodes.find((n) => n.id === parentId);
if (!parentNode) return null;
if (!parentNode?.data) return null;
const nodeCode = String(parentNode.data.nodeCode || '').toLowerCase();
const isJudge = ['判断', 'judge', 'condition', 'if', 'branch', 'gateway'].some((k) => nodeCode.includes(k));
@@ -144,7 +144,7 @@ const availableParentNodes = computed(() => {
return {
id: parentId,
name: parentNode.data.label,
name: parentNode.data.label || parentId,
};
})
.filter(Boolean);
@@ -154,7 +154,7 @@ const availableParentNodes = computed(() => {
// 检查节点输出是否被引用
const isNodeOutputQuoted = (nodeId: string): boolean => {
if (!props.selectedNode) return false;
if (!props.selectedNode?.data) return false;
const inputSource = props.selectedNode.data.inputSource;
if (!Array.isArray(inputSource)) return false;
@@ -177,7 +177,7 @@ const availableParams = computed(() => {
.filter((e) => e.target === nodeId)
.forEach((edge) => {
const parent = props.nodes.find((n) => n.id === edge.source);
if (parent && parent.data.nodeCode !== '__start__' && parent.data.nodeCode !== 'judge') {
if (parent?.data && parent.data.nodeCode !== '__start__' && parent.data.nodeCode !== 'judge') {
params.push({
label: `${parent.data.label}.output`,
value: `\${${parent.id}.output}`,