liukangdong
2024-10-12 bf79a36667124868583fcbf47af0e709e088b5e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<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
        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>