3 changed files with 304 additions and 1 deletions
			
			
		@ -0,0 +1,54 @@
					 | 
				
			||||
<template> | 
				
			||||
  <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" @ok="handleSubmit"> | 
				
			||||
    <BasicForm @register="registerForm" /> | 
				
			||||
  </BasicModal> | 
				
			||||
</template> | 
				
			||||
<script lang="ts" setup name="JobModal"> | 
				
			||||
import { ref, computed, unref } from 'vue' | 
				
			||||
import { BasicModal, useModalInner } from '@/components/Modal' | 
				
			||||
import { BasicForm, useForm } from '@/components/Form' | 
				
			||||
import { formSchema } from './job.data' | 
				
			||||
import { createJob, getJob, updateJob } from '@/api/infra/job' | 
				
			||||
 | 
				
			||||
const emit = defineEmits(['success', 'register']) | 
				
			||||
const isUpdate = ref(true) | 
				
			||||
const rowId = ref() | 
				
			||||
 | 
				
			||||
const [registerForm, { setFieldsValue, resetFields, validate }] = useForm({ | 
				
			||||
  labelWidth: 100, | 
				
			||||
  baseColProps: { span: 24 }, | 
				
			||||
  schemas: formSchema, | 
				
			||||
  showActionButtonGroup: false, | 
				
			||||
  actionColOptions: { span: 23 } | 
				
			||||
}) | 
				
			||||
 | 
				
			||||
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => { | 
				
			||||
  resetFields() | 
				
			||||
  setModalProps({ confirmLoading: false }) | 
				
			||||
  isUpdate.value = !!data?.isUpdate | 
				
			||||
 | 
				
			||||
  if (unref(isUpdate)) { | 
				
			||||
    const res = await getJob(data.record.id) | 
				
			||||
    rowId.value = res.id | 
				
			||||
    setFieldsValue({ ...res }) | 
				
			||||
  } | 
				
			||||
}) | 
				
			||||
 | 
				
			||||
const getTitle = computed(() => (!unref(isUpdate) ? '新增定时任务' : '编辑定时任务')) | 
				
			||||
 | 
				
			||||
async function handleSubmit() { | 
				
			||||
  try { | 
				
			||||
    const values = await validate() | 
				
			||||
    setModalProps({ confirmLoading: true }) | 
				
			||||
    if (unref(isUpdate)) { | 
				
			||||
      await updateJob(values) | 
				
			||||
    } else { | 
				
			||||
      await createJob(values) | 
				
			||||
    } | 
				
			||||
    closeModal() | 
				
			||||
    emit('success') | 
				
			||||
  } finally { | 
				
			||||
    setModalProps({ confirmLoading: false }) | 
				
			||||
  } | 
				
			||||
} | 
				
			||||
</script> | 
				
			||||
@ -1,3 +1,136 @@
					 | 
				
			||||
<template> | 
				
			||||
  <div>开发中</div> | 
				
			||||
  <div> | 
				
			||||
    <BasicTable @register="registerTable"> | 
				
			||||
      <template #toolbar> | 
				
			||||
        <a-button type="primary" :preIcon="IconEnum.ADD" @click="handleCreate"> {{ t('action.create') }} </a-button> | 
				
			||||
        <a-button type="warning" :preIcon="IconEnum.EXPORT" @click="handleExport"> {{ t('action.export') }} </a-button> | 
				
			||||
      </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: '开启', onClick: handleChangeStatus.bind(null, record, true) }, | 
				
			||||
              { icon: IconEnum.EDIT, label: '暂停', onClick: handleChangeStatus.bind(null, record, false) }, | 
				
			||||
              { icon: IconEnum.EDIT, label: '执行一次', onClick: handleRun.bind(null, record) }, | 
				
			||||
              { icon: IconEnum.EDIT, label: '任务详细', onClick: handleView.bind(null, record) }, | 
				
			||||
              { icon: IconEnum.EDIT, label: '调度日志', onClick: handleJobLog.bind(null, record) }, | 
				
			||||
              { | 
				
			||||
                icon: IconEnum.DELETE, | 
				
			||||
                color: 'error', | 
				
			||||
                label: t('action.delete'), | 
				
			||||
                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="Job"> | 
				
			||||
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' | 
				
			||||
 | 
				
			||||
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 | 
				
			||||
  }, | 
				
			||||
  useSearchForm: true, | 
				
			||||
  showTableSetting: true, | 
				
			||||
  showIndexColumn: false, | 
				
			||||
  actionColumn: { | 
				
			||||
    width: 140, | 
				
			||||
    title: t('common.action'), | 
				
			||||
    dataIndex: 'action', | 
				
			||||
    fixed: 'right' | 
				
			||||
  } | 
				
			||||
}) | 
				
			||||
 | 
				
			||||
