addTask.vue 4.59 KB
<template>
  <!-- 编辑 -->
  <dialogBox ref="addTask" class="scheduledtaskdialog" width="40%" :isMain="true" @submitForm="handleSubmit" @closeDialog="handleClose"
    v-model="myValue" customClass="editValidRule" title="新增定时任务">
    <div class="dialogCon" style="">
      <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
        <el-row>
          <el-col>
            <el-form-item label="任务名" prop="jobName">
              <el-input v-model="ruleForm.jobName" placeholder="任务名"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="类名" prop="beanName">
              <el-input v-model="ruleForm.beanName" placeholder="类名"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="cron表达式" prop="cronExpression">
              <el-input v-model="ruleForm.cronExpression" placeholder="cron表达式"></el-input>
            </el-form-item>
          </el-col>
          <el-col>
            <el-form-item label="方法名" prop="methodName">
              <el-input v-model="ruleForm.methodName" placeholder="方法名"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="任务描述" prop="remark">
              <el-input v-model="ruleForm.remark" type="textarea" :rows="4" placeholder="任务描述"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <message-tips :message="message" ref="msg" />
  </dialogBox>
</template>

<script>
  import sjsbTask from '@/api/sjsbTask.js'
  export default {
    props: {
      value: { type: Boolean, default: false },
      taskData: {
        type: Object,
        default: null
      }
    },
    data () {
      return {
        myValue: this.value,
        ruleForm: {
          jobName: '',
          cronExpression: '',
          beanName: '',
          methodName: '',
          methodParams: '',
          remark: ''
        },
        rules: {
          jobName: [
            { required: true, message: '任务名', trigger: 'blur' }
          ],
          cronExpression: [
            { required: true, message: 'cron表达式', trigger: 'blur' }
          ],
          beanName: [
            { required: true, message: '任务类名', trigger: 'blur' }
          ],
          methodName: [
            { required: true, message: '任务方法名', trigger: 'blur' }
          ]
        },
        message: ''
      }
    },
    methods: {
      /**
       * @description: handleSubmit
       * @author: renchao
       */
      handleSubmit () {
        let _this = this
        this.$refs['ruleForm'].validate(async (valid) => {
          if (valid) {
            if (!_this.taskData) {
              try {
                let res = await sjsbTask.sjsbTaskSave(_this.ruleForm)
                if (res.code == 200) {
                  _this.loading = false
                  _this.$message({
                    message: res.message,
                    type: 'success'
                  })
                  _this.handleClose()
                  _this.$parent.featchData()
                }
              } catch (error) {
                _this.message = error
                _this.$refs.msg.messageShow()
              }
            } else {
              try {
                let res = await sjsbTask.updateCron(_this.ruleForm)
                if (res.code == 200) {
                  _this.$message({
                    message: res.message,
                    type: 'success'
                  })
                  _this.handleClose()
                  _this.$parent.featchData()
                }
              } catch (error) {
                _this.message = error
                _this.$refs.msg.messageShow()
              }
            }
          } else {
            this.$message('请检查表单完整性')
            return false;
          }
        })
      },
      /**
       * @description: handleClose
       * @author: renchao
       */
      handleClose () {
        this.$emit("input", false);
      }
    },
    watch: {
      value (val) {
        this.myValue = val
      },
      taskData (val) {
        if (val != null) {
          this.ruleForm = val
        } else {
          this.ruleForm = {
            jobName: '',
            cronExpression: '',
            beanName: '',
            methodName: '',
            methodParams: '',
            remark: ''
          }
        }
      }
    }
  }
</script>


<style scoped lang="scss">
</style>