index.vue 18 KB

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