Browse Source

规则编排中删除记录时同步删除node-red中的规则

yanglzh 3 years ago
parent
commit
58f890419a
2 changed files with 33 additions and 5 deletions
  1. 19 4
      src/views/rule-engine/index.vue
  2. 14 1
      src/views/rule-engine/send.vue

+ 19 - 4
src/views/rule-engine/index.vue

@@ -103,13 +103,28 @@ 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/rule-engine?access_token=' + Session.get('token') + '#flow/' + row.flowId;
-	// const url = '/rule-engine/#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 = (row: any) => {
+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 });
+
 	ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, '提示', {
 		confirmButtonText: '确认',
 		cancelButtonText: '取消',

+ 14 - 1
src/views/rule-engine/send.vue

@@ -108,7 +108,20 @@ const edit = async (row: any) => {
 	window.open(url);
 };
 
-const onDel = (row: any) => {
+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);
+
 	ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, '提示', {
 		confirmButtonText: '确认',
 		cancelButtonText: '取消',