Quellcode durchsuchen

node-red同步删除规则同时,删除掉当前规则下的所有配置点的信息

yanglzh vor 3 Jahren
Ursprung
Commit
8986eb0657
2 geänderte Dateien mit 54 neuen und 36 gelöschten Zeilen
  1. 26 17
      src/views/rule-engine/index.vue
  2. 28 19
      src/views/rule-engine/send.vue

+ 26 - 17
src/views/rule-engine/index.vue

@@ -108,28 +108,37 @@ const edit = async (row: any) => {
 	window.open(url);
 };
 
-const onDel = async (row: any) => {
-	// 找到所有规则
-	const { data: flows } = await axios.get(flowsUrl, { headers });
-
-	const flowIndex = flows.findIndex((item: any) => item.id === row.flowId);
-
-	if (!flowIndex) {
-		ElMessage.error('规则不存在');
-		return;
-	}
-
-	// 删除指定规则
-	flows.splice(flowIndex, 1);
-
-	// 设置规则状态
-	await axios.post(flowsUrl, flows, { headers });
-
+const onDel = (row: any) => {
 	ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, '提示', {
 		confirmButtonText: '确认',
 		cancelButtonText: '取消',
 		type: 'warning',
 	}).then(async () => {
+		// 找到所有规则
+		const { data: flows } = await axios.get(flowsUrl, { headers });
+
+		const flowIndex = flows.findIndex((item: any) => item.id === row.flowId);
+
+		if (flowIndex === -1) {
+			ElMessage.error('规则不存在');
+			return;
+		}
+
+		// 删除指定规则
+		flows.splice(flowIndex, 1);
+
+		// 删除当前规则下的各个节点信息
+		const newFlows = flows.filter((item: any) => {
+			if (item.z === row.flowId) {
+				return false;
+			} else {
+				return true;
+			}
+		});
+
+		// 设置规则状态
+		await axios.post(flowsUrl, newFlows, { headers });
+
 		await api.del([row.id as string]);
 		ElMessage.success('删除成功');
 		getList();

+ 28 - 19
src/views/rule-engine/send.vue

@@ -13,7 +13,7 @@
 						<el-icon>
 							<ele-FolderAdd />
 						</el-icon>
-						新增数据转发
+						新增规则编排
 					</el-button>
 				</el-form-item>
 			</el-form>
@@ -103,33 +103,42 @@ const setStatus = async (row: any, status: number) => {
 
 const edit = async (row: any) => {
 	localStorage.setItem('auth-tokens', `{"access_token":"${Session.get('token')}"}`);
-	// const url = window.location.protocol + '//' + window.location.hostname + ':1880/?access_token=' + Session.get('token') + '#flow/' + row.flowId;
+	// const url = window.location.protocol + '//' + window.location.hostname + ':1880/rule-engine?access_token=' + Session.get('token') + '#flow/' + row.flowId;
 	const url = '/rule-engine/#flow/' + row.flowId;
 	window.open(url);
 };
 
-const onDel = async (row: any) => {
-	// 找到所有规则
-	const { data: flows } = await axios.get(flowsUrl, { headers });
-
-	const flowIndex = flows.findIndex((item: any) => item.id === row.flowId);
-
-	if (!flowIndex) {
-		ElMessage.error('规则不存在');
-		return;
-	}
-
-	// 删除指定规则
-	flows.splice(flowIndex, 1);
-	
-	// 设置规则状态
-	await axios.post(flowsUrl, flows, { headers });
-
+const onDel = (row: any) => {
 	ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, '提示', {
 		confirmButtonText: '确认',
 		cancelButtonText: '取消',
 		type: 'warning',
 	}).then(async () => {
+		// 找到所有规则
+		const { data: flows } = await axios.get(flowsUrl, { headers });
+
+		const flowIndex = flows.findIndex((item: any) => item.id === row.flowId);
+
+		if (flowIndex === -1) {
+			ElMessage.error('规则不存在');
+			return;
+		}
+
+		// 删除指定规则
+		flows.splice(flowIndex, 1);
+
+		// 删除当前规则下的各个节点信息
+		const newFlows = flows.filter((item: any) => {
+			if (item.z === row.flowId) {
+				return false;
+			} else {
+				return true;
+			}
+		});
+
+		// 设置规则状态
+		await axios.post(flowsUrl, newFlows, { headers });
+
 		await api.del([row.id as string]);
 		ElMessage.success('删除成功');
 		getList();