ClearAlarm.vue
3.87 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<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" />
<Tooltip title="移除" class="ml-4">
<Icon
icon="fluent:delete-off-20-regular"
size="20"
class="mr-2 cursor-pointer"
@click="handleDelete(index)"
v-if="clearRuleList.length > 1"
/>
</Tooltip>
</div>
</template>
<BasicForm @register="registerForm">
<template #operationType="{ model, field }">
<Select
:options="options"
v-model:value="model[field]"
@change="operationType = model[field]"
placeholder="请选择比较类型"
allowClear
/>
</template>
<template #time="{ model, field }">
<Input v-model:value="model[field]" placeholder="请输入持续时间">
<template #addonAfter>
<Select
v-model:value="model[`timeUnit`]"
:options="timeUnitOptions"
style="width: 60px"
/>
</template>
</Input>
</template>
</BasicForm>
<Card size="small" :bordered="false" style="border: 2px dashed #d9d9d9" 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, Input, Tooltip } from 'ant-design-vue';
import { trigger_condition_schema } from '../config/config.data.ts';
import { getAttribute } from '/@/api/ruleengine/ruleengineApi';
import ConditionScreening from './ConditionScreening.vue';
import { scheduleOptions, timeUnitOptions, options } from '../config/formatData.ts';
import { Icon } from '/@/components/Icon';
defineProps({
index: {
type: Number,
required: true,
},
clearRuleList: {
type: Array,
default: () => [],
},
});
const emit = defineEmits(['delete']);
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 operationType = ref<string>('');
provide('operationType', operationType);
const childGetFieldsValue = () => getFieldsValue();
const handleDelete = (index: number) => {
emit('delete', index);
};
defineExpose({
getFieldsValue,
updateFieldDeviceId,
resetFieldsValueFunc,
setFieldsFormValueFun,
childGetFieldsValue,
conditionScreeningRef,
schedule,
operationType,
});
</script>