ClearAlarm.vue
3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<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>