inleft
2022-03-01 88f419df77ade235ea5e5e24be204842a24b7b33
commit | author | age
9bcb19 1 <template>
I 2   <div>
3     <x-card v-if="hasPerm('sysTimers:page')">
4       <div slot="content" class="table-page-search-wrapper">
5         <a-form layout="inline">
6           <a-row :gutter="48">
7             <a-col :md="8" :sm="24">
8               <a-form-item label="任务名称">
9                 <a-input v-model="queryParam.timerName" allow-clear placeholder="请输入任务名称"/>
10               </a-form-item>
11             </a-col>
12             <a-col :md="8" :sm="24">
13               <a-form-item label="任务状态">
14                 <a-select v-model="queryParam.jobStatus" placeholder="请选择状态" >
15                   <a-select-option v-for="(item,index) in jobStatusDictTypeDropDown" :key="index" :value="item.code" >{{ item.value }}</a-select-option>
16                 </a-select>
17               </a-form-item>
18             </a-col>
19             <a-col :md="8" :sm="24">
20               <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
21               <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
22             </a-col>
23           </a-row>
24         </a-form>
25       </div>
26     </x-card>
27     <a-card :bordered="false">
28       <s-table
29         ref="table"
30         :columns="columns"
31         :data="loadData"
32         :alert="false"
33         :rowKey="(record) => record.id"
34       >
35         <template slot="operator" v-if="hasPerm('sysTimers:add')">
36           <a-button @click="$refs.addForm.add()" icon="plus" type="primary" v-if="hasPerm('sysTimers:add')">新增定时器</a-button>
37         </template>
38         <span slot="actionClass" slot-scope="text">
39           <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
40         </span>
41         <span slot="remark" slot-scope="text">
42           <ellipsis :length="10" tooltip>{{ text }}</ellipsis>
43         </span>
44         <span slot="jobStatus" slot-scope="text,record" v-if="hasPerm('sysTimers:start') || hasPerm('sysTimers:stop')">
45           <a-popconfirm placement="top" :title="text===1? '确定停止该任务?':'确定启动该任务?'" @confirm="() => editjobStatusStatus(text,record)">
46             <a-badge :status="text===1? 'processing':'default'" />
47             <a>{{ 'run_status' | dictType(text) }}</a>
48           </a-popconfirm>
49         </span>
50         <span slot="jobStatus" v-else>
51           <a-badge :status="text===1? 'processing':'default'" />
52           {{ 'run_status' | dictType(text) }}
53         </span>
54         <span slot="action" slot-scope="text, record">
55           <a v-if="hasPerm('sysTimers:edit')" @click="$refs.editForm.edit(record)">编辑</a>
56           <a-divider type="vertical" v-if="hasPerm('sysTimers:edit') & hasPerm('sysTimers:delete')"/>
57           <a-popconfirm v-if="hasPerm('sysTimers:delete')" placement="topRight" title="确认删除?" @confirm="() => sysTimersDelete(record)">
58             <a>删除</a>
59           </a-popconfirm>
60         </span>
61       </s-table>
62       <add-form ref="addForm" @ok="handleOk" />
63       <edit-form ref="editForm" @ok="handleOk" />
64     </a-card>
65   </div>
66 </template>
67 <script>
68   import { STable, Ellipsis, XCard } from '@/components'
69   import { sysTimersPage, sysTimersDelete, sysTimersStart, sysTimersStop } from '@/api/modular/system/timersManage'
70   import addForm from './addForm'
71   import editForm from './editForm'
72   export default {
73     name: 'PosIndex',
74     components: {
75       XCard,
76       STable,
77       Ellipsis,
78       addForm,
79       editForm
80     },
81     data () {
82       return {
83         // 查询参数
84         queryParam: {},
85         // 表头
86         columns: [
87           {
88             title: '任务名称',
89             dataIndex: 'timerName'
90           },
91           {
92             title: '任务class类名',
93             dataIndex: 'actionClass',
94             scopedSlots: { customRender: 'actionClass' }
95           },
96           {
97             title: '定时任务表达式',
98             dataIndex: 'cron'
99           },
100           {
101             title: '备注',
102             dataIndex: 'remark',
103             scopedSlots: { customRender: 'remark' }
104           },
105           {
106             title: '状态',
107             dataIndex: 'jobStatus',
108             scopedSlots: { customRender: 'jobStatus' }
109           }
110         ],
111         // 加载数据方法 必须为 Promise 对象
112         loadData: parameter => {
113           return sysTimersPage(Object.assign(parameter, this.queryParam)).then((res) => {
114             return res.data
115           })
116         },
117         jobStatusDictTypeDropDown: []
118       }
119     },
120     created () {
121       this.sysDictTypeDropDown()// 注释掉
122       if (this.hasPerm('sysTimers:edit') || this.hasPerm('sysTimers:delete')) {
123         this.columns.push({
124           title: '操作',
125           width: '150px',
126           dataIndex: 'action',
127           scopedSlots: { customRender: 'action' }
128         })
129       }
130     },
131     methods: {
132       /**
133        * 获取字典数据
134        */
135       sysDictTypeDropDown () {
136         this.jobStatusDictTypeDropDown = this.$options.filters['dictData']('run_status')
137       },
138       // jobStatusFilter (jobStatus) {
139       //   // eslint-disable-next-line eqeqeq
140       //   const values = this.jobStatusDictTypeDropDown.filter(item => item.code == jobStatus)
141       //   if (values.length > 0) {
142       //     return values[0].value
143       //   }
144       // },
145       /**
146        * 启动停止
147        */
148       editjobStatusStatus (code, record) {
149         // eslint-disable-next-line eqeqeq
150         if (code == 1) {
151           sysTimersStop({ id: record.id }).then(res => {
152             if (res.success) {
153               this.$message.success('停止成功')
154               this.$refs.table.refresh()
155             } else {
156               this.$message.error('停止失败:' + res.message)
157             }
158           })
159         // eslint-disable-next-line eqeqeq
160         } else if (code == 2) {
161           sysTimersStart({ id: record.id }).then(res => {
162             if (res.success) {
163               this.$message.success('启动成功')
164               this.$refs.table.refresh()
165             } else {
166               this.$message.error('启动失败:' + res.message)
167             }
168           })
169         }
170       },
171       sysTimersDelete (record) {
172         sysTimersDelete(record).then((res) => {
173           if (res.success) {
174             this.$message.success('删除成功')
175             this.$refs.table.refresh()
176           } else {
177             this.$message.error('删除失败:' + res.message)
178           }
179         }).catch((err) => {
180           this.$message.error('删除错误:' + err.message)
181         })
182       },
183       handleOk () {
184         this.$refs.table.refresh()
185       }
186     }
187   }
188 </script>
189 <style lang="less">
190   .table-operator {
191     margin-bottom: 18px;
192   }
193   button {
194     margin-right: 8px;
195   }
196 </style>