config.data.ts 8.7 KB
import { ref } from 'vue';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { screenLinkOrganizationGetApi } from '/@/api/ruleengine/ruleengineApi';

import { copyTransFun } from '/@/utils/fnUtils';

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

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: 'ApiTreeSelect',
    componentProps: {
      api: async () => {
        const data = await screenLinkOrganizationGetApi();
        copyTransFun(data as any as any[]);
        return data;
      },
      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 },
  },
];
// 持续时间
const isTimeDuration = (type) => {
  return type === 'DURATION';
};
const isReplace = (type) => {
  return type === 'REPEATING';
};
// 部分
const isPart = (type: string) => {
  return type === 'PART';
};

export const trigger_condition_schema: FormSchema[] = [
  {
    field: 'triggered',
    label: '',
    component: 'Select',
    componentProps: {
      placeholder: '请选择触发类型',
      options: [
        { label: '简单', value: 'SIMPLE' },
        { label: '持续时长', value: 'DURATION' },
        { label: '重复次数', value: 'REPEATING' },
      ],
    },
    colProps: { span: 6 },
  },
  {
    field: 'device',
    label: '',
    component: 'Select',
    componentProps: {
      placeholder: '请选择设备',
      options: [
        { label: '全部', value: 'ALL' },
        { label: '部分', value: 'PART' },
      ],
    },
    colProps: { span: 6 },
  },
  {
    field: 'entityId',
    label: '',
    component: 'Select',
    componentProps: {
      placeholder: '请选择设备',
      mode: 'multiple',
    },
    ifShow: ({ values }) => isPart(values.device),
    colProps: { span: 6 },
  },
  {
    field: 'time',
    label: '',
    component: 'Input',
    ifShow: ({ values }) => isTimeDuration(values.triggered),
    colProps: { span: 6 },
    slot: 'time',
  },
  {
    field: 'timeUnit',
    label: '',
    component: 'Select',
    defaultValue: 'SECONDS',
    ifShow: ({ values }) => isTimeDuration(values.triggered),
    show: false,
  },
  {
    field: 'replaceValue',
    label: '',
    component: 'Input',
    componentProps: {
      placeholder: '事件计数值',
    },
    ifShow: ({ values }) => isReplace(values.triggered),
    colProps: { span: 6 },
  },
  {
    field: 'triggerType',
    label: '',
    component: 'Select',
    componentProps: {
      placeholder: '设备触发',
      options: [
        { label: '设备触发', value: 'DEVICE_TRIGGER' },
        // { label: '定时触发', value: 'SCHEDULE_TRIGGER' },
        // { label: '场景触发', value: 'SCENE_TRIGGER' },
        // { label: '手动触发', value: 'HAND_ACT' },
      ],
    },
    colProps: { span: 6 },
  },

  {
    field: 'type1',
    label: '',
    component: 'Select',
    componentProps: {
      placeholder: '属性触发方式',
      options: [{ label: '属性触发', value: 'TIME_SERIES' }],
    },
    ifShow: ({ values }) => isDevice(values.triggerType),
    colProps: { span: 6 },
  },
  {
    field: 'type2',
    label: '',
    component: 'AutoComplete',
    componentProps: {
      placeholder: '请选择属性',
    },
    ifShow: ({ values }) => isDevice(values.triggerType),
    colProps: { span: 6 },
  },
  {
    field: 'operationType',
    label: '',
    component: 'Select',
    slot: 'operationType',
    colProps: { span: 6 },
  },
  {
    field: 'detail',
    label: '',
    component: 'InputTextArea',
    componentProps: {
      placeholder: '请输入详情',
    },
    colProps: {
      span: 13,
    },
  },
];
// !!!----------------------------------------------------^_^------------------------------------------------------------!!!
enum ActionEnum {
  DEVICE_OUT = 'DEVICE_OUT',
  ALARM_OUT = 'MSG_NOTIFY',
}
const isDeviceOut = (type: string) => type === ActionEnum.DEVICE_OUT;
const isAlarmOut = (type: string) => type === ActionEnum.ALARM_OUT;

export const actionSchema: FormSchema[] = [
  {
    field: 'outTarget',
    label: '',
    component: 'Select',
    required: true,
    componentProps: {
      placeholder: '请选择执行动作',
    },
    slot: 'outTarget',
    colProps: { span: 6 },
  },
  {
    field: 'device',
    label: '',
    component: 'Select',
    componentProps: {
      placeholder: '请选择设备',
      options: [
        { label: '全部', value: 'ALL' },
        { label: '部分', value: 'PART' },
      ],
    },
    ifShow: ({ values }) => isDeviceOut(values.outTarget),
    colProps: { span: 6 },
  },
  {
    field: 'deviceId',
    label: '',
    component: 'Select',
    componentProps: {
      placeholder: '请选择设备',
      mode: 'multiple',
    },
    ifShow: ({ values }) => isPart(values.device) && isDeviceOut(values.outTarget),
    colProps: { span: 6 },
  },
  {
    field: 'alarm_config',
    label: '',
    component: 'Select',
    componentProps: {
      placeholder: '请选择告警配置',
    },
    ifShow: ({ values }) => values.outTarget === 'MSG_NOTIFY',
    colProps: { span: 6 },
  },
  {
    field: 'doContext',
    component: 'Input',
    label: '',
    slot: 'doContext',
    show: ({ values }) => isDeviceOut(values.outTarget),
    colProps: {
      span: 24,
    },
  },
  {
    field: 'alarm_level',
    component: 'Select',
    label: '',
    show: ({ values }) => isAlarmOut(values.outTarget),
    componentProps: {
      placeholder: '请选择告警等级',
      options: [
        {
          label: '紧急',
          value: 'CRITICAL',
        },
        {
          label: '重要',
          value: 'MAJOR',
        },
        {
          label: '次要',
          value: 'MINOR',
        },
        {
          label: '警告',
          value: 'WARNING',
        },
        {
          label: '不确定',
          value: 'INDETERMINATE',
        },
      ],
    },
    colProps: {
      span: 6,
    },
  },
  {
    field: 'clear_alarm',
    component: 'Checkbox',
    label: '',
    show: ({ values }) => isAlarmOut(values.outTarget),
    colProps: {
      span: 8,
    },
    slot: 'clearAlarm',
  },
];