addTask.vue 4.14 KB
<template>
  <!-- 编辑 -->
  <dialogBox ref="addTask" width="60%" @submitForm="handleSubmit" :closed="true" @closeDialog="handleClose"
    customClass="editValidRule" multiple title="新增定时任务">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="任务名" prop="job_name">
            <el-input v-model="ruleForm.job_name" placeholder="任务名"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="任务分组" prop="job_group">
            <el-input v-model="ruleForm.job_group" placeholder="任务分组"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="cron表达式" prop="cron_expression">
            <el-input v-model="ruleForm.cron_expression" placeholder="cron表达式"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="任务类名" prop="bean_class">
            <el-input v-model="ruleForm.bean_class" placeholder="任务执行时调用哪个类的方法 包名+类名"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="24">
          <el-form-item label="任务描述" prop="description">
            <el-input v-model="ruleForm.description" placeholder="任务描述"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <message-tips :message="message" ref="msg" />
  </dialogBox>
</template>

<script>
import sjsbTask from '@/api/sjsbTask.js'
export default {
  props: {
    taskData: {
      type: Object,
      default: null
    }
  },
  data () {
    return {
      ruleForm: {
        job_name: '',
        job_group: '',
        cron_expression: '',
        bean_class: '',
        description: ''
      },
      rules: {
        job_name: [
          { required: true, message: '任务名', trigger: 'blur' }
        ],
        job_group: [
          { required: true, message: '分组', trigger: 'blur' }
        ],
        cron_expression: [
          { required: true, message: 'cron表达式', trigger: 'blur' }
        ],
        bean_class: [
          { required: true, message: '任务类名', trigger: 'blur' }
        ],
        description: [
          { required: true, message: '任务描述', trigger: 'blur' }
        ],
      },
      message: ''
    }
  },
  methods: {
    isShow () {
      this.$refs.addTask.isShow()
      setTimeout(() => {
        if (this.taskData) {
          this.ruleForm = _.cloneDeep(this.taskData)
        }
      }, 0)
    },
    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;
        }
      })
    },
    handleClose () {
      this.$refs.addTask.isHide()
      this.$refs['ruleForm'].resetFields()
    }
  }
}
</script>
<style rel="stylesheet/less" lang="less" scoped>

</style>