feat:【ele】【ai】工作流的代码迁移

This commit is contained in:
YunaiV
2025-11-15 09:26:36 +08:00
parent dc68abd4d9
commit 51fb4b479e
8 changed files with 985 additions and 88 deletions

View File

@@ -28,43 +28,52 @@ const [Drawer, drawerApi] = useVbenDrawer({
footer: false,
closeOnClickModal: false,
modal: false,
onOpenChange(isOpen: boolean) {
if (!isOpen) {
return;
}
try {
// 查找 start 节点
const startNode = getStartNode();
// 获取参数定义
const parameters: any[] = (startNode.data?.parameters as any[]) || [];
const paramDefinitions: Record<string, any> = {};
// 加入参数选项方便用户添加非必须参数
parameters.forEach((param: any) => {
paramDefinitions[param.name] = param;
});
// 自动装载需必填的参数
function mergeIfRequiredButNotSet(target: any[]) {
const needPushList = [];
for (const key in paramDefinitions) {
const param = paramDefinitions[key];
if (param.required) {
const item = target.find((item: any) => item.key === key);
if (!item) {
needPushList.push({
key: param.name,
value: param.defaultValue || '',
});
}
}
}
target.push(...needPushList);
}
mergeIfRequiredButNotSet(params4Test.value);
// 设置参数
paramsOfStartNode.value = paramDefinitions;
} catch (error) {
console.error('加载参数失败:', error);
}
},
});
/** 展示工作流测试抽屉 */
function testWorkflowModel() {
drawerApi.open();
const startNode = getStartNode();
// 获取参数定义
const parameters: any[] = (startNode.data?.parameters as any[]) || [];
const paramDefinitions: Record<string, any> = {};
// 加入参数选项方便用户添加非必须参数
parameters.forEach((param: any) => {
paramDefinitions[param.name] = param;
});
function mergeIfRequiredButNotSet(target: any) {
const needPushList = [];
for (const key in paramDefinitions) {
const param = paramDefinitions[key];
if (param.required) {
const item = target.find((item: any) => item.key === key);
if (!item) {
needPushList.push({
key: param.name,
value: param.defaultValue || '',
});
}
}
}
target.push(...needPushList);
}
// 自动装载需必填的参数
mergeIfRequiredButNotSet(params4Test.value);
paramsOfStartNode.value = paramDefinitions;
}
/** 运行流程 */
@@ -74,27 +83,26 @@ async function goRun() {
loading.value = true;
error.value = null;
testResult.value = null;
// / 查找start节点
const startNode = getStartNode();
// 查找start节点
const startNode = getStartNode();
// 获取参数定义
const parameters: any[] = (startNode.data?.parameters as any[]) || [];
const paramDefinitions: Record<string, any> = {};
parameters.forEach((param: any) => {
paramDefinitions[param.name] = param.dataType;
});
// 参数类型转换
const convertedParams: Record<string, any> = {};
for (const { key, value } of params4Test.value) {
const paramKey = key.trim();
if (!paramKey) continue;
if (!paramKey) {
continue;
}
let dataType = paramDefinitions[paramKey];
if (!dataType) {
dataType = 'String';
}
try {
convertedParams[paramKey] = convertParamValue(value, dataType);
} catch (error: any) {
@@ -102,13 +110,11 @@ async function goRun() {
}
}
const data = {
// 执行测试请求
testResult.value = await testWorkflow({
graph: JSON.stringify(val),
params: convertedParams,
};
const response = await testWorkflow(data);
testResult.value = response;
});
} catch (error: any) {
error.value =
error.response?.data?.message || '运行失败,请检查参数和网络连接';
@@ -120,6 +126,7 @@ async function goRun() {
/** 获取开始节点 */
function getStartNode() {
if (tinyflowRef.value) {
// TODO @xingyu不确定是不是这里封装了 Tinyflow现在 .getData() 会报错;
const val = tinyflowRef.value.getData();
const startNode = val!.nodes.find((node: any) => node.type === 'startNode');
if (!startNode) {
@@ -142,8 +149,9 @@ function removeParam(index: number) {
/** 类型转换函数 */
function convertParamValue(value: string, dataType: string) {
if (value === '') return null; // 空值处理
if (value === '') {
return null;
}
switch (dataType) {
case 'Number': {
const num = Number(value);
@@ -154,8 +162,12 @@ function convertParamValue(value: string, dataType: string) {
return String(value);
}
case 'Boolean': {
if (value.toLowerCase() === 'true') return true;
if (value.toLowerCase() === 'false') return false;
if (value.toLowerCase() === 'true') {
return true;
}
if (value.toLowerCase() === 'false') {
return false;
}
throw new Error('必须为 true/false');
}
case 'Array':
@@ -171,9 +183,9 @@ function convertParamValue(value: string, dataType: string) {
}
}
}
/** 表单校验 */
async function validate() {
// 获取最新的流程数据
if (!workflowData.value || !tinyflowRef.value) {
throw new Error('请设计流程');
}