From 3cedfede6934fcdabe7394d8a88d1826e72e78e2 Mon Sep 17 00:00:00 2001
From: wujingjing <gersonwu@qq.com>
Date: 星期五, 13 十二月 2024 17:14:09 +0800
Subject: [PATCH] Merge branch 'test' of http://47.103.154.90:83/r/WI/Web.Admin.V1.0 into test

---
 src/views/project/yw/dataManage/workFlowMgr/WorkFlowIndex.vue |  128 ++++++++++++++++++++++++++----------------
 1 files changed, 78 insertions(+), 50 deletions(-)

diff --git a/src/views/project/yw/dataManage/workFlowMgr/WorkFlowIndex.vue b/src/views/project/yw/dataManage/workFlowMgr/WorkFlowIndex.vue
index bea9012..5fd21c1 100644
--- a/src/views/project/yw/dataManage/workFlowMgr/WorkFlowIndex.vue
+++ b/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,73 @@
 			ElMessage.success('鍒犻櫎宸ヤ綔娴佹垚鍔�');
 			const index = tableData.value.findIndex((d) => d.id === row.id);
 			tableData.value.splice(index, 1);
+			work_update_data.value = work_update_data.value.filter((work) => work.id !== row.id);
+			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) => {
+	console.log('馃殌 ~ work_Data:', work_Data);
+	let new_tree_Data = [];
+	tree_Data.forEach((node, index) => {
+		if (node.group_type == OptClassificationMap[classificationEnum.Knowledge]) {
+			new_tree_Data.push(node);
+		}
+	});
+	console.log('馃殌 ~ new_tree_Data:', new_tree_Data);
+	// 涓烘瘡涓妭鐐瑰叧鑱斿伐浣滄祦鏁版嵁
+	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 +286,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
 

--
Gitblit v1.9.3