1
1
<template >
2
2
<content-wrap >
3
- <!-- 搜索栏 -->
4
- <el-form :model =" queryParams" ref =" queryFormRef" :inline =" true" label-width =" 100px" >
3
+ <!-- 搜索工作栏 -->
4
+ <el-form
5
+ class =" -mb-15px"
6
+ :model =" queryParams"
7
+ ref =" queryFormRef"
8
+ :inline =" true"
9
+ label-width =" 100px"
10
+ >
5
11
<el-form-item label =" 任务名称" prop =" name" >
6
12
<el-input
7
13
v-model =" queryParams.name"
8
14
placeholder =" 请输入任务名称"
9
15
clearable
10
16
@keyup.enter =" handleQuery"
17
+ class =" !w-240px"
11
18
/>
12
19
</el-form-item >
13
20
<el-form-item label =" 任务状态" prop =" status" >
14
- <el-select v-model =" queryParams.status" placeholder =" 请选择任务状态" clearable >
21
+ <el-select
22
+ v-model =" queryParams.status"
23
+ placeholder =" 请选择任务状态"
24
+ clearable
25
+ class =" !w-240px"
26
+ >
15
27
<el-option
16
- v-for =" dict in getDictOptions (DICT_TYPE.INFRA_JOB_STATUS)"
28
+ v-for =" dict in getIntDictOptions (DICT_TYPE.INFRA_JOB_STATUS)"
17
29
:key =" dict.value"
18
30
:label =" dict.label"
19
31
:value =" dict.value"
26
38
placeholder =" 请输入处理器的名字"
27
39
clearable
28
40
@keyup.enter =" handleQuery"
41
+ class =" !w-240px"
29
42
/>
30
43
</el-form-item >
31
44
<el-form-item >
34
47
<el-button
35
48
type =" primary"
36
49
plain
37
- @click =" openModal ('create')"
50
+ @click =" openForm ('create')"
38
51
v-hasPermi =" ['infra:job:create']"
39
52
>
40
53
<Icon icon =" ep:plus" class =" mr-5px" /> 新增
48
61
>
49
62
<Icon icon =" ep:download" class =" mr-5px" /> 导出
50
63
</el-button >
51
-
52
64
<el-button type =" info" plain @click =" handleJobLog" v-hasPermi =" ['infra:job:query']" >
53
65
<Icon icon =" ep:zoom-in" class =" mr-5px" /> 执行日志
54
66
</el-button >
55
67
</el-form-item >
56
68
</el-form >
69
+ </content-wrap >
57
70
71
+ <!-- 列表 -->
72
+ <content-wrap >
58
73
<el-table v-loading =" loading" :data =" list" >
59
74
<el-table-column label =" 任务编号" align =" center" prop =" id" />
60
75
<el-table-column label =" 任务名称" align =" center" prop =" name" />
61
76
<el-table-column label =" 任务状态" align =" center" prop =" status" >
62
77
<template #default =" scope " >
63
78
<dict-tag :type =" DICT_TYPE.INFRA_JOB_STATUS" :value =" scope.row.status" />
64
- </template > </ el-table-column
65
- > >
79
+ </template >
80
+ </ el-table-column >
66
81
<el-table-column label =" 处理器的名字" align =" center" prop =" handlerName" />
67
82
<el-table-column label =" 处理器的参数" align =" center" prop =" handlerParam" />
68
83
<el-table-column label =" CRON 表达式" align =" center" prop =" cronExpression" />
69
- <el-table-column label =" 操作" align =" center" class-name = " small-padding fixed-width " >
84
+ <el-table-column label =" 操作" align =" center" width = " 200 " >
70
85
<template #default =" scope " >
71
86
<el-button
87
+ type =" primary"
72
88
link
73
- icon =" el-icon-edit"
74
- @click =" openModal('update', scope.row.id)"
89
+ @click =" openForm('update', scope.row.id)"
75
90
v-hasPermi =" ['infra:job:update']"
76
- >修改</el-button
77
91
>
92
+ 修改
93
+ </el-button >
78
94
<el-button
95
+ type =" primary"
79
96
link
80
- icon =" el-icon-check"
81
97
@click =" handleChangeStatus(scope.row)"
82
98
v-hasPermi =" ['infra:job:update']"
83
- >{{ scope.row.status === InfraJobStatusEnum.STOP ? '开启' : '暂停' }}</el-button
84
99
>
100
+ {{ scope.row.status === InfraJobStatusEnum.STOP ? '开启' : '暂停' }}
101
+ </el-button >
85
102
<el-button
103
+ type =" danger"
86
104
link
87
- icon =" el-icon-delete"
88
105
@click =" handleDelete(scope.row)"
89
106
v-hasPermi =" ['infra:job:delete']"
90
- >删除</el-button
91
107
>
108
+ 删除
109
+ </el-button >
92
110
<el-dropdown
93
- class =" mt-1"
94
- :teleported =" true"
95
111
@command =" (command) => handleCommand(command, scope.row)"
96
112
v-hasPermi =" ['infra:job:trigger', 'infra:job:query']"
97
113
>
98
- <el-button link icon =" el-icon- d-arrow-right" > 更多</el-button >
114
+ <el-button type = " primary " link >< Icon icon =" ep: d-arrow-right" /> 更多</el-button >
99
115
<template #dropdown >
100
116
<el-dropdown-menu >
101
- <el-dropdown-item command =" handleRun" v-if =" hasPermi (['infra:job:trigger'])" >
117
+ <el-dropdown-item command =" handleRun" v-if =" checkPermi (['infra:job:trigger'])" >
102
118
执行一次
103
119
</el-dropdown-item >
104
- <el-dropdown-item command =" handleView" v-if =" hasPermi (['infra:job:query'])" >
120
+ <el-dropdown-item command =" handleView" v-if =" checkPermi (['infra:job:query'])" >
105
121
任务详细
106
122
</el-dropdown-item >
107
- <el-dropdown-item command =" handleJobLog" v-if =" hasPermi (['infra:job:query'])" >
123
+ <el-dropdown-item command =" handleJobLog" v-if =" checkPermi (['infra:job:query'])" >
108
124
调度日志
109
125
</el-dropdown-item >
110
126
</el-dropdown-menu >
114
130
</el-table-column >
115
131
</el-table >
116
132
<!-- 分页组件 -->
117
- <pagination
118
- v-show =" total > 0"
133
+ <Pagination
119
134
:total =" total"
120
135
v-model:page =" queryParams.pageNo"
121
136
v-model:limit =" queryParams.pageSize"
124
139
</content-wrap >
125
140
126
141
<!-- 表单弹窗:添加/修改 -->
127
- <job-form ref =" modalRef " @success =" getList" />
142
+ <job-form ref =" formRef " @success =" getList" />
128
143
<!-- 表单弹窗:查看 -->
129
144
<job-view ref =" viewModalRef" @success =" getList" />
130
145
</template >
131
-
132
146
<script setup lang="ts" name="Job">
133
- import { DICT_TYPE , getDictOptions } from ' @/utils/dict'
147
+ import { DICT_TYPE , getIntDictOptions } from ' @/utils/dict'
148
+ import { checkPermi } from ' @/utils/permission'
134
149
import JobForm from ' ./form.vue'
135
150
import JobView from ' ./view.vue'
136
151
import download from ' @/utils/download'
137
152
import * as JobApi from ' @/api/infra/job'
138
153
import { InfraJobStatusEnum } from ' @/utils/constants'
139
- import { CACHE_KEY , useCache } from ' @/hooks/web/useCache'
140
-
141
154
const { t } = useI18n () // 国际化
142
155
const message = useMessage () // 消息弹窗
143
- const { push } = useRouter ()
156
+ const { push } = useRouter () // 路由
144
157
145
158
const loading = ref (true ) // 列表的加载中
146
159
const total = ref (0 ) // 列表的总页数
@@ -167,30 +180,6 @@ const getList = async () => {
167
180
}
168
181
}
169
182
170
- const handleChangeStatus = async (row : JobApi .JobVO ) => {
171
- const text = row .status === InfraJobStatusEnum .STOP ? ' 开启' : ' 关闭'
172
-
173
- const status =
174
- row .status === InfraJobStatusEnum .STOP ? InfraJobStatusEnum .NORMAL : InfraJobStatusEnum .STOP
175
- message
176
- .confirm (' 确认要' + text + ' 定时任务编号为"' + row .id + ' "的数据项?' , t (' common.reminder' ))
177
- .then (async () => {
178
- row .status =
179
- row .status === InfraJobStatusEnum .NORMAL
180
- ? InfraJobStatusEnum .NORMAL
181
- : InfraJobStatusEnum .STOP
182
- await JobApi .updateJobStatusApi (row .id , status )
183
- message .success (text + ' 成功' )
184
- await getList ()
185
- })
186
- .catch (() => {
187
- row .status =
188
- row .status === InfraJobStatusEnum .NORMAL
189
- ? InfraJobStatusEnum .STOP
190
- : InfraJobStatusEnum .NORMAL
191
- })
192
- }
193
-
194
183
/** 搜索按钮操作 */
195
184
const handleQuery = () => {
196
185
queryParams .pageNo = 1
@@ -203,10 +192,47 @@ const resetQuery = () => {
203
192
handleQuery ()
204
193
}
205
194
195
+ /** 导出按钮操作 */
196
+ const handleExport = async () => {
197
+ try {
198
+ // 导出的二次确认
199
+ await message .exportConfirm ()
200
+ // 发起导出
201
+ exportLoading .value = true
202
+ const data = await JobApi .exportJobApi (queryParams )
203
+ download .excel (data , ' 定时任务.xls' )
204
+ } catch {
205
+ } finally {
206
+ exportLoading .value = false
207
+ }
208
+ }
209
+
206
210
/** 添加/修改操作 */
207
- const modalRef = ref ()
208
- const openModal = (type : string , id ? : number ) => {
209
- modalRef .value .openModal (type , id )
211
+ const formRef = ref ()
212
+ const openForm = (type : string , id ? : number ) => {
213
+ formRef .value .open (type , id )
214
+ }
215
+
216
+ /** 修改状态操作 */
217
+ const handleChangeStatus = async (row : JobApi .JobVO ) => {
218
+ try {
219
+ // 修改状态的二次确认
220
+ const text = row .status === InfraJobStatusEnum .STOP ? ' 开启' : ' 关闭'
221
+ await message .confirm (
222
+ ' 确认要' + text + ' 定时任务编号为"' + row .id + ' "的数据项?' ,
223
+ t (' common.reminder' )
224
+ )
225
+ const status =
226
+ row .status === InfraJobStatusEnum .STOP ? InfraJobStatusEnum .NORMAL : InfraJobStatusEnum .STOP
227
+ await JobApi .updateJobStatusApi (row .id , status )
228
+ message .success (text + ' 成功' )
229
+ // 刷新列表
230
+ await getList ()
231
+ } catch {
232
+ // 取消后,进行恢复按钮
233
+ row .status =
234
+ row .status === InfraJobStatusEnum .NORMAL ? InfraJobStatusEnum .STOP : InfraJobStatusEnum .NORMAL
235
+ }
210
236
}
211
237
212
238
/** 删除按钮操作 */
@@ -222,28 +248,6 @@ const handleDelete = async (id: number) => {
222
248
} catch {}
223
249
}
224
250
225
- /** 查看操作 */
226
- const viewModalRef = ref ()
227
- const handleView = (rowId ? : number ) => {
228
- viewModalRef .value .openModal (rowId )
229
- }
230
- // 执行日志
231
- const handleJobLog = (rowId ? : number ) => {
232
- if (rowId ) {
233
- push (' /job/job-log?id=' + rowId )
234
- } else {
235
- push (' /job/job-log' )
236
- }
237
- }
238
- // 执行一次
239
- const handleRun = (row : JobApi .JobVO ) => {
240
- message .confirm (' 确认要立即执行一次' + row .name + ' ?' , t (' common.reminder' )).then (async () => {
241
- await JobApi .runJobApi (row .id )
242
- message .success (' 执行成功' )
243
- await getList ()
244
- })
245
- }
246
-
247
251
/** '更多'操作按钮 */
248
252
const handleCommand = (command , row ) => {
249
253
switch (command ) {
@@ -261,36 +265,31 @@ const handleCommand = (command, row) => {
261
265
}
262
266
}
263
267
264
- /** 导出按钮操作 */
265
- const handleExport = async () => {
268
+ /** 执行一次 */
269
+ const handleRun = async (row : JobApi . JobVO ) => {
266
270
try {
267
- // 导出的二次确认
268
- await message .exportConfirm ()
269
- // 发起导出
270
- exportLoading .value = true
271
- const data = await JobApi .exportJobApi (queryParams )
272
- download .excel (data , ' 定时任务.xls' )
273
- } catch {
274
- } finally {
275
- exportLoading .value = false
276
- }
271
+ // 二次确认
272
+ await message .confirm (' 确认要立即执行一次' + row .name + ' ?' , t (' common.reminder' ))
273
+ // 提交执行
274
+ await JobApi .runJobApi (row .id )
275
+ message .success (' 执行成功' )
276
+ // 刷新列表
277
+ await getList ()
278
+ } catch {}
277
279
}
278
280
279
- // 权限判断:dropdown 与 v-hasPermi有冲突会造成大量的waring,改用v-if调用此方法
280
- const hasPermi = (permiKeys : string []) => {
281
- const { wsCache } = useCache ()
282
- const all_permission = ' *:*:*'
283
- const permissions = wsCache .get (CACHE_KEY .USER ).permissions
284
-
285
- if (permiKeys && permiKeys instanceof Array && permiKeys .length > 0 ) {
286
- const permissionFlag = permiKeys
287
-
288
- const hasPermissions = permissions .some ((permission : string ) => {
289
- return all_permission === permission || permissionFlag .includes (permission )
290
- })
291
- return hasPermissions
281
+ /** 查看操作 */
282
+ const viewModalRef = ref ()
283
+ const handleView = (rowId ? : number ) => {
284
+ viewModalRef .value .openForm (rowId )
285
+ }
286
+ // 执行日志
287
+ const handleJobLog = (rowId ? : number ) => {
288
+ if (rowId ) {
289
+ push (' /job/job-log?id=' + rowId )
290
+ } else {
291
+ push (' /job/job-log' )
292
292
}
293
- return false
294
293
}
295
294
296
295
/** 初始化 **/
0 commit comments