|
@@ -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,11 +51,19 @@ 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();
|
|
|
|
|
|
const { params, tableData, getList, loading } = useSearch<any[]>(api.getList, 'Data', { types: 0 });
|
|
|
|
|
|
+const headers = {
|
|
|
+ Authorization: 'Bearer ' + JSON.parse(sessionStorage.token),
|
|
|
+};
|
|
|
+
|
|
|
+const flowsUrl = window.location.origin + '/rule-engine/flows';
|
|
|
+// const flowsUrl = 'http://zhgy.sagoo.cn/rule-engine/flows';
|
|
|
+
|
|
|
getList();
|
|
|
|
|
|
const addOrEdit = async (row?: any) => {
|
|
@@ -67,9 +75,25 @@ const addOrEdit = async (row?: any) => {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-const setStatus = (id: number, status: number) => {
|
|
|
+const setStatus = async (row: any, status: number) => {
|
|
|
+ // 找到所有规则
|
|
|
+ const { data: flows } = await axios.get(flowsUrl, { headers });
|
|
|
+
|
|
|
+ const flow = flows.find((item: any) => item.id === row.flowId);
|
|
|
+
|
|
|
+ if (!flow) {
|
|
|
+ ElMessage.error('规则不存在');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 改变指定规则状态
|
|
|
+ flow.disabled = status ? false : true;
|
|
|
+
|
|
|
+ // 设置规则状态
|
|
|
+ await axios.post(flowsUrl, flows, { headers });
|
|
|
+
|
|
|
api
|
|
|
- .setStatus(id, status)
|
|
|
+ .setStatus(row.id, status)
|
|
|
.then(() => {
|
|
|
ElMessage.success('操作成功');
|
|
|
getList();
|
|
@@ -80,8 +104,8 @@ 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;
|
|
|
+ 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);
|
|
|
};
|
|
@@ -92,6 +116,31 @@ const onDel = (row: any) => {
|
|
|
cancelButtonText: '取消',
|
|
|
type: 'warning',
|
|
|
}).then(async () => {
|
|
|
+ // 找到所有规则
|
|
|
+ const { data: flows } = await axios.get(flowsUrl, { headers });
|
|
|
+
|
|
|
+ const flowIndex = flows.findIndex((item: any) => item.id === row.flowId);
|
|
|
+
|
|
|
+ if (flowIndex === -1) {
|
|
|
+ ElMessage.error('规则不存在');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 删除指定规则
|
|
|
+ flows.splice(flowIndex, 1);
|
|
|
+
|
|
|
+ // 删除当前规则下的各个节点信息
|
|
|
+ const newFlows = flows.filter((item: any) => {
|
|
|
+ if (item.z === row.flowId) {
|
|
|
+ return false;
|
|
|
+ } else {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 设置规则状态
|
|
|
+ await axios.post(flowsUrl, newFlows, { headers });
|
|
|
+
|
|
|
await api.del([row.id as string]);
|
|
|
ElMessage.success('删除成功');
|
|
|
getList();
|