config.form.data.ts 4.85 KB
import { BasicColumn, FormSchema } from '/@/components/Table';
import { JCronValidator } from '/@/components/Form/index';
import type { FormSchema as QFormSchema } from '/@/components/Form/index';
import { EJobGroup } from './config.data';
import { useI18n } from '/@/hooks/web/useI18n';

const { t } = useI18n();
// 定时任务表格配置
export const columnSchedue: BasicColumn[] = [
  {
    title: t('system.tasks.taskName'),
    dataIndex: 'jobName',
    width: 120,
  },
  {
    title: t('system.tasks.taskGroup'),
    dataIndex: 'jobGroup',
    width: 120,
    format: (text: string) => {
      return t(`system.tasks.EJobGroup.${text}`);
    },
  },
  {
    title: t('system.tasks.table.callTarget'),
    dataIndex: 'invokeTarget',
    width: 120,
  },
  {
    title: t('system.tasks.cron'),
    dataIndex: 'cronExpression',
    width: 160,
  },
  {
    title: t('system.tasks.state'),
    dataIndex: 'status',
    width: 160,
    slots: { customRender: 'status' },
  },
];

// 定时任务格查询配置
export const searchSchedueFormSchema: FormSchema[] = [
  {
    field: 'jobName',
    label: t('system.tasks.taskName'),
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 36,
    },
  },
  {
    field: 'jobGroup',
    label: t('system.tasks.taskGroup'),
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          label: t('system.tasks.table.default'),
          value: EJobGroup.DEFAULT,
        },
        {
          label: t('system.tasks.table.system'),
          value: EJobGroup.SYSTEM,
        },
        {
          label: t('system.tasks.table.report'),
          value: EJobGroup.REPORT,
        },
        {
          label: t('system.tasks.table.taskCenter'),
          value: EJobGroup.TASK_CENTER,
        },
      ],
    },
  },
  {
    field: 'status',
    label: t('system.tasks.table.taskState'),
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          label: t('common.enableText'),
          value: 1,
        },
        {
          label: t('common.disableText'),
          value: 0,
        },
      ],
    },
  },
];

// 新增编辑配置
export const formSchema: QFormSchema[] = [
  {
    field: 'jobName',
    label: t('system.tasks.taskName'),
    colProps: { span: 24 },
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: 'jobGroup',
    component: 'Select',
    label: t('system.tasks.taskGroup'),
    dynamicDisabled: true,
    colProps: {
      span: 24,
    },
    componentProps: {
      options: [
        {
          label: t('system.tasks.table.default'),
          value: EJobGroup.DEFAULT,
        },
        {
          label: t('system.tasks.table.system'),
          value: EJobGroup.SYSTEM,
        },
        {
          label: t('system.tasks.table.report'),
          value: EJobGroup.REPORT,
        },
        {
          label: t('system.tasks.table.taskCenter'),
          value: EJobGroup.TASK_CENTER,
        },
      ],
    },
  },
  {
    field: 'invokeTarget',
    label: t('system.tasks.table.callMethod'),
    helpMessage: [t('system.tasks.table.callMessage')],
    colProps: { span: 24 },
    required: true,
    component: 'Input',
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: 'cronExpression',
    label: t('system.tasks.cron'),
    component: 'JEasyCron',
    defaultValue: '* * * * * ? *',
    dynamicDisabled: true,
    colProps: {
      span: 24,
    },
    rules: [{ required: true, message: '请输入Cron表达式' }, { validator: JCronValidator }],
  },
  {
    field: 'misfirePolicy',
    component: 'RadioButtonGroup',
    label: t('system.tasks.table.strategy'),
    colProps: {
      span: 24,
    },
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: t('system.tasks.table.immediate'),
          value: 0,
        },
        {
          label: t('system.tasks.executeOnce'),
          value: 1,
        },
        {
          label: t('system.tasks.table.execution'),
          value: 2,
        },
      ],
    },
  },
  {
    field: 'concurrent',
    component: 'RadioButtonGroup',
    label: t('system.tasks.table.isConcurrent'),
    colProps: {
      span: 24,
    },
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: t('system.tasks.table.allow'),
          value: 0,
        },
        {
          label: t('system.tasks.table.disable'),
          value: 1,
        },
      ],
    },
  },
  {
    field: 'status',
    component: 'RadioGroup',
    label: t('system.tasks.state'),
    colProps: {
      span: 24,
    },
    defaultValue: 1,
    componentProps: {
      options: [
        {
          label: t('common.enableText'),
          value: 1,
        },
        {
          label: t('common.disableText'),
          value: 0,
        },
      ],
    },
  },
];