config.ts 3.43 KB
import { BasicColumn, FormSchema } from '/@/components/Table';
import moment from 'moment';
import { Tag } from 'ant-design-vue';
import { h } from 'vue';
import { useI18n } from '/@/hooks/web/useI18n';

const { t } = useI18n();
// 表格配置
export const columns: BasicColumn[] = [
  {
    title: t('deviceManagement.device.commandDeliveryTimeText'),
    dataIndex: 'createTime',
    format: (text) => {
      return moment(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: t('deviceManagement.device.commandDeliveryTypeText'),
    dataIndex: 'additionalInfo.cmdType',
    format: (text) => {
      return h(
        Tag,
        {
          color: Number(text) === 1 ? 'green' : 'blue',
        },
        () => (Number(text) === 1 ? t('enum.commandType.service') : t('enum.commandType.custom'))
      ) as unknown as any;
    },
  },
  {
    title: t('deviceManagement.device.responseTypeText'),
    dataIndex: 'request.oneway',
    format: (text) => {
      return !text ? t('enum.commandWay.twoway') : t('enum.commandWay.oneway');
    },
  },
  {
    title: t('deviceManagement.device.commandStatusText'),
    dataIndex: 'status',
    customRender: ({ text, record }) => {
      return h(
        Tag,
        {
          color:
            text == 'EXPIRED'
              ? 'red'
              : text == 'DELIVERED'
              ? 'blue'
              : text == 'QUEUED'
              ? '#00C9A7'
              : text == 'TIMEOUT'
              ? 'red'
              : text == 'SENT'
              ? '#00C9A7'
              : text == 'FAILED'
              ? 'red'
              : text == 'SUCCESSFUL'
              ? 'green'
              : 'red',
        },
        () => t(`enum.commandStatus.${record?.status}`)
      );
    },
  },
  {
    title: t('deviceManagement.device.responseContentText'),
    dataIndex: 'response111',
    slots: { customRender: 'responseContent' },
  },
  {
    title: t('deviceManagement.device.commandContentText'),
    dataIndex: 'request.body',
    slots: { customRender: 'recordContent' },
  },
];

// 表格查询表单
export const searchFormSchema: FormSchema[] = [
  {
    field: 'status',
    label: t('deviceManagement.device.commandStatusText'),
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          label: t('enum.commandStatus.QUEUED'),
          value: 'QUEUED',
        },
        {
          label: t('enum.commandStatus.SENT'),
          value: 'SENT',
        },
        {
          label: t('enum.commandStatus.DELIVERED'),
          value: 'DELIVERED',
        },

        {
          label: t('enum.commandStatus.SUCCESSFUL'),
          value: 'SUCCESSFUL',
        },
        {
          label: t('enum.commandStatus.TIMEOUT'),
          value: 'TIMEOUT',
        },
        {
          label: t('enum.commandStatus.EXPIRED'),
          value: 'EXPIRED',
        },
        {
          label: t('enum.commandStatus.FAILED'),
          value: 'FAILED',
        },
        {
          label: t('enum.commandStatus.DELETED'),
          value: 'DELETED',
        },
      ],
      placeholder: t('common.chooseText') + t('deviceManagement.device.commandStatusText'),
    },
  },
  {
    field: 'sendTime',
    label: t('deviceManagement.device.commandDeliveryTimeText'),
    component: 'RangePicker',
    componentProps: {
      showTime: {
        defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
      },
    },
    colProps: { span: 10 },
  },
];