config.ts 6.65 KB
import { FormSchema, BasicColumn } from '/@/components/Table';
import { DescItem } from '/@/components/Description/index';

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

export enum TriggerEnum {
  IS_DEVICE_ACT = 'SIMPLE',
  IS_TIME_ACT = 'DURATION',
  IS_SCENE_ACT = 'REPEATING',
  IS_CURRENT_CUSTOMER = 'CURRENT_CUSTOMER',
  IS_CURRENT_DEVICE = 'CURRENT_DEVICE',
}
export const isCurrentCus = (type: string) => {
  return type === TriggerEnum.IS_CURRENT_CUSTOMER;
};
export const isCurrentDev = (type: string) => {
  return type === TriggerEnum.IS_CURRENT_DEVICE;
};

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

export const isTimeAll = (type: string) => {
  return type === TriggerEnum.IS_SCENE_ACT;
};

export const keyColumns: BasicColumn[] = [
  {
    title: '键名',
    dataIndex: 'key1',
    width: 200,
  },
  {
    title: '键类型',
    dataIndex: 'type',
    width: 200,
  },
];
export const columnsView: BasicColumn[] = [
  {
    title: '键名',
    dataIndex: 'key1',
    width: 200,
  },
  {
    title: '操作',
    dataIndex: 'operation',
    width: 200,
    format: (text: string, record: Recordable) => {
      const findDay = [
        { label: '等于', value: 'EQUAL' },
        { label: '不等于', value: 'NOT_EQUAL' },
        { label: '开始于', value: 'STARTS_WITH' },
        { label: '结束于', value: 'ENDS_WITH' },
        { label: '包含', value: 'CONTAINS' },
        { label: '不包含', value: 'NOT_CONTAINS' },
        { label: '等于', value: 'EQUAL' },
        { label: '不等于', value: 'NOT_EQUAL' },
        { label: '大于', value: 'GREATER' },
        { label: '小于', value: 'LESS' },
        { label: '大于或等于', value: 'GREATER_OR_EQUAL' },
        { label: '小于或等于', value: 'LESS_OR_EQUAL' },
      ];
      const findRuleByValue = findDay.find((f) => {
        if (f.value == record.operation) {
          return f.label;
        }
      });
      if (findRuleByValue) {
        return findRuleByValue.label;
      }
    },
  },
  {
    title: '值',
    dataIndex: 'value1',
    width: 200,
  },
];

export const DescDetailSchema: DescItem[] = [
  {
    field: 'key1',
    label: '键名',
  },
  {
    field: 'type',
    label: '键类型',
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'conditionType',
    label: '条件类型',
    colProps: { span: 24 },
    component: 'Select',
    componentProps: {
      placeholder: '请选择报警日程表',
      options: [
        { label: '简单', value: 'SIMPLE' },
        { label: '持续时间', value: 'DURATION' },
        { label: '重复', value: 'REPEATING' },
      ],
    },
  },
  // {
  //   field: 'sourceType',
  //   label: '动态源类型',
  //   colProps: { span: 24 },
  //   component: 'Select',
  //   componentProps: {
  //     placeholder: '请选择动态源类型',
  //     options: [
  //       { label: '无动态值', value: '' },
  //       { label: '当前租户', value: 'CURRENT_TENANT' },
  //       { label: '当前客户', value: 'CURRENT_CUSTOMER' },
  //       { label: '当前设备', value: 'CURRENT_DEVICE' },
  //     ],
  //   },
  //   ifShow: ({ values }) => isWenDu(Reflect.get(values, 'conditionType')),
  //   show: ({ values }) => {
  //     return !!values.field5;
  //   },
  // },
  // {
  //   field: 'sourceAttribute',
  //   label: '源属性',
  //   colProps: { span: 24 },
  //   component: 'Input',
  //   componentProps: {
  //     placeholder: '源属性',
  //   },
  //   ifShow: ({ values }) => isWenDu(Reflect.get(values, 'conditionType')),
  //   show: ({ values }) => {
  //     return !!values.field5;
  //   },
  // },
  // {
  //   field: 'sourceType',
  //   label: '动态源类型',
  //   colProps: { span: 24 },
  //   component: 'Select',
  //   componentProps: {
  //     placeholder: '请选择动态源类型',
  //     options: [
  //       { label: '无动态值', value: '' },
  //       { label: '当前租户', value: 'CURRENT_TENANT' },
  //       { label: '当前客户', value: 'CURRENT_CUSTOMER' },
  //       { label: '当前设备', value: 'CURRENT_DEVICE' },
  //     ],
  //   },
  //   ifShow: ({ values }) => isTimeAll(Reflect.get(values, 'conditionType')),
  //   show: ({ values }) => {
  //     return !!values.field6;
  //   },
  // },
  // {
  //   field: 'sourceAttribute',
  //   label: '源属性',
  //   colProps: { span: 24 },
  //   component: 'Input',
  //   componentProps: {
  //     placeholder: '源属性',
  //   },
  //   ifShow: ({ values }) => isTimeAll(Reflect.get(values, 'conditionType')),
  //   show: ({ values }) => {
  //     return !!values.field6;
  //   },
  // },
  {
    field: 'defaultValue',
    label: '持续时间值',
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '请输入持续时间值(请输入数字)',
    },
    ifShow: ({ values }) => isWenDu(Reflect.get(values, 'conditionType')),
    show: ({ values }) => {
      return !values.field5;
    },
  },
  // {
  //   field: 'field5',
  //   component: 'Switch',
  //   label: '切换到动态值',
  //   colProps: {
  //     span: 8,
  //   },
  //   labelWidth: 200,
  //   ifShow: ({ values }) => isWenDu(Reflect.get(values, 'conditionType')),
  // },
  // {
  //   field: 'field6',
  //   component: 'Switch',
  //   label: '切换到动态值',
  //   colProps: {
  //     span: 8,
  //   },
  //   labelWidth: 200,
  //   ifShow: ({ values }) => isTimeAll(Reflect.get(values, 'conditionType')),
  // },
  {
    field: 'unit',
    label: '时间单位',
    colProps: { span: 24 },
    component: 'Select',
    componentProps: {
      placeholder: '请选择时间单位',
      options: [
        { label: '秒', value: 'SECONDS' },
        { label: '分钟', value: 'MINUTES' },
        { label: '小时', value: 'HOURS' },
        { label: '天', value: 'DAYS' },
      ],
    },
    ifShow: ({ values }) => isWenDu(Reflect.get(values, 'conditionType')),
  },
  {
    field: 'defaultValue',
    label: '事件计数值必填',
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '请输入事件计数值(应在1到2147483637之间)',
    },
    rules: [{ message: '事件计数应在1到2147483637之间', trigger: 'blur' }],
    ifShow: ({ values }) => isTimeAll(Reflect.get(values, 'conditionType')),
    show: ({ values }) => {
      return !values.field6;
    },
  },
  {
    field: 'inherit',
    label: '',
    component: 'Checkbox',
    renderComponentContent: 'Inherit from owner',
    ifShow: ({ values }) =>
      isCurrentCus(Reflect.get(values, 'sourceType')) ||
      isCurrentDev(Reflect.get(values, 'sourceType')),
  },
];