index.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. <template>
  2. <Card :bordered="false" dis-hover>
  3. <Alert closable="true">
  4. <template slot="desc">
  5. 启动定时任务两种方式:<br />
  6. 1、使用命令启动:php think timer start --d<br />
  7. 2、使用接口触发定时任务,接口地址 https://您的域名/api/crontab/run
  8. </template>
  9. </Alert>
  10. <Button type="primary" @click="addTask">添加定时任务</Button>
  11. <Table :columns="columns" :data="tableData" :loading="loading" class="ivu-mt">
  12. <template slot-scope="{ row }" slot="execution_cycle">
  13. <span>{{ taskTrip(row) }}</span>
  14. </template>
  15. <template slot-scope="{ row }" slot="is_open">
  16. <i-switch v-model="row.is_open" :true-value="1" :false-value="0" size="large" @on-change="handleChange(row)">
  17. <span slot="open">开启</span>
  18. <span slot="close">关闭</span>
  19. </i-switch>
  20. </template>
  21. <template slot-scope="{ row }" slot="action">
  22. <a @click="edit(row.id)">编辑</a>
  23. <Divider type="vertical" />
  24. <a @click="handleDelete(row, '删除秒杀商品', index)">删除</a>
  25. </template>
  26. </Table>
  27. <div class="acea-row row-right page">
  28. <Page :total="total" :current="page" show-elevator show-total @on-change="pageChange" :page-size="limit" />
  29. </div>
  30. <creatTask ref="addTask" @submitAsk="getList"></creatTask>
  31. </Card>
  32. </template>
  33. <script>
  34. import { timerIndex, showTimer } from '@/api/system';
  35. import creatTask from './createModal.vue';
  36. export default {
  37. name: 'system_crontab',
  38. components: { creatTask },
  39. data() {
  40. return {
  41. loading: false,
  42. columns: [
  43. {
  44. title: '名称',
  45. key: 'name',
  46. minWidth: 150,
  47. },
  48. {
  49. title: '任务说明',
  50. key: 'content',
  51. minWidth: 120,
  52. },
  53. // {
  54. // title: '最后执行时间',
  55. // key: 'last_execution_time',
  56. // minWidth: 120,
  57. // },
  58. // {
  59. // title: '下次执行时间',
  60. // key: 'next_execution_time',
  61. // minWidth: 120,
  62. // },
  63. {
  64. title: '执行周期',
  65. slot: 'execution_cycle',
  66. minWidth: 160,
  67. },
  68. {
  69. title: '是否开启',
  70. slot: 'is_open',
  71. minWidth: 100,
  72. },
  73. {
  74. title: '操作',
  75. slot: 'action',
  76. align: 'center',
  77. fixed: 'right',
  78. minWidth: 100,
  79. },
  80. ],
  81. tableData: [],
  82. page: 1,
  83. limit: 15,
  84. total: 1,
  85. };
  86. },
  87. created() {
  88. this.getList();
  89. },
  90. methods: {
  91. taskTrip(row) {
  92. switch (row.type) {
  93. case 1:
  94. return `每隔${row.second}秒执行一次`;
  95. case 2:
  96. return `每隔${row.minute}分钟执行一次`;
  97. case 3:
  98. return `每隔${row.hour}小时执行一次`;
  99. case 4:
  100. return `每隔${row.day}天执行一次`;
  101. case 5:
  102. return `每天${row.hour}时${row.minute}分${row.second}秒执行一次`;
  103. case 6:
  104. return `每个星期${row.week}的${row.hour}时${row.minute}分${row.second}秒执行一次`;
  105. case 7:
  106. return `每月${row.day}日的${row.hour}时${row.minute}分${row.second}秒执行一次`;
  107. }
  108. },
  109. // 列表
  110. getList() {
  111. this.loading = true;
  112. timerIndex({
  113. page: this.page,
  114. limit: this.limit,
  115. })
  116. .then((res) => {
  117. this.loading = false;
  118. let { count, list } = res.data;
  119. this.total = count;
  120. this.tableData = list;
  121. })
  122. .catch((res) => {
  123. this.loading = false;
  124. this.$Message.error(res.msg);
  125. });
  126. },
  127. addTask() {
  128. console.log(this.$refs.addTask);
  129. this.$refs.addTask.modal = true;
  130. },
  131. edit(id) {
  132. console.log(id);
  133. this.$refs.addTask.timerInfo(id);
  134. },
  135. // 删除
  136. handleDelete(row, tit, num) {
  137. let delfromData = {
  138. title: tit,
  139. num: num,
  140. url: `system/timer/del/${row.id}`,
  141. method: 'delete',
  142. ids: '',
  143. };
  144. this.$modalSure(delfromData)
  145. .then((res) => {
  146. this.$Message.success(res.msg);
  147. this.getList();
  148. })
  149. .catch((res) => {
  150. this.$Message.error(res.msg);
  151. });
  152. },
  153. // 是否开启
  154. handleChange({ id, is_open }) {
  155. showTimer(id, is_open)
  156. .then((res) => {
  157. this.$Message.success(res.msg);
  158. this.getList();
  159. })
  160. .catch((res) => {
  161. this.$Message.error(res.msg);
  162. });
  163. },
  164. pageChange(index) {
  165. this.page = index;
  166. this.getList();
  167. },
  168. },
  169. };
  170. </script>
  171. <style lang="stylus" scoped>
  172. .ivu-mt {
  173. padding-top:10px
  174. }
  175. </style>