|
@@ -30,10 +30,8 @@
|
|
</el-table-column>
|
|
</el-table-column>
|
|
<el-table-column label="操作" width="200" align="center">
|
|
<el-table-column label="操作" width="200" align="center">
|
|
<template #default="scope">
|
|
<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="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="warning" @click="edit(scope.row)">规则编辑</el-button>
|
|
<el-button size="small" text type="danger" v-auth="'del'" @click="onDel(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();
|
|
const editFormRef = ref();
|
|
|
|
|
|
// 规则引擎模式 node-red sagoo-rule
|
|
// 规则引擎模式 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 });
|
|
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 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) => {
|
|
const edit = async (row: any) => {
|