config.data.ts 4.79 KB
import { h, ref } from 'vue';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { screenLinkOrganizationGetApi } from '/@/api/ruleengine/ruleengineApi';
import { copyTransFun } from '/@/utils/fnUtils';
import { useComponentRegister } from '/@/components/Form';
import { OrgTreeSelect } from '/@/views/common/OrgTreeSelect';
import { useGo } from '/@/hooks/web/usePage';
import { Button } from 'ant-design-vue';
import { doQueryRuleChainList } from '/@/api/device/deviceConfigApi';
import { useI18n } from '/@/hooks/web/useI18n';

const { t } = useI18n(); // 加载国际化

useComponentRegister('OrgTreeSelect', OrgTreeSelect);

export type TOption = {
  label: string;
  value: string;
};

/**
 * 所使用的枚举值
 */

export enum TriggerEnum {
  IS_DEVICE_ACT = 'DEVICE_TRIGGER',
  IS_TIME_ACT = 'SCHEDULE_TRIGGER',
  IS_SCENE_ACT = 'SCENE_TRIGGER',
  IS_HAND_ACT = 'HAND_ACT',
  IS_MSG_NOTIFY = 'MSG_NOTIFY',
  IS_DEVICE_STATUS = 'DEVICE_STATUS',
  IS_TIME_ALL = 'SCHEDULE_TRIGGER',
}
export const isDevice = (type: string) => {
  return type === TriggerEnum.IS_DEVICE_ACT;
};

export const isTime = (type: string) => {
  return type === TriggerEnum.IS_TIME_ACT;
};

export const columns: BasicColumn[] = [
  {
    title: t('rule.linkedge.index.name'),
    dataIndex: 'name',
    width: 200,
  },
  {
    title: t('rule.linkedge.index.triggerType'),
    dataIndex: 'triggerType',
    format: (_: string, record: Recordable) => {
      return record.triggers[0]?.triggerType == 'DEVICE_TRIGGER'
        ? t('rule.linkedge.index.deviceTrigger')
        : record.triggers[0]?.triggerType == 'SCHEDULE_TRIGGER'
        ? t('rule.linkedge.index.scheduleTrigger')
        : record.triggers[0]?.triggerType == 'SCENE_TRIGGER'
        ? t('rule.linkedge.index.sceneTrigger')
        : t('rule.linkedge.index.handTrigger');
    },
    width: 200,
  },
  {
    title: t('rule.linkedge.index.status'),
    dataIndex: 'status',
    width: 120,
    slots: { customRender: 'status' },
  },
  {
    title: t('deviceManagement.product.ruleChainText'),
    dataIndex: 'ruleChainId',
    width: 200,
    customRender: ({ record }) => {
      const go = useGo();
      return h(
        Button,
        {
          type: 'link',
          onClick: () => {
            go(`/rule/chain/${record?.ruleChainId}`);
          },
        },
        () => record?.ruleChainName
      );
    },
  },
  {
    title: t('rule.linkedge.index.description'),
    dataIndex: 'description',
    width: 200,
  },
  {
    title: t('rule.linkedge.index.creatorName'),
    dataIndex: 'creatorName',
    width: 200,
  },
  {
    title: t('rule.linkedge.index.createTime'),
    dataIndex: 'createTime',
    width: 180,
  },
];
export const organizationId = ref('');
export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '场景联动名称',
    colProps: { span: 24 },
    required: true,
    component: 'Input',

    componentProps: {
      maxLength: 36,
      placeholder: '请输入场景联动名称',
    },
  },
  {
    required: true,
    field: 'organizationId',
    label: '所属组织',
    colProps: { span: 24 },
    component: 'OrgTreeSelect',
    componentProps: {
      onChange(value) {
        organizationId.value = value;
      },
    },
  },
  {
    field: 'description',
    label: '描述',
    colProps: { span: 24 },
    component: 'InputTextArea',
    componentProps: {
      maxLength: 255,
      placeholder: '请输入描述',
    },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'organizationId',
    label: t('rule.linkedge.index.affiliatedOrganization'),
    colProps: { span: 6 },
    component: 'ApiTreeSelect',
    componentProps: {
      placeholder: t('rule.linkedge.index.pleaseSelectOrganization'),
      api: async () => {
        const data = await screenLinkOrganizationGetApi();
        copyTransFun(data as any as any[]);
        return data;
      },
    },
  },
  {
    field: 'name',
    label: t('rule.linkedge.index.linkedgeName'),
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 36,
      placeholder: t('rule.linkedge.index.pleaseEnterSceneLinkageName'),
    },
  },
  {
    field: 'status',
    label: t('rule.linkedge.index.status'),
    component: 'Select',
    componentProps: {
      placeholder: t('rule.linkedge.index.pleaseSelectStatus'),
      options: [
        { label: t('common.enableText'), value: '1' },
        { label: t('common.disableText'), value: '0' },
      ],
    },
    colProps: { span: 6 },
  },
  {
    field: 'ruleChainId',
    label: t('deviceManagement.product.ruleChainText'),
    component: 'ApiSelect',
    colProps: { span: 6 },
    componentProps: {
      api: async () => {
        const result = await doQueryRuleChainList();
        return result.map((item) => ({ ...item, label: item.name, value: item.id.id }));
      },
    },
  },
];