index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. <!--
  2. * @Descripttion: 系统计划任务配置
  3. * @version: 1.2
  4. * @Author: sakuya
  5. * @Date: 2021年7月7日09:28:32
  6. * @LastEditors: sakuya
  7. * @LastEditTime: 2021年7月10日20:56:47
  8. -->
  9. <template>
  10. <el-main>
  11. <el-row :gutter="15">
  12. <el-col :xl="6" :lg="6" :md="8" :sm="12" :xs="24" v-for="item in list" :key="item.id">
  13. <el-card class="task task-item" shadow="hover">
  14. <h2>{{item.title}}</h2>
  15. <ul>
  16. <li>
  17. <h4>执行类</h4>
  18. <p>{{item.handler}}</p>
  19. </li>
  20. <li>
  21. <h4>定时规则</h4>
  22. <p>{{item.cron}}</p>
  23. </li>
  24. </ul>
  25. <div class="bottom">
  26. <div class="state">
  27. <el-tag v-if="item.state=='1'" size="small">准备就绪</el-tag>
  28. <el-tag v-if="item.state=='-1'" size="small" type="info">停用</el-tag>
  29. </div>
  30. <div class="handler">
  31. <el-popconfirm title="确定立即执行吗?" @confirm="run(item)">
  32. <template #reference>
  33. <el-button type="primary" icon="el-icon-caret-right" circle></el-button>
  34. </template>
  35. </el-popconfirm>
  36. <el-dropdown trigger="click">
  37. <el-button type="primary" icon="el-icon-more" circle plain></el-button>
  38. <template #dropdown>
  39. <el-dropdown-menu>
  40. <el-dropdown-item @click="edit(item)">编辑</el-dropdown-item>
  41. <el-dropdown-item @click="logs(item)">日志</el-dropdown-item>
  42. <el-dropdown-item @click="del(item)" divided>删除</el-dropdown-item>
  43. </el-dropdown-menu>
  44. </template>
  45. </el-dropdown>
  46. </div>
  47. </div>
  48. </el-card>
  49. </el-col>
  50. <el-col :xl="6" :lg="6" :md="8" :sm="12" :xs="24">
  51. <el-card class="task task-add" shadow="never" @click="add">
  52. <el-icon><el-icon-plus /></el-icon>
  53. <p>添加计划任务</p>
  54. </el-card>
  55. </el-col>
  56. </el-row>
  57. </el-main>
  58. <save-dialog v-if="dialog.save" ref="saveDialog" @success="handleSuccess" @closed="dialog.save=false"></save-dialog>
  59. <el-drawer title="计划任务日志" v-model="dialog.logsVisible" :size="600" direction="rtl" destroy-on-close>
  60. <logs></logs>
  61. </el-drawer>
  62. </template>
  63. <script>
  64. import saveDialog from './save'
  65. import logs from './logs'
  66. export default {
  67. name: 'task',
  68. components: {
  69. saveDialog,
  70. logs
  71. },
  72. provide() {
  73. return {
  74. list: this.list
  75. }
  76. },
  77. data() {
  78. return {
  79. dialog: {
  80. save: false,
  81. logsVisible: false
  82. },
  83. list: [
  84. {
  85. id: "1",
  86. title: "清理服务器缓存",
  87. handler: "cleanUpCacheHandler",
  88. cron: "59 59 23 * * ? *",
  89. state: "1"
  90. },
  91. {
  92. id: "2",
  93. title: "自动审核",
  94. handler: "automaticAuditHandler",
  95. cron: "0 0 * * * ? *",
  96. state: "1"
  97. },
  98. {
  99. id: "3",
  100. title: "清理未实名用户",
  101. handler: "deleteUserHandler",
  102. cron: "0 0 0 * * ? *",
  103. state: "-1"
  104. }
  105. ]
  106. }
  107. },
  108. mounted() {
  109. },
  110. methods: {
  111. add(){
  112. this.dialog.save = true
  113. this.$nextTick(() => {
  114. this.$refs.saveDialog.open()
  115. })
  116. },
  117. edit(task){
  118. this.dialog.save = true
  119. this.$nextTick(() => {
  120. this.$refs.saveDialog.open('edit').setData(task)
  121. })
  122. },
  123. del(task){
  124. this.$confirm(`确认删除 ${task.title} 计划任务吗?`,'提示', {
  125. type: 'warning',
  126. confirmButtonText: '删除',
  127. confirmButtonClass: 'el-button--danger'
  128. }).then(() => {
  129. this.list.splice(this.list.findIndex(item => item.id === task.id), 1)
  130. }).catch(() => {
  131. //取消
  132. })
  133. },
  134. logs(){
  135. this.dialog.logsVisible = true
  136. },
  137. run(task){
  138. this.$message.success(`已成功执行计划任务:${task.title}`)
  139. },
  140. //本地更新数据
  141. handleSuccess(data, mode){
  142. if(mode=='add'){
  143. data.id = new Date().getTime()
  144. this.list.push(data)
  145. }else if(mode=='edit'){
  146. this.list.filter(item => item.id===data.id ).forEach(item => {
  147. Object.assign(item, data)
  148. })
  149. }
  150. }
  151. }
  152. }
  153. </script>
  154. <style scoped>
  155. .task {height: 210px;}
  156. .task-item h2 {font-size: 15px;color: #3c4a54;padding-bottom:15px;}
  157. .task-item li {list-style-type:none;margin-bottom: 10px;}
  158. .task-item li h4 {font-size: 12px;font-weight: normal;color: #999;}
  159. .task-item li p {margin-top: 5px;}
  160. .task-item .bottom {border-top: 1px solid #EBEEF5;text-align: right;padding-top:10px;display: flex;justify-content: space-between;align-items: center;}
  161. .task-add {display: flex;flex-direction: column;align-items: center;justify-content: center;text-align: center;cursor: pointer;color: #999;}
  162. .task-add:hover {color: #409EFF;}
  163. .task-add i {font-size: 30px;}
  164. .task-add p {font-size: 12px;margin-top: 20px;}
  165. .dark .task-item .bottom {border-color: var(--el-border-color-light);}
  166. </style>