send.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <el-card shadow="hover">
  3. <div class="search">
  4. <el-form :inline="true">
  5. <el-form-item>
  6. <!-- <el-button size="default" type="primary" class="ml10" @click="getList(1)">
  7. <el-icon>
  8. <ele-Search />
  9. </el-icon>
  10. 查询
  11. </el-button> -->
  12. <el-button type="success" @click="addOrEdit()" v-auth="'add'">
  13. <el-icon>
  14. <ele-FolderAdd />
  15. </el-icon>
  16. 新增数据转发
  17. </el-button>
  18. </el-form-item>
  19. </el-form>
  20. </div>
  21. <el-table :data="tableData" style="width: 100%" v-loading="loading">
  22. <el-table-column type="index" label="序号" width="80" align="center" />
  23. <el-table-column prop="name" label="名称" show-overflow-tooltip></el-table-column>
  24. <el-table-column prop="expound" label="说明" show-overflow-tooltip></el-table-column>
  25. <el-table-column prop="createdAt" label="创建时间" min-width="100" align="center"></el-table-column>
  26. <el-table-column prop="status" label="状态" width="100" align="center">
  27. <template #default="scope">
  28. <el-tag type="success" size="small" v-if="scope.row.status == 1">已启动</el-tag>
  29. <el-tag type="info" size="small" v-else>已停止</el-tag>
  30. </template>
  31. </el-table-column>
  32. <el-table-column label="操作" width="200" align="center">
  33. <template #default="scope">
  34. <el-button size="small" text type="info" v-auth="'startOrStop'" v-if="scope.row.status" @click="setStatus(scope.row, 0)">停止</el-button>
  35. <el-button size="small" text type="primary" v-auth="'startOrStop'" v-else @click="setStatus(scope.row, 1)">启动</el-button>
  36. <el-button size="small" text type="warning" v-auth="'edit'" @click="addOrEdit(scope.row)">编辑</el-button>
  37. <el-button size="small" text type="warning" @click="edit(scope.row)">规则编辑</el-button>
  38. <el-button size="small" text type="danger" v-auth="'del'" @click="onDel(scope.row)">删除</el-button>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. <pagination v-if="params.total" :total="params.total" v-model:page="params.pageNum" v-model:limit="params.pageSize" @pagination="getList()" />
  43. <EditForm ref="editFormRef" @getList="getList()" :types="1"></EditForm>
  44. </el-card>
  45. </template>
  46. <script lang="ts" setup>
  47. import { ref } from 'vue';
  48. import api from '/@/api/rule';
  49. import { ElMessageBox, ElMessage } from 'element-plus';
  50. import { useSearch } from '/@/hooks/useCommon';
  51. import EditForm from './edit.vue';
  52. import axios from 'axios';
  53. const editFormRef = ref();
  54. const { params, tableData, getList, loading } = useSearch<any[]>(api.getList, 'Data', { types: 1 });
  55. const headers = {
  56. Authorization: 'Bearer ' + localStorage.token,
  57. };
  58. const flowsUrl = window.location.origin + '/rule-engine/flows';
  59. getList();
  60. const addOrEdit = async (row?: any) => {
  61. if (row) {
  62. editFormRef.value.open(row);
  63. return;
  64. } else {
  65. editFormRef.value.open();
  66. }
  67. };
  68. const setStatus = async (row: any, status: number) => {
  69. // 找到所有规则
  70. const { data: flows } = await axios.get(flowsUrl, { headers });
  71. const flow = flows.find((item: any) => item.id === row.flowId);
  72. if (!flow) {
  73. ElMessage.error('规则不存在');
  74. return;
  75. }
  76. // 改变指定规则状态
  77. flow.disabled = status ? false : true;
  78. // 设置规则状态
  79. await axios.post(flowsUrl, flows, { headers });
  80. api
  81. .setStatus(row.id, status)
  82. .then(() => {
  83. ElMessage.success('操作成功');
  84. getList();
  85. })
  86. .catch(() => {
  87. ElMessage.error('操作失败');
  88. });
  89. };
  90. const edit = async (row: any) => {
  91. localStorage.setItem('auth-tokens', `{"access_token":"${localStorage.token}"}`);
  92. const url = '/rule-engine/#flow/' + row.flowId;
  93. window.open(url);
  94. };
  95. const onDel = (row: any) => {
  96. ElMessageBox.confirm(`此操作将删除:“${row.name}”,是否继续?`, '提示', {
  97. confirmButtonText: '确认',
  98. cancelButtonText: '取消',
  99. type: 'warning',
  100. }).then(async () => {
  101. // 找到所有规则
  102. const { data: flows } = await axios.get(flowsUrl, { headers });
  103. const flowIndex = flows.findIndex((item: any) => item.id === row.flowId);
  104. if (flowIndex >= 0) {
  105. // 删除指定规则
  106. flows.splice(flowIndex, 1);
  107. // 删除当前规则下的各个节点信息
  108. const newFlows = flows.filter((item: any) => {
  109. if (item.z === row.flowId) {
  110. return false;
  111. } else {
  112. return true;
  113. }
  114. });
  115. // 设置规则状态
  116. await axios.post(flowsUrl, newFlows, { headers });
  117. }
  118. await api.del([row.id as string]);
  119. ElMessage.success('删除成功');
  120. getList();
  121. });
  122. };
  123. </script>