@ -1,19 +1,31 @@
< template >
< content-wrap >
<!-- 搜索栏 -- >
< el-form :model = "queryParams" ref = "queryFormRef" :inline = "true" label -width = " 100px " >
<!-- 搜索工作 栏 -- >
< el-form
class = "-mb-15px"
:model = "queryParams"
ref = "queryFormRef"
:inline = "true"
label -width = " 100px "
>
< el-form-item label = "任务名称" prop = "name" >
< el-input
v-model = "queryParams.name"
placeholder = "请输入任务名称"
clearable
@keyup.enter ="handleQuery"
class = "!w-240px"
/ >
< / el-form-item >
< el-form-item label = "任务状态" prop = "status" >
< el-select v-model = "queryParams.status" placeholder="请选择任务状态" clearable >
< el-select
v-model = "queryParams.status"
placeholder = "请选择任务状态"
clearable
class = "!w-240px"
>
< el-option
v-for = "dict in getDictOptions(DICT_TYPE.INFRA_JOB_STATUS)"
v-for = "dict in getInt DictOptions(DICT_TYPE.INFRA_JOB_STATUS)"
:key = "dict.value"
:label = "dict.label"
:value = "dict.value"
@ -26,6 +38,7 @@
placeholder = "请输入处理器的名字"
clearable
@keyup.enter ="handleQuery"
class = "!w-240px"
/ >
< / el-form-item >
< el-form-item >
@ -34,7 +47,7 @@
< el-button
type = "primary"
plain
@click ="openModal ('create')"
@click ="openForm ('create')"
v-hasPermi = "['infra:job:create']"
>
< Icon icon = "ep:plus" class = "mr-5px" / > 新增
@ -48,63 +61,66 @@
>
< Icon icon = "ep:download" class = "mr-5px" / > 导出
< / el-button >
< el-button type = "info" plain @click ="handleJobLog" v-hasPermi = "['infra:job:query']" >
< Icon icon = "ep:zoom-in" class = "mr-5px" / > 执行日志
< / el-button >
< / el-form-item >
< / el-form >
< / content-wrap >
<!-- 列表 -- >
< content-wrap >
< el-table v-loading = "loading" :data="list" >
< el -table -column label = "任务编号" align = "center" prop = "id" / >
< el-table-column label = "任务名称" align = "center" prop = "name" / >
< el-table-column label = "任务状态" align = "center" prop = "status" >
< template # default = "scope" >
< dict-tag :type = "DICT_TYPE.INFRA_JOB_STATUS" :value = "scope.row.status" / >
< / template > < / e l - t a b l e - c o l u m n
> >
< / template >
< / el-table-column >
< el-table-column label = "处理器的名字" align = "center" prop = "handlerName" / >
< el-table-column label = "处理器的参数" align = "center" prop = "handlerParam" / >
< el-table-column label = "CRON 表达式" align = "center" prop = "cronExpression" / >
< el-table-column label = "操作" align = "center" class -name = " small -padding fixed -width ">
< el-table-column label = "操作" align = "center" width = "200 ">
< template # default = "scope" >
< el-button
type = "primary"
link
icon = "el-icon-edit "
@click ="openModal('update', scope.row.id)"
@click ="openForm('update', scope.row.id) "
v-hasPermi = "['infra:job:update']"
> 修改 < / e l - b u t t o n
>
修改
< / el-button >
< el-button
type = "primary"
link
icon = "el-icon-check"
@click ="handleChangeStatus(scope.row)"
v-hasPermi = "['infra:job:update']"
> { { scope . row . status === InfraJobStatusEnum . STOP ? '开启' : '暂停' } } < / e l - b u t t o n
>
{ { scope . row . status === InfraJobStatusEnum . STOP ? '开启' : '暂停' } }
< / el-button >
< el-button
type = "danger"
link
icon = "el-icon-delete"
@click ="handleDelete(scope.row)"
v-hasPermi = "['infra:job:delete']"
> 删除 < / e l - b u t t o n
>
删除
< / el-button >
< el-dropdown
class = "mt-1"
:teleported = "true"
@command ="(command) => handleCommand(command, scope.row)"
v-hasPermi = "['infra:job:trigger', 'infra:job:query']"
>
< el-button link icon = "el-icon- d-arrow-right" > 更多 < / el-button >
< el-button type = "primary" link > < Icon icon = "ep: d-arrow-right" / > 更多 < / el-button >
< template # dropdown >
< el-dropdown-menu >
< el-dropdown-item command = "handleRun" v-if = "has Permi(['infra:job:trigger'])" >
< el-dropdown-item command = "handleRun" v-if = "check Permi(['infra:job:trigger'])" >
执行一次
< / el -dropdown -item >
< el-dropdown-item command = "handleView" v-if = "has Permi(['infra:job:query'])" >
< el-dropdown-item command = "handleView" v-if = "check Permi(['infra:job:query'])" >
任务详细
< / el -dropdown -item >
< el-dropdown-item command = "handleJobLog" v-if = "has Permi(['infra:job:query'])" >
< el-dropdown-item command = "handleJobLog" v-if = "check Permi(['infra:job:query'])" >
调度日志
< / el -dropdown -item >
< / el-dropdown-menu >
@ -114,8 +130,7 @@
< / el-table-column >
< / el-table >
<!-- 分页组件 -- >
< p agination
v-show = "total > 0"
< P agination
:total = "total"
v -model :page = "queryParams.pageNo"
v -model :limit = "queryParams.pageSize"
@ -124,23 +139,21 @@
< / content-wrap >
<!-- 表单弹窗 : 添加 / 修改 -- >
< job-form ref = "modal Ref" @success ="getList" / >
< job-form ref = "form Ref" @success ="getList" / >
<!-- 表单弹窗 : 查看 -- >
< job-view ref = "viewModalRef" @success ="getList" / >
< / template >
< script setup lang = "ts" name = "Job" >
import { DICT _TYPE , getDictOptions } from '@/utils/dict'
import { DICT _TYPE , getInt DictOptions } from '@/utils/dict'
import { checkPermi } from '@/utils/permission'
import JobForm from './form.vue'
import JobView from './view.vue'
import download from '@/utils/download'
import * as JobApi from '@/api/infra/job'
import { InfraJobStatusEnum } from '@/utils/constants'
import { CACHE _KEY , useCache } from '@/hooks/web/useCache'
const { t } = useI18n ( ) // 国际化
const message = useMessage ( ) // 消息弹窗
const { push } = useRouter ( )
const { push } = useRouter ( ) // 路由
const loading = ref ( true ) // 列表的加载中
const total = ref ( 0 ) // 列表的总页数
@ -167,30 +180,6 @@ const getList = async () => {
}
}
const handleChangeStatus = async ( row : JobApi . JobVO ) => {
const text = row . status === InfraJobStatusEnum . STOP ? '开启' : '关闭'
const status =
row . status === InfraJobStatusEnum . STOP ? InfraJobStatusEnum . NORMAL : InfraJobStatusEnum . STOP
message
. confirm ( '确认要' + text + '定时任务编号为"' + row . id + '"的数据项?' , t ( 'common.reminder' ) )
. then ( async ( ) => {
row . status =
row . status === InfraJobStatusEnum . NORMAL
? InfraJobStatusEnum . NORMAL
: InfraJobStatusEnum . STOP
await JobApi . updateJobStatusApi ( row . id , status )
message . success ( text + '成功' )
await getList ( )
} )
. catch ( ( ) => {
row . status =
row . status === InfraJobStatusEnum . NORMAL
? InfraJobStatusEnum . STOP
: InfraJobStatusEnum . NORMAL
} )
}
/** 搜索按钮操作 */
const handleQuery = ( ) => {
queryParams . pageNo = 1
@ -203,10 +192,47 @@ const resetQuery = () => {
handleQuery ( )
}
/** 导出按钮操作 */
const handleExport = async ( ) => {
try {
// 导出的二次确认
await message . exportConfirm ( )
// 发起导出
exportLoading . value = true
const data = await JobApi . exportJobApi ( queryParams )
download . excel ( data , '定时任务.xls' )
} catch {
} finally {
exportLoading . value = false
}
}
/** 添加/修改操作 */
const modal Ref = ref ( )
const openModal = ( type : string , id ? : number ) => {
modal Ref. value . openModal ( type , id )
const form Ref = ref ( )
const openForm = ( type : string , id ? : number ) => {
form Ref. value . open ( type , id )
}
/** 修改状态操作 */
const handleChangeStatus = async ( row : JobApi . JobVO ) => {
try {
// 修改状态的二次确认
const text = row . status === InfraJobStatusEnum . STOP ? '开启' : '关闭'
await message . confirm (
'确认要' + text + '定时任务编号为"' + row . id + '"的数据项?' ,
t ( 'common.reminder' )
)
const status =
row . status === InfraJobStatusEnum . STOP ? InfraJobStatusEnum . NORMAL : InfraJobStatusEnum . STOP
await JobApi . updateJobStatusApi ( row . id , status )
message . success ( text + '成功' )
// 刷新列表
await getList ( )
} catch {
// 取消后,进行恢复按钮
row . status =
row . status === InfraJobStatusEnum . NORMAL ? InfraJobStatusEnum . STOP : InfraJobStatusEnum . NORMAL
}
}
/** 删除按钮操作 */
@ -222,28 +248,6 @@ const handleDelete = async (id: number) => {
} catch { }
}
/** 查看操作 */
const viewModalRef = ref ( )
const handleView = ( rowId ? : number ) => {
viewModalRef . value . openModal ( rowId )
}
// 执行日志
const handleJobLog = ( rowId ? : number ) => {
if ( rowId ) {
push ( '/job/job-log?id=' + rowId )
} else {
push ( '/job/job-log' )
}
}
// 执行一次
const handleRun = ( row : JobApi . JobVO ) => {
message . confirm ( '确认要立即执行一次' + row . name + '?' , t ( 'common.reminder' ) ) . then ( async ( ) => {
await JobApi . runJobApi ( row . id )
message . success ( '执行成功' )
await getList ( )
} )
}
/** '更多'操作按钮 */
const handleCommand = ( command , row ) => {
switch ( command ) {
@ -261,36 +265,31 @@ const handleCommand = (command, row) => {
}
}
/** 导出按钮操作 */
const handleExport = async ( ) => {
/** 执行一次 */
const handleRun = async ( row : JobApi . JobVO ) => {
try {
// 导出的 二次确认
await message . exportC onfirm( )
// 发起导出
exportLoading . value = true
const data = await JobApi . exportJobApi ( queryParams )
download . excel ( data , '定时任务.xls' )
} catch {
} finally {
exportLoading . value = false
}
// 二次确认
await message . c onfirm( '确认要立即执行一次' + row . name + '?' , t ( 'common.reminder' ) )
// 提交执行
await JobApi . runJobApi ( row . id )
message . success ( '执行成功' )
// 刷新列表
await getList ( )
} catch { }
}
// 权限判断: dropdown 与 v-hasPermi有冲突会造成大量的waring, 改用v-if调用此方法
const hasPermi = ( permiKeys : string [ ] ) => {
const { wsCache } = useCache ( )
const all _ permission = '*:*:*'
const permissions = wsCache . get ( CACHE _KEY . USER ) . permissions
if ( permiKeys && permiKeys instanceof Array && permiKeys . length > 0 ) {
const permissionFlag = permiKeys
const hasPermissions = permissions . some ( ( permission : string ) => {
return all _permission === permission || permissionFlag . includes ( permission )
} )
return hasPermissions
/** 查看操作 */
const viewModalRef = ref ( )
const handleView = ( rowId ? : number ) => {
viewModalRef . value . o penForm ( rowId )
}
// 执行日志
const handleJobLog = ( rowId ? : number ) => {
if ( rowId ) {
push ( '/job/job-log?id=' + rowId )
} else {
push ( '/job/job-log' )
}
return false
}
/** 初始化 **/