index.vue 18 KB

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