Преглед изворни кода

规则引擎,增加编辑时候同步改名到node-red服务

yanglzh пре 3 година
родитељ
комит
88924b543c
2 измењених фајлова са 26 додато и 5 уклоњено
  1. 23 5
      src/views/rule-engine/edit.vue
  2. 3 0
      src/views/rule-engine/send.vue

+ 23 - 5
src/views/rule-engine/edit.vue

@@ -29,7 +29,7 @@ import { ref, reactive, nextTick } from 'vue';
 import api from '/@/api/rule';
 import axios from 'axios';
 import { ruleRequired } from '/@/utils/validator';
-import {  ElMessage } from 'element-plus';
+import { ElMessage } from 'element-plus';
 
 const emit = defineEmits(['getList']);
 
@@ -40,6 +40,11 @@ const props = defineProps({
 	},
 });
 
+const headers = {
+	Authorization: 'Bearer ' + JSON.parse(sessionStorage.token),
+};
+const flowsUrl = window.location.protocol + '//' + window.location.hostname + '/rule-engine/flow';
+
 const showDialog = ref(false);
 const formRef = ref();
 
@@ -65,7 +70,7 @@ const onSubmit = async () => {
 
 	if (!formData.id) {
 		const { data } = await axios.post(
-			window.location.protocol + '//' + window.location.hostname + '/rule-engine/flow',
+			flowsUrl,
 			{
 				label: formData.name,
 				disabled: true,
@@ -74,12 +79,25 @@ const onSubmit = async () => {
 				nodes: [],
 			},
 			{
-				headers: {
-					Authorization: 'Bearer ' + JSON.parse(sessionStorage.token),
-				},
+				headers,
 			}
 		);
 		formData.flowId = data.id;
+	} else {
+		// 找到所有规则
+		const { data: flows } = await axios.get(flowsUrl + 's', { headers });
+
+		const flow = flows.find((item: any) => item.id === formData.flowId);
+
+		if (!flow) {
+			ElMessage.error('规则不存在');
+			return;
+		}
+
+		flow.label = formData.name;
+
+		// 设置规则状态
+		await axios.post(flowsUrl + 's', flows, { headers });
 	}
 
 	const theApi = formData.id ? api.edit : api.add;

+ 3 - 0
src/views/rule-engine/send.vue

@@ -121,6 +121,9 @@ const onDel = async (row: any) => {
 
 	// 删除指定规则
 	flows.splice(flowIndex, 1);
+	
+	// 设置规则状态
+	await axios.post(flowsUrl, flows, { headers });
 
 	ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, '提示', {
 		confirmButtonText: '确认',