wujingjing
2024-12-13 aa4ca7f747ca6be14b7ffc71ac84966be1e3689f
src/views/project/yw/dataManage/workFlowMgr/WorkFlowIndex.vue
@@ -154,62 +154,23 @@
//#region ====================== 工作流列表 ======================
const workFlowDataLoading = ref(false);
const isFormulaTableDrag = ref(false);
const workFlowTableData = ref([]);
const tree_update_data = ref([]);
const work_update_data = ref([]);
const tableData = ref([]);
//获取场景list
const initData = async () => {
   const [treeData, workData] = await Promise.all([agentGroupApi.getSceneGroupTreeByPost(), get_workflow_agent_list()]);
   const tree_Data = treeData.groups ?? [];
   const work_Data = workData.values ?? [];
   let result = [];
   let new_tree_Data = [];
   tree_Data.forEach((node, index) => {
      if (node.group_type == OptClassificationMap[classificationEnum.Knowledge]) {
         new_tree_Data.push(node);
      }
   });
   new_tree_Data.forEach((node, index) => {
      node.sampleList = [];
      work_Data.forEach((work, index) => {
         if (node.group_id == work.agent_group) {
            let work_obj = {
               ...work,
               published: work.published,
               create_user: work.create_user,
               create_time: work.create_time,
               prompt: work.supervisor.prompt,
               note: work.note,
            };
            node.sampleList.push(work_obj);
         }
      });
      if (node.p_group_id) {
         node.group_name = `${node.group_name} (${node.sampleList.length})`;
      }
   });
   const byParentData = convertListToTree(new_tree_Data, {
      ID: 'group_id',
      ParentID: 'p_group_id',
      Children: 'children',
   });
   byParentData.forEach((item) => {
      if (item.children && item.children.length > 0) {
         item.children.forEach((child_node) => {
            item.sampleList = item.sampleList.concat(child_node.sampleList);
         });
      }
      result.push(item);
      item.group_name = `${item.group_name} (${item.sampleList.length})`;
   });
   listLeftData.value = byParentData;
   const firstListTreeNode = byParentData[0];
   tree_update_data.value = tree_Data;
   work_update_data.value = work_Data;
   const byParent_Data = updateSampleListsAndGroupNames(tree_Data, work_Data);
   listLeftData.value = byParent_Data;
   const firstListTreeNode = byParent_Data[0];
   tableData.value = firstListTreeNode.sampleList;
   currentNode.value = firstListTreeNode;
};
// 删除一条数据
const deleteCurrentFormulaRow = (row: any) => {
   ElMessageBox.confirm(`确定删除工作流:【${row.title}】?`, '提示', {
      confirmButtonText: '确定',
@@ -224,14 +185,69 @@
         ElMessage.success('删除工作流成功');
         const index = tableData.value.findIndex((d) => d.id === row.id);
         tableData.value.splice(index, 1);
         removeDataAndRecalculateGroupNames(tree_update_data.value, work_update_data.value, row.id);
      } else {
         ElMessage.error('删除工作流失败' + (res?.json_msg ? `,${JSON.stringify(res.json_msg)}` : ''));
      }
   });
};
// 更新树形结构和工作流列表
const updateSampleListsAndGroupNames = (tree_Data, work_Data) => {
   let new_tree_Data = [];
   tree_Data.forEach((node, index) => {
      if (node.group_type == OptClassificationMap[classificationEnum.Knowledge]) {
         new_tree_Data.push(node);
      }
   });
   // 为每个节点关联工作流数据
   new_tree_Data.forEach((node) => {
      node.sampleList = work_Data
         .filter((work) => work.agent_group === node.group_id)
         .map((work) => ({
            ...work,
            published: work.published,
            create_user: work.create_user,
            create_time: work.create_time,
            prompt: work.supervisor.prompt,
            note: work.note,
         }));
      if (node.p_group_id) {
         node.group_name = node.group_name.replace(/ \([^)]*\)$/, '') + ` (${node.sampleList.length})`;
      }
   });
const changeExample = (item) => {
   openChatTest(item);
   // 将列表转换为树形结构
   const byParentData = convertListToTree(new_tree_Data, {
      ID: 'group_id',
      ParentID: 'p_group_id',
      Children: 'children',
   });
   // 合并子节点的工作流列表,并更新组名
   byParentData.forEach((item) => {
      if (item.children && item.children.length > 0) {
         item.children.forEach((child_node) => {
            item.sampleList = item.sampleList.concat(child_node.sampleList);
         });
      }
      item.group_name = item.group_name.replace(/ \([^)]*\)$/, '') + ` (${item.sampleList.length})`;
   });
   return byParentData;
};
// 插入一条数据时调用
const addDataAndRecalculateGroupNames = (new_tree_Data, work_Data, newWorkData) => {
   // 添加新数据到 work_Data
   work_Data.push(newWorkData);
   // 重新计算工作流列表和组名
   return updateSampleListsAndGroupNames(new_tree_Data, work_Data);
};
// 删除一条数据时调用
const removeDataAndRecalculateGroupNames = (new_tree_Data, work_Data, workIdToRemove) => {
   // 过滤掉要删除的数据
   work_Data = work_Data.filter((work) => work.id !== workIdToRemove);
   // 重新计算工作流列表和组名
   return updateSampleListsAndGroupNames(new_tree_Data, work_Data);
};
//#endregion
@@ -266,7 +282,15 @@
};
//新增一条信息
const insertOpt = (newData) => {
   tableData.value.unshift({ ...newData });
   const itemToAdd = {
      ...newData,
      supervisor: {
         ...newData.supervisor, // 保留原有的 supervisor 属性
         prompt: newData.prompt, // 但确保 prompt 是最新的
      },
   };
   tableData.value.unshift(itemToAdd);
   addDataAndRecalculateGroupNames(tree_update_data.value, work_update_data.value, itemToAdd);
};
//#endregion