Parcourir la source

fix: 修复规则引擎启动停止的接口,及配置传参错误问题

yanglzh il y a 9 mois
Parent
commit
9bc63ef099
7 fichiers modifiés avec 312 ajouts et 315 suppressions
  1. 1 1
      .env
  2. 1 1
      .env.development
  3. 1 1
      .env.golocal
  4. 131 131
      src/views/iot/rule-engine/edit.vue
  5. 141 143
      src/views/iot/rule-engine/index.vue
  6. 36 36
      src/views/iot/rule-engine/send.vue
  7. 1 2
      writeEnv.mjs

+ 1 - 1
.env

@@ -28,7 +28,7 @@ VITE_ICE104_API = '/ice104'
 # 规则引擎模式 sagoo-rule node-red
 VITE_RULE_MODEL = 'sagoo-rule'
 # sagoo rule api
-VITE_RULE_SERVER_URL = '/rule-api/api/v1/rules/'
+VITE_RULE_SERVER_URL = '/rule-api'
 # sagoo media api
 VITE_MEDIA_SERVER_URL = '/media'
 

+ 1 - 1
.env.development

@@ -5,7 +5,7 @@ VITE_NGINX_PROXY = ''
 VITE_SERVER_ORIGIN = 'http://127.0.0.1:8199'
 
 # 规则引擎服务地址
-VITE_RULE_SERVER_URL = 'http://127.0.0.1:9090/api/v1/rules/'
+VITE_RULE_SERVER_URL = 'http://127.0.0.1:9090'
 
 # 流媒体服务地址
 VITE_MEDIA_SERVER_URL = 'http://127.0.0.1:8080'

+ 1 - 1
.env.golocal

@@ -6,5 +6,5 @@ VITE_ROUTER_MODE = 'hash'
 
 VITE_SERVER_ORIGIN = ''
 
-VITE_RULE_SERVER_URL = 'http://127.0.0.1:9090/api/v1/rules/'
+VITE_RULE_SERVER_URL = 'http://127.0.0.1:9090'
 VITE_MEDIA_SERVER_URL = 'http://127.0.0.1:8080'

+ 131 - 131
src/views/iot/rule-engine/edit.vue

@@ -1,167 +1,167 @@
 <template>
-	<el-dialog class="api-edit" v-model="showDialog" :title="`${formData.id ? '编辑' : '新增'}`" width="600px" :close-on-click-modal="false" :close-on-press-escape="false">
-		<el-form ref="formRef" :model="formData" :rules="ruleForm" label-width="80px">
-			<el-form-item label="名称" prop="name">
-				<el-input v-model.trim="formData.name" placeholder="输入名称" />
-			</el-form-item>
-			<el-form-item label="说明" prop="expound">
-				<el-input v-model="formData.expound" type="textarea" :rows="3" />
-			</el-form-item>
-		</el-form>
-		<template #footer>
-			<div class="dialog-footer">
-				<el-button @click="showDialog = false">取消</el-button>
-				<el-button type="primary" @click="onSubmit">确定</el-button>
-			</div>
-		</template>
-	</el-dialog>
+  <el-dialog class="api-edit" v-model="showDialog" :title="`${formData.id ? '编辑' : '新增'}`" width="600px" :close-on-click-modal="false" :close-on-press-escape="false">
+    <el-form ref="formRef" :model="formData" :rules="ruleForm" label-width="80px">
+      <el-form-item label="名称" prop="name">
+        <el-input v-model.trim="formData.name" placeholder="输入名称" />
+      </el-form-item>
+      <el-form-item label="说明" prop="expound">
+        <el-input v-model="formData.expound" type="textarea" :rows="3" />
+      </el-form-item>
+    </el-form>
+    <template #footer>
+      <div class="dialog-footer">
+        <el-button @click="showDialog = false">取消</el-button>
+        <el-button type="primary" @click="onSubmit">确定</el-button>
+      </div>
+    </template>
+  </el-dialog>
 </template>
 
 <script lang="ts" setup>
