topic.tsx 7.05 KB
import { BasicColumn } from '/@/components/Table/src/types/table';
import { h, unref } from 'vue';
import { useClipboard } from '@vueuse/core';
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
const { createMessage } = useMessage();
export const handeleCopy = async (e) => {
  const { t } = useI18n();
  const { copied, copy } = useClipboard({ legacy: true });
  await copy(JSON.parse(JSON.stringify(unref(e), null, 2)));
  if (unref(copied)) {
    createMessage.success(t('common.copyOk'));
  }
};

export const getTopicTableColumn = (): BasicColumn[] => {
  const { t } = useI18n();

  return [
    {
      title: t('deviceManagement.product.deviceText'),
      dataIndex: 'deviceType',
      width: 40,
      align: 'left',
      customRender: ({ text, index }: { text: any; index: number }) => {
        const obj: any = {
          children: text,
          attrs: {},
        };
        if (text !== t('deviceManagement.product.gatewayWithDirectWithSensorDeviceText')) {
          if (index === 0) {
            obj.attrs.rowSpan = 6;
          }
          if (index > 0 && index < 6) {
            obj.attrs.rowSpan = 0;
          }
          if (index > 6) {
            obj.attrs.rowSpan = 0;
          }
          if (index === 6) {
            obj.attrs.rowSpan = 4;
          }
          return obj;
        } else {
          return obj;
        }
      },
    },
    {
      title: t('deviceManagement.product.featureText'),
      dataIndex: 'function',
      width: 80,
      align: 'left',
      slots: { customRender: 'function' },
    },
    {
      title: t('deviceManagement.product.releaseTopicText'),
      dataIndex: 'release',
      width: 80,
      align: 'left',
      customRender: ({ text }: { text: any }) => {
        return h(
          'span',

          {
            style: { cursor: 'pointer' },
            onClick: () => {
              handeleCopy(text);
            },
          },
          text
        );
      },
    },
    {
      title: t('deviceManagement.product.subscribeTopicText'),
      dataIndex: 'subscribe',
      width: 80,
      align: 'left',
      customRender: ({ text }: { text: any }) => {
        return h(
          'span',
          {
            style: { cursor: 'pointer' },
            onClick: () => {
              handeleCopy(text);
            },
          },
          text
        );
      },
    },
    {
      title: t('deviceManagement.product.platformText'),
      dataIndex: 'platform',
      width: 30,
      slots: { customRender: 'platform' },
    },
    {
      title: t('deviceManagement.product.deviceText'),
      dataIndex: 'device',
      width: 30,
      slots: { customRender: 'device' },
    },
  ];
};

export const getList = () => {
  const { t } = useI18n();

  return [
    {
      // deviceType: '网关/直连设备',
      deviceType: t('deviceManagement.product.gatewayWithDirectDeviceText'),
      function: t('deviceManagement.product.gatewayWithDirectTelemetryText'),
      release: 'v1/devices/me/telemetry',
      subscribe: 'v1/devices/me/telemetry',
      platform: t('deviceManagement.product.subscribeText'),
      device: t('deviceManagement.product.releaseText'),
    },
    {
      deviceType: t('deviceManagement.product.gatewayWithDirectDeviceText'),
      function: t('deviceManagement.product.serverCommandToDeviceText'),
      release: 'v1/devices/me/rpc/request/$request_id',
      subscribe: 'v1/devices/me/rpc/request/+',
      platform: t('deviceManagement.product.releaseText'),
      device: t('deviceManagement.product.subscribeText'),
    },
    {
      deviceType: t('deviceManagement.product.gatewayWithDirectDeviceText'),
      function: t('deviceManagement.product.deviceResponseCommandToServerText'),
      release: 'v1/devices/me/rpc/response/$request_id',
      subscribe: 'v1/devices/me/rpc/response/+',
      platform: t('deviceManagement.product.subscribeText'),
      device: t('deviceManagement.product.releaseText'),
    },
    {
      deviceType: t('deviceManagement.product.gatewayWithDirectDeviceText'),
      function: t('deviceManagement.product.directAttributeReportText'),
      release: 'v1/devices/me/attributes',
      subscribe: 'v1/devices/me/attributes',
      platform: t('deviceManagement.product.subscribeText'),
      device: t('deviceManagement.product.releaseText'),
    },

    {
      deviceType: t('deviceManagement.product.gatewayWithDirectDeviceText'),
      function: t('deviceManagement.product.deviceRequestServerAttributeText'),
      release: 'v1/devices/me/attributes/request/$request_id',
      subscribe: 'v1/devices/me/attributes/response/+',
      platform: t('deviceManagement.product.subscribeText'),
      device: t('deviceManagement.product.releaseText'),
    },
    {
      deviceType: t('deviceManagement.product.gatewayWithDirectDeviceText'),
      function: t('deviceManagement.product.serverResponseDeviceAttributeText'),
      release: 'v1/devices/me/attributes/response/$request_id',
      subscribe: 'v1/devices/me/attributes/response/+',
      platform: t('deviceManagement.product.releaseText'),
      device: t('deviceManagement.product.subscribeText'),
    },
    {
      deviceType: t('deviceManagement.product.sensorDeviceText'),
      function: t('deviceManagement.product.deviceRequestSensorAttributeText'),
      release: 'v1/gateway/attributes/request',
      subscribe: 'v1/gateway/attributes/request',
      platform: t('deviceManagement.product.subscribeText'),
      device: t('deviceManagement.product.releaseText'),
    },
    {
      deviceType: t('deviceManagement.product.sensorDeviceText'),
      function: t('deviceManagement.product.serverResponseDeviceAttributeText'),
      release: 'v1/gateway/attributes/response',
      subscribe: 'v1/gateway/attributes/response',
      platform: t('deviceManagement.product.releaseText'),
      device: t('deviceManagement.product.subscribeText'),
    },
    {
      deviceType: t('deviceManagement.product.sensorDeviceText'),
      function: t('deviceManagement.product.deviceReportClientAttributeText'),
      release: 'v1/gateway/attributes',
      subscribe: 'v1/gateway/attributes',
      platform: t('deviceManagement.product.subscribeText'),
      device: t('deviceManagement.product.releaseText'),
    },
    {
      deviceType: t('deviceManagement.product.sensorDeviceText'),
      function: t('deviceManagement.product.gatewaySubTelemetryText'),
      release: 'v1/gateway/telemetry',
      subscribe: 'v1/gateway/telemetry',
      platform: t('deviceManagement.product.subscribeText'),
      device: t('deviceManagement.product.releaseText'),
    },
    {
      deviceType: t('deviceManagement.product.gatewayWithDirectWithSensorDeviceText'),
      function: t('deviceManagement.product.eventReportText'),
      release: `v1/devices/event/\${deviceId} ${t(
        'deviceManagement.product.orText'
      )} \${deviceName}/\${identifier}`,
      subscribe: `v1/devices/event/\${deviceId} ${t(
        'deviceManagement.product.orText'
      )} \${deviceName}/\${identifier}`,
      platform: t('deviceManagement.product.subscribeText'),
      device: t('deviceManagement.product.releaseText'),
    },
  ];
};