index.vue 18 KB

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