function handleCreate() { | 
				
			||||
  openModal(true, { | 
				
			||||
    isUpdate: false | 
				
			||||
  }) | 
				
			||||
} | 
				
			||||
 | 
				
			||||
function handleEdit(record: Recordable) { | 
				
			||||
  openModal(true, { | 
				
			||||
    record, | 
				
			||||
    isUpdate: true | 
				
			||||
  }) | 
				
			||||
} | 
				
			||||
 | 
				
			||||
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) { | 
				
			||||
  // TODO | 
				
			||||
  console.info(record) | 
				
			||||
} | 
				
			||||
 | 
				
			||||
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> | 
				
			||||
					 | 
				
			||||
@ -0,0 +1,116 @@
					 | 
				
			||||
import { BasicColumn, FormSchema, useRender } from '@/components/Table' | 
				
			||||
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict' | 
				
			||||
 | 
				
			||||
export const columns: BasicColumn[] = [ | 
				
			||||
  { | 
				
			||||
    title: '任务编号', | 
				
			||||
    dataIndex: 'id', | 
				
			||||
    width: 100 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '任务名称', | 
				
			||||
    dataIndex: 'name', | 
				
			||||
    width: 180 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '处理器的名字', | 
				
			||||
    dataIndex: 'handlerName', | 
				
			||||
    width: 180 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '处理器的参数', | 
				
			||||
    dataIndex: 'handlerParam', | 
				
			||||
    width: 180 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: 'CRON 表达式', | 
				
			||||
    dataIndex: 'cronExpression', | 
				
			||||
    width: 200 | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    title: '任务状态', | 
				
			||||
    dataIndex: 'status', | 
				
			||||
    width: 180, | 
				
			||||
    customRender: ({ text }) => { | 
				
			||||
      return useRender.renderDict(text, DICT_TYPE.INFRA_JOB_STATUS) | 
				
			||||
    } | 
				
			||||
  } | 
				
			||||
] | 
				
			||||
 | 
				
			||||
export const searchFormSchema: FormSchema[] = [ | 
				
			||||
  { | 
				
			||||
    label: '任务名称', | 
				
			||||
    field: 'name', | 
				
			||||
    component: 'Input', | 
				
			||||
    colProps: { span: 8 } | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '任务状态', | 
				
			||||
    field: 'status', | 
				
			||||
    component: 'Select', | 
				
			||||
    componentProps: { | 
				
			||||
      options: getIntDictOptions(DICT_TYPE.INFRA_JOB_STATUS) | 
				
			||||
    }, | 
				
			||||
    colProps: { span: 8 } | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '处理器的名字', | 
				
			||||
    field: 'handlerName', | 
				
			||||
    component: 'Input', | 
				
			||||
    colProps: { span: 8 } | 
				
			||||
  } | 
				
			||||
] | 
				
			||||
 | 
				
			||||
export const formSchema: FormSchema[] = [ | 
				
			||||
  { | 
				
			||||
    label: '任务编号', | 
				
			||||
    field: 'id', | 
				
			||||
    show: false, | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '任务名称', | 
				
			||||
    field: 'name', | 
				
			||||
    required: true, | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '处理器的名字', | 
				
			||||
    field: 'handlerName', | 
				
			||||
    required: true, | 
				
			||||
    dynamicDisabled: ({ values }) => !!values.id, | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '处理器的参数', | 
				
			||||
    field: 'handlerParam', | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: 'CRON 表达式', | 
				
			||||
    field: 'cronExpression', | 
				
			||||
    required: true, | 
				
			||||
    component: 'Input' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '重试次数', | 
				
			||||
    field: 'retryCount', | 
				
			||||
    required: true, | 
				
			||||
    helpMessage: '设置为 0 时,不进行重试', | 
				
			||||
    component: 'InputNumber' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '重试间隔', | 
				
			||||
    field: 'retryInterval', | 
				
			||||
    required: true, | 
				
			||||
    helpMessage: '单位:毫秒。设置为 0 时,无需间隔', | 
				
			||||
    component: 'InputNumber', | 
				
			||||
    suffix: '毫秒' | 
				
			||||
  }, | 
				
			||||
  { | 
				
			||||
    label: '监控超时时间', | 
				
			||||
    field: 'monitorTimeout', | 
				
			||||
    component: 'Input', | 
				
			||||
    suffix: '毫秒' | 
				
			||||
  } | 
				
			||||
] | 
				
			||||
		Reference in new issue