device.data.ts 2.49 KB
import { formatToDate } from '/@/utils/dateUtil';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { DeviceTypeEnum, DeviceState } from '/@/api/device/model/deviceModel';

// 表格列数据
export const columns: BasicColumn[] = [
  {
    title: '状态',
    dataIndex: 'deviceState',
    width: 80,
    slots: { customRender: 'deviceState' },
  },
  {
    title: '设备图片',
    dataIndex: 'deviceInfo.avatar',
    width: 80,
    slots: { customRender: 'img' },
  },
  {
    dataIndex: 'name',
    title: '设备名称/设备SN',
    width: 200,
    align: 'left',
    slots: { customRender: 'name', title: 'deviceTitle' },
    ellipsis: true,
  },
  {
    title: '设备类型',
    dataIndex: 'deviceType',
    width: 100,
    slots: { customRender: 'deviceType' },
  },
  {
    title: '所属产品',
    dataIndex: 'deviceProfile.name',
    width: 180,
    slots: { customRender: 'deviceProfile' },
    ellipsis: true,
  },
  {
    title: '所属组织',
    dataIndex: 'organizationDTO.name',
    width: 100,
  },
  {
    title: '客户',
    dataIndex: 'customerName',
    width: 100,
  },
  {
    title: '标签',
    dataIndex: 'label',
    width: 100,
  },
  {
    title: '最后连接时间',
    dataIndex: 'lastOnlineTime',
    format: (text) => text && formatToDate(text, 'YYYY-MM-DD HH:mm:ss'),
    width: 160,
  },
  {
    title: '最后断开时间',
    dataIndex: 'lastOfflineTime',
    format: (text) => text && formatToDate(text, 'YYYY-MM-DD HH:mm:ss'),
    width: 160,
  },
];

// 查询字段
export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '设备名称',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 255,
      placeholder: '请输入设备名称',
    },
  },
  {
    field: 'deviceType',
    label: '设备类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '网关设备', value: DeviceTypeEnum.GATEWAY },
        { label: '直连设备', value: DeviceTypeEnum.DIRECT_CONNECTION },
        { label: '网关子设备', value: DeviceTypeEnum.SENSOR },
      ],
    },
    colProps: { span: 6 },
  },
  {
    field: 'deviceState',
    label: '设备状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '待激活', value: DeviceState.INACTIVE },
        { label: '在线', value: DeviceState.ONLINE },
        { label: '离线', value: DeviceState.OFFLINE },
      ],
    },
    colProps: { span: 6 },
  },
];