Skip to content

Commit f8878f7

Browse files
committed
REVIEW 定时任务(列表)
1 parent cebe6f9 commit f8878f7

File tree

7 files changed

+131
-173
lines changed

7 files changed

+131
-173
lines changed

src/types/auto-components.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ declare module '@vue/runtime-core' {
2323
DictTag: typeof import('./../components/DictTag/src/DictTag.vue')['default']
2424
Echart: typeof import('./../components/Echart/src/Echart.vue')['default']
2525
Editor: typeof import('./../components/Editor/src/Editor.vue')['default']
26+
ElAutoResizer: typeof import('element-plus/es')['ElAutoResizer']
2627
ElBadge: typeof import('element-plus/es')['ElBadge']
2728
ElButton: typeof import('element-plus/es')['ElButton']
2829
ElButtonGroup: typeof import('element-plus/es')['ElButtonGroup']
@@ -70,6 +71,7 @@ declare module '@vue/runtime-core' {
7071
ElSwitch: typeof import('element-plus/es')['ElSwitch']
7172
ElTable: typeof import('element-plus/es')['ElTable']
7273
ElTableColumn: typeof import('element-plus/es')['ElTableColumn']
74+
ElTableV2: typeof import('element-plus/es')['ElTableV2']
7375
ElTabPane: typeof import('element-plus/es')['ElTabPane']
7476
ElTabs: typeof import('element-plus/es')['ElTabs']
7577
ElTag: typeof import('element-plus/es')['ElTag']

src/views/infra/job/form.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ const formRules = reactive({
107107
const formRef = ref() // 表单 Ref
108108
109109
/** 打开弹窗 */
110-
const openModal = async (type: string, id?: number) => {
110+
const open = async (type: string, id?: number) => {
111111
modelVisible.value = true
112112
modelTitle.value = t('action.' + type)
113113
formType.value = type
@@ -122,7 +122,7 @@ const openModal = async (type: string, id?: number) => {
122122
}
123123
}
124124
}
125-
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
125+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
126126
127127
/** cron表达式按钮操作 */
128128
const handleShowCron = () => {

src/views/infra/job/index.vue

Lines changed: 104 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,31 @@
11
<template>
22
<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+
>
511
<el-form-item label="任务名称" prop="name">
612
<el-input
713
v-model="queryParams.name"
814
placeholder="请输入任务名称"
915
clearable
1016
@keyup.enter="handleQuery"
17+
class="!w-240px"
1118
/>
1219
</el-form-item>
1320
<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+
>
1527
<el-option
16-
v-for="dict in getDictOptions(DICT_TYPE.INFRA_JOB_STATUS)"
28+
v-for="dict in getIntDictOptions(DICT_TYPE.INFRA_JOB_STATUS)"
1729
:key="dict.value"
1830
:label="dict.label"
1931
:value="dict.value"
@@ -26,6 +38,7 @@
2638
placeholder="请输入处理器的名字"
2739
clearable
2840
@keyup.enter="handleQuery"
41+
class="!w-240px"
2942
/>
3043
</el-form-item>
3144
<el-form-item>
@@ -34,7 +47,7 @@
3447
<el-button
3548
type="primary"
3649
plain
37-
@click="openModal('create')"
50+
@click="openForm('create')"
3851
v-hasPermi="['infra:job:create']"
3952
>
4053
<Icon icon="ep:plus" class="mr-5px" /> 新增
@@ -48,63 +61,66 @@
4861
>
4962
<Icon icon="ep:download" class="mr-5px" /> 导出
5063
</el-button>
51-
5264
<el-button type="info" plain @click="handleJobLog" v-hasPermi="['infra:job:query']">
5365
<Icon icon="ep:zoom-in" class="mr-5px" /> 执行日志
5466
</el-button>
5567
</el-form-item>
5668
</el-form>
69+
</content-wrap>
5770

71+
<!-- 列表 -->
72+
<content-wrap>
5873
<el-table v-loading="loading" :data="list">
5974
<el-table-column label="任务编号" align="center" prop="id" />
6075
<el-table-column label="任务名称" align="center" prop="name" />
6176
<el-table-column label="任务状态" align="center" prop="status">
6277
<template #default="scope">
6378
<dict-tag :type="DICT_TYPE.INFRA_JOB_STATUS" :value="scope.row.status" />
64-
</template> </el-table-column
65-
>>
79+
</template>
80+
</el-table-column>
6681
<el-table-column label="处理器的名字" align="center" prop="handlerName" />
6782
<el-table-column label="处理器的参数" align="center" prop="handlerParam" />
6883
<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">
7085
<template #default="scope">
7186
<el-button
87+
type="primary"
7288
link
73-
icon="el-icon-edit"
74-
@click="openModal('update', scope.row.id)"
89+
@click="openForm('update', scope.row.id)"
7590
v-hasPermi="['infra:job:update']"
76-
>修改</el-button
7791
>
92+
修改
93+
</el-button>
7894
<el-button
95+
type="primary"
7996
link
80-
icon="el-icon-check"
8197
@click="handleChangeStatus(scope.row)"
8298
v-hasPermi="['infra:job:update']"
83-
>{{ scope.row.status === InfraJobStatusEnum.STOP ? '开启' : '暂停' }}</el-button
8499
>
100+
{{ scope.row.status === InfraJobStatusEnum.STOP ? '开启' : '暂停' }}
101+
</el-button>
85102
<el-button
103+
type="danger"
86104
link
87-
icon="el-icon-delete"
88105
@click="handleDelete(scope.row)"
89106
v-hasPermi="['infra:job:delete']"
90-
>删除</el-button
91107
>
108+
删除
109+
</el-button>
92110
<el-dropdown
93-
class="mt-1"
94-
:teleported="true"
95111
@command="(command) => handleCommand(command, scope.row)"
96112
v-hasPermi="['infra:job:trigger', 'infra:job:query']"
97113
>
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>
99115
<template #dropdown>
100116
<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'])">
102118
执行一次
103119
</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'])">
105121
任务详细
106122
</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'])">
108124
调度日志
109125
</el-dropdown-item>
110126
</el-dropdown-menu>
@@ -114,8 +130,7 @@
114130
</el-table-column>
115131
</el-table>
116132
<!-- 分页组件 -->
117-
<pagination
118-
v-show="total > 0"
133+
<Pagination
119134
:total="total"
120135
v-model:page="queryParams.pageNo"
121136
v-model:limit="queryParams.pageSize"
@@ -124,23 +139,21 @@
124139
</content-wrap>
125140

126141
<!-- 表单弹窗:添加/修改 -->
127-
<job-form ref="modalRef" @success="getList" />
142+
<job-form ref="formRef" @success="getList" />
128143
<!-- 表单弹窗:查看 -->
129144
<job-view ref="viewModalRef" @success="getList" />
130145
</template>
131-
132146
<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'
134149
import JobForm from './form.vue'
135150
import JobView from './view.vue'
136151
import download from '@/utils/download'
137152
import * as JobApi from '@/api/infra/job'
138153
import { InfraJobStatusEnum } from '@/utils/constants'
139-
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
140-
141154
const { t } = useI18n() // 国际化
142155
const message = useMessage() // 消息弹窗
143-
const { push } = useRouter()
156+
const { push } = useRouter() // 路由
144157
145158
const loading = ref(true) // 列表的加载中
146159
const total = ref(0) // 列表的总页数
@@ -167,30 +180,6 @@ const getList = async () => {
167180
}
168181
}
169182
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-
194183
/** 搜索按钮操作 */
195184
const handleQuery = () => {
196185
queryParams.pageNo = 1
@@ -203,10 +192,47 @@ const resetQuery = () => {
203192
handleQuery()
204193
}
205194
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+
206210
/** 添加/修改操作 */
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+
}
210236
}
211237
212238
/** 删除按钮操作 */
@@ -222,28 +248,6 @@ const handleDelete = async (id: number) => {
222248
} catch {}
223249
}
224250
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-
247251
/** '更多'操作按钮 */
248252
const handleCommand = (command, row) => {
249253
switch (command) {
@@ -261,36 +265,31 @@ const handleCommand = (command, row) => {
261265
}
262266
}
263267
264-
/** 导出按钮操作 */
265-
const handleExport = async () => {
268+
/** 执行一次 */
269+
const handleRun = async (row: JobApi.JobVO) => {
266270
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 {}
277279
}
278280
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')
292292
}
293-
return false
294293
}
295294
296295
/** 初始化 **/

0 commit comments

Comments
 (0)