index.ts 2.73 KB
import moment from 'moment';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { ApplicationRecordItemType } from '/@/api/application/model/record';
import { Tag } from 'ant-design-vue';
import { h } from 'vue';
import { formatClassifyText } from '../../api/config';
import { findDictItemByCode } from '/@/api/system/dict';

const { t } = useI18n();

// 表格数据
export const columns: BasicColumn[] = [
  {
    title: t('application.record.text.applicationName'),
    dataIndex: 'applicationName',
    width: 120,
  },
  {
    title: t('application.record.text.apiName'),
    dataIndex: 'apiName',
    width: 120,
  },
  {
    title: t('application.record.text.categoryName'),
    dataIndex: 'classify',
    width: 180,
    format(text) {
      return formatClassifyText[text];
    },
  },
  {
    title: t('application.record.text.interfaceResponse'),
    dataIndex: 'message',
    width: 180,
  },
  {
    title: t('application.record.text.callTime'),
    dataIndex: 'requestTime',
    width: 120,
    format(text) {
      return moment(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: t('application.record.text.interfaceStatus'),
    dataIndex: 'state',
    width: 180,
    customRender({ record }: { record: ApplicationRecordItemType }) {
      const flag = record?.state === 1;
      return h(Tag, { color: !flag ? 'red' : 'blue' }, () =>
        flag ? t('common.successText') : t('common.failText')
      );
    },
  },
];

// 分页查询
export const searchFormSchema: FormSchema[] = [
  {
    field: 'applicationName',
    label: t('application.record.text.applicationName'),
    component: 'Input',
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: 'apiName',
    label: t('application.record.text.apiName'),
    component: 'Input',
    componentProps: {
      maxLength: 255,
    },
  },
  {
    field: 'classify',
    label: t('application.api.text.categoryName'),
    component: 'ApiSelect',
    componentProps: {
      api: findDictItemByCode,
      params: {
        dictCode: 'open_api_classify',
      },
      labelField: 'itemText',
      valueField: 'itemValue',
    },
  },
  {
    field: 'state',
    label: t('application.record.text.interfaceStatus'),
    component: 'Select',
    componentProps: {
      options: [
        {
          label: t('common.successText'),
          value: 1,
        },
        {
          label: t('common.failText'),
          value: 0,
        },
      ],
    },
  },
  {
    field: 'callTime',
    label: t('application.record.text.callTime'),
    component: 'RangePicker',
    componentProps: {
      showTime: {
        defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
      },
    },
  },
];