executed-list.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <?php
  2. ?>
  3. <div id="app" v-cloak>
  4. <el-card shadow="never" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  5. <div slot="header">
  6. <el-breadcrumb separator="/">
  7. <el-breadcrumb-item>
  8. <span style="color: #409EFF;cursor: pointer" @click="$navigate({r:'admin/task/index'})">
  9. 定时任务
  10. </span>
  11. </el-breadcrumb-item>
  12. <el-breadcrumb-item>任务执行记录</el-breadcrumb-item>
  13. </el-breadcrumb>
  14. </div>
  15. <div class="table-body">
  16. <el-form :inline="true" :model="search_data" size="small" class="demo-form-inline">
  17. <el-form-item>
  18. <el-input placeholder="请输入任务名称" v-model="search_data.name"></el-input>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-input placeholder="请输入任务ID精准搜索" v-model="search_data.task_id"></el-input>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-select v-model="search_data.type" placeholder="请选择任务类型">
  25. <el-option v-for="(value,index) in task_type" :key="index" :label="value" :value="index"> </el-option>
  26. </el-select>
  27. </el-form-item>
  28. <el-form-item>
  29. <el-select v-model="search_data.status" placeholder="请选择任务状态">
  30. <el-option v-for="(val,idx) in execute_status" :key="idx" :label="val" :value="idx"> </el-option>
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item>
  34. <el-date-picker style="margin-top: 1px;" @change="changeTime" v-model="datetime" type="datetimerange" value-format="yyyy-MM-dd HH:mm:ss" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
  35. </el-form-item>
  36. <el-form-item>
  37. <el-button size="small" type="primary" @click="search">搜索</el-button>
  38. <el-button size="small" type="danger" @click="clearSearch" v-if="show_clear_search_btn">清除条件</el-button>
  39. </el-form-item>
  40. </el-form-item>
  41. <el-table v-loading="listLoading" :data="list" stripe style="width: 100%">
  42. <el-table-column label="ID" prop="id" align="center" min-width="80"></el-table-column>
  43. <!-- <el-table-column label="执行命令" prop="command" align="center" show-overflow-tooltip>
  44. <template slot-scope="scope">
  45. <div>{{scope.row.command}}</div>
  46. </template>
  47. </el-table-column> -->
  48. <el-table-column label="任务名称" prop="name" align="center" show-overflow-tooltip>
  49. <template slot-scope="scope">
  50. <div>{{scope.row.name}}</div>
  51. </template>
  52. </el-table-column>
  53. <el-table-column label="任务类型" prop="type" align="center">
  54. <template slot-scope="scope">
  55. <div>{{task_type[scope.row.type]}}</div>
  56. </template>
  57. </el-table-column>
  58. <el-table-column label="执行耗时" prop="" align="center">
  59. <template slot-scope="scope">
  60. <div>{{scope.row.running_time}}ms</div>
  61. </template>
  62. </el-table-column>
  63. <!-- <el-table-column label="预设执行时间" prop="start_time" align="center">
  64. <template slot-scope="scope">
  65. <div>{{scope.row.start_time|dateTimeFormat('Y-m-d H:i:s')}}</div>
  66. </template>
  67. </el-table-column> -->
  68. <el-table-column label="实际执行时间" prop="execute_time" align="center">
  69. <template slot-scope="scope">
  70. <div>{{scope.row.execute_time|dateTimeFormat('Y-m-d H:i:s')}}</div>
  71. </template>
  72. </el-table-column>
  73. <el-table-column label="执行完成时间" prop="complete_time" align="center">
  74. <template slot-scope="scope">
  75. <div>{{scope.row.complete_time|dateTimeFormat('Y-m-d H:i:s')}}</div>
  76. </template>
  77. </el-table-column>
  78. <el-table-column label="执行状态" prop="exec_process" align="center">
  79. <template slot-scope="scope">
  80. <div>{{execute_status[scope.row.exec_process]}}</div>
  81. </template>
  82. </el-table-column>
  83. <!-- <el-table-column label="任务输出" prop="result" align="center" min-width="180">
  84. <template slot-scope="scope">
  85. <div>{{scope.row.result}}</div>
  86. </template>
  87. </el-table-column> -->
  88. <el-table-column label="预警通知" prop="wraning" align="center">
  89. <template slot-scope="scope">
  90. <div v-if="scope.row.wraning==1">待发送</div>
  91. <div v-else-if="scope.row.wraning==2">已发送</div>
  92. <div v-else>--</div>
  93. </template>
  94. </el-table-column>
  95. <el-table-column label="创建时间" prop="created_at" align="center">
  96. <template slot-scope="scope">
  97. <div>{{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</div>
  98. </template>
  99. </el-table-column>
  100. <el-table-column label="操作" min-width="120" align="center">
  101. <template slot-scope="scope">
  102. <el-button type="text" @click="recordDetail(scope.row.id)">查看详情</el-button>
  103. <el-button type="text" @click="taskRecordDelete(scope.row.id, scope.$index)">删除</el-button>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <div style="text-align: right;margin: 20px 0;">
  108. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  109. </div>
  110. </div>
  111. </el-card>
  112. </div>
  113. <script>
  114. const app = new Vue({
  115. el: '#app',
  116. data() {
  117. return {
  118. list: [{
  119. title: "测试标题"
  120. }],
  121. listLoading: false,
  122. page: 1,
  123. pageCount: 0,
  124. search_data: { // 筛选条件
  125. start: null,
  126. end: null,
  127. task_id: null,
  128. command: null,
  129. type: null,
  130. status: null,
  131. },
  132. datetime: [],
  133. task_type: {
  134. 0: '全部类型',
  135. 1: 'shell脚本',
  136. 2: '站内脚本',
  137. 3: '访问URL'
  138. },
  139. execute_status: {
  140. 1: '准备中',
  141. 2: '执行中',
  142. 3: '任务失败',
  143. 4: '已完成'
  144. }
  145. };
  146. },
  147. mounted: function() {
  148. this.getList();
  149. },
  150. computed: {
  151. show_clear_search_btn: function() {
  152. return !isEmpty(this.search_data.start) || !isEmpty(this.search_data.end) ||
  153. !isEmpty(this.search_data.task_id) || !isEmpty(this.search_data.name) || !isEmpty(this.search_data.type) || !isEmpty(this.search_data.status);
  154. }
  155. },
  156. methods: {
  157. changeTime(e) {
  158. // console.log(e);return null;
  159. if (e) {
  160. this.search_data.start = e[0];
  161. this.search_data.end = e[1];
  162. } else {
  163. this.search_data.start = '';
  164. this.search_data.end = '';
  165. }
  166. },
  167. sortChange(row) {
  168. if (row.prop) {
  169. this.search_data.sort_field = row.prop;
  170. this.search_data.sort_type = row.order == "descending" ? 'desc' : 'asc';
  171. } else {
  172. this.search_data.sort_prop = null;
  173. this.search_data.sort_type = null;
  174. }
  175. this.getList(this.search_data);
  176. },
  177. search() {
  178. this.getList(this.search_data);
  179. },
  180. clearSearch() {
  181. this.search_data.start = null;
  182. this.search_data.end = null;
  183. this.search_data.task_id = null;
  184. this.search_data.name = null;
  185. this.datetime = [];
  186. this.getList();
  187. },
  188. pagination(currentPage) {
  189. let self = this;
  190. self.page = currentPage;
  191. self.getList();
  192. },
  193. // 获取任务列表
  194. getList() {
  195. let self = this;
  196. if (self.listLoading == false) {
  197. self.listLoading = true;
  198. request({
  199. params: {
  200. r: 'admin/task/executed-list',
  201. page: self.page,
  202. start_time: this.search_data.start,
  203. end_time: this.search_data.end,
  204. task_id: this.search_data.task_id,
  205. name: this.search_data.name,
  206. type: this.search_data.type,
  207. status: this.search_data.status,
  208. },
  209. method: 'get',
  210. }).then(e => {
  211. self.listLoading = false;
  212. if (e.data.code == 0) {
  213. self.list = e.data.data.list;
  214. self.pageCount = e.data.data.page_count;
  215. } else {
  216. self.$message.error(e.data.msg);
  217. }
  218. }).catch(e => {
  219. self.$message.error(e.data.msg);
  220. self.listLoading = false;
  221. });
  222. }
  223. },
  224. // 执行记录详情
  225. recordDetail(id) {
  226. let params = {
  227. r: 'admin/task/executed-detail',
  228. };
  229. if (id) params = Object.assign(params, {
  230. id: id
  231. });
  232. navigateTo(params);
  233. },
  234. // 执行记录删除
  235. taskRecordDelete(id, index) {
  236. let self = this;
  237. self.$confirm('删除记录不可恢复,是否继续?', '提示', {
  238. confirmButtonText: '确定',
  239. cancelButtonText: '取消',
  240. type: 'warning'
  241. }).then(() => {
  242. self.listLoading = true;
  243. request({
  244. params: {
  245. r: 'admin/task/executed-record-del'
  246. },
  247. method: 'post',
  248. data: { id: id }
  249. }).then(e => {
  250. self.listLoading = false;
  251. if (e.data.code == 0) {
  252. self.list.splice(index, 1);
  253. self.$message.success(e.data.msg);
  254. } else {
  255. self.$message.error(e.data.msg);
  256. }
  257. }).catch(e => {
  258. self.listLoading = false;
  259. self.$message.error(e);
  260. });
  261. });
  262. },
  263. }
  264. });
  265. </script>