device.data.ts 6.31 KB
import { formatToDate } from '/@/utils/dateUtil';
import { BasicColumn } from '/@/components/Table';
import { FormSchema } from '/@/components/Table';
import { DeviceTypeEnum, DeviceState, DeviceRecord } from '/@/api/device/model/deviceModel';
import { deviceProfile } from '/@/api/device/deviceManager';
import { h } from 'vue';
import { Tag, Tooltip } from 'ant-design-vue';
import { handeleCopy } from '../../profiles/step/topic';
import edgefornt from '/@/assets/icons/edgefornt.svg';

export enum DeviceListAuthEnum {
  /**
   * @description 新增
   */
  CREATE = 'api:yt:device:post',

  /**
   * @description 删除
   */
  DELETE = 'api:yt:device:delete',

  /**
   * @description 编辑
   */
  UPDATE = 'api:yt:device:update',

  /**
   * @description 详情
   */
  DETAIL = 'api:yt:device:get',

  /**
   * @description 导入
   */
  IMPORT = 'api:yt:device:import',

  /**
   * @description 公开
   */
  PUBLIC = 'api:yt:device:public',

  /**
   * @description 上下线
   */
  ONLINE = 'api:yt:device:online:record',

  /**
   * @description 管理设备凭证
   */
  EQUIPMENT = 'api:yt:device:equipment',

  /**
   * @description 分配客户
   */
  ASSIGN = 'api:yt:device:assign',

  /**
   * @description 命令下发
   */
  RPC = 'api:yt:device:rpc',

  /**
   * @description 更新产品
   */
  UPDATE_PRODUCT = 'api:yt:device:update:product',
}

// 表格列数据
export const columns: BasicColumn[] = [
  {
    title: '状态',
    dataIndex: 'deviceState',
    width: 110,
    className: 'device-status',
    slots: { customRender: 'deviceState' },
  },
  {
    title: '设备图片',
    dataIndex: 'deviceInfo.avatar',
    width: 70,
    slots: { customRender: 'img' },
  },
  {
    dataIndex: 'name',
    title: '别名/设备名称',
    width: 210,
    slots: { customRender: 'name', title: 'deviceTitle' },
    className: 'device-name-edge',
    customRender: ({ record }) => {
      return h('div', { class: 'py-3 px-3.5' }, [
        record.alias &&
          h(
            'div',
            {
              class: 'cursor-pointer truncate',
            },
            h(
              Tooltip,
              {
                placement: 'topLeft',
                title: `${record.alias}`,
              },
              () => `${record.alias}`
            )
          ),
        h(
          'div',
          {
            class: 'cursor-pointer text-blue-500 truncate',
            onClick: () => {
              handeleCopy(`${record.name}`);
            },
          },
          h(
            Tooltip,
            {
              placement: 'topLeft',
              title: `${record.name}`,
            },
            () => `${record.name}`
          )
        ),
        record.isEdge
          ? h('div', { class: 'absolute top-0 left-0', fill: '#1890ff' }, [
              h('img', { src: edgefornt }),
              h(
                'span',
                {
                  class:
                    'absolute top-0.5 left-0.5 text-light-50 transform -rotate-45 translate-y-0',
                },
                '边'
              ),
            ])
          : '',
      ]);
    },
  },
  {
    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: 'public',
    width: 100,
    customRender({ record }: { record: DeviceRecord }) {
      const flag = record?.customerAdditionalInfo?.isPublic;
      return h(Tag, { color: flag ? 'blue' : 'orange' }, () => (flag ? '公开' : '私有'));
    },
  },
  {
    title: '最后连接时间',
    dataIndex: 'lastOnlineTime',
    format: (text) => text && formatToDate(text, 'YYYY-MM-DD HH:mm:ss'),
    width: 160,
  },
  {
    title: '最后断开时间',
    dataIndex: 'lastOfflineTime',
    format: (text) => {
      return 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 },
      ],
      placeholder: '请选择设备类型',
    },
    colProps: { span: 6 },
  },
  {
    field: 'deviceState',
    label: '设备状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '待激活', value: DeviceState.INACTIVE },
        { label: '在线', value: DeviceState.ONLINE },
        { label: '离线', value: DeviceState.OFFLINE },
        { label: '活动', value: DeviceState.ACTIVE },
      ],
      placeholder: '请选择设备状态',
    },
    colProps: { span: 6 },
  },
  {
    field: 'deviceProfileId',
    label: '产品',
    component: 'ApiSelect',
    colProps: { span: 6 },
    componentProps: () => {
      return {
        showSearch: true,
        labelField: 'name',
        valueField: 'tbProfileId',
        resultField: 'data',
        placeholder: '请选择产品',
        api: deviceProfile,
        filterOption: (inputValue: string, option: Record<'label' | 'value', string>) =>
          option.label.includes(inputValue),
      };
    },
  },
  {
    field: 'isCollect',
    label: '是否收藏',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
      placeholder: '请选择',
    },
  },
  {
    field: 'alarmStatus',
    label: '是否告警',
    component: 'Select',
    colProps: { span: 6 },
    componentProps: {
      options: [
        { label: '是', value: 1 },
        { label: '否', value: 0 },
      ],
      placeholder: '请选择设备是否存在告警',
    },
  },
];