index.vue 8.77 KB
<template>
  <div class="timedTask from-clues">
    <div class="from-clues-header">
      <el-form ref="form" :model="form" label-width="80px">
        <el-row>
          <el-col :span="6">
            <el-form-item label="搜索标题">
              <el-input v-model="form.job_name" placeholder="请输入标题"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="18" class="btnColRight">
            <el-button type="primary" @click="handleSubmit">搜索</el-button>
            <el-button type="primary" @click="handleAdd">新增</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="from-clues-content">
      <lb-table :page-size="pageData.size" :current-page.sync="pageData.current" :total="pageData.total"
        @size-change="handleSizeChange" @p-current-change="handleCurrentChange" :column="tableData.columns"
        :data="tableData.data">
      </lb-table>
      <add-task ref="task" :taskData="taskData" />
      <message-tips ref="msg" :message="message" />
    </div>
  </div>
</template>
<script>
// 定时任务
import data from "./data"
import system from '@/api/system.js'
import tableMixin from '@/mixins/tableMixin.js'
import addTask from '../components/addTask.vue'
export default {
  name: "timedTask",
  mixins: [tableMixin],
  components: {
    addTask
  },
  data () {
    return {
      taskData: null,
      form: {
        job_name: '',
        currentPage: 1
      },
      selectionList: [],
      tableData: {
        columns: [{
          label: '序号',
          type: 'index',
          width: '50',
          index: this.indexMethod,
        }].concat(data.columns()).concat([
          {
            label: "操作",
            width: 380,
            render: (h, scope) => {
              return (
                <div>
                  <el-button type="text" size="mini" style="color: #67C23A"
                    v-show={scope.row.job_status !== '1' && scope.row.job_status !== '2'}
                    icon="el-icon-magic-stick"
                    onClick={() => { this.handleRecovery(scope.row) }}>激活
                  </el-button>

                  <el-button type="text" size="mini"
                    style="color: #67C23A;margin-left:0"
                    icon="el-icon-refresh-right"
                    v-show={scope.row.job_status === '2'}
                    onClick={() => { this.handleActivation(scope.row) }}>恢复
                  </el-button>

                  <el-button type="text" size="mini"
                    v-show={scope.row.job_status !== '1'}
                    icon="el-icon-stopwatch"
                    onClick={() => { this.handletest(scope.row) }}>手动测试
                  </el-button>
                  <el-button type="text" size="mini"
                    v-show={scope.row.job_status === '1'}
                    icon="el-icon-video-pause"
                    onClick={() => { this.handleSuspend(scope.row) }}>暂停
                  </el-button>
                  <el-button type="text" size="mini"
                    icon="el-icon-edit"
                    v-show={scope.row.job_status === '2' || scope.row.job_status === '-1' || scope.row.job_status === '0'}
                    onClick={() => { this.handleEdit(scope.row) }}>编辑
                  </el-button>
                  <el-button type="text" size="mini"
                    icon="el-icon-delete" style="color:#F56C6C"
                    v-show={scope.row.job_status !== '1'}
                    onClick={() => { this.handleDel(scope.row) }}>删除
                  </el-button>
                </div>
              );
            },
          },
        ]),
        data: []
      },
      pageData: {
        total: 0,
        pageSize: 15,
        current: 1,
      },
    }
  },
  methods: {
    handleAdd () {
      this.taskData = null
      this.$refs.task.isShow()
    },
    async featchData () {
      try {
        this.form = Object.assign(this.form, this.formData)
        let { result: { list, total, pages: pageSize, pageNum: current }
        } = await system.getTaskListByName(this.form)
        this.tableData.data = list
        this.pageData = {
          pageSize,
          current,
          total
        }
      } catch (error) {
        this.message = error
        this.$refs.msg.messageShow()
      }
    },
    // 暂停
    handleSuspend (row) {
      this.$confirm('此操将进行暂停操作, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          system.pauseJob(row.id)
            .then((res) => {
              if ((res.code = 200)) {
                this.$message({
                  type: 'success',
                  message: res.message,
                })
                this.featchData()
              }
            })
            .catch((error) => {
              this.$alert(error, '提示', {
                confirmButtonText: '确定',
                type: 'error'
              })
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          })
        })
    },
    // 激活
    handleRecovery (row) {
      this.$confirm('此操将进行激活操作, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          system.activateJob(row.id)
            .then((res) => {
              if ((res.code = 200)) {
                this.$message({
                  type: 'success',
                  message: res.message,
                })
                this.featchData()
              }
            })
            .catch((error) => {
              this.$alert(error, '提示', {
                confirmButtonText: '确定',
                type: 'error'
              })
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          })
        })
    },
    // 恢复
    handleActivation (row) {
      this.$confirm('此操将进行恢复操作, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          system.resumeJob(row.id)
            .then((res) => {
              if ((res.code = 200)) {
                this.$message({
                  type: 'success',
                  message: res.message,
                })
                this.featchData()
              }
            })
            .catch((error) => {
              this.$alert(error, '提示', {
                confirmButtonText: '确定',
                type: 'error'
              })
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          })
        })
    },
    // 手动测试
    handletest (row) {
      this.$confirm('此操将进行手动测试, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          system.sjsbTaskRun(row.id)
            .then((res) => {
              if ((res.code = 200)) {
                this.$alert(res.message, '提示', {
                  confirmButtonText: '确定',
                  type: 'success'
                });
                this.featchData()
              }
            })
            .catch((error) => {
              this.$alert(error, '提示', {
                confirmButtonText: '确定',
                type: 'error'
              })
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          })
        })
    },
    handleEdit (row) {
      this.taskData = row
      this.$refs.task.isShow()
    },
    handleDel (row) {
      this.$confirm('此操将进行删除操作, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(() => {
          system.sjsbTaskRemove(row.id)
            .then((res) => {
              if ((res.code = 200)) {
                this.$message({
                  type: 'success',
                  message: res.message,
                })
                this.featchData()
              }
            })
            .catch((error) => {
              this.$alert(error, '提示', {
                confirmButtonText: '确定',
                type: 'error'
              })
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消',
          })
        })
    }
  }
}
</script>
<style scoped lang="scss">
@import "~@/styles/mixin.scss";
@import "~@/styles/public.scss";
</style>