Ver código fonte

增加新版本规则引擎的启用停用操作

yanglzh 11 meses atrás
pai
commit
4dbff87a29

+ 1 - 2
src/views/iot/rule-engine/index.vue

@@ -59,7 +59,6 @@ const headers = {
 };
 
 const flowsUrl = window.location.origin + '/rule-engine/flows';
-// const flowsUrl = 'http://zhgy.sagoo.cn/rule-engine/flows';
 
 getList();
 
@@ -74,7 +73,7 @@ const addOrEdit = async (row?: any) => {
 
 const setStatus = async (row: any, status: number) => {
 	if (model === 'sagoo-rule') {
-		axios.post(`${import.meta.env.VITE_RULE_SERVER_URL}/api/v1/rule/${row.flowId}/${status ? 'enable' : 'stop'}`, {}, { headers })
+		axios.get(`${import.meta.env.VITE_RULE_SERVER_URL}/api/v1/rule/${row.flowId}/${status ? 'enable' : 'stop'}`, { headers })
 			.then(() => {
 				api
 					.setStatus(row.id, status)

+ 41 - 27
src/views/iot/rule-engine/send.vue

@@ -30,10 +30,8 @@
         </el-table-column>
         <el-table-column label="操作" width="200" align="center">
           <template #default="scope">
-            <template v-if="model === 'node-red'">
-              <el-button size="small" text type="info" v-auth="'startOrStop'" v-if="scope.row.status" @click="setStatus(scope.row, 0)">停止</el-button>
-              <el-button size="small" text type="primary" v-auth="'startOrStop'" v-else @click="setStatus(scope.row, 1)">启动</el-button>
-            </template>
+            <el-button size="small" text type="info" v-auth="'startOrStop'" v-if="scope.row.status" @click="setStatus(scope.row, 0)">停止</el-button>
+            <el-button size="small" text type="primary" v-auth="'startOrStop'" v-else @click="setStatus(scope.row, 1)">启动</el-button>
             <el-button size="small" text type="primary" v-auth="'edit'" @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" v-auth="'del'" @click="onDel(scope.row)">删除</el-button>
@@ -58,7 +56,7 @@ import { getToken } from "/@/utils/auth";
 const editFormRef = ref();
 
 // 规则引擎模式 node-red sagoo-rule
-const model = import.meta.env.VITE_RULE_MODEL
+const model: 'node-red' | 'sagoo-rule' = import.meta.env.VITE_RULE_MODEL
 
 const { params, tableData, getList, loading } = useSearch<any[]>(api.getList, 'Data', { types: 1 });
 
@@ -79,31 +77,47 @@ const addOrEdit = async (row?: any) => {
 };
 
 const setStatus = async (row: any, status: number) => {
-  // 找到所有规则
-  const { data: flows } = await axios.get(flowsUrl, { headers });
+  if (model === 'sagoo-rule') {
+    axios.get(`${import.meta.env.VITE_RULE_SERVER_URL}/api/v1/rule/${row.flowId}/${status ? 'enable' : 'stop'}`, { headers })
+      .then(() => {
+        api
+          .setStatus(row.id, status)
+          .then(() => {
+            ElMessage.success('操作成功');
+            getList();
+          })
+          .catch(() => {
+            ElMessage.error('操作失败');
+          });
+      })
+      .catch(() => {
+        ElMessage.error('操作失败')
+      })
+  } else {
+    // 找到所有规则
+    const { data: flows } = await axios.get(flowsUrl, { headers });
 
-  const flow = flows.find((item: any) => item.id === row.flowId);
+    const flow = flows.find((item: any) => item.id === row.flowId);
 
-  if (!flow) {
-    ElMessage.error('规则不存在');
-    return;
-  }
+    if (!flow) {
+      ElMessage.error('规则不存在');
+      return;
+    }
 
-  // 改变指定规则状态
-  flow.disabled = status ? false : true;
-
-  // 设置规则状态
-  await axios.post(flowsUrl, flows, { headers });
-
-  api
-    .setStatus(row.id, status)
-    .then(() => {
-      ElMessage.success('操作成功');
-      getList();
-    })
-    .catch(() => {
-      ElMessage.error('操作失败');
-    });
+    // 改变指定规则状态
+    flow.disabled = status ? false : true;
+    // 设置规则状态
+    await axios.post(flowsUrl, flows, { headers });
+    api
+      .setStatus(row.id, status)
+      .then(() => {
+        ElMessage.success('操作成功');
+        getList();
+      })
+      .catch(() => {
+        ElMessage.error('操作失败');
+      });
+  }
 };
 
 const edit = async (row: any) => {