config.ts 3.03 KB
import { BasicColumn, FormSchema } from '/@/components/Table';
import { findDictItemByCode } from '/@/api/system/dict';
import { h, unref } from 'vue';
import { Tooltip } from 'ant-design-vue';
import { FunctionTypeEnum } from '/@/enums/objectModelEnum';
import { useMessage } from '/@/hooks/web/useMessage';
import { useClipboard } from '@vueuse/core';
import { DictEnum } from '/@/enums/dictEnum';
import { useI18n } from '/@/hooks/web/useI18n';

// import {
//   EventType,
//   EventTypeColor,
//   EventTypeName,
// } from '/@/views/device/list/cpns/tabs/EventManage/config';

const { t } = useI18n();

export const columns: BasicColumn[] = [
  {
    title: t('deviceManagement.product.categoryName'),
    dataIndex: 'name',
    slots: { customRender: 'name' },
  },
  {
    title: t('deviceManagement.product.area'),
    dataIndex: 'dictItemName',
    format: (text: string) => {
      return t(text);
    },
  },
];

export const formatFunctionType: Record<FunctionTypeEnum, string> = {
  [FunctionTypeEnum.PROPERTIES]: t('deviceManagement.product.properties'),
  [FunctionTypeEnum.EVENTS]: t('deviceManagement.product.events'),
  [FunctionTypeEnum.SERVICE]: t('deviceManagement.product.services'),
};

const handleCopy = async (value: string) => {
  const { createMessage } = useMessage();
  const { copied, copy } = useClipboard({ legacy: true });
  const { t } = useI18n();
  await copy(value);
  if (unref(copied)) createMessage.success(t('common.copyOk'));
  else createMessage.success(t('common.copyFail'));
};

export const columnsDrawer: BasicColumn[] = [
  {
    title: t('deviceManagement.product.featureTypeText'),
    dataIndex: 'functionType',
    width: 90,
    format: (text: FunctionTypeEnum) => {
      return formatFunctionType[text];
    },
  },
  {
    title: t('deviceManagement.product.featureNameText'),
    dataIndex: 'functionName',
    width: 90,
    ellipsis: true,
  },
  {
    title: t('deviceManagement.product.identifierText'),
    dataIndex: 'identifier',
    width: 90,
    ellipsis: true,
    customRender: ({ text }: Record<'text', string>) => {
      return h(Tooltip, { title: text }, () =>
        h('span', { class: 'cursor-pointer', onClick: () => handleCopy(text) }, text)
      );
    },
  },
  {
    title: t('deviceManagement.product.dataTypeText'),
    dataIndex: 'functionJson.dataType.type',
    width: 100,
    format: (text: string) => {
      return text || '--';
    },
    ellipsis: true,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'dictItemId',
    label: '',
    component: 'ApiSelect',
    colProps: { span: 7 },
    componentProps() {
      return {
        api: findDictItemByCode,
        params: {
          dictCode: DictEnum.CATEGORY_FIELD,
        },
        labelField: 'itemText',
        valueField: 'itemValue',
        placeholder: t('deviceManagement.product.pleaseSelectArea'),
      };
    },
  },
  {
    field: 'name',
    label: '',
    component: 'Input',
    colProps: { span: 9 },
    componentProps: {
      placeholder: t('deviceManagement.product.pleaseEnterCategoryName'),
    },
  },
];