config.data.ts 3.41 KB
import { 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';

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: '场景联动名称',
    dataIndex: 'name',
    width: 200,
  },
  {
    title: '触发方式',
    dataIndex: 'triggerType',
    format: (_: string, record: Recordable) => {
      return record.triggers[0]?.triggerType == 'DEVICE_TRIGGER'
        ? '设备触发'
        : record.triggers[0]?.triggerType == 'SCHEDULE_TRIGGER'
        ? '定时触发'
        : record.triggers[0]?.triggerType == 'SCENE_TRIGGER'
        ? '场景触发'
        : '手动触发';
    },
    width: 200,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 120,
    slots: { customRender: 'status' },
  },
  {
    title: '描述',
    dataIndex: 'description',
    width: 200,
  },
  {
    title: '创建者',
    dataIndex: 'creatorName',
    width: 200,
  },
  {
    title: '创建时间',
    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: '所属组织',
    colProps: { span: 6 },
    component: 'ApiTreeSelect',
    componentProps: {
      placeholder: '请选择组织',
      api: async () => {
        const data = await screenLinkOrganizationGetApi();
        copyTransFun(data as any as any[]);
        return data;
      },
    },
  },
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    colProps: { span: 6 },
    componentProps: {
      maxLength: 36,
      placeholder: '请输入场景联动名称',
    },
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    componentProps: {
      placeholder: '请选择状态',
      options: [
        { label: '启用', value: '1' },
        { label: '禁用', value: '0' },
      ],
    },
    colProps: { span: 6 },
  },
];