MrShi
2025-03-12 69a1b3bf45738f048361ee4ccb6bdc64fce35720
admin/src/views/timer/timer.vue
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,169 @@
<template>
  <TableLayout :permissions="['business:quartz:query']">
    <!-- æœç´¢è¡¨å• -->
    <el-form ref="searchForm" slot="search-form" :model="searchForm" label-width="100px" inline>
      <el-form-item label="Bean名称" prop="beanName">
        <el-input v-model="searchForm.beanName" placeholder="请输入发布人" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <el-form-item label="模块名称" prop="module">
        <el-input v-model="searchForm.module" placeholder="请输入发布人" @keypress.enter.native="search"></el-input>
      </el-form-item>
      <section>
        <el-button type="primary" @click="search">搜索</el-button>
        <!-- <el-button type="primary" :loading="isWorking.export" v-permissions="['business:devices:exportExcel']" @click="exportExcel">导出</el-button> -->
        <el-button @click="reset">重置</el-button>
      </section>
    </el-form>
    <!-- è¡¨æ ¼å’Œåˆ†é¡µ -->
    <template v-slot:table-wrap>
      <ul class="toolbar" v-permissions="['business:quartz:create']">
        <li><el-button type="primary" @click="$refs.OperaTimerWindow.open('新建任务')" icon="el-icon-plus" v-permissions="['business:devices:create']">新建</el-button></li>
      </ul>
      <el-table
          :height="tableHeightNew"
        v-loading="isWorking.search"
        :data="tableData.list"
        stripe
        border
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="index" prop="index" label="序号" align="center" min-width="50px"></el-table-column>
        <el-table-column prop="beanName" label="BEAN名称" align="center" min-width="150px"></el-table-column>
        <el-table-column prop="module" label="模块名称" align="center" min-width="180px"></el-table-column>
        <el-table-column prop="params" label="执行参数" align="center" min-width="180px"></el-table-column>
        <el-table-column prop="state" label="状态" align="center" min-width="100px">
          <template slot-scope="{row}">
              <span v-if="row.state ==1" style="color:green">正常</span>
              <span v-if="row.state ==2" style="color: red">暂停</span>
              <span v-if="row.state ==3" style="color: red">已删除</span>
          </template>
        </el-table-column>
        <el-table-column prop="cronExpres" label="表达式" align="center" min-width="100px"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center" min-width="180px"></el-table-column>
        <el-table-column prop="remark" label="备注" align="center" min-width="180px"></el-table-column>
        <el-table-column
          v-if="containPermissions(['business:quartz:update'])"
          label="操作"
          fixed="right"
          min-width="220"
          align="center"
        >
          <template slot-scope="{row}">
            <el-button type="text" @click="$refs.OperaTimerWindow.open('编辑任务', row)" v-permissions="['business:quartz:update']">编辑</el-button>
            <el-button type="text"  @click="runById(row)"  v-permissions="['business:quartz:update']">执行一次</el-button>
            <el-button type="text"   v-if="row.state == 1" style="color: red" @click="pauseById(row)"  v-permissions="['business:quartz:update']">暂停</el-button>
            <el-button type="text"  v-if="row.state == 2" style="color: green" @click="resumeById(row)"   v-permissions="['business:quartz:update']">恢复</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
        :pagination="tableData.pagination"
      ></pagination>
    </template>
    <!-- æ–°å»º/修改 -->
    <OperaTimerWindow ref="OperaTimerWindow" @success="handlePageChange"/>
  </TableLayout>
</template>
<script>
import BaseTable from '@/components/base/BaseTable'
import TableLayout from '@/layouts/TableLayout'
import Pagination from '@/components/common/Pagination'
import OperaTimerWindow from '@/views/timer/components/OperaTimerWindow'
import {runOnceById} from "@/api/timer/timer";
export default {
  name: 'Devices',
  extends: BaseTable,
  components: { TableLayout, Pagination, OperaTimerWindow },
  data () {
    return {
      // æœç´¢
      searchForm: {
        id: '',
        beanName: '',
        module: ''
      },
      pausing:false,
      running:false,
      resuming:false,
      room: []
    }
  },
  provide() {
    return {
      room: () => this.room
    }
  },
  created () {
    this.config({
      module: '设备管理信息表',
      api: '/timer/timer',
      'field.id': 'id',
      'field.main': 'id'
    })
    this.search()
  },
  methods: {
    pauseById (row) {
      this.__checkApi()
      this.$dialog.actionConfirm('确认暂停该任务吗?')
          .then(() => {
            this.pausing = true
            this.api.pauseById(row.id)
                .then(() => {
                  this.$message.info('暂停成功')
                  this.search()
                })
                .catch(e => {
                  // this.$tip.apiFailed(e)
                })
                .finally(() => {
                  this.pausing = false
                })
          })
          .catch(() => {})
    },
    resumeById (row) {
      this.__checkApi()
      this.$dialog.actionConfirm('确认恢复该任务吗?')
          .then(() => {
            this.resuming = true
            this.api.resumeById(row.id)
                .then(() => {
                  this.$message.info('恢复成功')
                  this.search()
                })
                .catch(e => {
                  // this.$tip.apiFailed(e)
                })
                .finally(() => {
                  this.resuming = false
                })
          })
          .catch(() => {})
    },
    runById (row) {
      this.__checkApi()
      this.$dialog.actionConfirm('确认执行一次该任务吗?')
          .then(() => {
            this.running = true
            this.api.runOnceById(row.id)
                .then(() => {
                  this.$message.info('执行成功')
                  this.search()
                })
                .catch(e => {
                  // this.$tip.apiFailed(e)
                })
                .finally(() => {
                  this.running = false
                })
          })
          .catch(() => {})
    }
  },
}
</script>