detail.config.ts 6.44 KB
import { formatToDateTime } from '/@/utils/dateUtil';
import { FormSchema } from '/@/components/Form';
import { BasicColumn } from '/@/components/Table';
import { DeviceTypeEnum } from '/@/api/device/model/deviceModel';
import { getCustomerList } from '/@/api/device/deviceManager';
import { DescItem } from '/@/components/Description/index';
import moment from 'moment';
// 设备详情的描述
export const descSchema: DescItem[] = [
  {
    field: 'createTime',
    label: '创建时间',
  },
  {
    field: 'name',
    label: '设备名称',
  },
  {
    field: 'label',
    label: '设备标签',
  },
  {
    field: 'deviceProfile.name',
    label: '设备配置',
  },
  {
    field: 'gatewayName',
    label: '所属网关',
    show: (data) => !!data.gatewayName,
  },
  {
    field: 'deviceType',
    label: '设备类型',
    render: (text) => {
      return text === DeviceTypeEnum.GATEWAY
        ? '网关设备'
        : text == DeviceTypeEnum.DIRECT_CONNECTION
        ? '直连设备'
        : '网关子设备';
    },
  },
  {
    field: 'description',
    label: '描述',
    span: 2,
  },
];

// 实时数据表格
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 },
    componentProps: {
      maxLength: 36,
    },
  },
  {
    field: 'endTime',
    label: '告警时间',
    component: 'DatePicker',
    componentProps: {
      valueFormat: 'x',
      showTime: { defaultValue: moment('23:59:59', 'HH:mm:ss') },
    },
    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',
    componentProps: {
      maxLength: 255,
    },
  },
];
// 子设备
export const childDeviceSchemas: FormSchema[] = [
  {
    field: 'deviceState',
    label: '设备状态',
    colProps: { span: 6 },
    component: 'Select',
    componentProps: {
      maxLength: 255,
      options: [
        { label: '待激活', value: 'INACTIVE' },
        { label: '在线', value: 'ONLINE' },
        { label: '离线', value: 'OFFLINE' },
      ],
    },
  },
  {
    field: 'name',
    label: '设备名称',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 255,
      placeholder: '请输入设备名称',
    },
  },
];
export const childDeviceColumns: BasicColumn[] = [
  {
    title: '名称',
    dataIndex: 'tbDeviceName',
    width: 120,
  },
  {
    title: '标签',
    dataIndex: 'label',
    width: 160,
  },
  {
    title: '状态',
    dataIndex: 'deviceState',
    slots: { customRender: 'deviceState' },
    width: 160,
  },
  {
    title: '最后连接时间',
    dataIndex: 'lastOnlineTime',
    format: (text) => formatToDateTime(text, 'YYYY-MM-DD HH:mm:ss'),
    width: 160,
  },
  {
    title: '更新时间',
    dataIndex: 'createdTime',
    format: (text) => formatToDateTime(text, 'YYYY-MM-DD HH:mm:ss'),
    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 '激活未确认';
  }
};

export const customerForm: FormSchema[] = [
  {
    field: 'customerId',
    label: '分配客户',
    component: 'ApiSelect',
    componentProps: {
      api: getCustomerList,
      immediate: false,
      labelField: 'realName',
      valueField: 'customerId',
    },
    required: true,
    colProps: { span: 12 },
  },
];