trigger.vue
4.77 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<template>
<div>
<CollapseContainer style="background-color: #f2f2f2" :title="`触发器 ${triggerIndex + 1}`">
<template #action>
<div class="flex">
<div>
<span class="mr-2">启用规则</span>
<RadioGroup v-model:value="schedule" :options="scheduleOptions" />
</div>
<Tooltip title="移除" class="ml-4">
<Icon
icon="fluent:delete-off-20-regular"
size="20"
class="mr-2 cursor-pointer"
@click="handleDelete(triggerIndex)"
/>
</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>
</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 { Icon } from '/@/components/Icon';
import { Tooltip, 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;
defineProps({
triggerIndex: {
type: Number,
required: true,
},
});
const emit = defineEmits(['deleteTrigger']);
const conditionScreeningRef = ref();
const [registerForm, { resetFields, getFieldsValue, updateSchema, setFieldsValue }] = useForm({
schemas: trigger_condition_schema,
showActionButtonGroup: false,
});
const getFieldsValueFunc = () => {
const predicate = conditionScreeningRef?.value?.refItem?.conditionScreeningRefs?.value?.map(
(item) => {
return item.getFieldsValue();
}
);
return { ...getFieldsValue(), predicate, schedule: schedule.value };
};
const updateFieldDeviceId = (deviceList: any[]) => {
updateSchema({
field: 'entityId',
componentProps: {
options: deviceList,
onChange(e) {
if (e) {
updateFieldAttributeFunc();
}
},
},
});
};
const resetFieldsValueFunc = () => resetFields();
// 回显数据函数
const setFieldsFormValueFun = (fieldsValue) => {
setFieldsValue(fieldsValue);
};
const updateFieldAttributeFunc = async () => {
const data1 = await getAttribute();
const options = data1.map((m) => {
return {
label: m,
value: m,
};
});
updateSchema({
field: 'type2',
componentProps: {
placeholder: '请选择属性',
options,
onChange(value) {
if (value) {
updateSchema([
{
field: 'operation',
ifShow: true,
},
{
field: 'value',
ifShow: true,
},
]);
setFieldsValue({
operation: '',
value: '',
});
return;
}
updateSchema([
{
field: 'operation',
ifShow: false,
},
{
field: 'value',
ifShow: false,
},
]);
setFieldsValue({
operation: '',
value: '',
});
},
},
});
};
const handleDelete = (triggerIndex) => {
emit('deleteTrigger', triggerIndex);
};
const schedule = ref('ANY_TIME');
const scheduleOptions = [
{ label: '始终启用', value: 'ANY_TIME' },
{ label: '定时启用', value: 'SPECIFIC_TIME' },
{ label: '自定义启用', value: 'CUSTOM' },
];
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({
getFieldsValueFunc,
updateFieldDeviceId,
resetFieldsValueFunc,
setFieldsFormValueFun,
childGetFieldsValue,
});
</script>