index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
  4. <el-form-item label="任务名称" prop="name">
  5. <el-input v-model="queryParams.name" placeholder="请输入任务名称" clearable size="small" @keyup.enter.native="handleQuery"/>
  6. </el-form-item>
  7. <el-form-item label="任务状态" prop="status">
  8. <el-select v-model="queryParams.status" placeholder="请选择任务状态" clearable size="small">
  9. <el-option v-for="dict in this.getDictDatas(DICT_TYPE.INF_JOB_STATUS)"
  10. :key="dict.value" :label="dict.label" :value="dict.value"/>
  11. </el-select>
  12. </el-form-item>
  13. <el-form-item label="处理器的名字" prop="handlerName">
  14. <el-input v-model="queryParams.handlerName" placeholder="请输入处理器的名字" clearable size="small" @keyup.enter.native="handleQuery"/>
  15. </el-form-item>
  16. <el-form-item>
  17. <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  18. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  19. </el-form-item>
  20. </el-form>
  21. <el-row :gutter="10" class="mb8">
  22. <el-col :span="1.5">
  23. <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAdd"
  24. v-hasPermi="['infra:job:create']">新增</el-button>
  25. </el-col>
  26. <el-col :span="1.5">
  27. <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport"
  28. v-hasPermi="['infra:job:export']">导出</el-button>
  29. </el-col>
  30. <el-col :span="1.5">
  31. <el-button type="info" icon="el-icon-s-operation" size="mini" @click="handleJobLog"
  32. v-hasPermi="['monitor:job:query']">日志</el-button>
  33. </el-col>
  34. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  35. </el-row>
  36. <el-table v-loading="loading" :data="jobList">
  37. <el-table-column label="任务编号" align="center" prop="id" />
  38. <el-table-column label="任务名称" align="center" prop="name" />
  39. <el-table-column label="任务状态" align="center" prop="status">
  40. <template slot-scope="scope">
  41. <span>{{ getDictDataLabel(DICT_TYPE.INF_JOB_STATUS, scope.row.status) }}</span>
  42. </template>
  43. </el-table-column>>
  44. <el-table-column label="处理器的名字" align="center" prop="handlerName" />
  45. <el-table-column label="处理器的参数" align="center" prop="handlerParam" />
  46. <el-table-column label="CRON 表达式" align="center" prop="cronExpression" />
  47. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  48. <template slot-scope="scope">
  49. <el-button size="mini" type="text" icon="el-icon-view" @click="handleView(scope.row)"
  50. v-hasPermi="['infra:job:query']">详细</el-button>
  51. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  52. v-hasPermi="['infra:job:update']">修改</el-button>
  53. <el-button size="mini" type="text" icon="el-icon-check" @click="handleChangeStatus(scope.row, true)"
  54. v-hasPermi="['infra:job:update']">开启</el-button>
  55. <el-button size="mini" type="text" icon="el-icon-close" @click="handleChangeStatus(scope.row, false)"
  56. v-hasPermi="['infra:job:update']">暂停</el-button>
  57. <el-button size="mini" type="text" icon="el-icon-caret-right" @click="handleRun(scope.row)"
  58. v-hasPermi="['infra:job:trigger']">执行一次</el-button>
  59. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  60. v-hasPermi="['infra:job:delete']">删除</el-button>
  61. </template>
  62. </el-table-column>
  63. </el-table>
  64. <!-- 分页组件 -->
  65. <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  66. @pagination="getList"/>
  67. <!-- 添加或修改定时任务对话框 -->
  68. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  69. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  70. <el-form-item label="任务名称" prop="name">
  71. <el-input v-model="form.name" placeholder="请输入任务名称" />
  72. </el-form-item>
  73. <el-form-item label="处理器的名字" prop="handlerName">
  74. <el-input v-model="form.handlerName" placeholder="请输入处理器的名字" v-bind:readonly="form.id !== undefined" />
  75. </el-form-item>
  76. <el-form-item label="处理器的参数" prop="handlerParam">
  77. <el-input v-model="form.handlerParam" placeholder="请输入处理器的参数" />
  78. </el-form-item>
  79. <el-form-item label="CRON 表达式" prop="cronExpression">
  80. <el-input v-model="form.cronExpression" placeholder="请输入CRON 表达式" />
  81. </el-form-item>
  82. <el-form-item label="监控超时时间" prop="monitorTimeout">
  83. <el-input v-model="form.monitorTimeout" placeholder="请输入监控超时时间,单位:毫秒" />
  84. </el-form-item>
  85. </el-form>
  86. <div slot="footer" class="dialog-footer">
  87. <el-button type="primary" @click="submitForm">确 定</el-button>
  88. <el-button @click="cancel">取 消</el-button>
  89. </div>
  90. </el-dialog>
  91. <!-- 任务日志详细 -->
  92. <el-dialog title="任务详细" :visible.sync="openView" width="700px" append-to-body>
  93. <el-form ref="form" :model="form" label-width="200px" size="mini">
  94. <el-row>
  95. <el-col :span="24">
  96. <el-form-item label="任务编号:">{{ form.id }}</el-form-item>
  97. <el-form-item label="任务名称:">{{ form.name }}</el-form-item>
  98. <el-form-item label="任务名称:">{{ getDictDataLabel(DICT_TYPE.INF_JOB_STATUS, form.status) }}</el-form-item>
  99. <el-form-item label="处理器的名字:">{{ form.handlerName }}</el-form-item>
  100. <el-form-item label="处理器的参数:">{{ form.handlerParam }}</el-form-item>
  101. <el-form-item label="cron表达式:">{{ form.cronExpression }}</el-form-item>
  102. <el-form-item label="最后一次执行的开始时间:">{{ parseTime(form.executeBeginTime) }}</el-form-item>
  103. <el-form-item label="最后一次执行的开始时间:">{{ parseTime(form.executeEndTime) }}</el-form-item>
  104. <el-form-item label="上一次触发时间:">{{ parseTime(form.firePrevTime) }}</el-form-item>
  105. <el-form-item label="下一次触发时间:">{{ parseTime(form.fireNextTime) }}</el-form-item>
  106. <el-form-item label="监控超时时间:">{{ form.monitorTimeout > 0 ? form.monitorTimeout + " 毫秒" : "未开启" }}</el-form-item>
  107. </el-col>
  108. </el-row>
  109. </el-form>
  110. <div slot="footer" class="dialog-footer">
  111. <el-button @click="openView = false">关 闭</el-button>
  112. </div>
  113. </el-dialog>
  114. </div>
  115. </template>
  116. <script>
  117. import { listJob, getJob, delJob, addJob, updateJob, exportJob, runJob, updateJobStatus } from "@/api/infra/job";
  118. import { InfJobStatusEnum } from "@/utils/constants";
  119. export default {
  120. name: "Job",
  121. data() {
  122. return {
  123. // 遮罩层
  124. loading: true,
  125. // 显示搜索条件
  126. showSearch: true,
  127. // 总条数
  128. total: 0,
  129. // 定时任务表格数据
  130. jobList: [],
  131. // 弹出层标题
  132. title: "",
  133. // 是否显示弹出层
  134. open: false,
  135. // 是否显示详细弹出层
  136. openView: false,
  137. // 状态字典
  138. statusOptions: [],
  139. // 查询参数
  140. queryParams: {
  141. pageNo: 1,
  142. pageSize: 10,
  143. name: undefined,
  144. status: undefined,
  145. handlerName: undefined
  146. },
  147. // 表单参数
  148. form: {},
  149. // 表单校验
  150. rules: {
  151. name: [{ required: true, message: "任务名称不能为空", trigger: "blur" }],
  152. handlerName: [{ required: true, message: "处理器的名字不能为空", trigger: "blur" }],
  153. cronExpression: [{ required: true, message: "CRON 表达式不能为空", trigger: "blur" }],
  154. }
  155. };
  156. },
  157. created() {
  158. this.getList();
  159. },
  160. methods: {
  161. /** 查询定时任务列表 */
  162. getList() {
  163. this.loading = true;
  164. listJob(this.queryParams).then(response => {
  165. this.jobList = response.data.list;
  166. this.total = response.data.total;
  167. this.loading = false;
  168. });
  169. },
  170. /** 取消按钮 */
  171. cancel() {
  172. this.open = false;
  173. this.reset();
  174. },
  175. /** 表单重置 */
  176. reset() {
  177. this.form = {
  178. id: undefined,
  179. name: undefined,
  180. handlerName: undefined,
  181. handlerParam: undefined,
  182. cronExpression: undefined,
  183. monitorTimeout: undefined,
  184. };
  185. this.resetForm("form");
  186. },
  187. /** 搜索按钮操作 */
  188. handleQuery() {
  189. this.queryParams.pageNo = 1;
  190. this.getList();
  191. },
  192. /** 重置按钮操作 */
  193. resetQuery() {
  194. this.resetForm("queryForm");
  195. this.handleQuery();
  196. },
  197. /** 立即执行一次 **/
  198. handleRun(row) {
  199. this.$confirm('确认要立即执行一次"' + row.name + '"任务吗?', "警告", {
  200. confirmButtonText: "确定",
  201. cancelButtonText: "取消",
  202. type: "warning"
  203. }).then(function() {
  204. return runJob(row.id);
  205. }).then(() => {
  206. this.msgSuccess("执行成功");
  207. })
  208. },
  209. /** 任务详细信息 */
  210. handleView(row) {
  211. getJob(row.id).then(response => {
  212. this.form = response.data;
  213. this.openView = true;
  214. });
  215. },
  216. /** 任务日志列表查询 */
  217. handleJobLog() {
  218. this.$router.push("/job/log");
  219. },
  220. /** 新增按钮操作 */
  221. handleAdd() {
  222. this.reset();
  223. this.open = true;
  224. this.title = "添加任务";
  225. },
  226. /** 修改按钮操作 */
  227. handleUpdate(row) {
  228. this.reset();
  229. const id = row.id;
  230. getJob(id).then(response => {
  231. this.form = response.data;
  232. this.open = true;
  233. this.title = "修改任务";
  234. });
  235. },
  236. /** 提交按钮 */
  237. submitForm: function() {
  238. this.$refs["form"].validate(valid => {
  239. if (valid) {
  240. if (this.form.id !== undefined) {
  241. updateJob(this.form).then(response => {
  242. this.msgSuccess("修改成功");
  243. this.open = false;
  244. this.getList();
  245. });
  246. } else {
  247. addJob(this.form).then(response => {
  248. this.msgSuccess("新增成功");
  249. this.open = false;
  250. this.getList();
  251. });
  252. }
  253. }
  254. });
  255. },
  256. /** 删除按钮操作 */
  257. handleDelete(row) {
  258. const ids = row.id;
  259. this.$confirm('是否确认删除定时任务编号为"' + ids + '"的数据项?', "警告", {
  260. confirmButtonText: "确定",
  261. cancelButtonText: "取消",
  262. type: "warning"
  263. }).then(function() {
  264. return delJob(ids);
  265. }).then(() => {
  266. this.getList();
  267. this.msgSuccess("删除成功");
  268. })
  269. },
  270. /** 更新状态操作 */
  271. handleChangeStatus(row, open) {
  272. const id = row.id;
  273. let status = open ? InfJobStatusEnum.NORMAL : InfJobStatusEnum.STOP;
  274. let statusStr = open ? '开启' : '关闭';
  275. this.$confirm('是否确认' + statusStr + '定时任务编号为"' + id + '"的数据项?', "警告", {
  276. confirmButtonText: "确定",
  277. cancelButtonText: "取消",
  278. type: "warning"
  279. }).then(function() {
  280. return updateJobStatus(id, status);
  281. }).then(() => {
  282. this.getList();
  283. this.msgSuccess(statusStr + "成功");
  284. })
  285. },
  286. /** 导出按钮操作 */
  287. handleExport() {
  288. const queryParams = this.queryParams;
  289. this.$confirm("是否确认导出所有定时任务数据项?", "警告", {
  290. confirmButtonText: "确定",
  291. cancelButtonText: "取消",
  292. type: "warning"
  293. }).then(function() {
  294. return exportJob(queryParams);
  295. }).then(response => {
  296. this.downloadExcel(response, '定时任务.xls');
  297. })
  298. }
  299. }
  300. };
  301. </script>