condition.vue
3.92 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
<template>
<CollapseContainer style="background-color: #f2f2f2" :title="`执行条件 ${conditionIndex + 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(conditionIndex)"
/>
</Tooltip>
</div>
</template>
<BasicForm @register="registerCondition">
<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>
</template>
<script lang="ts" setup>
import { ref, provide } from 'vue';
import { CollapseContainer } from '/@/components/Container/index';
import { BasicForm, useForm } from '/@/components/Form/index';
import { Tooltip, Radio, Card, Select } from 'ant-design-vue';
import { trigger_condition_schema } from '../config';
import { getAttribute } from '/@/api/ruleengine/ruleengineApi';
import { Icon } from '/@/components/Icon';
import ConditionScreening from './ConditionScreening.vue';
const RadioGroup = Radio.Group;
defineProps({
conditionIndex: {
type: Number,
required: true,
},
});
const emit = defineEmits(['deleteCondition']);
const [registerCondition, { getFieldsValue, updateSchema, resetFields, setFieldsValue }] =
useForm({
schemas: trigger_condition_schema,
showActionButtonGroup: false,
});
const conditionScreeningRef = ref();
const getFieldsValueFunc = () => {
const predicate = conditionScreeningRef?.value?.refItem?.conditionScreeningRefs?.value?.map(
(item) => {
return item.getFieldsValue();
}
);
return { ...getFieldsValue(), predicate, schedule: schedule.value };
};
const resetFieldsValueFunc = () => resetFields();
const updateFieldDeviceId = (deviceList: any[]) => {
updateSchema({
field: 'entityId',
componentProps: {
options: deviceList,
onChange(e) {
if (e) {
updateFieldAttributeFunc();
}
},
},
});
};
const setFieldsFormValueFun = (fieldsValue) => {
setFieldsValue(fieldsValue);
};
const updateFieldAttributeFunc = async () => {
const data1 = await getAttribute();
const data = data1.map((m) => ({ label: m, value: m }));
updateSchema({
field: 'type',
componentProps: {
placeholder: '请选择属性',
options: data,
},
});
};
const handleDelete = (conditionIndex) => {
emit('deleteCondition', conditionIndex);
};
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',
},
];
provide('operationType', operationType);
// 子组件获取父组件的值
const childGetFieldsValue = () => getFieldsValue();
defineExpose({
getFieldsValueFunc,
updateFieldDeviceId,
resetFieldsValueFunc,
setFieldsFormValueFun,
childGetFieldsValue,
});
</script>