index.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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"
  9. @click="$navigate({r:'admin/task/index'})">
  10. 定时任务
  11. </span>
  12. </el-breadcrumb-item>
  13. <el-breadcrumb-item>任务列表</el-breadcrumb-item>
  14. <el-button style="margin: -5px 0;float: right" type="primary" size="small" @click="$navigate({r:'admin/task/edit'})">添加任务 </el-button>
  15. </el-breadcrumb>
  16. </div>
  17. <div class="table-body">
  18. <el-form :inline="true" :model="search_data" size="small" class="demo-form-inline">
  19. <el-form-item>
  20. <el-input placeholder="请输入任务名称" v-model="search_data.name"></el-input>
  21. </el-form-item>
  22. <el-form-item>
  23. <el-input placeholder="请输入ID精准搜索" v-model="search_data.id"></el-input>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-select v-model="search_data.type" placeholder="请选择任务类型">
  27. <el-option v-for="(value,index) in task_type" :key="index" :label="value" :value="index"> </el-option>
  28. </el-select>
  29. </el-form-item>
  30. <el-form-item>
  31. <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>
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button size="small" type="primary" @click="search">搜索</el-button>
  35. <el-button size="small" type="danger" @click="clearSearch" v-if="show_clear_search_btn">清除条件</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <el-table v-loading="listLoading" :data="list" stripe style="width: 100%">
  39. <el-table-column label="ID" prop="id" align="center" min-width="80"></el-table-column>
  40. <el-table-column label="标题" prop="name" align="center" min-width="120">
  41. <template slot-scope="scope">
  42. <div size="small">{{scope.row.name}}</div>
  43. </template>
  44. </el-table-column>
  45. <el-table-column label="任务执行规则" prop="rule" align="center" min-width="200"></el-table-column>
  46. <el-table-column label="执行命令" prop="command" align="center" min-width="300" show-overflow-tooltip>
  47. <template slot-scope="scope">
  48. <div>{{scope.row.command}}</div>
  49. </template>
  50. </el-table-column>
  51. <el-table-column label="任务类型" prop="type" align="center">
  52. <template slot-scope="scope">
  53. <div>{{task_type[scope.row.type]}}</div>
  54. </template>
  55. </el-table-column>
  56. <el-table-column label="任务类型" prop="type" align="center">
  57. <template slot-scope="scope">
  58. <div v-if="scope.row.status==1">启用</div>
  59. <div v-else-if="scope.row.status==0">禁用</div>
  60. </template>
  61. </el-table-column>
  62. <el-table-column label="添加时间" prop="type" align="center">
  63. <template slot-scope="scope">
  64. <div>{{scope.row.created_at|dateTimeFormat('Y-m-d H:i:s')}}</div>
  65. </template>
  66. </el-table-column>
  67. <el-table-column label="操作" min-width="150" align="center">
  68. <template slot-scope="scope">
  69. <el-button type="text" @click="handle('edit',scope.row)">编辑</el-button>
  70. <el-button type="text" @click="taskDelete(scope.row.id, scope.$index)">删除</el-button>
  71. </template>
  72. </el-table-column>
  73. </el-table>
  74. <div style="text-align: right;margin: 20px 0;">
  75. <el-pagination @current-change="pagination" background layout="prev, pager, next" :page-count="pageCount"></el-pagination>
  76. </div>
  77. </div>
  78. </el-card>
  79. </div>
  80. <script>
  81. const app = new Vue({
  82. el: '#app',
  83. data() {
  84. return {
  85. list: [{
  86. title: "测试标题"
  87. }],
  88. listLoading: false,
  89. page: 1,
  90. pageCount: 0,
  91. search_data: { // 筛选条件
  92. start: null,
  93. end: null,
  94. id: null,
  95. name: null,
  96. type: null,
  97. },
  98. datetime: [],
  99. task_type: {
  100. 0: '全部类型',
  101. 1: 'shell脚本',
  102. 2: '站内脚本',
  103. 3: '访问URL'
  104. },
  105. };
  106. },
  107. mounted: function() {
  108. this.getList();
  109. },
  110. computed: {
  111. show_clear_search_btn: function() {
  112. return !isEmpty(this.search_data.start) || !isEmpty(this.search_data.end) ||
  113. !isEmpty(this.search_data.id) || !isEmpty(this.search_data.name) || !isEmpty(this.search_data.type);
  114. }
  115. },
  116. methods: {
  117. changeTime(e) {
  118. // console.log(e)
  119. if (e) {
  120. this.search_data.start = e[0];
  121. this.search_data.end = e[1];
  122. } else {
  123. this.search_data.start = '';
  124. this.search_data.end = '';
  125. }
  126. },
  127. sortChange(row) {
  128. if (row.prop) {
  129. this.search_data.sort_field = row.prop;
  130. this.search_data.sort_type = row.order == "descending" ? 'desc' : 'asc';
  131. } else {
  132. this.search_data.sort_prop = null;
  133. this.search_data.sort_type = null;
  134. }
  135. this.getList(this.search_data);
  136. },
  137. search() {
  138. this.getList(this.search_data);
  139. },
  140. clearSearch() {
  141. this.search_data.start = null;
  142. this.search_data.end = null;
  143. this.search_data.id = null;
  144. this.search_data.name = null;
  145. this.datetime = [];
  146. this.getList();
  147. },
  148. handle(type, data = null) {
  149. let id = data ? parseInt(data.id) : '';
  150. switch (type) {
  151. case 'edit':
  152. let params = {
  153. //编辑页面路径
  154. r: 'admin/task/edit'
  155. };
  156. if (id) params = Object.assign(params, {
  157. id: id
  158. });
  159. navigateTo(params);
  160. break;
  161. }
  162. },
  163. pagination(currentPage) {
  164. let self = this;
  165. self.page = currentPage;
  166. self.getList();
  167. },
  168. // 获取任务列表
  169. getList() {
  170. let self = this;
  171. if (self.listLoading == false) {
  172. self.listLoading = true;
  173. request({
  174. params: {
  175. r: 'admin/task/index',
  176. page: self.page,
  177. start_time: this.search_data.start,
  178. end_time: this.search_data.end,
  179. id: this.search_data.id,
  180. name: this.search_data.name,
  181. type: this.search_data.type
  182. },
  183. method: 'get',
  184. }).then(e => {
  185. self.listLoading = false;
  186. if (e.data.code == 0) {
  187. self.list = e.data.data.list;
  188. self.pageCount = e.data.data.page_count;
  189. } else {
  190. self.$message.error(e.data.msg);
  191. }
  192. }).catch(e => {
  193. self.$message.error(e.data.msg);
  194. self.listLoading = false;
  195. });
  196. }
  197. },
  198. // 删除任务
  199. taskDelete(id, index) {
  200. let self = this;
  201. self.$confirm('删除任务不可恢复,是否继续?', '提示', {
  202. confirmButtonText: '确定',
  203. cancelButtonText: '取消',
  204. type: 'warning'
  205. }).then(() => {
  206. self.listLoading = true;
  207. request({
  208. params: {
  209. r: 'admin/task/delete'
  210. },
  211. method: 'post',
  212. data: {
  213. id: id
  214. }
  215. }).then(e => {
  216. self.listLoading = false;
  217. if (e.data.code == 0) {
  218. self.list.splice(index, 1);
  219. self.$message.success('删除成功');
  220. } else {
  221. self.$message.error(e.data.msg);
  222. }
  223. }).catch(e => {
  224. self.listLoading = false;
  225. self.$message.error(e);
  226. });
  227. });
  228. }
  229. }
  230. });
  231. </script>