config.ts 4.61 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 columns: BasicColumn[] = [
  {
    title: '键名',
    dataIndex: 'key',
    width: 200,
  },
  {
    title: '键类型',
    dataIndex: 'type',
    width: 200,
  },
];
export const columnsView: BasicColumn[] = [
  {
    title: '键名',
    dataIndex: 'key',
    width: 200,
  },
  {
    title: '键类型',
    dataIndex: 'type',
    width: 200,
  },
];

export const DescDetailSchema: DescItem[] = [
  {
    field: 'key',
    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')),
  },
  {
    field: 'sourceAttribute',
    label: '源属性',
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '源属性',
    },
    ifShow: ({ values }) => isWenDu(Reflect.get(values, 'conditionType')),
  },
  {
    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')),
  },
  {
    field: 'sourceAttribute',
    label: '源属性',
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '源属性',
    },
    ifShow: ({ values }) => isTimeAll(Reflect.get(values, 'conditionType')),
  },
  {
    field: 'defaultValue',
    label: '持续时间值',
    colProps: { span: 24 },
    component: 'Input',
    componentProps: {
      placeholder: '请输入持续时间值(请输入数字)',
    },
    ifShow: ({ values }) => isWenDu(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: '请输入事件计数值必填(请输入数字)',
    },
    rules: [{ message: '事件计数应在1到2147483637之间', trigger: 'blur' }],
    ifShow: ({ values }) => isTimeAll(Reflect.get(values, 'conditionType')),
  },
  {
    field: 'inherit',
    label: '',
    component: 'Checkbox',
    renderComponentContent: 'Inherit from owner',
    ifShow: ({ values }) =>
      isCurrentCus(Reflect.get(values, 'sourceType')) ||
      isCurrentDev(Reflect.get(values, 'sourceType')),
  },
];