schedule-add-or-update.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <template>
  2. <!-- <el-dialog
  3. :title="!dataForm.id ? '新增' : '修改'"
  4. :close-on-click-modal="false"
  5. :visible.sync="visible"> -->
  6. <div>
  7. <div class="my-title">{{ !dataForm.id ? '新增' : '修改' }}</div>
  8. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="100px">
  9. <el-form-item label="bean名称" prop="beanName">
  10. <el-input v-model="dataForm.beanName" placeholder="spring bean名称, 如: testTask"></el-input>
  11. </el-form-item>
  12. <el-form-item label="参数" prop="params">
  13. <el-input v-model="dataForm.params" placeholder="参数"></el-input>
  14. </el-form-item>
  15. <el-form-item label="cron表达式" prop="cronExpression">
  16. <el-input v-model="dataForm.cronExpression" placeholder="如: 0 0 12 * * ?"></el-input>
  17. </el-form-item>
  18. <el-form-item label="备注" prop="remark">
  19. <el-input v-model="dataForm.remark" placeholder="备注"></el-input>
  20. </el-form-item>
  21. </el-form>
  22. <span slot="footer" class="dialog-footer">
  23. <el-button @click="onChose">取消</el-button>
  24. <el-button type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
  25. </span>
  26. </div>
  27. <!-- </el-dialog> -->
  28. </template>
  29. <script>
  30. export default {
  31. data () {
  32. return {
  33. visible: false,
  34. dataForm: {
  35. id: 0,
  36. beanName: '',
  37. params: '',
  38. cronExpression: '',
  39. remark: '',
  40. status: 0
  41. },
  42. dataRule: {
  43. beanName: [
  44. { required: true, message: '用户名不能为空', trigger: 'blur' }
  45. ],
  46. cronExpression: [
  47. { required: true, message: 'cron表达式不能为空', trigger: 'blur' }
  48. ]
  49. }
  50. }
  51. },
  52. methods: {
  53. init (id) {
  54. this.dataForm.id = id || 0
  55. this.visible = true
  56. this.$nextTick(() => {
  57. this.$refs['dataForm'].resetFields()
  58. if (this.dataForm.id) {
  59. this.$http({
  60. url: this.$http.adornUrl(`/user-service/sys/schedule/info/${this.dataForm.id}`),
  61. method: 'get',
  62. params: this.$http.adornParams()
  63. }).then(({data}) => {
  64. if (data && data.code === '200') {
  65. this.dataForm.beanName = data.data.beanName
  66. this.dataForm.params = data.data.params
  67. this.dataForm.cronExpression = data.data.cronExpression
  68. this.dataForm.remark = data.data.remark
  69. this.dataForm.status = data.data.status
  70. }
  71. })
  72. }
  73. })
  74. },
  75. onChose () {
  76. this.$emit('onChose')
  77. },
  78. // 表单提交
  79. dataFormSubmit () {
  80. this.$refs['dataForm'].validate((valid) => {
  81. if (valid) {
  82. this.$http({
  83. url: this.$http.adornUrl(`/user-service/sys/schedule/${!this.dataForm.id ? 'save' : 'update'}`),
  84. method: !this.dataForm.id ? 'post' : 'put',
  85. data: this.$http.adornData({
  86. 'jobId': this.dataForm.id || undefined,
  87. 'beanName': this.dataForm.beanName,
  88. 'params': this.dataForm.params,
  89. 'cronExpression': this.dataForm.cronExpression,
  90. 'remark': this.dataForm.remark,
  91. 'status': !this.dataForm.id ? undefined : this.dataForm.status
  92. })
  93. }).then(({data}) => {
  94. if (data && data.code === '200') {
  95. this.$message({
  96. message: '操作成功',
  97. type: 'success',
  98. duration: 1500,
  99. onClose: () => {
  100. this.onChose()
  101. this.$emit('refreshDataList')
  102. }
  103. })
  104. } else {
  105. this.$message.error(data.msg)
  106. }
  107. })
  108. }
  109. })
  110. }
  111. }
  112. }
  113. </script>