config.ts 3.31 KB
import { FormSchema } from '/@/components/Table';

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

export enum TriggerEnum {
  IS_DEVICE_ACT = 'DEVICE_ACT',
  IS_TIME_ACT = 'TIME_ACT',
  IS_SCENE_ACT = 'SCENE_ACT',
}

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 formSchema: FormSchema[] = [
  {
    field: 'detail',
    label: '条件类型',
    colProps: { span: 24 },
    component: 'Select',
    componentProps: {
      placeholder: '请选择报警日程表',
      options: [
        { label: '简单', value: 'DEVICE_ACT' },
        { label: '持续时间', value: 'TIME_ACT' },
        { label: '重复', value: 'SCENE_ACT' },
      ],
    },
  },
  {
    field: 'type1',
    label: '动态源类型',
    colProps: { span: 24 },
    component: 'Select',
    componentProps: {
      placeholder: '请选择动态源类型',
      options: [
        { label: '无动态值', value: 'second' },
        { label: '当前租户', value: 'minute' },
        { label: '当前客户', value: 'hour' },
        { label: '当前设备', value: 'day' },
      ],
    },
    ifShow: ({ values }) => isWenDu(Reflect.get(values, 'detail')),
  },
  {
    field: 'time1',
    label: '源属性',
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '源属性',
    },
    ifShow: ({ values }) => isWenDu(Reflect.get(values, 'detail')),
  },
  {
    field: 'type1',
    label: '动态源类型',
    colProps: { span: 24 },
    component: 'Select',
    componentProps: {
      placeholder: '请选择动态源类型',
      options: [
        { label: '无动态值', value: 'second' },
        { label: '当前租户', value: 'minute' },
        { label: '当前客户', value: 'hour' },
        { label: '当前设备', value: 'day' },
      ],
    },
    ifShow: ({ values }) => isTimeAll(Reflect.get(values, 'detail')),
  },
  {
    field: 'time1',
    label: '源属性',
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '源属性',
    },
    ifShow: ({ values }) => isTimeAll(Reflect.get(values, 'detail')),
  },
  {
    field: 'time',
    label: '持续时间值',
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '请输入持续时间值',
    },
    ifShow: ({ values }) => isWenDu(Reflect.get(values, 'detail')),
  },
  {
    field: 'r',
    label: '时间单位',
    colProps: { span: 24 },
    component: 'Select',
    componentProps: {
      placeholder: '请选择报警日程表',
      options: [
        { label: '秒', value: 'second' },
        { label: '分钟', value: 'minute' },
        { label: '小时', value: 'hour' },
        { label: '天', value: 'day' },
      ],
    },
    ifShow: ({ values }) => isWenDu(Reflect.get(values, 'detail')),
  },
  {
    field: 'time',
    label: '事件计数值必填',
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '请输入事件计数值必填',
    },
    rules: [{ message: '事件计数应在1到2147483637之间', trigger: 'blur' }],
    ifShow: ({ values }) => isTimeAll(Reflect.get(values, 'detail')),
  },
];