index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="任务名称" prop="jobName">
  5. <el-input
  6. v-model="queryParams.jobName"
  7. placeholder="请输入任务名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="任务组名" prop="jobGroup">
  14. <el-select v-model="queryParams.jobGroup" placeholder="请选择任务组名" clearable size="small">
  15. <el-option
  16. v-for="dict in jobGroupOptions"
  17. :key="dict.dictValue"
  18. :label="dict.dictLabel"
  19. :value="dict.dictValue"
  20. />
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="任务状态" prop="status">
  24. <el-select v-model="queryParams.status" placeholder="请选择任务状态" clearable size="small">
  25. <el-option
  26. v-for="dict in statusOptions"
  27. :key="dict.dictValue"
  28. :label="dict.dictLabel"
  29. :value="dict.dictValue"
  30. />
  31. </el-select>
  32. </el-form-item>
  33. <el-form-item>
  34. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  35. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <el-row :gutter="10" class="mb8">
  39. <el-col :span="1.5">
  40. <el-button
  41. type="primary"
  42. plain
  43. icon="el-icon-plus"
  44. size="mini"
  45. @click="handleAdd"
  46. v-hasPermi="['monitor:job:add']"
  47. >新增</el-button>
  48. </el-col>
  49. <el-col :span="1.5">
  50. <el-button
  51. type="success"
  52. plain
  53. icon="el-icon-edit"
  54. size="mini"
  55. :disabled="single"
  56. @click="handleUpdate"
  57. v-hasPermi="['monitor:job:edit']"
  58. >修改</el-button>
  59. </el-col>
  60. <el-col :span="1.5">
  61. <el-button
  62. type="danger"
  63. plain
  64. icon="el-icon-delete"
  65. size="mini"
  66. :disabled="multiple"
  67. @click="handleDelete"
  68. v-hasPermi="['monitor:job:remove']"
  69. >删除</el-button>
  70. </el-col>
  71. <el-col :span="1.5">
  72. <el-button
  73. type="warning"
  74. plain
  75. icon="el-icon-download"
  76. size="mini"
  77. :loading="exportLoading"
  78. @click="handleExport"
  79. v-hasPermi="['monitor:job:export']"
  80. >导出</el-button>
  81. </el-col>
  82. <el-col :span="1.5">
  83. <el-button
  84. type="info"
  85. plain
  86. icon="el-icon-s-operation"
  87. size="mini"
  88. @click="handleJobLog"
  89. v-hasPermi="['monitor:job:query']"
  90. >日志</el-button>
  91. </el-col>
  92. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  93. </el-row>
  94. <el-table v-loading="loading" :data="jobList" @selection-change="handleSelectionChange">
  95. <el-table-column type="selection" width="55" align="center" />
  96. <el-table-column label="任务编号" align="center" prop="jobId" />
  97. <el-table-column label="任务名称" align="center" prop="jobName" :show-overflow-tooltip="true" />
  98. <el-table-column label="任务组名" align="center" prop="jobGroup" :formatter="jobGroupFormat" />
  99. <el-table-column label="调用目标字符串" align="center" prop="invokeTarget" :show-overflow-tooltip="true" />
  100. <el-table-column label="cron执行表达式" align="center" prop="cronExpression" :show-overflow-tooltip="true" />
  101. <el-table-column label="状态" align="center">
  102. <template slot-scope="scope">
  103. <el-switch
  104. v-model="scope.row.status"
  105. active-value="0"
  106. inactive-value="1"
  107. @change="handleStatusChange(scope.row)"
  108. ></el-switch>
  109. </template>
  110. </el-table-column>
  111. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  112. <template slot-scope="scope">
  113. <el-button
  114. size="mini"
  115. type="text"
  116. icon="el-icon-edit"
  117. @click="handleUpdate(scope.row)"
  118. v-hasPermi="['monitor:job:edit']"
  119. >修改</el-button>
  120. <el-button
  121. size="mini"
  122. type="text"
  123. icon="el-icon-delete"
  124. @click="handleDelete(scope.row)"
  125. v-hasPermi="['monitor:job:remove']"
  126. >删除</el-button>
  127. <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)">
  128. <span class="el-dropdown-link">
  129. <i class="el-icon-d-arrow-right el-icon--right"></i>更多
  130. </span>
  131. <el-dropdown-menu slot="dropdown">
  132. <el-dropdown-item command="handleRun" icon="el-icon-caret-right"
  133. v-hasPermi="['monitor:job:changeStatus']">执行一次</el-dropdown-item>
  134. <el-dropdown-item command="handleView" icon="el-icon-view"
  135. v-hasPermi="['monitor:job:query']">任务详细</el-dropdown-item>
  136. <el-dropdown-item command="handleJobLog" icon="el-icon-s-operation"
  137. v-hasPermi="['monitor:job:query']">调度日志</el-dropdown-item>
  138. </el-dropdown-menu>
  139. </el-dropdown>
  140. </template>
  141. </el-table-column>
  142. </el-table>
  143. <pagination
  144. v-show="total>0"
  145. :total="total"
  146. :page.sync="queryParams.pageNum"
  147. :limit.sync="queryParams.pageSize"
  148. @pagination="getList"
  149. />
  150. <!-- 添加或修改定时任务对话框 -->
  151. <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
  152. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  153. <el-row>
  154. <el-col :span="12">
  155. <el-form-item label="任务名称" prop="jobName">
  156. <el-input v-model="form.jobName" placeholder="请输入任务名称" />
  157. </el-form-item>
  158. </el-col>
  159. <el-col :span="12">
  160. <el-form-item label="任务分组" prop="jobGroup">
  161. <el-select v-model="form.jobGroup" placeholder="请选择">
  162. <el-option
  163. v-for="dict in jobGroupOptions"
  164. :key="dict.dictValue"
  165. :label="dict.dictLabel"
  166. :value="dict.dictValue"
  167. ></el-option>
  168. </el-select>
  169. </el-form-item>
  170. </el-col>
  171. <el-col :span="24">
  172. <el-form-item prop="invokeTarget">
  173. <span slot="label">
  174. 调用方法
  175. <el-tooltip placement="top">
  176. <div slot="content">
  177. Bean调用示例:ryTask.ryParams('ry')
  178. <br />Class类调用示例:com.ruoyi.quartz.task.RyTask.ryParams('ry')
  179. <br />参数说明:支持字符串,布尔类型,长整型,浮点型,整型
  180. </div>
  181. <i class="el-icon-question"></i>
  182. </el-tooltip>
  183. </span>
  184. <el-input v-model="form.invokeTarget" placeholder="请输入调用目标字符串" />
  185. </el-form-item>
  186. </el-col>
  187. <el-col :span="12">
  188. <el-form-item label="cron表达式" prop="cronExpression">
  189. <el-input v-model="form.cronExpression" placeholder="请输入cron执行表达式" />
  190. </el-form-item>
  191. </el-col>
  192. <el-col :span="12">
  193. <el-form-item label="是否并发" prop="concurrent">
  194. <el-radio-group v-model="form.concurrent" size="small">
  195. <el-radio-button label="0">允许</el-radio-button>
  196. <el-radio-button label="1">禁止</el-radio-button>
  197. </el-radio-group>
  198. </el-form-item>
  199. </el-col>
  200. <el-col :span="24">
  201. <el-form-item label="错误策略" prop="misfirePolicy">
  202. <el-radio-group v-model="form.misfirePolicy" size="small">
  203. <el-radio-button label="1">立即执行</el-radio-button>
  204. <el-radio-button label="2">执行一次</el-radio-button>
  205. <el-radio-button label="3">放弃执行</el-radio-button>
  206. </el-radio-group>
  207. </el-form-item>
  208. </el-col>
  209. <el-col :span="24">
  210. <el-form-item label="状态">
  211. <el-radio-group v-model="form.status">
  212. <el-radio
  213. v-for="dict in statusOptions"
  214. :key="dict.dictValue"
  215. :label="dict.dictValue"
  216. >{{dict.dictLabel}}</el-radio>
  217. </el-radio-group>
  218. </el-form-item>
  219. </el-col>
  220. </el-row>
  221. </el-form>
  222. <div slot="footer" class="dialog-footer">
  223. <el-button type="primary" @click="submitForm">确 定</el-button>
  224. <el-button @click="cancel">取 消</el-button>
  225. </div>
  226. </el-dialog>
  227. <!-- 任务日志详细 -->
  228. <el-dialog title="任务详细" :visible.sync="openView" width="700px" append-to-body>
  229. <el-form ref="form" :model="form" label-width="120px" size="mini">
  230. <el-row>
  231. <el-col :span="12">
  232. <el-form-item label="任务编号:">{{ form.jobId }}</el-form-item>
  233. <el-form-item label="任务名称:">{{ form.jobName }}</el-form-item>
  234. </el-col>
  235. <el-col :span="12">
  236. <el-form-item label="任务分组:">{{ jobGroupFormat(form) }}</el-form-item>
  237. <el-form-item label="创建时间:">{{ form.createTime }}</el-form-item>
  238. </el-col>
  239. <el-col :span="12">
  240. <el-form-item label="cron表达式:">{{ form.cronExpression }}</el-form-item>
  241. </el-col>
  242. <el-col :span="12">
  243. <el-form-item label="下次执行时间:">{{ parseTime(form.nextValidTime) }}</el-form-item>
  244. </el-col>
  245. <el-col :span="24">
  246. <el-form-item label="调用目标方法:">{{ form.invokeTarget }}</el-form-item>
  247. </el-col>
  248. <el-col :span="12">
  249. <el-form-item label="任务状态:">
  250. <div v-if="form.status == 0">正常</div>
  251. <div v-else-if="form.status == 1">失败</div>
  252. </el-form-item>
  253. </el-col>
  254. <el-col :span="12">
  255. <el-form-item label="是否并发:">
  256. <div v-if="form.concurrent == 0">允许</div>
  257. <div v-else-if="form.concurrent == 1">禁止</div>
  258. </el-form-item>
  259. </el-col>
  260. <el-col :span="12">
  261. <el-form-item label="执行策略:">
  262. <div v-if="form.misfirePolicy == 0">默认策略</div>
  263. <div v-else-if="form.misfirePolicy == 1">立即执行</div>
  264. <div v-else-if="form.misfirePolicy == 2">执行一次</div>
  265. <div v-else-if="form.misfirePolicy == 3">放弃执行</div>
  266. </el-form-item>
  267. </el-col>
  268. </el-row>
  269. </el-form>
  270. <div slot="footer" class="dialog-footer">
  271. <el-button @click="openView = false">关 闭</el-button>
  272. </div>
  273. </el-dialog>
  274. </div>
  275. </template>
  276. <script>
  277. import { listJob, getJob, delJob, addJob, updateJob, exportJob, runJob, changeJobStatus } from "@/api/monitor/job";
  278. export default {
  279. name: "Job",
  280. data() {
  281. return {
  282. // 遮罩层
  283. loading: true,
  284. // 导出遮罩层
  285. exportLoading: false,
  286. // 选中数组
  287. ids: [],
  288. // 非单个禁用
  289. single: true,
  290. // 非多个禁用
  291. multiple: true,
  292. // 显示搜索条件
  293. showSearch: true,
  294. // 总条数
  295. total: 0,
  296. // 定时任务表格数据
  297. jobList: [],
  298. // 弹出层标题
  299. title: "",
  300. // 是否显示弹出层
  301. open: false,
  302. // 是否显示详细弹出层
  303. openView: false,
  304. // 任务组名字典
  305. jobGroupOptions: [],
  306. // 状态字典
  307. statusOptions: [],
  308. // 查询参数
  309. queryParams: {
  310. pageNum: 1,
  311. pageSize: 10,
  312. jobName: undefined,
  313. jobGroup: undefined,
  314. status: undefined
  315. },
  316. // 表单参数
  317. form: {},
  318. // 表单校验
  319. rules: {
  320. jobName: [
  321. { required: true, message: "任务名称不能为空", trigger: "blur" }
  322. ],
  323. invokeTarget: [
  324. { required: true, message: "调用目标字符串不能为空", trigger: "blur" }
  325. ],
  326. cronExpression: [
  327. { required: true, message: "cron执行表达式不能为空", trigger: "blur" }
  328. ]
  329. }
  330. };
  331. },
  332. created() {
  333. this.getList();
  334. this.getDicts("sys_job_group").then(response => {
  335. this.jobGroupOptions = response.data;
  336. });
  337. this.getDicts("sys_job_status").then(response => {
  338. this.statusOptions = response.data;
  339. });
  340. },
  341. methods: {
  342. /** 查询定时任务列表 */
  343. getList() {
  344. this.loading = true;
  345. listJob(this.queryParams).then(response => {
  346. this.jobList = response.rows;
  347. this.total = response.total;
  348. this.loading = false;
  349. });
  350. },
  351. // 任务组名字典翻译
  352. jobGroupFormat(row, column) {
  353. return this.selectDictLabel(this.jobGroupOptions, row.jobGroup);
  354. },
  355. // 状态字典翻译
  356. statusFormat(row, column) {
  357. return this.selectDictLabel(this.statusOptions, row.status);
  358. },
  359. // 取消按钮
  360. cancel() {
  361. this.open = false;
  362. this.reset();
  363. },
  364. // 表单重置
  365. reset() {
  366. this.form = {
  367. jobId: undefined,
  368. jobName: undefined,
  369. jobGroup: undefined,
  370. invokeTarget: undefined,
  371. cronExpression: undefined,
  372. misfirePolicy: 1,
  373. concurrent: 1,
  374. status: "0"
  375. };
  376. this.resetForm("form");
  377. },
  378. /** 搜索按钮操作 */
  379. handleQuery() {
  380. this.queryParams.pageNum = 1;
  381. this.getList();
  382. },
  383. /** 重置按钮操作 */
  384. resetQuery() {
  385. this.resetForm("queryForm");
  386. this.handleQuery();
  387. },
  388. // 多选框选中数据
  389. handleSelectionChange(selection) {
  390. this.ids = selection.map(item => item.jobId);
  391. this.single = selection.length != 1;
  392. this.multiple = !selection.length;
  393. },
  394. // 更多操作触发
  395. handleCommand(command, row) {
  396. switch (command) {
  397. case "handleRun":
  398. this.handleRun(row);
  399. break;
  400. case "handleView":
  401. this.handleView(row);
  402. break;
  403. case "handleJobLog":
  404. this.handleJobLog(row);
  405. break;
  406. default:
  407. break;
  408. }
  409. },
  410. // 任务状态修改
  411. handleStatusChange(row) {
  412. let text = row.status === "0" ? "启用" : "停用";
  413. this.$confirm('确认要"' + text + '""' + row.jobName + '"任务吗?', "警告", {
  414. confirmButtonText: "确定",
  415. cancelButtonText: "取消",
  416. type: "warning"
  417. }).then(function() {
  418. return changeJobStatus(row.jobId, row.status);
  419. }).then(() => {
  420. this.msgSuccess(text + "成功");
  421. }).catch(function() {
  422. row.status = row.status === "0" ? "1" : "0";
  423. });
  424. },
  425. /* 立即执行一次 */
  426. handleRun(row) {
  427. this.$confirm('确认要立即执行一次"' + row.jobName + '"任务吗?', "警告", {
  428. confirmButtonText: "确定",
  429. cancelButtonText: "取消",
  430. type: "warning"
  431. }).then(function() {
  432. return runJob(row.jobId, row.jobGroup);
  433. }).then(() => {
  434. this.msgSuccess("执行成功");
  435. }).catch(() => {});
  436. },
  437. /** 任务详细信息 */
  438. handleView(row) {
  439. getJob(row.jobId).then(response => {
  440. this.form = response.data;
  441. this.openView = true;
  442. });
  443. },
  444. /** 任务日志列表查询 */
  445. handleJobLog(row) {
  446. const jobId = row.jobId || 0;
  447. this.$router.push({ path: '/job/log', query: { jobId: jobId } })
  448. },
  449. /** 新增按钮操作 */
  450. handleAdd() {
  451. this.reset();
  452. this.open = true;
  453. this.title = "添加任务";
  454. },
  455. /** 修改按钮操作 */
  456. handleUpdate(row) {
  457. this.reset();
  458. const jobId = row.jobId || this.ids;
  459. getJob(jobId).then(response => {
  460. this.form = response.data;
  461. this.open = true;
  462. this.title = "修改任务";
  463. });
  464. },
  465. /** 提交按钮 */
  466. submitForm: function() {
  467. this.$refs["form"].validate(valid => {
  468. if (valid) {
  469. if (this.form.jobId != undefined) {
  470. updateJob(this.form).then(response => {
  471. this.msgSuccess("修改成功");
  472. this.open = false;
  473. this.getList();
  474. });
  475. } else {
  476. addJob(this.form).then(response => {
  477. this.msgSuccess("新增成功");
  478. this.open = false;
  479. this.getList();
  480. });
  481. }
  482. }
  483. });
  484. },
  485. /** 删除按钮操作 */
  486. handleDelete(row) {
  487. const jobIds = row.jobId || this.ids;
  488. this.$confirm('是否确认删除定时任务编号为"' + jobIds + '"的数据项?', "警告", {
  489. confirmButtonText: "确定",
  490. cancelButtonText: "取消",
  491. type: "warning"
  492. }).then(function() {
  493. return delJob(jobIds);
  494. }).then(() => {
  495. this.getList();
  496. this.msgSuccess("删除成功");
  497. }).catch(() => {});
  498. },
  499. /** 导出按钮操作 */
  500. handleExport() {
  501. const queryParams = this.queryParams;
  502. this.$confirm("是否确认导出所有定时任务数据项?", "警告", {
  503. confirmButtonText: "确定",
  504. cancelButtonText: "取消",
  505. type: "warning"
  506. }).then(() => {
  507. this.exportLoading = true;
  508. return exportJob(queryParams);
  509. }).then(response => {
  510. this.download(response.msg);
  511. this.exportLoading = false;
  512. }).catch(() => {});
  513. }
  514. }
  515. };
  516. </script>