-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 { 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 { getToken } from "/@/utils/auth";
-import { v4 as uuid } from 'uuid'
+import { v4 as uuid } from "uuid";
 
-const emit = defineEmits(['getList']);
+const emit = defineEmits(["getList"]);
 
 const props = defineProps({
-	types: {
-		type: Number,
-		default: 0, // 规则编排是0 数据转发是1
-	},
-	model: {
-		type: String,
-		default: 'sagoo-rule', // sagoo-rule 、node-red
-	},
+  types: {
+    type: Number,
+    default: 0, // 规则编排是0 数据转发是1
+  },
+  model: {
+    type: String,
+    default: "sagoo-rule", // sagoo-rule 、node-red
+  },
 });
 
 const headers = {
-	Authorization: 'Bearer ' + getToken(),
+  Authorization: "Bearer " + getToken(),
 };
-const flowsUrl = window.location.origin + '/rule-engine/flow';
+const flowsUrl = window.location.origin + "/rule-engine/flow";
 // const flowsUrl = 'http://zhgy.sagoo.cn/rule-engine/flow';
 
 const showDialog = ref(false);
 const formRef = ref();
 
 const baseForm = {
-	id: undefined,
-	name: '',
-	types: props.types,
-	// types: 0,
-	flowId: '',
-	expound: '',
+  id: undefined,
+  name: "",
+  types: props.types,
+  // types: 0,
+  flowId: "",
+  expound: "",
 };
 
 const formData = reactive({
-	...baseForm,
+  ...baseForm,
 });
 
 const ruleForm = {
-	name: [ruleRequired('规则名称不能为空')],
+  name: [ruleRequired("规则名称不能为空")],
 };
 
 const onSubmit = async () => {
-	await formRef.value.validate();
-
-	// 不同引擎,用不同处理方式
-	if (props.model === 'sagoo-rule') {
-		if (!formData.id) {
-			const id = uuid()
-			await axios.post(
-				import.meta.env.VITE_RULE_SERVER_URL + id,
-				{
-					"ruleChain": {
-						"id": id,
-						"name": formData.name,
-						"root": true,
-						"additionalInfo": {
-							"description": formData.expound,
-							"layoutX": "130",
-							"layoutY": "220"
-						}
-					},
-					"metadata": {
-						"nodes": [],
-						"endpoints": [],
-						"connections": []
-					}
-				},
-				{ headers }
-			);
-			formData.flowId = id;
-		} else {
-			// 找到规则
-			const { data } = await axios.get(import.meta.env.VITE_RULE_SERVER_URL + formData.flowId, { headers }).catch(() => {
-				ElMessage.error('规则不存在')
-			}) as any
-
-			// 修改名称和说明
-			data.ruleChain.name = formData.name
-			data.ruleChain.additionalInfo.description = formData.expound
-
-			// 保存
-			await axios.post(import.meta.env.VITE_RULE_SERVER_URL + formData.flowId, data, { headers });
-		}
-	} else if (props.model === 'node-red') {
-		if (!formData.id) {
-			const { data } = await axios.post(
-				flowsUrl,
-				{
-					label: formData.name,
-					disabled: true,
-					info: '',
-					env: [],
-					nodes: [],
-				},
-				{
-					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;
-
-	await theApi(formData);
-
-	ElMessage.success('操作成功');
-	resetForm();
-	showDialog.value = false;
-	emit('getList');
+  await formRef.value.validate();
+
+  // 不同引擎,用不同处理方式
+  if (props.model === "sagoo-rule") {
+    if (!formData.id) {
+      const id = uuid();
+      await axios.post(
+        import.meta.env.VITE_RULE_SERVER_URL + "/api/v1/rules/" + id,
+        {
+          ruleChain: {
+            id: id,
+            name: formData.name,
+            root: true,
+            additionalInfo: {
+              description: formData.expound,
+              layoutX: "130",
+              layoutY: "220",
+            },
+          },
+          metadata: {
+            nodes: [],
+            endpoints: [],
+            connections: [],
+          },
+        },
+        { headers }
+      );
+      formData.flowId = id;
+    } else {
+      // 找到规则
+      const { data } = (await axios.get(import.meta.env.VITE_RULE_SERVER_URL + "/api/v1/rules/" + formData.flowId, { headers }).catch(() => {
+        ElMessage.error("规则不存在");
+      })) as any;
+
+      // 修改名称和说明
+      data.ruleChain.name = formData.name;
+      data.ruleChain.additionalInfo.description = formData.expound;
+
+      // 保存
+      await axios.post(import.meta.env.VITE_RULE_SERVER_URL + "/api/v1/rules/" + formData.flowId, data, { headers });
+    }
+  } else if (props.model === "node-red") {
+    if (!formData.id) {
+      const { data } = await axios.post(
+        flowsUrl,
+        {
+          label: formData.name,
+          disabled: true,
+          info: "",
+          env: [],
+          nodes: [],
+        },
+        {
+          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;
+
+  await theApi(formData);
+
+  ElMessage.success("操作成功");
+  resetForm();
+  showDialog.value = false;
+  emit("getList");
 };
 
 const resetForm = async () => {
-	Object.assign(formData, { ...baseForm });
-	formRef.value && formRef.value.resetFields();
+  Object.assign(formData, { ...baseForm });
+  formRef.value && formRef.value.resetFields();
 };
 
 const open = async (row: any) => {
-	resetForm();
-	showDialog.value = true;
-	nextTick(() => {
-		Object.assign(formData, { ...row });
-	});
+  resetForm();
+  showDialog.value = true;
+  nextTick(() => {
+    Object.assign(formData, { ...row });
+  });
 };
 
 defineExpose({ open });

+ 141 - 143
src/views/iot/rule-engine/index.vue

@@ -1,172 +1,170 @@
 <template>
-	<div class="page">
-		<el-card shadow="nover">
-			<el-form inline>
-				<el-form-item>
-					<el-button type="primary" v-auth="'add'" @click="addOrEdit()">
-						<el-icon>
-							<ele-FolderAdd />
-						</el-icon>
-						新增规则编排
-					</el-button>
-				</el-form-item>
-			</el-form>
-			<el-table :data="tableData" style="width: 100%" v-loading="loading">
-				<el-table-column type="index" label="序号" width="80" align="center" />
-				<el-table-column prop="name" label="名称" show-overflow-tooltip></el-table-column>
-				<el-table-column prop="expound" label="说明" show-overflow-tooltip></el-table-column>
-				<el-table-column prop="createdAt" label="创建时间" min-width="100" align="center"></el-table-column>
-				<el-table-column prop="status" label="状态" width="100" align="center">
-					<template #default="scope">
-						<el-tag type="success" size="small" v-if="scope.row.status == 1">已启动</el-tag>
-						<el-tag type="info" size="small" v-else>已停止</el-tag>
-					</template>
-				</el-table-column>
-				<el-table-column label="操作" width="200" align="center">
-					<template #default="scope">
-						<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="info" v-auth="'del'" @click="onDel(scope.row)">删除</el-button>
-					</template>
-				</el-table-column>
-			</el-table>
-			<pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
-			<EditForm :model="model" ref="editFormRef" @getList="getList(1)" :types="0"></EditForm>
-		</el-card>
-	</div>
+  <div class="page">
+    <el-card shadow="nover">
+      <el-form inline>
+        <el-form-item>
+          <el-button type="primary" v-auth="'add'" @click="addOrEdit()">
+            <el-icon>
+              <ele-FolderAdd />
+            </el-icon>
+            新增规则编排
+          </el-button>
+        </el-form-item>
+      </el-form>
+      <el-table :data="tableData" style="width: 100%" v-loading="loading">
+        <el-table-column type="index" label="序号" width="80" align="center" />
+        <el-table-column prop="name" label="名称" show-overflow-tooltip></el-table-column>
+        <el-table-column prop="expound" label="说明" show-overflow-tooltip></el-table-column>
+        <el-table-column prop="createdAt" label="创建时间" min-width="100" align="center"></el-table-column>
+        <el-table-column prop="status" label="状态" width="100" align="center">
+          <template #default="scope">
+            <el-tag type="success" size="small" v-if="scope.row.status == 1">已启动</el-tag>
+            <el-tag type="info" size="small" v-else>已停止</el-tag>
+          </template>
+        </el-table-column>
+        <el-table-column label="操作" width="200" align="center">
+          <template #default="scope">
+            <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="info" v-auth="'del'" @click="onDel(scope.row)">删除</el-button>
+          </template>
+        </el-table-column>
+      </el-table>
+      <pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
+      <EditForm :model="model" ref="editFormRef" @getList="getList(1)" :types="0"></EditForm>
+    </el-card>
+  </div>
 </template>
 
 <script lang="ts" setup>
-import { ref } from 'vue';
-import api from '/@/api/rule';
-import { ElMessageBox, ElMessage } from 'element-plus';
-import { useSearch } from '/@/hooks/useCommon';
-import EditForm from './edit.vue';
-import axios from 'axios';
+import { ref } from "vue";
+import api from "/@/api/rule";
+import { ElMessageBox, ElMessage } from "element-plus";
+import { useSearch } from "/@/hooks/useCommon";
+import EditForm from "./edit.vue";
+import axios from "axios";
 import { getToken } from "/@/utils/auth";
 
 const editFormRef = ref();
 
 // 规则引擎模式 node-red、 sagoo-rule
-const model: 'node-red' | 'sagoo-rule' = 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: 0 });
+const { params, tableData, getList, loading } = useSearch<any[]>(api.getList, "Data", { types: 0 });
 
 const headers = {
-	Authorization: 'Bearer ' + getToken(),
+  Authorization: "Bearer " + getToken(),
 };
 
-const flowsUrl = window.location.origin + '/rule-engine/flows';
+const flowsUrl = window.location.origin + "/rule-engine/flows";
 
 getList();
 
 const addOrEdit = async (row?: any) => {
-	if (row) {
-		editFormRef.value.open(row);
-		return;
-	} else {
-		editFormRef.value.open();
-	}
+  if (row) {
+    editFormRef.value.open(row);
+    return;
+  } else {
+    editFormRef.value.open();
+  }
 };
 
 const setStatus = async (row: any, status: number) => {
-	if (model === 'sagoo-rule') {
-		axios.get(`${import.meta.env.VITE_RULE_SERVER_URL}${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);
-
-		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('操作失败');
-			});
-	}
-
+  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);
+
+    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("操作失败");
+      });
+  }
 };
 
 const edit = async (row: any) => {
-	if (model == 'sagoo-rule') {
-		localStorage.setItem('auth-tokens', `{"access_token":"${getToken()}"}`);
-		const url = '/plugin/rule/index.html#' + row.flowId;
-		window.open(url);
-
-	} else if (model == 'node-red') {
-		localStorage.setItem('auth-tokens', `{"access_token":"${getToken()}"}`);
-		const url = '/rule-engine/#flow/' + row.flowId;
-		window.open(url);
-	}
+  if (model == "sagoo-rule") {
+    localStorage.setItem("auth-tokens", `{"access_token":"${getToken()}"}`);
+    const url = "/plugin/rule/index.html#" + row.flowId;
+    window.open(url);
+  } else if (model == "node-red") {
+    localStorage.setItem("auth-tokens", `{"access_token":"${getToken()}"}`);
+    const url = "/rule-engine/#flow/" + row.flowId;
+    window.open(url);
+  }
 };
 
 const onDel = (row: any) => {
-	ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, '提示', {
-		confirmButtonText: '确认',
-		cancelButtonText: '取消',
-		type: 'warning',
-	}).then(async () => {
-
-		if (model == 'sagoo-rule') {
-			await axios.delete(import.meta.env.VITE_RULE_SERVER_URL + row.flowId, { headers }).catch(() => {
-				ElMessage.error('规则不存在')
-			})
-		} else if (model == 'node-red') {
-			// 找到所有规则
-			const { data: flows } = await axios.get(flowsUrl, { headers });
-
-			const flowIndex = flows.findIndex((item: any) => item.id === row.flowId);
-
-			if (flowIndex >= 0) {
-				// 删除指定规则
-				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();
-	});
+  ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, "提示", {
+    confirmButtonText: "确认",
+    cancelButtonText: "取消",
+    type: "warning",
+  }).then(async () => {
+    if (model == "sagoo-rule") {
+      await axios.delete(import.meta.env.VITE_RULE_SERVER_URL + "/api/v1/rules/" + row.flowId, { headers }).catch(() => {
+        ElMessage.error("规则不存在");
+      });
+    } else if (model == "node-red") {
+      // 找到所有规则
+      const { data: flows } = await axios.get(flowsUrl, { headers });
+
+      const flowIndex = flows.findIndex((item: any) => item.id === row.flowId);
+
+      if (flowIndex >= 0) {
+        // 删除指定规则
+        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();
+  });
 };
 </script>

+ 36 - 36
src/views/iot/rule-engine/send.vue

@@ -45,25 +45,25 @@
 </template>
 
 <script lang="ts" setup>
-import { ref } from 'vue';
-import api from '/@/api/rule';
-import { ElMessageBox, ElMessage } from 'element-plus';
-import { useSearch } from '/@/hooks/useCommon';
-import EditForm from './edit.vue';
-import axios from 'axios';
+import { ref } from "vue";
+import api from "/@/api/rule";
+import { ElMessageBox, ElMessage } from "element-plus";
+import { useSearch } from "/@/hooks/useCommon";
+import EditForm from "./edit.vue";
+import axios from "axios";
 import { getToken } from "/@/utils/auth";
 
 const editFormRef = ref();
 
 // 规则引擎模式 node-red sagoo-rule
-const model: 'node-red' | 'sagoo-rule' = 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 });
 
 const headers = {
-  Authorization: 'Bearer ' + getToken(),
+  Authorization: "Bearer " + getToken(),
 };
-const flowsUrl = window.location.origin + '/rule-engine/flows';
+const flowsUrl = window.location.origin + "/rule-engine/flows";
 
 getList();
 
@@ -77,22 +77,23 @@ const addOrEdit = async (row?: any) => {
 };
 
 const setStatus = async (row: any, status: number) => {
-  if (model === 'sagoo-rule') {
-    axios.get(`${import.meta.env.VITE_RULE_SERVER_URL}${row.flowId}/${status ? 'enable' : 'stop'}`, { headers })
+  if (model === "sagoo-rule") {
+    axios
+      .get(`${import.meta.env.VITE_RULE_SERVER_URL}/api/v1/rules/${row.flowId}/${status ? "enable" : "stop"}`, { headers })
       .then(() => {
         api
           .setStatus(row.id, status)
           .then(() => {
-            ElMessage.success('操作成功');
+            ElMessage.success("操作成功");
             getList();
           })
           .catch(() => {
-            ElMessage.error('操作失败');
+            ElMessage.error("操作失败");
           });
       })
       .catch(() => {
-        ElMessage.error('操作失败')
-      })
+        ElMessage.error("操作失败");
+      });
   } else {
     // 找到所有规则
     const { data: flows } = await axios.get(flowsUrl, { headers });
@@ -100,7 +101,7 @@ const setStatus = async (row: any, status: number) => {
     const flow = flows.find((item: any) => item.id === row.flowId);
 
     if (!flow) {
-      ElMessage.error('规则不存在');
+      ElMessage.error("规则不存在");
       return;
     }
 
@@ -111,39 +112,38 @@ const setStatus = async (row: any, status: number) => {
     api
       .setStatus(row.id, status)
       .then(() => {
-        ElMessage.success('操作成功');
+        ElMessage.success("操作成功");
         getList();
       })
       .catch(() => {
-        ElMessage.error('操作失败');
+        ElMessage.error("操作失败");
       });
   }
 };
 
 const edit = async (row: any) => {
-  if (model == 'sagoo-rule') {
-    localStorage.setItem('auth-tokens', `{"access_token":"${getToken()}"}`);
-    const url = '/plugin/rule/index.html#' + row.flowId;
+  if (model == "sagoo-rule") {
+    localStorage.setItem("auth-tokens", `{"access_token":"${getToken()}"}`);
+    const url = "/plugin/rule/index.html#" + row.flowId;
     window.open(url);
-
-  } else if (model == 'node-red') {
-    localStorage.setItem('auth-tokens', `{"access_token":"${getToken()}"}`);
-    const url = '/rule-engine/#flow/' + row.flowId;
+  } else if (model == "node-red") {
+    localStorage.setItem("auth-tokens", `{"access_token":"${getToken()}"}`);
+    const url = "/rule-engine/#flow/" + row.flowId;
     window.open(url);
   }
 };
 
 const onDel = (row: any) => {
-  ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, '提示', {
-    confirmButtonText: '确认',
-    cancelButtonText: '取消',
-    type: 'warning',
+  ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, "提示", {
+    confirmButtonText: "确认",
+    cancelButtonText: "取消",
+    type: "warning",
   }).then(async () => {
-    if (model == 'sagoo-rule') {
-      await axios.delete(import.meta.env.VITE_RULE_SERVER_URL + row.flowId, { headers }).catch(() => {
-        ElMessage.error('规则不存在')
-      })
-    } else if (model == 'node-red') {
+    if (model == "sagoo-rule") {
+      await axios.delete(import.meta.env.VITE_RULE_SERVER_URL + "/api/v1/rules/" + row.flowId, { headers }).catch(() => {
+        ElMessage.error("规则不存在");
+      });
+    } else if (model == "node-red") {
       // 找到所有规则
       const { data: flows } = await axios.get(flowsUrl, { headers });
 
@@ -168,7 +168,7 @@ const onDel = (row: any) => {
     }
 
     await api.del([row.id as string]);
-    ElMessage.success('删除成功');
+    ElMessage.success("删除成功");
     getList();
   });
 };

+ 1 - 2
writeEnv.mjs

@@ -11,7 +11,6 @@ const baseUrl = VITE_SERVER_ORIGIN + VITE_NGINX_PROXY + VITE_API_SUFFIX_URL
 
 const configFile = './public/config.js'
 const configJson = {
-	topo: baseUrl,
 	topo: {
 		server: baseUrl,
 		imgServer: VITE_SERVER_ORIGIN + VITE_NGINX_PROXY,
@@ -40,4 +39,4 @@ try {
 } catch (err) {
 	console.error(`-> 更新配置成功: `)
 	console.error(err)
-}
+}