index.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="m-container">
  3. <h2>定时任务 <div class="squrt"></div>
  4. </h2>
  5. <div class="m-core">
  6. <div class="tableWrap">
  7. <el-table style="width: 100%"
  8. :header-cell-style="{background:'#EDEEF0',color:'#444'}"
  9. :data='tableData'>
  10. <el-table-column prop="id"
  11. align='center'
  12. label="任务编号">
  13. </el-table-column>
  14. <el-table-column prop="description"
  15. align='center'
  16. label="英文名">
  17. </el-table-column>
  18. <el-table-column prop="name"
  19. align='center'
  20. label="任务名">
  21. </el-table-column>
  22. <el-table-column align='center'
  23. prop="timeExp"
  24. label="表达式">
  25. </el-table-column>
  26. <el-table-column prop="status"
  27. align='center'
  28. label="任务状态">
  29. <template slot-scope="scope">
  30. <div>
  31. {{ getStatus(scope.row.status) }}
  32. </div>
  33. </template>
  34. </el-table-column>
  35. <el-table-column align='center'
  36. label="操作">
  37. <template slot-scope="scope">
  38. <el-button type="text" v-if="scope.row.status == 1 || scope.row.status == 3" @click="onPause(scope.row)">暂停</el-button>
  39. <el-button type="text" v-if="scope.row.status == 1 || scope.row.status == 3" @click="onExecute(scope.row)">执行</el-button>
  40. <el-button type="text" v-if="scope.row.status == 0" @click="onResume(scope.row)">恢复</el-button>
  41. </template>
  42. </el-table-column>
  43. </el-table>
  44. </div>
  45. </div>
  46. </div>
  47. </template>
  48. <script>
  49. import { taskList, pause, execute, resume } from '@/api/task'
  50. export default {
  51. data () {
  52. return {
  53. tableData: []
  54. }
  55. },
  56. mounted () {
  57. this.__init()
  58. },
  59. methods: {
  60. __init () {
  61. taskList().then(res => {
  62. if(res.code == 200) {
  63. let result = res.data
  64. this.tableData = result.rows
  65. }
  66. })
  67. },
  68. onPause(row) {
  69. this.$confirm('您确定暂停吗?', '提示', {
  70. confirmButtonText: '确定',
  71. cancelButtonText: '取消',
  72. type: 'warning'
  73. }).then(() => {
  74. pause({ taskId: row.id }).then(res => {
  75. if(res.code == 200) {
  76. this.$message.success('暂停成功')
  77. this.__init()
  78. } else {
  79. this.$message.error(res.msg)
  80. }
  81. })
  82. }).catch(() => { })
  83. },
  84. onExecute(row) {
  85. this.$confirm('您确定执行吗?', '提示', {
  86. confirmButtonText: '确定',
  87. cancelButtonText: '取消',
  88. type: 'warning'
  89. }).then(() => {
  90. execute({ taskId: row.id }).then(res => {
  91. if(res.code == 200) {
  92. this.$message.success('执行成功')
  93. this.__init()
  94. } else {
  95. this.$message.error(res.msg)
  96. }
  97. })
  98. }).catch(() => { })
  99. },
  100. onResume(row) {
  101. this.$confirm('您确定恢复吗?', '提示', {
  102. confirmButtonText: '确定',
  103. cancelButtonText: '取消',
  104. type: 'warning'
  105. }).then(() => {
  106. resume({ taskId: row.id }).then(res => {
  107. if(res.code == 200) {
  108. this.$message.success('恢复成功')
  109. this.__init()
  110. } else {
  111. this.$message.error(res.msg)
  112. }
  113. })
  114. }).catch(() => { })
  115. },
  116. getStatus(index) {
  117. let template = {
  118. // -1: "执行失败",
  119. 0: "暂停",
  120. 1: "准备就绪",
  121. 2: "执行中",
  122. 3: "执行成功"
  123. }
  124. if(index == -1) {
  125. return '执行失败'
  126. }
  127. return template[index]
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scope>
  133. </style>