fix: 修复管理端前端 lint 与构建问题

- 收敛 easyflow-ui-admin 的 lint、格式和类型问题

- 修正 demo 页面与管理端前端构建失败点

- 验证 pnpm lint 与 pnpm build 均已通过
This commit is contained in:
2026-04-05 21:39:13 +08:00
parent bb72e19c84
commit 7e7c236c2a
240 changed files with 5151 additions and 4701 deletions

View File

@@ -1,154 +1,172 @@
import {type Edge, type Node, useNodesData, useStore} from '@xyflow/svelte';
import type {Parameter} from '#types';
import {getCurrentNodeId, getOptions} from '#components/utils/NodeUtils';
import {nodeIcons} from '../../consts';
import { type Edge, type Node, useNodesData, useStore } from '@xyflow/svelte';
import type { Parameter } from '#types';
import { getCurrentNodeId, getOptions } from '#components/utils/NodeUtils';
import { nodeIcons } from '../../consts';
const fillRefNodeIds = (refNodeIds: string[], currentNodeId: string, edges: Edge[]) => {
for (const edge of edges) {
if (edge.target === currentNodeId && edge.source) {
refNodeIds.push(edge.source);
fillRefNodeIds(refNodeIds, edge.source, edges);
}
const fillRefNodeIds = (
refNodeIds: string[],
currentNodeId: string,
edges: Edge[],
) => {
for (const edge of edges) {
if (edge.target === currentNodeId && edge.source) {
refNodeIds.push(edge.source);
fillRefNodeIds(refNodeIds, edge.source, edges);
}
}
};
const getChildren = (params: any, parentId: string, nodeIsChildren: boolean, nodeType: string) => {
if (!params || params.length === 0) return [];
return params.map((param: any) => {
const getChildren = (
params: any,
parentId: string,
nodeIsChildren: boolean,
nodeType: string,
) => {
if (!params || params.length === 0) return [];
return params.map((param: any) => {
const dataType = nodeIsChildren
? `Array<${param.dataType || 'String'}>`
: param.dataType || 'String';
return {
label: param.name,
dataType: dataType,
value: parentId + '.' + param.name,
selectable: true,
nodeType: nodeType,
children: getChildren(
param.children,
parentId + '.' + param.name,
nodeIsChildren,
nodeType,
),
};
});
};
const nodeToOptions = (
node: Node,
nodeIsChildren: boolean,
currentNode: Node,
) => {
const options = getOptions();
const nodeType = node.type || '';
let icon: string | undefined = nodeIcons[nodeType];
if (!icon && options?.customNodes && options.customNodes[nodeType]) {
icon = options.customNodes[nodeType].icon;
}
// 如果仍然获取不到,尝试使用 data.icon (作为回退)
if (!icon && node.data && node.data.icon) {
icon = node.data.icon as string;
}
const title = node.data.title;
if (nodeType === 'startNode') {
const parameters = node.data.parameters as Array<Parameter>;
const children = [];
if (parameters)
for (const parameter of parameters) {
const dataType = nodeIsChildren
? `Array<${param.dataType || 'String'}>`
: (param.dataType || 'String');
return {
label: param.name,
dataType: dataType,
value: parentId + '.' + param.name,
selectable: true,
nodeType: nodeType,
children: getChildren(param.children, parentId + '.' + param.name, nodeIsChildren, nodeType)
};
});
};
const nodeToOptions = (node: Node, nodeIsChildren: boolean, currentNode: Node) => {
const options = getOptions();
const nodeType = node.type || '';
let icon: string | undefined = nodeIcons[nodeType];
if (!icon && options?.customNodes && options.customNodes[nodeType]) {
icon = options.customNodes[nodeType].icon;
}
// 如果仍然获取不到,尝试使用 data.icon (作为回退)
if (!icon && node.data && node.data.icon) {
icon = node.data.icon as string;
}
const title = node.data.title;
if (nodeType === 'startNode') {
const parameters = node.data.parameters as Array<Parameter>;
const children = [];
if (parameters)
for (const parameter of parameters) {
const dataType = nodeIsChildren
? `Array<${parameter.dataType || 'String'}>`
: (parameter.dataType || 'String');
children.push({
label: parameter.name,
dataType: dataType,
value: node.id + '.' + parameter.name,
selectable: true,
nodeType: nodeType
});
}
return {
label: title,
icon: icon,
value: node.id,
selectable: false,
nodeType: nodeType,
children
};
} else if (nodeType === 'loopNode' && currentNode.parentId) {
return {
label: title,
icon: icon,
value: node.id,
selectable: false,
nodeType: nodeType,
children: [
{
label: 'loopItem',
dataType: 'Any',
value: node.id + '.loopItem',
selectable: true,
nodeType: nodeType
},
{
label: 'index',
dataType: 'Number',
value: node.id + '.index',
selectable: true,
nodeType: nodeType
}
]
};
} else {
const outputDefs = node.data.outputDefs;
if (outputDefs) {
return {
label: title,
icon: icon,
value: node.id,
selectable: false,
nodeType: nodeType,
children: getChildren(outputDefs, node.id, nodeIsChildren, nodeType)
};
}
? `Array<${parameter.dataType || 'String'}>`
: parameter.dataType || 'String';
children.push({
label: parameter.name,
dataType: dataType,
value: node.id + '.' + parameter.name,
selectable: true,
nodeType: nodeType,
});
}
return {
label: title,
icon: icon,
value: node.id,
selectable: false,
nodeType: nodeType,
children,
};
} else if (nodeType === 'loopNode' && currentNode.parentId) {
return {
label: title,
icon: icon,
value: node.id,
selectable: false,
nodeType: nodeType,
children: [
{
label: 'loopItem',
dataType: 'Any',
value: node.id + '.loopItem',
selectable: true,
nodeType: nodeType,
},
{
label: 'index',
dataType: 'Number',
value: node.id + '.index',
selectable: true,
nodeType: nodeType,
},
],
};
} else {
const outputDefs = node.data.outputDefs;
if (outputDefs) {
return {
label: title,
icon: icon,
value: node.id,
selectable: false,
nodeType: nodeType,
children: getChildren(outputDefs, node.id, nodeIsChildren, nodeType),
};
}
}
};
export const useRefOptions: any = (useChildrenOnly: boolean = false) => {
const currentNodeId = getCurrentNodeId();
const currentNode = useNodesData(currentNodeId);
const { nodes, edges, nodeLookup } = $derived(useStore());
const currentNodeId = getCurrentNodeId();
const currentNode = useNodesData(currentNodeId);
const { nodes, edges, nodeLookup } = $derived(useStore());
let selectItems = $derived.by(() => {
const resultOptions = [];
if (!currentNode.current) {
return [];
let selectItems = $derived.by(() => {
const resultOptions = [];
if (!currentNode.current) {
return [];
}
//通过 nodeLookup.get 才会得到有 parentId 的 node
const cNode = nodeLookup.get(currentNodeId)!;
if (useChildrenOnly) {
for (const node of nodes) {
const nodeIsChildren = node.parentId === currentNode.current.id;
if (nodeIsChildren) {
const nodeOptions = nodeToOptions(node, nodeIsChildren, cNode);
nodeOptions && resultOptions.push(nodeOptions);
}
}
} else {
const refNodeIds: string[] = [];
fillRefNodeIds(refNodeIds, currentNodeId, edges);
//通过 nodeLookup.get 才会得到有 parentId 的 node
const cNode = nodeLookup.get(currentNodeId)!;
if (useChildrenOnly) {
for (const node of nodes) {
const nodeIsChildren = node.parentId === currentNode.current.id;
if (nodeIsChildren) {
const nodeOptions = nodeToOptions(node, nodeIsChildren, cNode);
nodeOptions && resultOptions.push(nodeOptions);
}
}
} else {
const refNodeIds: string[] = [];
fillRefNodeIds(refNodeIds, currentNodeId, edges);
for (const node of nodes) {
if (refNodeIds.includes(node.id)) {
const nodeIsChildren = node.parentId === currentNode.current.id;
const nodeOptions = nodeToOptions(node, nodeIsChildren, cNode);
nodeOptions && resultOptions.push(nodeOptions);
}
}
for (const node of nodes) {
if (refNodeIds.includes(node.id)) {
const nodeIsChildren = node.parentId === currentNode.current.id;
const nodeOptions = nodeToOptions(node, nodeIsChildren, cNode);
nodeOptions && resultOptions.push(nodeOptions);
}
}
}
return resultOptions;
});
return resultOptions;
});
return {
get current() {
return selectItems;
}
};
return {
get current() {
return selectItems;
},
};
};