index.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 align='center'
  27. prop="modifyOn"
  28. label="最后执行时间">
  29. <template slot-scope="scope">
  30. <div>
  31. {{ scope.row.modifyOn | dateForMinFormat }}
  32. </div>
  33. </template>
  34. </el-table-column>
  35. <el-table-column prop="status"
  36. align='center'
  37. label="任务状态">
  38. <template slot-scope="scope">
  39. <div>
  40. {{ getStatus(scope.row.status) }}
  41. </div>
  42. </template>
  43. </el-table-column>
  44. <el-table-column align='center'
  45. label="操作">
  46. <template slot-scope="scope">
  47. <el-button type="text" v-if="scope.row.status == 1 || scope.row.status == 3" @click="onPause(scope.row)">暂停</el-button>
  48. <el-button type="text" v-if="scope.row.status == 1 || scope.row.status == 3" @click="onExecute(scope.row)">执行</el-button>
  49. <el-button type="text" v-if="scope.row.status == 0" @click="onResume(scope.row)">恢复</el-button>
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <pagination
  54. sync
  55. :total.sync="pageInfo.total"
  56. :page.sync="pageInfo.page"
  57. :limit.sync="pageInfo.limit"
  58. :page-sizes="pageInfo.page_size"
  59. @pagination="__init"
  60. />
  61. </div>
  62. </div>
  63. </div>
  64. </template>
  65. <script>
  66. import pagination from "@/components/Pagination/index";
  67. import { taskList, pause, execute, resume } from '@/api/task'
  68. export default {
  69. components: { pagination },
  70. data () {
  71. return {
  72. tableData: [],
  73. pageInfo: {
  74. // 分页规则
  75. limit: 10, // 限制显示条数
  76. page: 1, // 当前页
  77. total: 0, // 总条数
  78. page_size: [10, 20, 40, 50] // 选择限制显示条数
  79. },
  80. }
  81. },
  82. mounted () {
  83. this.__init()
  84. },
  85. methods: {
  86. __init () {
  87. taskList({
  88. rows: this.pageInfo.limit,
  89. page: this.pageInfo.page
  90. }).then(res => {
  91. if(res.code == 200) {
  92. let result = res.data
  93. this.tableData = result.rows
  94. this.pageInfo.total = result.total;
  95. }
  96. })
  97. },
  98. onPause(row) {
  99. this.$confirm('您确定暂停吗?', '提示', {
  100. confirmButtonText: '确定',
  101. cancelButtonText: '取消',
  102. type: 'warning'
  103. }).then(() => {
  104. pause({ taskId: row.id }).then(res => {
  105. if(res.code == 200) {
  106. this.$message.success('暂停成功')
  107. this.__init()
  108. } else {
  109. this.$message.error(res.msg)
  110. }
  111. })
  112. }).catch(() => { })
  113. },
  114. onExecute(row) {
  115. this.$confirm('您确定执行吗?', '提示', {
  116. confirmButtonText: '确定',
  117. cancelButtonText: '取消',
  118. type: 'warning'
  119. }).then(() => {
  120. execute({ taskId: row.id }).then(res => {
  121. if(res.code == 200) {
  122. this.$message.success('执行成功')
  123. this.__init()
  124. } else {
  125. this.$message.error(res.msg)
  126. }
  127. })
  128. }).catch(() => { })
  129. },
  130. onResume(row) {
  131. this.$confirm('您确定恢复吗?', '提示', {
  132. confirmButtonText: '确定',
  133. cancelButtonText: '取消',
  134. type: 'warning'
  135. }).then(() => {
  136. resume({ taskId: row.id }).then(res => {
  137. if(res.code == 200) {
  138. this.$message.success('恢复成功')
  139. this.__init()
  140. } else {
  141. this.$message.error(res.msg)
  142. }
  143. })
  144. }).catch(() => { })
  145. },
  146. getStatus(index) {
  147. let template = {
  148. // -1: "执行失败",
  149. 0: "暂停",
  150. 1: "准备就绪",
  151. 2: "执行中",
  152. 3: "执行成功"
  153. }
  154. if(index == -1) {
  155. return '执行失败'
  156. }
  157. return template[index]
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss" scope>
  163. </style>