execMonitor.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <div class="workflow-exec">
  3. <el-card>
  4. <div slot="header" class="card-header">
  5. <span>工作流执行监控</span>
  6. <div>
  7. <el-select v-model="searchWorkflowId" placeholder="选择工作流" clearable style="width: 200px; margin-right: 10px" @change="getList">
  8. <el-option v-for="w in workflowList" :key="w.id" :label="w.templateName" :value="w.id" />
  9. </el-select>
  10. <el-button type="primary" @click="getList">
  11. <i class="el-icon-search"></i>查询
  12. </el-button>
  13. </div>
  14. </div>
  15. <el-table :data="tableData" v-loading="loading" border>
  16. <el-table-column type="index" label="序号" width="60" align="center" />
  17. <el-table-column prop="instanceName" label="实例名称" min-width="180" show-overflow-tooltip />
  18. <el-table-column prop="contactName" label="联系人" width="120" />
  19. <el-table-column prop="status" label="状态" width="100" align="center">
  20. <template slot-scope="{ row }">
  21. <el-tag :type="getStatusType(row.status)">{{ getStatusText(row.status) }}</el-tag>
  22. </template>
  23. </el-table-column>
  24. <el-table-column prop="currentNodeName" label="当前节点" width="150" show-overflow-tooltip />
  25. <el-table-column label="进度" width="120" align="center">
  26. <template slot-scope="{ row }">
  27. {{ row.completedNodes || 0 }}/{{ row.totalNodes || 0 }}
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="startTime" label="开始时间" width="170" />
  31. <el-table-column prop="lastActivityTime" label="最后活动" width="170" />
  32. <el-table-column label="操作" width="280" fixed="right">
  33. <template slot-scope="{ row }">
  34. <el-button type="primary" size="mini" @click="handleViewLogs(row)">日志</el-button>
  35. <el-button v-if="row.status === 'running'" type="warning" size="mini" @click="handlePause(row)">暂停</el-button>
  36. <el-button v-if="row.status === 'paused'" type="success" size="mini" @click="handleResume(row)">恢复</el-button>
  37. <el-button v-if="row.status !== 'completed' && row.status !== 'terminated'" type="danger" size="mini" @click="handleTerminate(row)">终止</el-button>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. </el-card>
  42. <el-dialog title="节点执行日志" :visible.sync="logDialogVisible" width="900px">
  43. <el-timeline>
  44. <el-timeline-item
  45. v-for="log in nodeLogs"
  46. :key="log.id"
  47. :timestamp="log.createTime"
  48. :type="getLogTimelineType(log.status)"
  49. placement="top"
  50. >
  51. <el-card shadow="hover">
  52. <div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px">
  53. <div>
  54. <el-tag size="small">{{ log.nodeName }}</el-tag>
  55. <el-tag size="small" type="info" style="margin-left: 5px">{{ log.nodeType }}</el-tag>
  56. <el-tag size="small" :type="log.status === 'sent' ? 'success' : 'primary'" style="margin-left: 5px">
  57. {{ log.status === 'sent' ? '发送' : '接收' }}
  58. </el-tag>
  59. </div>
  60. <span v-if="log.durationMs" style="color: #909399; font-size: 12px">{{ log.durationMs }}ms</span>
  61. </div>
  62. <div v-if="log.outputContent" style="margin-bottom: 5px">
  63. <strong>发送内容:</strong>
  64. <p style="margin: 5px 0; padding: 8px; background: #f5f7fa; border-radius: 4px; white-space: pre-wrap">{{ log.outputContent }}</p>
  65. </div>
  66. <div v-if="log.inputContent">
  67. <strong>接收内容:</strong>
  68. <p style="margin: 5px 0; padding: 8px; background: #ecf5ff; border-radius: 4px; white-space: pre-wrap">{{ log.inputContent }}</p>
  69. </div>
  70. <div v-if="log.errorMessage" style="color: #f56c6c; margin-top: 5px">
  71. <strong>错误:</strong>{{ log.errorMessage }}
  72. </div>
  73. </el-card>
  74. </el-timeline-item>
  75. </el-timeline>
  76. <div v-if="!nodeLogs.length" style="text-align: center; color: #909399; padding: 20px">暂无执行日志</div>
  77. </el-dialog>
  78. </div>
  79. </template>
  80. <script>
  81. import { workflowExecApi } from '@/api/company/workflowExec'
  82. import { listAllWorkflowTemplates } from '@/api/company/workflowLobster'
  83. export default {
  84. name: 'WorkflowExecMonitor',
  85. data() {
  86. return {
  87. loading: false,
  88. tableData: [],
  89. searchWorkflowId: null,
  90. workflowList: [],
  91. logDialogVisible: false,
  92. nodeLogs: []
  93. }
  94. },
  95. created() {
  96. this.getWorkflowList()
  97. this.getList()
  98. },
  99. methods: {
  100. async getWorkflowList() {
  101. try {
  102. const res = await listAllWorkflowTemplates()
  103. this.workflowList = res.data || []
  104. } catch (e) {
  105. this.workflowList = []
  106. }
  107. },
  108. async getList() {
  109. this.loading = true
  110. try {
  111. const res = await workflowExecApi.listInstances(this.searchWorkflowId)
  112. this.tableData = res.data || []
  113. } catch (error) {
  114. this.$message.error('获取列表失败')
  115. } finally {
  116. this.loading = false
  117. }
  118. },
  119. async handleViewLogs(row) {
  120. try {
  121. const res = await workflowExecApi.getNodeLogs(row.id)
  122. this.nodeLogs = res.data || []
  123. this.logDialogVisible = true
  124. } catch (error) {
  125. this.$message.error('获取日志失败')
  126. }
  127. },
  128. async handlePause(row) {
  129. try {
  130. await workflowExecApi.pause(row.id)
  131. this.$message.success('已暂停')
  132. this.getList()
  133. } catch (error) {
  134. this.$message.error('操作失败')
  135. }
  136. },
  137. async handleResume(row) {
  138. try {
  139. await workflowExecApi.resume(row.id)
  140. this.$message.success('已恢复')
  141. this.getList()
  142. } catch (error) {
  143. this.$message.error('操作失败')
  144. }
  145. },
  146. async handleTerminate(row) {
  147. try {
  148. await this.$confirm('确定要终止该工作流实例吗?', '提示', { type: 'warning' })
  149. await workflowExecApi.terminate(row.id, '手动终止')
  150. this.$message.success('已终止')
  151. this.getList()
  152. } catch (error) {
  153. if (error !== 'cancel') this.$message.error('操作失败')
  154. }
  155. },
  156. getStatusType(status) {
  157. const map = { running: 'success', paused: 'warning', completed: 'info', terminated: 'danger', pending: '' }
  158. return map[status] || ''
  159. },
  160. getStatusText(status) {
  161. const map = { running: '运行中', paused: '已暂停', completed: '已完成', terminated: '已终止', pending: '待启动' }
  162. return map[status] || status
  163. },
  164. getLogTimelineType(status) {
  165. return status === 'sent' ? 'success' : 'primary'
  166. }
  167. }
  168. }
  169. </script>
  170. <style scoped>
  171. .card-header { display: flex; justify-content: space-between; align-items: center; }
  172. .card-header div { display: flex; gap: 10px; align-items: center; }
  173. </style>