You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
4.6 KiB

<template>
2 years ago
<div>
<BasicTable @register="registerTable">
<template #toolbar>
<a-button type="primary" v-auth="['infra:job:create']" :preIcon="IconEnum.ADD" @click="handleCreate">
{{ t('action.create') }}
</a-button>
<a-button type="warning" v-auth="['infra:job:export']" :preIcon="IconEnum.EXPORT" @click="handleExport">
{{ t('action.export') }}
</a-button>
2 years ago
</template>
<template #bodyCell="{ column, record }">
<template v-if="column.key === 'action'">
<TableAction
:actions="[{ icon: IconEnum.EDIT, label: t('action.edit'), onClick: handleEdit.bind(null, record) }]"
:dropDownActions="[
{ icon: IconEnum.EDIT, label: '开启', auth: 'infra:job:update', onClick: handleChangeStatus.bind(null, record, true) },
{ icon: IconEnum.EDIT, label: '暂停', auth: 'infra:job:update', onClick: handleChangeStatus.bind(null, record, false) },
{ icon: IconEnum.EDIT, label: '执行一次', auth: 'infra:job:trigger', onClick: handleRun.bind(null, record) },
{ icon: IconEnum.EDIT, label: '任务详细', auth: 'infra:job:query', onClick: handleView.bind(null, record) },
{ icon: IconEnum.EDIT, label: '调度日志', auth: 'infra:job:query', onClick: handleJobLog.bind(null, record) },
2 years ago
{
icon: IconEnum.DELETE,
color: 'error',
label: t('action.delete'),
auth: 'infra:job:delete',
2 years ago
popConfirm: {
title: t('common.delMessage'),
placement: 'left',
confirm: handleDelete.bind(null, record)
}
}
]"
/>
</template>
</template>
</BasicTable>
<JobModal @register="registerModal" @success="reload()" />
</div>
</template>
<script lang="ts" setup name="InfraJob">
2 years ago
import { useGo } from '@/hooks/web/usePage'
2 years ago
import { useI18n } from '@/hooks/web/useI18n'
import { useMessage } from '@/hooks/web/useMessage'
import { useModal } from '@/components/Modal'
import JobModal from './JobModal.vue'
import { IconEnum } from '@/enums/appEnum'
import { BasicTable, useTable, TableAction } from '@/components/Table'
import { JobExportReqVO, deleteJob, exportJob, getJobPage, runJob, updateJobStatus } from '@/api/infra/job'
import { columns, searchFormSchema } from './job.data'
import { InfraJobStatusEnum } from '@/enums/systemEnum'
2 years ago
const go = useGo()
2 years ago
const { t } = useI18n()
const { createConfirm, createMessage } = useMessage()
const [registerModal, { openModal }] = useModal()
const [registerTable, { getForm, reload }] = useTable({
title: '定时任务列表',
api: getJobPage,
columns,
formConfig: { labelWidth: 120, schemas: searchFormSchema },
2 years ago
useSearchForm: true,
showTableSetting: true,
showIndexColumn: false,
actionColumn: {
width: 140,
title: t('common.action'),
dataIndex: 'action',
fixed: 'right'
}
})
function handleCreate() {
openModal(true, { isUpdate: false })
2 years ago
}
function handleEdit(record: Recordable) {
openModal(true, { record, isUpdate: true })
2 years ago
}
function handleChangeStatus(record: Recordable, open: boolean) {
let status = open ? InfraJobStatusEnum.NORMAL : InfraJobStatusEnum.STOP
let statusStr = open ? '开启' : '关闭'
createConfirm({
title: '调整状态',
iconType: 'warning',
content: '是否确认' + statusStr + '定时任务编号为"' + record.id + '"的数据项?',
async onOk() {
await updateJobStatus(record.id, status)
createMessage.success(t('common.successText'))
}
})
}
function handleRun(record: Recordable) {
createConfirm({
title: '执行',
iconType: 'warning',
content: '确认要立即执行一次"' + record.name + '"任务吗?',
async onOk() {
await runJob(record.id)
createMessage.success(t('common.successText'))
}
})
}
function handleView(record: Recordable) {
// TODO
console.info(record)
}
function handleJobLog(record: Recordable) {
2 years ago
if (record.id > 0) {
go('/job/job-log?id=' + record.id)
} else {
go('/job/job-log')
}
2 years ago
}
async function handleExport() {
createConfirm({
title: t('common.exportTitle'),
iconType: 'warning',
content: t('common.exportMessage'),
async onOk() {
await exportJob(getForm().getFieldsValue() as JobExportReqVO)
createMessage.success(t('common.exportSuccessText'))
}
})
}
async function handleDelete(record: Recordable) {
await deleteJob(record.id)
createMessage.success(t('common.delSuccessText'))
reload()
}
</script>