timer.data.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. import { BasicColumn } from '/@/components/Table';
  2. import { FormSchema } from '/@/components/Table';
  3. import { h } from 'vue';
  4. import { Switch, Tag } from 'ant-design-vue';
  5. import { useMessage } from '/@/hooks/web/useMessage';
  6. import { usePermission } from '/@/hooks/web/usePermission';
  7. import { setTimerStatus } from '/@/api/sys/admin';
  8. const { hasPermission } = usePermission();
  9. export const columns: BasicColumn[] = [
  10. {
  11. title: '任务名称',
  12. dataIndex: 'timerName',
  13. width: 150,
  14. fixed: 'left',
  15. },
  16. {
  17. title: '请求地址',
  18. dataIndex: 'requestUrl',
  19. width: 200,
  20. },
  21. {
  22. title: '请求类型',
  23. dataIndex: 'requestType',
  24. width: 100,
  25. customRender: ({ record }) => {
  26. const requestType = record.requestType;
  27. switch (requestType) {
  28. case 0:
  29. return h(Tag, { color: 'orange' }, () => 'RUN');
  30. case 1:
  31. return h(Tag, { color: 'orange' }, () => 'GET');
  32. case 2:
  33. return h(Tag, { color: 'orange' }, () => 'POST');
  34. case 3:
  35. return h(Tag, { color: 'orange' }, () => 'PUT');
  36. case 4:
  37. return h(Tag, { color: 'orange' }, () => 'DELETE');
  38. }
  39. return requestType;
  40. },
  41. },
  42. {
  43. title: '任务类型',
  44. dataIndex: 'timerType',
  45. width: 100,
  46. customRender: ({ record }) => {
  47. return record.timerType == 0 ? record.interval + 's' : record.cron;
  48. },
  49. },
  50. {
  51. title: '执行类型',
  52. dataIndex: 'executeType',
  53. width: 100,
  54. customRender: ({ record }) => {
  55. return record.executeType == 0 ? '并行' : '串行';
  56. },
  57. },
  58. {
  59. title: '执行一次',
  60. dataIndex: 'doOnce',
  61. width: 100,
  62. customRender: ({ record }) => {
  63. return record.doOnce ? '是' : '否';
  64. },
  65. },
  66. {
  67. title: '立即执行',
  68. dataIndex: 'startNow',
  69. width: 100,
  70. customRender: ({ record }) => {
  71. return record.startNow ? '是' : '否';
  72. },
  73. },
  74. {
  75. title: '状态',
  76. dataIndex: 'status',
  77. width: 120,
  78. customRender: ({ record }) => {
  79. if (!Reflect.has(record, 'pendingStatus')) {
  80. record.pendingStatus = false;
  81. }
  82. return h(Switch, {
  83. checked: record.status === 0,
  84. checkedChildren: '运行中',
  85. unCheckedChildren: '已停止',
  86. disabled: !hasPermission('sysTimer:setStatus'),
  87. loading: record.pendingStatus,
  88. onChange(checked: boolean) {
  89. record.pendingStatus = true;
  90. const newStatus = checked ? 0 : 1;
  91. const { createMessage } = useMessage();
  92. setTimerStatus(record.timerName, newStatus)
  93. .then(() => {
  94. record.status = newStatus;
  95. createMessage.success(`已成功修改任务状态`);
  96. })
  97. .catch(() => {
  98. createMessage.error('修改任务状态失败');
  99. })
  100. .finally(() => {
  101. record.pendingStatus = false;
  102. });
  103. },
  104. });
  105. },
  106. },
  107. {
  108. title: '执行次数',
  109. dataIndex: 'tally',
  110. width: 100,
  111. customRender: ({ record }) => {
  112. return h(Tag, { color: 'red' }, () => record.tally);
  113. },
  114. },
  115. {
  116. title: '创建时间',
  117. dataIndex: 'createTime',
  118. width: 180,
  119. },
  120. {
  121. title: '备注',
  122. dataIndex: 'remark',
  123. },
  124. ];
  125. export const searchFormSchema: FormSchema[] = [
  126. {
  127. field: 'timerName',
  128. label: '任务名称',
  129. component: 'Input',
  130. colProps: { span: 8 },
  131. },
  132. ];
  133. export const formSchema: FormSchema[] = [
  134. {
  135. field: 'timerName',
  136. label: '任务名称',
  137. component: 'Input',
  138. required: true,
  139. colProps: { span: 24 },
  140. },
  141. {
  142. field: 'requestUrl',
  143. label: '请求地址',
  144. component: 'Input',
  145. required: true,
  146. colProps: { span: 24 },
  147. },
  148. {
  149. field: 'requestType',
  150. label: '请求类型',
  151. component: 'RadioButtonGroup',
  152. defaultValue: 2,
  153. componentProps: {
  154. options: [
  155. { label: 'RUN', value: 0 },
  156. { label: 'GET', value: 1 },
  157. { label: 'POST', value: 2 },
  158. { label: 'PUT', value: 3 },
  159. { label: 'DELETE', value: 4 },
  160. ],
  161. },
  162. required: true,
  163. },
  164. {
  165. label: '请求参数',
  166. field: 'requestPara',
  167. component: 'InputTextArea',
  168. colProps: { span: 24 },
  169. },
  170. {
  171. label: 'Headers参数',
  172. field: 'headers',
  173. component: 'InputTextArea',
  174. colProps: { span: 24 },
  175. },
  176. {
  177. field: 'timerType',
  178. label: '任务类型',
  179. component: 'Select',
  180. defaultValue: 0,
  181. componentProps: {
  182. options: [
  183. { label: '间隔模式', value: 0 },
  184. { label: 'Cron模式', value: 1 },
  185. ],
  186. style: { width: '100%' },
  187. },
  188. required: true,
  189. colProps: { span: 12 },
  190. },
  191. {
  192. field: 'interval',
  193. label: '执行间隔',
  194. component: 'InputNumber',
  195. defaultValue: 5,
  196. required: true,
  197. colProps: { span: 12 },
  198. componentProps: { style: { width: '100%' } },
  199. ifShow: ({ values }) => values.timerType == 0,
  200. },
  201. {
  202. field: 'cron',
  203. label: 'Cron表达式',
  204. component: 'Input',
  205. required: true,
  206. colProps: { span: 12 },
  207. componentProps: { style: { width: '100%' } },
  208. ifShow: ({ values }) => values.timerType == 1,
  209. },
  210. {
  211. label: '备注',
  212. field: 'remark',
  213. component: 'InputTextArea',
  214. colProps: { span: 24 },
  215. },
  216. ];