ClearAlarm.vue 3.19 KB
<template>
  <div>
    <CollapseContainer style="background-color: #f2f2f2" title="清除告警" :canExpan="false">
      <template #action>
        <div>
          <span class="mr-2">启用规则</span>
          <RadioGroup v-model:value="schedule" :options="scheduleOptions" />
        </div>
      </template>
      <BasicForm @register="registerForm">
        <template #operationType="{ model, field }">
          <Select
            :options="options"
            v-model:value="model[field]"
            @change="operationType = model[field]"
            placeholder="请选择比较类型"
            allowClear
          />
        </template>
      </BasicForm>
      <Card size="small" :bordered="false" style="border: 2px dashed #797979" v-if="operationType">
        <ConditionScreening
          :childGetFieldsValue="childGetFieldsValue"
          ref="conditionScreeningRef"
        />
      </Card>
    </CollapseContainer>
  </div>
</template>
<script lang="ts" setup>
  import { ref, provide } from 'vue';
  import { CollapseContainer } from '/@/components/Container/index';
  import { BasicForm, useForm } from '/@/components/Form/index';
  import { Radio, Card, Select } from 'ant-design-vue';
  import { trigger_condition_schema } from '../config';
  import { getAttribute } from '/@/api/ruleengine/ruleengineApi';
  import ConditionScreening from './ConditionScreening.vue';

  const RadioGroup = Radio.Group;

  const [registerForm, { resetFields, getFieldsValue, updateSchema, setFieldsValue }] = useForm({
    schemas: trigger_condition_schema,
    showActionButtonGroup: false,
  });

  const updateFieldDeviceId = (deviceList: any[]) => {
    updateSchema({
      field: 'entityId',
      componentProps: {
        options: deviceList,
        onChange(e) {
          if (e) {
            updateFieldAttributeFunc();
          }
        },
      },
    });
  };
  const conditionScreeningRef = ref();
  const resetFieldsValueFunc = () => resetFields();
  // 回显数据函数
  const setFieldsFormValueFun = (fieldsValue) => {
    setFieldsValue(fieldsValue);
  };
  const updateFieldAttributeFunc = async () => {
    const data = await getAttribute();
    const options = data.map((m) => {
      return {
        label: m,
        value: m,
      };
    });
    updateSchema({
      field: 'type2',
      componentProps: {
        placeholder: '请选择属性',
        options,
      },
    });
  };
  const schedule = ref('ANY_TIME');
  const scheduleOptions = [
    { label: '始终启用', value: 'ANY_TIME' },
    { label: '定时启用', value: 'SPECIFIC_TIME' },
    { label: '自定义启用', value: 'SPECIFIC_TIME' },
  ];
  const operationType = ref<string>('');
  const options = [
    {
      label: '数字',
      value: 'NUMERIC',
    },
    {
      label: '布尔值',
      value: 'BOOLEAN',
    },
    {
      label: '字符串',
      value: 'STRING',
    },
    {
      label: '时间',
      value: 'TIME',
    },
  ];
  const childGetFieldsValue = () => getFieldsValue();
  provide('operationType', operationType);

  defineExpose({
    getFieldsValue,
    updateFieldDeviceId,
    resetFieldsValueFunc,
    setFieldsFormValueFun,
    childGetFieldsValue,
    conditionScreeningRef,
    schedule,
  });
</script>