topic.tsx 4.96 KB
import { BasicColumn } from '/@/components/Table/src/types/table';
import { h, unref } from 'vue';
import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard';
import { useMessage } from '/@/hooks/web/useMessage';
const { createMessage } = useMessage();

const handeleCopy = (e) => {
  const { isSuccessRef } = useCopyToClipboard(JSON.parse(JSON.stringify(unref(e), null, 2)));
  unref(isSuccessRef);
  createMessage.success('复制成功!');
};

export const topicTableColumn: BasicColumn[] = [
  {
    title: '设备类型',
    dataIndex: 'deviceType',
    width: 40,
    align: 'left',
    customRender: ({ text, index }: { text: any; index: number }) => {
      const obj: any = {
        children: text,
        attrs: {},
      };
      if (text !== '网关/直连/网关子设备') {
        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: '功能',
    dataIndex: 'function',
    width: 80,
    align: 'left',
    slots: { customRender: 'function' },
  },
  {
    title: '发布主题',
    dataIndex: 'release',
    width: 80,
    align: 'left',
    customRender: ({ text }: { text: any }) => {
      return h(
        'span',
        {
          onClick: () => {
            handeleCopy(text);
          },
        },
        text
      );
    },
  },
  {
    title: '订阅主题',
    dataIndex: 'subscribe',
    width: 80,
    align: 'left',
    customRender: ({ text }: { text: any }) => {
      return h(
        'span',
        {
          onClick: () => {
            handeleCopy(text);
          },
        },
        text
      );
    },
  },
  {
    title: '平台',
    dataIndex: 'platform',
    width: 30,
    slots: { customRender: 'platform' },
  },
  {
    title: '设备',
    dataIndex: 'device',
    width: 30,
    slots: { customRender: 'device' },
  },
];

export const list = [
  {
    deviceType: '网关/直连设备',
    function: '网关/直连设备遥测',
    release: 'v1/devices/me/telemetry',
    subscribe: 'v1/devices/me/telemetry',
    platform: '订阅',
    device: '发布',
  },
  {
    deviceType: '网关/直连设备',
    function: '服务端命令下发到设备端',
    release: 'v1/devices/me/rpc/request/$request_id',
    subscribe: 'v1/devices/me/rpc/request/+',
    platform: '发布',
    device: '订阅',
  },
  {
    deviceType: '网关/直连设备',
    function: '设备端响应命令到服务端',
    release: 'v1/devices/me/rpc/response/$request_id',
    subscribe: 'v1/devices/me/rpc/response/+',
    platform: '订阅',
    device: '发布',
  },
  {
    deviceType: '网关/直连设备',
    function: '直连设备属性上报',
    release: 'v1/devices/me/attributes',
    subscribe: 'v1/devices/me/attributes',
    platform: '订阅',
    device: '发布',
  },

  {
    deviceType: '网关/直连设备',
    function: '设备端请求服务端共享属性及客户端属性',
    release: 'v1/devices/me/attributes/response/$request_id',
    subscribe: 'v1/devices/me/attributes/response/+',
    platform: '订阅',
    device: '发布',
  },
  {
    deviceType: '网关/直连设备',
    function: '服务端响应共享属性集客户端属性给设备端',
    release: 'v1/devices/me/attributes/response/$request_id',
    subscribe: 'v1/devices/me/attributes/response/+',
    platform: '发布',
    device: '订阅',
  },
  {
    deviceType: '网关子设备',
    function: '设备端请求服务端子设备共享属性及客户端属性',
    release: 'v1/gateway/attributes/request',
    subscribe: 'v1/gateway/attributes/request',
    platform: '订阅',
    device: '发布',
  },
  {
    deviceType: '网关子设备',
    function: '服务端响应子设备共享属性及客户端属性给设备端',
    release: 'v1/gateway/attributes/response',
    subscribe: 'v1/gateway/attributes/response',
    platform: '发布',
    device: '订阅',
  },
  {
    deviceType: '网关子设备',
    function: '设备端上报子设备客户端属性',
    release: 'v1/gateway/attributes',
    subscribe: 'v1/gateway/attributes',
    platform: '订阅',
    device: '发布',
  },
  {
    deviceType: '网关子设备',
    function: '网关子设备遥测',
    release: 'v1/gateway/telemetry',
    subscribe: 'v1/gateway/telemetry',
    platform: '订阅',
    device: '发布',
  },
  {
    deviceType: '网关/直连/网关子设备',
    function: '事件上报',
    release: 'v1/devices/event/${deviceId}/${identifier}/{$eventType}',
    subscribe: 'v1/devices/event/${deviceId}/${identifier}/{$eventType}',
    platform: '订阅',
    device: '发布',
  },
];