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

// 表格配置
export const columns: BasicColumn[] = [
  {
    title: '命令下发时间',
    dataIndex: 'createTime',
    format: (text) => {
      return moment(text).format('YYYY-MM-DD HH:mm:ss');
    },
  },
  {
    title: '命令类型',
    dataIndex: 'additionalInfo.cmdType',
    format: (text) => {
      return h(
        Tag,
        {
          color: Number(text) === 1 ? 'green' : 'blue',
        },
        () => (Number(text) === 1 ? '服务' : '自定义')
      ) as unknown as any;
    },
  },
  {
    title: '响应类型',
    dataIndex: 'request.oneway',
    format: (text) => {
      return !text ? '双向' : '单向';
    },
  },
  {
    title: '命令状态',
    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',
        },
        () => record?.statusName
      );
    },
  },
  {
    title: '响应内容',
    dataIndex: 'response111',
    slots: { customRender: 'responseContent' },
  },
  {
    title: '命令内容',
    dataIndex: 'request.body',
    slots: { customRender: 'recordContent' },
  },
];

// 表格查询表单
export const searchFormSchema: FormSchema[] = [
  {
    field: 'status',
    label: '命令状态',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          label: '队列中',
          value: 'QUEUED',
        },
        {
          label: '已发送',
          value: 'SENT',
        },
        {
          label: '发送成功',
          value: 'DELIVERED',
        },

        {
          label: '响应成功',
          value: 'SUCCESSFUL',
        },
        {
          label: '超时',
          value: 'TIMEOUT',
        },
        {
          label: '已过期',
          value: 'EXPIRED',
        },
        {
          label: '响应失败',
          value: 'FAILED',
        },
        {
          label: '已删除',
          value: 'DELETED',
        },
      ],
      placeholder: '请选择命令状态',
    },
  },
  {
    field: 'sendTime',
    label: '命令下发时间',
    component: 'RangePicker',
    componentProps: {
      showTime: {
        defaultValue: [moment('00:00:00', 'HH:mm:ss'), moment('23:59:59', 'HH:mm:ss')],
      },
    },
    colProps: { span: 10 },
  },
];