浏览代码

流程引擎iot端规则引擎设置启动停止操作时候 调用node-red的启动停止

yanglzh 3 年之前
父节点
当前提交
53b5afe9f9
共有 3 个文件被更改,包括 62 次插入11 次删除
  1. 1 1
      src/views/rule-engine/edit.vue
  2. 33 7
      src/views/rule-engine/index.vue
  3. 28 3
      src/views/rule-engine/send.vue

+ 1 - 1
src/views/rule-engine/edit.vue

@@ -68,7 +68,7 @@ const onSubmit = async () => {
 			window.location.protocol + '//' + window.location.hostname + '/rule-engine/flow',
 			{
 				label: formData.name,
-				disabled: false,
+				disabled: true,
 				info: '',
 				env: [],
 				nodes: [],

+ 33 - 7
src/views/rule-engine/index.vue

@@ -31,8 +31,8 @@
 			</el-table-column>
 			<el-table-column label="操作" width="200" align="center">
 				<template #default="scope">
-					<el-button size="small" text type="info" v-if="scope.row.status" @click="setStatus(scope.row.id, 0)">停止</el-button>
-					<el-button size="small" text type="primary" v-else @click="setStatus(scope.row.id, 1)">启动</el-button>
+					<el-button size="small" text type="info" v-if="scope.row.status" @click="setStatus(scope.row, 0)">停止</el-button>
+					<el-button size="small" text type="primary" v-else @click="setStatus(scope.row, 1)">启动</el-button>
 					<el-button size="small" text type="warning" @click="addOrEdit(scope.row)">编辑</el-button>
 					<el-button size="small" text type="warning" @click="edit(scope.row)">规则编辑</el-button>
 					<el-button size="small" text type="danger" @click="onDel(scope.row)">删除</el-button>
@@ -51,6 +51,7 @@ import { ElMessageBox, ElMessage } from 'element-plus';
 import { useSearch } from '/@/hooks/useCommon';
 import { Session } from '/@/utils/storage';
 import EditForm from './edit.vue';
+import axios from 'axios';
 
 const editFormRef = ref();
 
@@ -67,9 +68,33 @@ const addOrEdit = async (row?: any) => {
 	}
 };
 
-const setStatus = (id: number, status: number) => {
+const setStatus = async (row: any, status: number) => {
+	// 找到所有规则
+	const { data: flows } = await axios.get(window.location.protocol + '//' + window.location.hostname + '/rule-engine/flows?_=' + Date.now(), {
+		headers: {
+			Authorization: 'Bearer ' + JSON.parse(sessionStorage.token),
+		},
+	});
+
+	const flow = flows.find((item: any) => item.id === row.flowId);
+
+	if (!flow) {
+		ElMessage.error('规则不存在');
+		return;
+	}
+
+	// 改变指定规则状态
+	flow.disabled = status ? true : false;
+
+	// 设置规则状态
+	await axios.post(window.location.protocol + '//' + window.location.hostname + '/rule-engine/flows', flows, {
+		headers: {
+			Authorization: 'Bearer ' + JSON.parse(sessionStorage.token),
+		},
+	});
+
 	api
-		.setStatus(id, status)
+		.setStatus(row.id, status)
 		.then(() => {
 			ElMessage.success('操作成功');
 			getList();
@@ -80,9 +105,10 @@ const setStatus = (id: number, 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 = '/rule-engine/#flow/' + row.flowId;
+	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;
 	window.open(url);
 };
 

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

@@ -51,6 +51,7 @@ import { ElMessageBox, ElMessage } from 'element-plus';
 import { useSearch } from '/@/hooks/useCommon';
 import { Session } from '/@/utils/storage';
 import EditForm from './edit.vue';
+import axios from 'axios';
 
 const editFormRef = ref();
 
@@ -67,9 +68,33 @@ const addOrEdit = async (row?: any) => {
 	}
 };
 
-const setStatus = (id: number, status: number) => {
+const setStatus = async (row: any, status: number) => {
+	// 找到所有规则
+	const { data: flows } = await axios.get(window.location.protocol + '//' + window.location.hostname + '/rule-engine/flows?_=' + Date.now(), {
+		headers: {
+			Authorization: 'Bearer ' + JSON.parse(sessionStorage.token),
+		},
+	});
+
+	const flow = flows.find((item: any) => item.id === row.flowId);
+
+	if (!flow) {
+		ElMessage.error('规则不存在');
+		return;
+	}
+
+	// 改变指定规则状态
+	flow.disabled = status ? true : false;
+
+	// 设置规则状态
+	await axios.post(window.location.protocol + '//' + window.location.hostname + '/rule-engine/flows', flows, {
+		headers: {
+			Authorization: 'Bearer ' + JSON.parse(sessionStorage.token),
+		},
+	});
+
 	api
-		.setStatus(id, status)
+		.setStatus(row.id, status)
 		.then(() => {
 			ElMessage.success('操作成功');
 			getList();
@@ -80,7 +105,7 @@ const setStatus = (id: number, status: number) => {
 };
 
 const edit = async (row: any) => {
-	localStorage.setItem('auth-tokens',`{"access_token":"${Session.get('token')}"}`);
+	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 = '/rule-engine/#flow/' + row.flowId;
 	window.open(url);