detail.config.ts 5.36 KB
import { formatToDateTime } from '/@/utils/dateUtil';
import { FormSchema } from '/@/components/Form';
import { BasicColumn } from '/@/components/Table';
import { DeviceTypeEnum } from '/@/api/device/model/deviceModel';

export const columns: BasicColumn[] = [
  {
    title: '设备名称',
    dataIndex: 'name',
    width: 120,
    key: 'name',
  },
  {
    title: '设备标签',
    dataIndex: 'label',
    width: 100,
    key: 'label',
  },
  {
    title: '设备配置',
    dataIndex: 'deviceProfile.name',
    width: 160,
    key: 'deviceProfile.name',
  },

  {
    title: '设备类型',
    dataIndex: 'deviceType',
    key: 'deviceType',
    customRender({ text }) {
      return text === DeviceTypeEnum.GATEWAY
        ? '网关设备'
        : text == DeviceTypeEnum.DIRECT_CONNECTION
        ? '直连设备'
        : '网关子设备';
    },
  },
  {
    title: '描述',
    dataIndex: 'description',
    width: 180,
    key: 'description',
  },
];
// 实时数据表格
export const realTimeDataColumns: BasicColumn[] = [
  {
    title: '键',
    dataIndex: 'key',
    width: 100,
  },
  {
    title: '值',
    dataIndex: 'value',
    width: 160,
  },
  {
    title: '最后更新时间',
    dataIndex: 'time',
    width: 120,
    format: (text) => formatToDateTime(text, 'YYYY-MM-DD HH:mm:ss'),
  },
];

// 告警
export const alarmSearchSchemas: FormSchema[] = [
  {
    field: 'status',
    label: '告警状态',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        {
          label: '清除未确认',
          value: 'CLEARED_UNACK',
        },
        {
          label: '激活未确认',
          value: 'ACTIVE_UNACK',
        },
        {
          label: '清除已确认',
          value: 'CLEARED_ACK',
        },
        {
          label: '激活已确认',
          value: 'ACTIVE_ACK',
        },
      ],
    },
  },
  {
    field: 'alarmType',
    label: '告警类型',
    component: 'Input',
    colProps: { span: 6 },
  },
  {
    field: 'endTime',
    label: '告警时间范围',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'x',
    },
    colProps: { span: 6 },
  },
];
export const alarmColumns: BasicColumn[] = [
  {
    title: '告警时间',
    dataIndex: 'createdTime',
    width: 120,
  },
  {
    title: '告警设备',
    dataIndex: 'deviceName',
    width: 100,
  },
  {
    title: '类型',
    dataIndex: 'type',
    width: 160,
  },
  {
    title: '告警级别',
    dataIndex: 'severity',
    width: 160,
    format: (text) => alarmLevel(text),
  },
  {
    title: '状态',
    dataIndex: 'status',
    format: (text) => statusType(text),
    width: 160,
  },
];

export const alarmSchemasForm: FormSchema[] = [
  {
    field: 'deviceName',
    label: '告警设备',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },

  {
    field: 'startTs',
    label: '开始时间',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'endTs',
    label: '结束时间',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'ackTs',
    label: '处理时间',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
    ifShow: ({ values }) => values.status === '激活已确认' || values.status === '清除已确认',
  },
  {
    field: 'clearTs',
    label: '清除时间',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
    ifShow: ({ values }) => values.status === '清除已确认' || values.status === '清除未确认',
  },
  {
    field: 'type',
    label: '告警类型',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'severity',
    label: '严重程度',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Input',
    componentProps: {
      disabled: true,
    },
  },
  {
    field: 'details',
    label: '详情',
    component: 'InputTextArea',
  },
];

// 子设备
export const childDeviceSchemas: FormSchema[] = [
  {
    field: 'icon',
    label: '设备配置',
    component: 'Select',
    colProps: { span: 12 },
  },
  {
    field: 'icon',
    label: '设备名称',
    component: 'Input',
    colProps: { span: 12 },
  },
];
export const childDeviceColumns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 120,
  },
  {
    title: '设备配置',
    dataIndex: 'label',
    width: 100,
  },
  {
    title: '标签',
    dataIndex: 'aaa',
    width: 160,
  },
  {
    title: '状态',
    dataIndex: 'bbb',
    width: 160,
  },
  {
    title: '最后连接时间',
    dataIndex: 'ccc',
    width: 160,
  },
  {
    title: '创建时间',
    dataIndex: 'ddd',
    width: 160,
  },
];

export const alarmLevel = (type: string): string => {
  if (type === 'CRITICAL') {
    return '危险';
  } else if (type === 'MAJOR') {
    return '重要';
  } else if (type === 'MINOR') {
    return '次要';
  } else if (type === 'WARNING') {
    return '警告';
  } else {
    return '不确定';
  }
};
export const statusType = (type: string): string => {
  if (type === 'CLEARED_UNACK') {
    return '清除未确认';
  } else if (type === 'CLEARED_ACK') {
    return '清除已确认';
  } else if (type === 'ACTIVE_ACK') {
    return '激活已确认';
  } else {
    return '激活未确认';
  }
};