Commit cc26522d385bcadf34c598857339bcc9729b9597

Authored by xp.Huang
2 parents 00cb376a 71790862

Merge branch 'ft-dev' into 'main'

refractor:重构场景联动

See merge request huang/yun-teng-iot-front!153
... ... @@ -151,7 +151,7 @@ export const columns: BasicColumn[] = [
151 151 },
152 152 ];
153 153
154   -export const getData = ref(null);
  154 +export const changeOriginId = ref(null);
155 155
156 156 export const formSchema: FormSchema[] = [
157 157 {
... ... @@ -189,7 +189,7 @@ export const formSchema: FormSchema[] = [
189 189 },
190 190 });
191 191 } else {
192   - getData.value = v;
  192 + changeOriginId.value = v;
193 193 }
194 194 },
195 195 };
... ... @@ -511,6 +511,8 @@ export const useActionDrawerSchema: FormSchema[] = [
511 511 field: 'doContext',
512 512 component: 'InputTextArea',
513 513 label: '',
  514 + // defaultValue:
  515 + // '{"method": "setDOValue","params": {"devID": "492S211218028819","data": {"DO1": 1}}}',
514 516 componentProps: {
515 517 maxLength: 255,
516 518 placeholder: '请输入下发指定',
... ... @@ -521,22 +523,22 @@ export const useActionDrawerSchema: FormSchema[] = [
521 523 span: 12,
522 524 },
523 525 },
524   - {
525   - field: 'no',
526   - component: 'InputTextArea',
527   - label: '',
528   - defaultValue:
529   - '(可复制)下发指定格式(JSON格式:{"method": "setDOValue","params": {"devID": "492S211218028819","data": {"DO1": 1}})',
530   - componentProps: {
531   - maxLength: 255,
532   - disabled: true,
533   - },
534   - ifShow: ({ values }) =>
535   - !isScene(Reflect.get(values, 'outTarget')) && !isMsg(Reflect.get(values, 'outTarget')),
536   - colProps: {
537   - span: 12,
538   - },
539   - },
  526 + // {
  527 + // field: 'no',
  528 + // component: 'InputTextArea',
  529 + // label: '',
  530 + // defaultValue:
  531 + // '(可复制)下发指定格式(JSON格式:{"method": "setDOValue","params": {"devID": "492S211218028819","data": {"DO1": 1}})',
  532 + // componentProps: {
  533 + // maxLength: 255,
  534 + // disabled: true,
  535 + // },
  536 + // ifShow: ({ values }) =>
  537 + // !isScene(Reflect.get(values, 'outTarget')) && !isMsg(Reflect.get(values, 'outTarget')),
  538 + // colProps: {
  539 + // span: 12,
  540 + // },
  541 + // },
540 542 {
541 543 field: 'wu2',
542 544 component: 'Input',
... ...
src/views/rule/linkedge/cpns/action.vue renamed from src/views/rule/linkedge/addForm/doaction.vue
... ... @@ -12,7 +12,7 @@
12 12 </CollapseContainer>
13 13 </template>
14 14 <script lang="ts">
15   - import { defineComponent, ref } from 'vue';
  15 + import { defineComponent, reactive, ref } from 'vue';
16 16 import { CollapseContainer } from '/@/components/Container/index';
17 17 import { BasicForm, useForm } from '/@/components/Form/index';
18 18 import { Input } from 'ant-design-vue';
... ... @@ -20,10 +20,9 @@
20 20
21 21 export default defineComponent({
22 22 components: { CollapseContainer, BasicForm, [Input.name]: Input },
23   - props: ['deviceInfo2', 'editActionFather', 'newActionMapFather'],
24   -
  23 + props: ['bindActionFather', 'bindActionEntryIdFather'],
25 24 setup(props) {
26   - const fieldValue: any = ref({});
  25 + let fieldValue = reactive({});
27 26 const option = ref<[]>([]);
28 27 const [registerAction, { setFieldsValue, getFieldsValue, resetFields, updateSchema }] =
29 28 useForm({
... ... @@ -32,8 +31,8 @@
32 31 actionColOptions: { span: 24 },
33 32 });
34 33 const getFieldsValueFunc = () => {
35   - fieldValue.value = getFieldsValue();
36   - return fieldValue.value;
  34 + fieldValue = getFieldsValue();
  35 + return fieldValue;
37 36 };
38 37 const resetFieldsValueFunc = () => {
39 38 resetFields();
... ... @@ -61,20 +60,20 @@
61 60
62 61 //回显数据
63 62 const setFieldsFormValueFun = () => {
64   - if (props.editActionFather !== 1) {
  63 + if (props.bindActionFather !== 1) {
65 64 setTimeout(() => {
66   - setFieldsValue(props.editActionFather);
  65 + setFieldsValue(props.bindActionFather);
67 66 }, 10);
68 67 }
69 68 };
70 69 setFieldsFormValueFun();
71 70 const editSelectDevice = () => {
72   - if (props.newActionMapFather !== 1) {
  71 + if (props.bindActionEntryIdFather !== 1) {
73 72 setTimeout(() => {
74 73 updateSchema({
75 74 field: 'deviceId',
76 75 componentProps: {
77   - options: props.newActionMapFather,
  76 + options: props.bindActionEntryIdFather,
78 77 },
79 78 });
80 79 }, 10);
... ... @@ -109,7 +108,7 @@
109 108 vertical-align: middle;
110 109 display: inline-block;
111 110 position: relative;
112   - top: 20px;
  111 + top: 1vh;
113 112 left: 5px;
114 113 }
115 114 </style>
... ...
src/views/rule/linkedge/cpns/condition.vue renamed from src/views/rule/linkedge/addForm/condition.vue
... ... @@ -12,7 +12,7 @@
12 12 </CollapseContainer>
13 13 </template>
14 14 <script lang="ts">
15   - import { defineComponent, ref } from 'vue';
  15 + import { defineComponent, reactive, ref } from 'vue';
16 16 import { CollapseContainer } from '/@/components/Container/index';
17 17 import { BasicForm, useForm } from '/@/components/Form/index';
18 18 import { Input } from 'ant-design-vue';
... ... @@ -21,10 +21,9 @@
21 21
22 22 export default defineComponent({
23 23 components: { CollapseContainer, BasicForm, [Input.name]: Input },
24   - props: ['deviceInfo1', 'editConditionFather', 'newConditionMapFather'],
25   -
  24 + props: ['bindConditionFather', 'bindConditionEntryIdFather'],
26 25 setup(props) {
27   - const fieldValue: any = ref({});
  26 + let fieldValue = reactive({});
28 27 const option = ref<[]>([]);
29 28 const [registerCondition, { setFieldsValue, getFieldsValue, updateSchema, resetFields }] =
30 29 useForm({
... ... @@ -33,8 +32,8 @@
33 32 actionColOptions: { span: 24 },
34 33 });
35 34 const getFieldsValueFunc = () => {
36   - fieldValue.value = getFieldsValue();
37   - return fieldValue.value;
  35 + fieldValue = getFieldsValue();
  36 + return fieldValue;
38 37 };
39 38 const resetFieldsValueFunc = () => {
40 39 resetFields();
... ... @@ -49,7 +48,7 @@
49 48 onChange(e) {
50 49 if (e) {
51 50 setTimeout(() => {
52   - updateFieldType2Func(e);
  51 + updateFieldAttributeFunc(e);
53 52 }, 10);
54 53 }
55 54 },
... ... @@ -64,7 +63,7 @@
64 63 onChange(e) {
65 64 if (e) {
66 65 setTimeout(() => {
67   - updateFieldType2Func(e);
  66 + updateFieldAttributeFunc(e);
68 67 }, 10);
69 68 }
70 69 },
... ... @@ -73,8 +72,7 @@
73 72 }, 10);
74 73 }
75 74 };
76   -
77   - const updateFieldType2Func = async (e) => {
  75 + const updateFieldAttributeFunc = async (e) => {
78 76 const data1 = await screenLinkPageByDeviceIdGetAttribut('DEVICE', e);
79 77 const data = data1.map((m) => {
80 78 return {
... ... @@ -119,26 +117,33 @@
119 117 });
120 118 }, 10);
121 119 };
122   -
  120 + const clearSelectAttribute = () => {
  121 + updateSchema({
  122 + field: 'type',
  123 + componentProps: {
  124 + options: [],
  125 + },
  126 + });
  127 + };
123 128 //回显数据
124 129 const setFieldsFormValueFun = () => {
125   - if (props.editConditionFather !== 1) {
  130 + if (props.bindConditionFather !== 1) {
126 131 setTimeout(() => {
127   - setFieldsValue(props.editConditionFather);
  132 + setFieldsValue(props.bindConditionFather);
128 133 setFieldsValue({
129 134 type:
130   - props.editConditionFather?.triggerCondition?.condition[0]?.valueType == 'NUMERIC'
  135 + props.bindConditionFather?.triggerCondition?.condition[0]?.valueType == 'NUMERIC'
131 136 ? 'NUMERIC1'
132 137 : 'NUMERIC2',
133 138 operation1:
134   - props.editConditionFather?.triggerCondition?.condition[0]?.predicate?.operation,
  139 + props.bindConditionFather?.triggerCondition?.condition[0]?.predicate?.operation,
135 140 operation2:
136   - props.editConditionFather?.triggerCondition?.condition[0]?.predicate?.operation,
  141 + props.bindConditionFather?.triggerCondition?.condition[0]?.predicate?.operation,
137 142 value1:
138   - props.editConditionFather?.triggerCondition?.condition[0]?.predicate?.value
  143 + props.bindConditionFather?.triggerCondition?.condition[0]?.predicate?.value
139 144 ?.defaultValue,
140 145 value2:
141   - props.editConditionFather?.triggerCondition?.condition[0]?.predicate?.value
  146 + props.bindConditionFather?.triggerCondition?.condition[0]?.predicate?.value
142 147 ?.defaultValue,
143 148 });
144 149 }, 100);
... ... @@ -146,12 +151,12 @@
146 151 };
147 152 setFieldsFormValueFun();
148 153 const editSelectDevice = () => {
149   - if (props.newConditionMapFather !== 1) {
  154 + if (props.bindConditionEntryIdFather !== 1) {
150 155 setTimeout(() => {
151 156 updateSchema({
152 157 field: 'entityId',
153 158 componentProps: {
154   - options: props.newConditionMapFather,
  159 + options: props.bindConditionEntryIdFather,
155 160 },
156 161 });
157 162 }, 100);
... ... @@ -167,13 +172,15 @@
167 172 },
168 173 });
169 174 };
  175 +
170 176 return {
171 177 updateFieldDeviceId,
172   - resetFieldsValueFunc,
173 178 clearSelectDevice,
174 179 editSelectDevice,
175 180 getFieldsValueFunc,
176 181 registerCondition,
  182 + resetFieldsValueFunc,
  183 + clearSelectAttribute,
177 184 };
178 185 },
179 186 });
... ...
  1 +export const formatTriggerData = (m) => {
  2 + return {
  3 + triggerType: m?.triggerType,
  4 + entityId: m?.entityId || m?.entityId1 || m?.entityId2,
  5 + triggerCondition: {
  6 + condition: [
  7 + {
  8 + key: {
  9 + key: m.type2 == null ? 'CO2' : m.type2,
  10 + type: m.type1 == null ? 'TIME_SERIES' : m.type1,
  11 + },
  12 + valueType: 'NUMERIC',
  13 + predicate: {
  14 + type: 'NUMERIC',
  15 + value: {
  16 + defaultValue: Number(m.value),
  17 + },
  18 + operation: m.operation == null ? 'EQUAL' : m.operation,
  19 + },
  20 + },
  21 + ],
  22 + spec: {
  23 + type: 'SIMPLE',
  24 + },
  25 + },
  26 + };
  27 +};
  28 +
  29 +export const formatConditionData = (m) => {
  30 + return {
  31 + triggerType: m?.triggerType,
  32 + entityId: m?.entityId,
  33 + triggerCondition: {
  34 + condition: [
  35 + {
  36 + key: {
  37 + key: m.type == null ? 'CO2' : m.type,
  38 + type: 'TIME_SERIES',
  39 + },
  40 + valueType: 'NUMERIC',
  41 + // value: {},
  42 + predicate: {
  43 + type: 'NUMERIC',
  44 + value: {
  45 + defaultValue: Number(m.value) == null ? 0 : Number(m.value),
  46 + },
  47 + operation: m.operation,
  48 + },
  49 + },
  50 + ],
  51 + spec: {
  52 + type: 'SIMPLE',
  53 + },
  54 + },
  55 + };
  56 +};
... ...
src/views/rule/linkedge/cpns/trigger.vue renamed from src/views/rule/linkedge/addForm/trigger.vue
... ... @@ -7,14 +7,14 @@
7 7 :showResetButton="false"
8 8 :showSubmitButton="false"
9 9 :emptySpan="10"
10   - @register="registerTrigger"
  10 + @register="registerForm"
11 11 />
12 12 </div>
13 13 </CollapseContainer>
14 14 </div>
15 15 </template>
16 16 <script lang="ts">
17   - import { defineComponent, ref } from 'vue';
  17 + import { defineComponent, reactive, ref } from 'vue';
18 18 import { CollapseContainer } from '/@/components/Container/index';
19 19 import { BasicForm, useForm } from '/@/components/Form/index';
20 20 import { Input } from 'ant-design-vue';
... ... @@ -23,20 +23,21 @@
23 23
24 24 export default defineComponent({
25 25 components: { CollapseContainer, BasicForm, [Input.name]: Input },
26   - props: ['deviceInfo', 'editTriggerFather', 'newFilterMapFather'],
  26 + props: ['bindTriggerFather', 'bindTriggerEntryIdFather'],
27 27 setup(props) {
28   - const fieldValue: any = ref({});
  28 + let fieldValue = reactive({});
29 29 const option = ref<[]>([]);
30 30 const data = ref<[]>([]);
31   - const [registerTrigger, { resetFields, setFieldsValue, getFieldsValue, updateSchema }] =
32   - useForm({
  31 + const [registerForm, { setFieldsValue, resetFields, getFieldsValue, updateSchema }] = useForm(
  32 + {
33 33 labelWidth: 100,
34 34 schemas: useTriggerDrawerSchema,
35 35 actionColOptions: { span: 24 },
36   - });
  36 + }
  37 + );
37 38 const getFieldsValueFunc = () => {
38   - fieldValue.value = getFieldsValue();
39   - return fieldValue.value;
  39 + fieldValue = getFieldsValue();
  40 + return fieldValue;
40 41 };
41 42 const updateFieldDeviceId = (v) => {
42 43 if (v.length == 0 || v.length > 0) {
... ... @@ -48,7 +49,7 @@
48 49 onChange(e) {
49 50 if (e) {
50 51 setTimeout(() => {
51   - updateFieldType2Func(e);
  52 + updateFieldAttributeFunc(e);
52 53 }, 10);
53 54 }
54 55 },
... ... @@ -63,7 +64,7 @@
63 64 onChange(e) {
64 65 if (e) {
65 66 setTimeout(() => {
66   - updateFieldType2Func(e);
  67 + updateFieldAttributeFunc(e);
67 68 }, 10);
68 69 }
69 70 },
... ... @@ -72,8 +73,7 @@
72 73 }, 10);
73 74 }
74 75 };
75   -
76   - const updateFieldType2Func = async (e) => {
  76 + const updateFieldAttributeFunc = async (e) => {
77 77 const data1 = await screenLinkPageByDeviceIdGetAttribut('DEVICE', e);
78 78 data.value = data1.map((m) => {
79 79 return {
... ... @@ -81,7 +81,6 @@
81 81 value: m,
82 82 };
83 83 });
84   -
85 84 updateSchema({
86 85 field: 'type2',
87 86 componentProps: {
... ... @@ -127,28 +126,26 @@
127 126 },
128 127 ]);
129 128 };
130   -
131 129 const resetFieldsValueFunc = () => {
132 130 resetFields();
133 131 };
134   -
135 132 //回显数据
136 133 const setFieldsFormValueFun = () => {
137   - if (props.editTriggerFather != 1) {
  134 + if (props.bindTriggerFather != 1) {
138 135 setTimeout(() => {
139   - setFieldsValue(props.editTriggerFather);
  136 + setFieldsValue(props.bindTriggerFather);
140 137 setFieldsValue({
141   - entityId1: props.editTriggerFather.entityId,
142   - entityId2: props.editTriggerFather.entityId,
143   - type1: props.editTriggerFather?.triggerCondition?.condition[0]?.key?.type,
144   - type2: props.editTriggerFather?.triggerCondition?.condition[0]?.key?.key,
  138 + entityId1: props.bindTriggerFather.entityId,
  139 + entityId2: props.bindTriggerFather.entityId,
  140 + type1: props.bindTriggerFather?.triggerCondition?.condition[0]?.key?.type,
  141 + type2: props.bindTriggerFather?.triggerCondition?.condition[0]?.key?.key,
145 142 operation:
146   - props.editTriggerFather?.triggerCondition?.condition[0]?.predicate?.operation,
  143 + props.bindTriggerFather?.triggerCondition?.condition[0]?.predicate?.operation,
147 144 value:
148   - props.editTriggerFather?.triggerCondition?.condition[0]?.predicate?.value
  145 + props.bindTriggerFather?.triggerCondition?.condition[0]?.predicate?.value
149 146 ?.defaultValue,
150 147 });
151   - if (props.editTriggerFather?.triggerCondition?.condition[0]?.key?.key) {
  148 + if (props.bindTriggerFather?.triggerCondition?.condition[0]?.key?.key) {
152 149 updateSchema([
153 150 {
154 151 field: 'operation',
... ... @@ -163,7 +160,6 @@
163 160 }, 1);
164 161 }
165 162 };
166   -
167 163 setFieldsFormValueFun();
168 164 //新增清空设备选择
169 165 const clearSelectDevice = () => {
... ... @@ -183,47 +179,28 @@
183 179 });
184 180 };
185 181 const editSelectDevice = () => {
186   - if (props.newFilterMapFather != 1) {
  182 + if (props.bindTriggerEntryIdFather != 1) {
187 183 setTimeout(() => {
188 184 updateSchema({
189 185 field: 'entityId',
190 186 componentProps: {
191   - options: props.newFilterMapFather,
  187 + options: props.bindTriggerEntryIdFather,
192 188 },
193 189 });
194 190 }, 100);
195 191 }
196 192 };
197 193 editSelectDevice();
198   - //新增清空场景触发器选择
199   - const clearSelectScene = () => {
200   - updateSchema({
201   - field: 'sceneLinkageId',
202   - componentProps: {
203   - options: [],
204   - },
205   - });
206   - };
207   - const editSelectScene = (v) => {
208   - updateSchema({
209   - field: 'sceneLinkageId',
210   - componentProps: {
211   - options: v,
212   - },
213   - });
214   - };
215 194 return {
216 195 updateOperatorAndValue,
217 196 clearSelectAttribute,
218   - updateFieldType2Func,
  197 + updateFieldAttributeFunc,
219 198 updateFieldDeviceId,
220 199 resetFieldsValueFunc,
221   - clearSelectScene,
222   - editSelectScene,
223 200 clearSelectDevice,
224 201 editSelectDevice,
225 202 getFieldsValueFunc,
226   - registerTrigger,
  203 + registerForm,
227 204 };
228 205 },
229 206 });
... ...
... ... @@ -49,7 +49,7 @@
49 49 </div>
50 50 </template>
51 51 <script lang="ts">
52   - import { defineComponent, getCurrentInstance, ref, computed } from 'vue';
  52 + import { defineComponent, ref, computed } from 'vue';
53 53 import { BasicTable, useTable, TableAction } from '/@/components/Table';
54 54 import { useDrawer } from '/@/components/Drawer';
55 55 import SceneLinkAgeDrawer from './useDrawer.vue';
... ... @@ -72,7 +72,6 @@
72 72 const isCustomer = computed(() => userStore.getRoleList.includes(RoleEnum.CUSTOMER_USER));
73 73 const isSysadmin = computed(() => userStore.getRoleList.includes(RoleEnum.SYS_ADMIN));
74 74 const isPlatform = computed(() => userStore.getRoleList.includes(RoleEnum.PLATFORM_ADMIN));
75   - const { proxy } = getCurrentInstance() as any;
76 75 const sceneLinkAgeDrawerRef: any = ref(null);
77 76 const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete(
78 77 screenLinkPageDeleteApi,
... ... @@ -107,13 +106,6 @@
107 106 openDrawer(true, {
108 107 isUpdate: false,
109 108 });
110   - try {
111   - setTimeout(() => {
112   - proxy.$refs.sceneLinkAgeDrawerRef.defaultAddAction();
113   - }, 50);
114   - } catch (e) {
115   - return e;
116   - }
117 109 }
118 110
119 111 const useSelectionChange = () => {
... ...
... ... @@ -4,31 +4,29 @@
4 4 v-bind="$attrs"
5 5 @register="registerDrawer"
6 6 showFooter
7   - :title="getTitle"
8   - width="1000px"
9   - @ok="handleSubmit"
  7 + width="50vw"
  8 + @ok="handleSubmit(drawerStatus)"
10 9 @close="handleClose"
11 10 >
12 11 <div>
  12 + <!-- 基础表单 -->
13 13 <BasicForm @register="registerForm" />
  14 + <!-- 基础表单 -->
14 15 <!-- 触发器 -->
15 16 <div style="border-radius: 4px">
16 17 <template
17   - v-for="(item, index) in isUpdate == false ? addTriggerPushData : editTriggerPushData"
  18 + v-for="(item, index) in !drawerStatus ? triggerData : editTriggerData"
18 19 :key="index"
19 20 >
20 21 <span style="display: none">{{ item + index }}</span>
21   - <span style="position: relative; top: 3.2vh; left: 0.5vw">触发器 {{ index + 1 }}</span>
22   - <div style="display: block">
23   - <AddTriggerForm
24   - ref="refTriggerChild"
25   - :editTriggerFather="isUpdate == false ? 1 : item"
26   - :newFilterMapFather="isUpdate == false ? 1 : newFilterMap"
27   - :deviceInfo="getDeviceInfo"
28   - />
29   - </div>
30   - <div style="height: 3vh"></div>
  22 + <span style="position: relative; top: 3.2vh; left: 0.6vw">触发器 {{ index + 1 }}</span>
  23 + <useTriggerCpn
  24 + ref="triggerBindRef"
  25 + :bindTriggerFather="!drawerStatus ? 1 : item"
  26 + :bindTriggerEntryIdFather="!drawerStatus ? 1 : getTriggerFatherEntryIdData"
  27 + />
31 28 </template>
  29 + <!-- 按钮 -->
32 30 <div
33 31 style="
34 32 display: flex;
... ... @@ -39,47 +37,47 @@
39 37 "
40 38 >
41 39 <div style="display: flex; width: 4vw; height: 4vh">
42   - <Button type="primary" style="border-radius: 2px" class="mt-5" @click="addTrigger"
43   - >新增触发器</Button
  40 + <Button
  41 + type="primary"
  42 + style="border-radius: 2px"
  43 + class="mt-5"
  44 + @click="triggerClickAdd(drawerStatus)"
  45 + >触发器</Button
44 46 >
45 47 </div>
46 48 <div style="display: flex; width: 4vw; height: 4vh">
47 49 <Button
48   - v-if="addTriggerPushData.length != 0 || editTriggerPushData.length != 0"
  50 + v-if="triggerData.length !== 0 || editTriggerData.length !== 0"
49 51 type="default"
50 52 style="border-radius: 2px; background-color: rgba(237, 111, 111, 1)"
51 53 class="mt-5"
52   - @click="removeTrigger"
  54 + @click="triggerClickRemove(drawerStatus)"
53 55 >
54 56 <span style="color: white">删除</span></Button
55 57 >
56 58 </div>
57 59 </div>
  60 + <!-- 按钮 -->
58 61 </div>
  62 + <!-- 触发器 -->
59 63 <div style="height: 5vh"></div>
60 64 <!-- 执行条件 -->
61   - <div style="border-radius: 4px" class="condition-style">
  65 + <div style="border-radius: 4px">
62 66 <template
63   - v-for="(item, index) in isUpdate == false
64   - ? addConditionPushData
65   - : editConditionPushData"
  67 + v-for="(item, index) in !drawerStatus ? conditionData : editConditionData"
66 68 :key="index"
67 69 >
68 70 <span style="display: none">{{ item + index }}</span>
69   - <span style="position: relative; top: 3.2vh; left: 0.5vw"
  71 + <span style="position: relative; top: 3.2vh; left: 0.6vw"
70 72 >执行条件 {{ index + 1 }}</span
71 73 >
72   -
73   - <div>
74   - <AddConditiForm
75   - :editConditionFather="isUpdate == false ? 1 : item"
76   - :newConditionMapFather="isUpdate == false ? 1 : newConditionFilterMap"
77   - :deviceInfo1="getDeviceInfo1"
78   - ref="refConditionChild"
79   - />
80   - </div>
81   - <div style="height: 3vh"></div>
  74 + <useConditionCpn
  75 + ref="conditionBindRef"
  76 + :bindConditionFather="!drawerStatus ? 1 : item"
  77 + :bindConditionEntryIdFather="!drawerStatus ? 1 : getConditionFatherEntryIdData"
  78 + />
82 79 </template>
  80 + <!-- 按钮 -->
83 81 <div
84 82 style="
85 83 display: flex;
... ... @@ -90,45 +88,45 @@
90 88 "
91 89 >
92 90 <div style="display: flex; width: 4vw; height: 4vh">
93   - <Button type="primary" style="border-radius: 2px" class="mt-5" @click="addCondition"
94   - >新增执行条件</Button
  91 + <Button
  92 + type="primary"
  93 + style="border-radius: 2px"
  94 + class="mt-5"
  95 + @click="conditionClickAdd(drawerStatus)"
  96 + >执行条件</Button
95 97 >
96 98 </div>
97 99 <div style="display: flex; width: 4vw; height: 4vh">
98 100 <Button
99   - v-if="addConditionPushData.length != 0 || editConditionPushData.length != 0"
100   - style="border-radius: 2px; background-color: rgba(237, 111, 111, 1)"
  101 + v-if="conditionData.length !== 0 || editConditionData.length !== 0"
101 102 type="default"
  103 + style="border-radius: 2px; background-color: rgba(237, 111, 111, 1)"
102 104 class="mt-5"
103   - @click="removeCondition"
  105 + @click="conditionClickRemove(drawerStatus)"
104 106 >
105 107 <span style="color: white">删除</span></Button
106 108 >
107 109 </div>
108 110 </div>
  111 + <!-- 按钮 -->
109 112 </div>
110   - <!-- 执行动作 -->
  113 + <!-- 执行条件 -->
111 114 <div style="height: 5vh"></div>
  115 + <!-- 执行动作 -->
112 116 <div style="border-radius: 4px">
113 117 <template
114   - v-for="(item, index) in isUpdate == false ? addActionPushData : editActionPushData"
  118 + v-for="(item, index) in !drawerStatus ? actionData : editActionData"
115 119 :key="index"
116 120 >
117 121 <span style="display: none">{{ item + index }}</span>
118   - <span style="position: relative; top: 4.2vh; left: 0.65vw"
119   - >执行动作 {{ index + 1 }}</span
120   - >
121   -
122   - <div>
123   - <AddActionForm
124   - :editActionFather="isUpdate == false ? 1 : item"
125   - :newActionMapFather="isUpdate == false ? 1 : newActionFilterMap"
126   - :deviceInfo2="getDeviceInfo2"
127   - ref="refActionChild"
128   - />
129   - </div>
130   - <div style="height: 3vh"></div>
  122 + <span style="position: relative; top: 3.6vh; left: 1vw">执行动作 {{ index + 1 }}</span>
  123 + <useActionCpn
  124 + ref="actionBindRef"
  125 + :bindActionFather="!drawerStatus ? 1 : item"
  126 + :bindActionEntryIdFather="!drawerStatus ? 1 : getActionFatherEntryIdData"
  127 + />
131 128 </template>
  129 + <!-- 按钮 -->
132 130 <div
133 131 style="
134 132 display: flex;
... ... @@ -139,737 +137,366 @@
139 137 "
140 138 >
141 139 <div style="display: flex; width: 4vw; height: 4vh">
142   - <Button type="primary" style="border-radius: 2px" class="mt-5" @click="addAction"
143   - >新增执行动作</Button
  140 + <Button
  141 + type="primary"
  142 + style="border-radius: 2px"
  143 + class="mt-5"
  144 + @click="actionClickAdd(drawerStatus)"
  145 + >执行动作</Button
144 146 >
145 147 </div>
146 148 <div style="display: flex; width: 4vw; height: 4vh">
147 149 <Button
148   - v-if="addActionPushData.length !== 0 || editActionPushData.length !== 0"
149   - style="border-radius: 2px; background-color: rgba(237, 111, 111, 1)"
  150 + v-if="actionData.length !== 0 || editActionData.length !== 0"
150 151 type="default"
  152 + style="border-radius: 2px; background-color: rgba(237, 111, 111, 1)"
151 153 class="mt-5"
152   - @click="removeAction"
  154 + @click="actionClickRemove(drawerStatus)"
153 155 >
154 156 <span style="color: white">删除</span></Button
155 157 >
156 158 </div>
157 159 </div>
158   - <div style="height: 5vh"></div>
  160 + <!-- 按钮 -->
159 161 </div>
  162 + <!-- 执行动作 -->
160 163 </div>
161 164 </BasicDrawer>
162 165 </div>
163 166 </template>
164 167 <script lang="ts">
165   - import { defineComponent, ref, computed, unref, reactive, getCurrentInstance, watch } from 'vue';
166   - import { BasicForm, useForm } from '/@/components/Form';
167   - import { formSchema, getData } from './config';
  168 + import { defineComponent, reactive, ref, getCurrentInstance, watch } from 'vue';
168 169 import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  170 + import { formSchema, changeOriginId } from './config';
  171 + import { BasicForm, useForm } from '/@/components/Form';
  172 + import useTriggerCpn from './cpns/trigger.vue';
  173 + import useConditionCpn from './cpns/condition.vue';
  174 + import useActionCpn from './cpns/action.vue';
  175 + import { Button } from '/@/components/Button';
  176 + import { formatTriggerData, formatConditionData } from './cpns/format-data/index';
  177 + import { useMessage } from '/@/hooks/web/useMessage';
169 178 import {
170 179 screenLinkPageAddApi,
171   - screenLinkPageUpdateApi,
172 180 screenLinkPageByDeptIdGetDevice,
  181 + screenLinkPageUpdateApi,
173 182 } from '/@/api/ruleengine/ruleengineApi';
174   - import { useMessage } from '/@/hooks/web/useMessage';
175   - import AddTriggerForm from './addForm/trigger.vue';
176   - import AddConditiForm from './addForm/condition.vue';
177   - import AddActionForm from './addForm/doaction.vue';
178   - import { IAddTrigger } from './index';
179   - import { Button } from '/@/components/Button';
180 183
181 184 export default defineComponent({
182 185 name: 'ConfigDrawer',
183 186 components: {
184 187 BasicDrawer,
185 188 BasicForm,
186   - AddTriggerForm,
187   - AddConditiForm,
188   - AddActionForm,
  189 + useTriggerCpn,
  190 + useConditionCpn,
  191 + useActionCpn,
189 192 Button,
190 193 },
191   - emits: ['success', 'register', 'registerForm'],
  194 + emits: ['register', 'success'],
192 195 setup(_, { emit }) {
193 196 const { proxy } = getCurrentInstance() as any;
194   - const lastEditRefTriggerChildDataArray = ref<[]>([]);
195   - const lastRefTriggerChildDataArray = ref<[]>([]);
196   - const lastRefConditionChildDataArray = ref<[]>([]);
197   - const lastRefActionChildDataArray = ref<[]>([]);
198   - let refTriggerChildData: any = reactive({});
199   - let refConditionChildData: any = reactive({});
200   - let refActionChildData: any = reactive({});
201   - const addTriggerData = reactive<IAddTrigger>({
202   - triggerType: '',
203   - entityId: '',
204   - touchWay: '',
205   - attributeChoose: '',
206   - compare: '',
207   - value: '',
208   - });
209   - const addTriggerPushData = ref<[]>([]);
210   - const addConditionPushData = ref<[]>([]);
211   - const addActionPushData = ref<[]>([]);
212   - //edit data
213   - const editTriggerPushData = ref<[]>([]);
214   - const editConditionPushData = ref<[]>([]);
215   - const editActionPushData = ref<[]>([]);
216   - const getChildData = ref(null);
217   - const refTriggerChild = ref(null);
218   - const refConditionChild = ref(null);
219   - const refActionChild = ref(null);
220   - const getConditionChildData = ref(null);
221 197 const { createMessage } = useMessage();
222   - const isUpdate = ref(true);
223   - let getAllFormData: any = reactive({});
224   - let getValuesFormData: any = reactive({});
  198 + const triggerData = reactive([]);
  199 + const conditionData = reactive([]);
  200 + const actionData = reactive([1]);
  201 + const triggerBindRef = ref(null);
  202 + const conditionBindRef = ref(null);
  203 + const actionBindRef = ref(null);
  204 + let getTriggerFormValue: any = reactive({});
  205 + let getConditionFormValue: any = reactive({});
  206 + let getActionFormValue: any = reactive({});
  207 + const drawerStatus = ref(true);
  208 + let postAddOrEditData: any = reactive({});
  209 + let concatTrigger: any = reactive([]);
  210 + let concatCondition: any = reactive([]);
  211 + let concatAction: any = reactive([]);
  212 + let optionsItemDeviceId: any = ref([]);
  213 + let editTriggerData: any = ref([]);
  214 + let editConditionData: any = ref([]);
  215 + let editActionData: any = ref([]);
  216 + let getTriggerFatherEntryIdData: any = reactive([]);
  217 + let getConditionFatherEntryIdData: any = reactive([]);
  218 + let getActionFatherEntryIdData: any = reactive([]);
  219 + const editEntryIdData: any = ref([]);
225 220 const getId = ref('');
226 221 const getTenantId = ref('');
227   - const getDeviceInfo = ref(null);
228   - const getDeviceInfo1 = ref(null);
229   - const getDeviceInfo2 = ref(null);
230   - const newFilterMap = ref<[]>([]);
231   - const newConditionFilterMap = ref<[]>([]);
232   - const newActionFilterMap = ref<[]>([]);
233   - let filterNewConditionArr = [];
234   - const pushEditArray = ref<any>([{}]);
235   - const pushEditConditionArray = ref<any>([{}]);
236   - const pushEditActionArray = ref<any>([{}]);
237   - let filterArrayTrigger = [];
238   - const filterArrayCondition = ref<[]>([]);
239   - const filterArrayAction = ref<[]>([]);
240   - let filterNewTriggerArr = [];
241   - let triggersObj = {
242   - triggers: [],
243   - };
244   - let conditionsObj = {
245   - doConditions: [],
246   - };
247   - let actionsObj = {
248   - doActions: [],
249   - };
250   - let optionsItemArray = ref<[]>([]);
251   - const isNoChange = ref(false);
252   - let kongTriggerObj = {};
253   - let kongConditionObj = {};
254   - let kongActionObj = {};
255   - let optionsEditArray = ref<[]>([]);
256   - const oldOrigzaition = ref('');
257   -
258   - const [registerForm, { resetFields, setFieldsValue, validateFields }] = useForm({
  222 + const [registerForm, { resetFields, validate, setFieldsValue }] = useForm({
259 223 labelWidth: 120,
260 224 schemas: formSchema,
261 225 showActionButtonGroup: false,
262 226 });
263 227 const [registerDrawer, { setDrawerProps, closeDrawer }] = useDrawerInner(async (data) => {
264   - await resetFields();
265 228 setDrawerProps({ confirmLoading: false });
266   - isUpdate.value = !!data?.isUpdate;
267   - if (!unref(isUpdate)) {
  229 + drawerStatus.value = data.isUpdate;
  230 + if (!drawerStatus.value) {
  231 + triggerData.length = 0;
  232 + conditionData.length = 0;
  233 + actionData.length = 0;
  234 + resetFields();
  235 + defaultAddAction();
268 236 try {
269   - refTriggerChildData = {};
270   - refConditionChildData = {};
271   - refActionChildData = {};
272   - getAllFormData = {};
273   - triggersObj = {
274   - triggers: [],
275   - };
276   - conditionsObj = {
277   - doConditions: [],
278   - };
279   - actionsObj = {
280   - doActions: [],
281   - };
282   - filterNewTriggerArr.length = 0;
283   - filterNewConditionArr.length = 0;
284   - lastRefTriggerChildDataArray.value.length = 0;
285   - lastRefConditionChildDataArray.value.length = 0;
286   - lastRefActionChildDataArray.value.length = 0;
287   - editTriggerPushData.value.length = 0;
288   - editConditionPushData.value.length = 0;
289   - editActionPushData.value.length = 0;
290   - addTriggerPushData.value.length = 0;
291   - addConditionPushData.value.length = 0;
292   - addActionPushData.value.length = 0;
293   - handleClose();
294   - optionsItemArray.value.length = 0;
295   - optionsItemArray.value = [];
296   - optionsEditArray.value = [];
297   - optionsEditArray.value.length = 0;
298   - try {
299   - proxy.$refs.refTriggerChild?.resetFieldsValueFunc();
300   - proxy.$refs.refTriggerChild?.clearSelectDevice();
301   - proxy.$refs.refTriggerChild?.clearSelectAttribute();
302   - proxy.$refs.refConditionChild?.resetFieldsValueFunc();
303   - proxy.$refs.refConditionChild?.clearSelectDevice();
304   - proxy.$refs.refActionChild?.resetFieldsValueFunc();
305   - proxy.$refs.refActionChild?.clearSelectDevice();
306   - clearActionsAllDevice();
307   - resetActionsAllArrayFunc();
308   - } catch {}
309   - } catch (e) {
310   - return e;
311   - }
  237 + proxy.$refs.triggerBindRef?.resetFieldsValueFunc();
  238 + proxy.$refs.triggerBindRef?.clearSelectDevice();
  239 + proxy.$refs.triggerBindRef?.clearSelectAttribute();
  240 + proxy.$refs.conditionBindRef?.resetFieldsValueFunc();
  241 + proxy.$refs.conditionBindRef?.clearSelectDevice();
  242 + proxy.$refs.conditionBindRef?.clearSelectAttribute();
  243 + proxy.$refs.actionBindRef?.clearSelectDevice();
  244 + proxy.$refs.actionBindRef.resetFieldsValueFunc();
  245 + } catch {}
312 246 } else {
313   - try {
314   - optionsEditArray.value = [];
315   - optionsEditArray.value.length = 0;
316   - kongTriggerObj = {};
317   - kongConditionObj = {};
318   - kongActionObj = {};
319   - pushEditArray.value = [];
320   - pushEditArray.value.length = 0;
321   - pushEditConditionArray.value.length = 0;
322   - pushEditConditionArray.value = [];
323   - pushEditActionArray.value = [];
324   - pushEditActionArray.value.length = 0;
325   - newFilterMap.value = [];
326   - newConditionFilterMap.value = [];
327   - newActionFilterMap.value = [];
328   - clearAllArrayFunc();
329   - editTriggerPushData.value = [];
330   - editTriggerPushData.value.length = 0;
331   - editConditionPushData.value = [];
332   - editConditionPushData.value.length = 0;
333   - editActionPushData.value = [];
334   - editActionPushData.value.length = 0;
335   - lastEditRefTriggerChildDataArray.value = [];
336   - getId.value = data.record.id;
337   - getTenantId.value = data.record.tenantId;
338   - await setFieldsValue({
339   - ...data.record,
340   - });
341   - editTriggerPushData.value = data.record.triggers;
342   - isNoChange.value = true;
343   - editConditionPushData.value = data.record.doConditions;
344   - editActionPushData.value = data.record.doActions;
345   - const options = await screenLinkPageByDeptIdGetDevice({
346   - organizationId: data.record.organizationId,
347   - });
348   - data.record.triggers.forEach((f1) => {
349   - options.items?.forEach((f2) => {
350   - if (f2.tbDeviceId == f1.entityId) {
351   - newFilterMap.value.push({
352   - value: f2.tbDeviceId,
353   - label: f2.name,
354   - } as never);
355   - }
356   - });
357   - });
358   - data.record.doConditions.forEach((f1) => {
359   - options.items?.forEach((f2) => {
360   - if (f2.tbDeviceId == f1.entityId) {
361   - newConditionFilterMap.value.push({
362   - value: f2.tbDeviceId,
363   - label: f2.name,
364   - } as never);
365   - }
366   - });
  247 + emit('success');
  248 + editTriggerData.value.length = 0;
  249 + editConditionData.value.length = 0;
  250 + editActionData.value.length = 0;
  251 + editEntryIdData.value.length = 0;
  252 + await setFieldsValue({
  253 + ...data.record,
  254 + });
  255 + getId.value = data.record.id;
  256 + getTenantId.value = data.record.tenantId;
  257 + editTriggerData.value = data.record.triggers;
  258 + editConditionData.value = data.record.doConditions;
  259 + editActionData.value = data.record.doActions;
  260 + const options = await screenLinkPageByDeptIdGetDevice({
  261 + organizationId: data.record.organizationId,
  262 + });
  263 + data.record.triggers.forEach((f1) => {
  264 + options.items?.forEach((f2) => {
  265 + if (f2.tbDeviceId == f1.entityId) {
  266 + getTriggerFatherEntryIdData.push({
  267 + value: f2.tbDeviceId,
  268 + label: f2.name,
  269 + } as never);
  270 + }
367 271 });
368   - data.record.doActions.forEach((f1) => {
369   - options.items?.forEach((f2) => {
370   - if (f2.tbDeviceId == f1.deviceId) {
371   - newActionFilterMap.value.push({
372   - value: f2.tbDeviceId,
373   - label: f2.name,
374   - } as never);
375   - }
376   - });
  272 + });
  273 + data.record.doConditions.forEach((f1) => {
  274 + options.items?.forEach((f2) => {
  275 + if (f2.tbDeviceId == f1.entityId) {
  276 + getConditionFatherEntryIdData.push({
  277 + value: f2.tbDeviceId,
  278 + label: f2.name,
  279 + } as never);
  280 + }
377 281 });
378   - optionsEditArray.value = options.items.map((v) => {
379   - return {
380   - value: v.tbDeviceId,
381   - label: v.name,
382   - };
  282 + });
  283 + data.record.doActions.forEach((f1) => {
  284 + options.items?.forEach((f2) => {
  285 + if (f2.tbDeviceId == f1.deviceId) {
  286 + getActionFatherEntryIdData.push({
  287 + value: f2.tbDeviceId,
  288 + label: f2.name,
  289 + } as never);
  290 + }
383 291 });
384   - setTimeout(() => {
385   - proxy.$refs.refTriggerChild?.updateFieldDeviceId(optionsEditArray.value);
386   - proxy.$refs.refConditionChild?.updateFieldDeviceId(optionsEditArray.value);
387   - proxy.$refs.refActionChild?.updateFieldDeviceId(optionsEditArray.value);
388   - }, 20);
389   - emit('success');
390   - } catch (e) {
391   - return e;
392   - }
  292 + });
  293 + editEntryIdData.value = options.items.map((v) => {
  294 + return {
  295 + value: v.tbDeviceId,
  296 + label: v.name,
  297 + };
  298 + });
  299 + setTimeout(() => {
  300 + proxy.$refs.triggerBindRef?.updateFieldDeviceId(editEntryIdData.value);
  301 + proxy.$refs.conditionBindRef?.updateFieldDeviceId(editEntryIdData.value);
  302 + proxy.$refs.actionBindRef?.updateFieldDeviceId(editEntryIdData.value);
  303 + }, 10);
393 304 }
394 305 });
395   - const getTitle = computed(() => (!unref(isUpdate) ? '新增场景联动' : '编辑场景联动'));
396   - const handleClose = () => {
397   - editTriggerPushData.value.length = 0;
398   - pushEditArray.value.length = 0;
399   - pushEditConditionArray.value.length = 0;
400   - pushEditActionArray.value.length = 0;
401   - lastRefTriggerChildDataArray.value.length = 0;
402   - lastRefTriggerChildDataArray.value = [];
403   - lastRefConditionChildDataArray.value.length = 0;
404   - lastRefActionChildDataArray.value.length = 0;
405   - lastRefActionChildDataArray.value = [];
406   - filterArrayTrigger.length = 0;
407   - filterArrayCondition.value.length = 0;
408   - filterArrayAction.value.length = 0;
409   - proxy.$refs.refTriggerChild?.resetFieldsValueFunc();
410   - proxy.$refs.refTriggerChild?.clearSelectDevice();
411   - proxy.$refs.refTriggerChild?.clearSelectAttribute();
412   - proxy.$refs.refConditionChild?.resetFieldsValueFunc();
413   - proxy.$refs.refConditionChild?.clearSelectDevice();
414   - proxy.$refs.refActionChild?.resetFieldsValueFunc();
415   - proxy.$refs.refActionChild?.clearSelectDevice();
416   - };
417   -
418   - const clearAllArrayFunc = () => {
419   - unref(addTriggerPushData).length = 0;
420   - unref(addConditionPushData).length = 0;
421   - unref(addActionPushData).length = 0;
422   - lastRefTriggerChildDataArray.value.length = 0;
423   - lastRefConditionChildDataArray.value.length = 0;
424   - lastRefActionChildDataArray.value.length = 0;
425   - lastEditRefTriggerChildDataArray.value.length = 0;
426   - };
427   - const resetActionsAllArrayFunc = () => {
428   - try {
429   - proxy.$refs.refActionChild.resetFieldsValueFunc();
430   - } catch (e) {
431   - return e;
432   - }
433   - };
434   - const clearActionsAllDevice = () => {
435   - try {
436   - proxy.$refs.refActionChild.clearSelectDevice();
437   - } catch (e) {
438   - return e;
439   - }
440   - };
441   -
442   - watch(getData, async (newV: string) => {
443   - oldOrigzaition.value = newV;
444   - const options = await screenLinkPageByDeptIdGetDevice({ organizationId: newV });
445   - optionsItemArray.value = options.items.map((v) => {
  306 + watch(changeOriginId, async (newV: string) => {
  307 + const result = await screenLinkPageByDeptIdGetDevice({ organizationId: newV });
  308 + optionsItemDeviceId.value = result.items.map((v) => {
446 309 return {
447 310 value: v.tbDeviceId,
448 311 label: v.name,
449 312 };
450 313 });
451 314 setTimeout(() => {
452   - proxy.$refs.refTriggerChild?.updateFieldDeviceId(optionsItemArray.value);
453   - proxy.$refs.refConditionChild?.updateFieldDeviceId(optionsItemArray.value);
454   - proxy.$refs.refActionChild?.updateFieldDeviceId(optionsItemArray.value);
  315 + proxy.$refs.triggerBindRef?.updateFieldDeviceId(optionsItemDeviceId.value);
  316 + proxy.$refs.conditionBindRef?.updateFieldDeviceId(optionsItemDeviceId.value);
  317 + proxy.$refs.actionBindRef?.updateFieldDeviceId(optionsItemDeviceId.value);
455 318 }, 10);
456 319 });
457 320
458   - //获取触发器方法
459   - const refTriggerChildDataFunc = () => {
460   - try {
461   - refTriggerChildData = proxy.$refs.refTriggerChild.getFieldsValueFunc();
462   - } catch (e) {
463   - return e;
464   - }
465   - };
466   - //获取执行条件方法
467   - const refConditionChildDataFunc = () => {
  321 + /**
  322 + * 获取触发器表单值
  323 + */
  324 + const getTriggerFormValueFunc = () => {
468 325 try {
469   - refConditionChildData = proxy.$refs.refConditionChild.getFieldsValueFunc();
470   - } catch (e) {
471   - return e;
472   - }
  326 + getTriggerFormValue = proxy.$refs.triggerBindRef.getFieldsValueFunc();
  327 + } catch {}
473 328 };
474   - //获取执行动作方法
475   - const refActionChildDataFunc = () => {
476   - try {
477   - refActionChildData = proxy.$refs.refActionChild.getFieldsValueFunc();
478   - } catch (e) {
479   - return e;
  329 + const triggerClickAdd = (e) => {
  330 + if (!e) {
  331 + getTriggerFormValueFunc();
  332 + triggerData.push(getTriggerFormValue as never);
  333 + setTimeout(() => {
  334 + proxy.$refs.triggerBindRef?.updateFieldDeviceId(optionsItemDeviceId.value);
  335 + }, 10);
  336 + } else {
  337 + //TODO
  338 + editTriggerData.value.push(getTriggerFormValue);
480 339 }
481 340 };
482   -
483   - const getDefaultValue = () => {
484   - if (!unref(isUpdate)) {
485   - refTriggerChildDataFunc();
486   - refConditionChildDataFunc();
487   - refActionChildDataFunc();
488   - let newTriggerArray = addTriggerPushData.value.concat(refTriggerChildData);
489   - let newConditionArray = addConditionPushData.value.concat(refConditionChildData);
490   - let newActionArray = addActionPushData.value.concat(refActionChildData);
491   - (newTriggerArray as any) = newTriggerArray.map((m: any) => {
492   - return {
493   - triggerType: m?.triggerType,
494   - entityId: m?.entityId || m?.entityId1 || m?.entityId2,
495   - triggerCondition: {
496   - condition: [
497   - {
498   - key: {
499   - key: m.type2 == null ? 'CO2' : m.type2,
500   - type: m.type1 == null ? 'TIME_SERIES' : m.type1,
501   - },
502   - valueType: 'NUMERIC',
503   - predicate: {
504   - type: 'NUMERIC',
505   - value: {
506   - defaultValue: Number(m.value),
507   - },
508   - operation: m.operation == null ? 'EQUAL' : m.operation,
509   - },
510   - },
511   - ],
512   - spec: {
513   - type: 'SIMPLE',
514   - },
515   - },
516   - };
517   - });
518   - (newConditionArray as any) = newConditionArray.map((m: any) => {
519   - return {
520   - triggerType: m?.triggerType,
521   - entityId: m?.entityId,
522   - triggerCondition: {
523   - condition: [
524   - {
525   - key: {
526   - key: m.type == null ? 'CO2' : m.type,
527   - type: 'TIME_SERIES',
528   - },
529   - valueType: 'NUMERIC',
530   - // value: {},
531   - predicate: {
532   - type: 'NUMERIC',
533   - value: {
534   - defaultValue: Number(m.value) == null ? 0 : Number(m.value),
535   - },
536   - operation: m.operation,
537   - },
538   - },
539   - ],
540   - spec: {
541   - type: 'SIMPLE',
542   - },
543   - },
544   - };
545   - });
546   - newTriggerArray.shift();
547   - newConditionArray.shift();
548   - newActionArray.shift();
549   - delete getAllFormData.id;
550   - delete getAllFormData.getTenantId;
551   - triggersObj = {
552   - triggers: newTriggerArray,
553   - };
554   - conditionsObj = {
555   - doConditions: newConditionArray,
556   - };
557   - actionsObj = {
558   - doActions: newActionArray,
559   - };
560   - Object.assign(getAllFormData, triggersObj, conditionsObj, actionsObj);
  341 + const triggerClickRemove = (e) => {
  342 + if (!e) {
  343 + triggerData.pop();
561 344 } else {
562   - editTriggerPushData.value.forEach((f) => {
563   - kongTriggerObj = f;
564   - pushEditArray.value.push(kongTriggerObj);
565   - });
566   - editConditionPushData.value.forEach((f) => {
567   - kongConditionObj = f;
568   - pushEditConditionArray.value.push(kongConditionObj);
569   - });
570   - editActionPushData.value.forEach((f) => {
571   - kongActionObj = f;
572   - pushEditActionArray.value.push(kongActionObj);
573   - });
574   - refTriggerChildDataFunc();
575   - let newTriggerArray = pushEditArray.value.concat(refTriggerChildData);
576   - newTriggerArray = newTriggerArray.filter((f) => Object.keys(f).length !== 0);
577   - newTriggerArray.shift();
578   - triggersObj = {
579   - triggers: isNoChange.value ? editTriggerPushData.value : newTriggerArray,
580   - };
581   - refConditionChildDataFunc();
582   - let newConditionArray = pushEditConditionArray.value.concat(refConditionChildData);
583   - newConditionArray = newConditionArray.filter((f) => Object.keys(f).length !== 0);
584   - newConditionArray.shift();
585   - conditionsObj = {
586   - doConditions: newConditionArray,
587   - };
588   - refActionChildDataFunc();
589   - let newActionArray = pushEditActionArray.value.concat(refActionChildData);
590   - newActionArray = newActionArray.filter((f) => Object.keys(f).length !== 0);
591   - newActionArray.shift();
592   - actionsObj = {
593   - doActions: newActionArray,
594   - };
595   - Object.assign(getAllFormData, triggersObj, conditionsObj, actionsObj);
  345 + editTriggerData.value.pop();
596 346 }
597 347 };
598 348
599   - const handleSubmit = async () => {
600   - if (!unref(isUpdate)) {
601   - getDefaultValue();
602   - getValuesFormData = await validateFields();
603   - if (!getValuesFormData) return;
604   - let isKongNum = 0;
605   - getAllFormData.doActions.forEach((f) => {
606   - isKongNum = Object.keys(f).length;
607   - });
608   - if (getAllFormData.doActions.length == 1 && isKongNum == 0)
609   - return createMessage.error('请填写执行动作');
610   - Object.assign(getAllFormData, getValuesFormData);
611   - await screenLinkPageAddApi(getAllFormData);
612   - createMessage.success('场景联动新增成功');
613   - closeDrawer();
614   - emit('success');
615   - } else {
616   - getDefaultValue();
617   - getValuesFormData = await validateFields();
618   - Object.assign(getAllFormData, getValuesFormData);
619   - getAllFormData.id = getId.value;
620   - getAllFormData.tenantId = getTenantId.value;
621   - refTriggerChildData = {};
622   - refConditionChildData = {};
623   - refActionChildData = {};
624   - pushEditArray.value.length = 0;
625   - pushEditConditionArray.value.length = 0;
626   - pushEditActionArray.value.length = 0;
627   - await screenLinkPageUpdateApi(getAllFormData);
628   - createMessage.success('场景联动编辑成功');
629   - closeDrawer();
630   - emit('success');
631   - }
  349 + /**
  350 + * 获取执行条件表单值
  351 + */
  352 + const getConditionFormValueFunc = () => {
  353 + try {
  354 + getConditionFormValue = proxy.$refs.conditionBindRef.getFieldsValueFunc();
  355 + } catch {}
632 356 };
633   - //新增触发器
634   - const addTrigger = () => {
635   - if (!unref(isUpdate)) {
636   - refTriggerChildDataFunc();
637   - unref(addTriggerPushData).push(refTriggerChildData as never);
  357 + const conditionClickAdd = (e) => {
  358 + if (!e) {
  359 + getConditionFormValueFunc();
  360 + conditionData.push(getConditionFormValue as never);
638 361 setTimeout(() => {
639   - proxy.$refs.refTriggerChild?.updateFieldDeviceId(optionsItemArray.value);
640   - }, 20);
  362 + proxy.$refs.conditionBindRef?.updateFieldDeviceId(optionsItemDeviceId.value);
  363 + }, 10);
641 364 } else {
642   - isNoChange.value = false;
643   - unref(editTriggerPushData).push(refTriggerChildData as never);
644   - refTriggerChildDataFunc();
645   - pushEditArray.value.push(refTriggerChildData);
646   - pushEditArray.value = pushEditArray.value.map((m) => {
647   - return {
648   - triggerType: m?.triggerType,
649   - entityId: m?.entityId || m?.entityId1 || m?.entityId2,
650   - triggerCondition: {
651   - condition: [
652   - {
653   - key: {
654   - key: m.type2 == null ? 'CO2' : m.type2,
655   - type: m.type1 == null ? 'TIME_SERIES' : m.type1,
656   - },
657   - valueType: 'NUMERIC',
658   - predicate: {
659   - type: 'NUMERIC',
660   - value: {
661   - defaultValue: Number(m.value),
662   - },
663   - operation: m.operation == null ? 'EQUAL' : m.operation,
664   - },
665   - },
666   - ],
667   - spec: {
668   - type: 'SIMPLE',
669   - },
670   - },
671   - };
672   - });
673   - try {
674   - setTimeout(() => {
675   - proxy.$refs.refTriggerChild?.updateFieldDeviceId({
676   - status: 'edit',
677   - item: optionsEditArray.value,
678   - });
679   - }, 20);
680   - } catch (e) {
681   - return e;
682   - }
683   - refTriggerChildData = {};
  365 + //TODO
684 366 }
685 367 };
686   - const removeTrigger = () => {
687   - if (!unref(isUpdate)) {
688   - try {
689   - unref(addTriggerPushData).pop();
690   - } catch (e) {
691   - return e;
692   - }
  368 + const conditionClickRemove = (e) => {
  369 + if (!e) {
  370 + conditionData.pop();
693 371 } else {
694   - try {
695   - unref(editTriggerPushData).pop();
696   - } catch (e) {
697   - return e;
698   - }
  372 + editConditionData.value.pop();
699 373 }
700 374 };
701 375
702   - //新增执行条件
703   - const addCondition = () => {
704   - if (!unref(isUpdate)) {
705   - refConditionChildDataFunc();
706   - unref(addConditionPushData).push(refConditionChildData as never);
707   - try {
708   - setTimeout(() => {
709   - proxy.$refs.refConditionChild?.updateFieldDeviceId(optionsItemArray.value);
710   - }, 20);
711   - } catch (e) {
712   - return e;
713   - }
714   - } else {
715   - isNoChange.value = false;
716   - unref(editConditionPushData).push(refConditionChildData as never);
717   - refConditionChildDataFunc();
718   - pushEditConditionArray.value.push(refConditionChildData);
719   - pushEditConditionArray.value = pushEditConditionArray.value.map((m) => {
720   - return {
721   - triggerType: m?.triggerType,
722   - entityId: m?.entityId,
723   - triggerCondition: {
724   - condition: [
725   - {
726   - key: {
727   - key: m.type == null ? 'CO2' : m.type,
728   - type: 'TIME_SERIES',
729   - },
730   - valueType: 'NUMERIC',
731   - // value: {},
732   - predicate: {
733   - type: 'NUMERIC',
734   - value: {
735   - defaultValue: Number(m.value) == null ? 0 : Number(m.value),
736   - },
737   - operation: m.operation,
738   - },
739   - },
740   - ],
741   - spec: {
742   - type: 'SIMPLE',
743   - },
744   - },
745   - };
746   - });
747   - try {
748   - setTimeout(() => {
749   - proxy.$refs.refConditionChild?.updateFieldDeviceId({
750   - status: 'edit',
751   - item: optionsEditArray.value,
752   - });
753   - }, 20);
754   - } catch (e) {
755   - return e;
756   - }
757   - refConditionChildData = {};
  376 + /**
  377 + * 获取执行动作表单值
  378 + */
  379 + const getActionFormValueFunc = () => {
  380 + try {
  381 + getActionFormValue = proxy.$refs.actionBindRef.getFieldsValueFunc();
  382 + } catch {}
  383 + };
  384 + //默认新增执行动作
  385 + const defaultAddAction = () => {
  386 + if (actionData.length == 0) {
  387 + actionClickAdd(false);
758 388 }
759 389 };
760   - const removeCondition = () => {
761   - if (!unref(isUpdate)) {
762   - try {
763   - unref(addConditionPushData).pop();
764   - } catch (e) {
765   - return e;
766   - }
  390 + const actionClickAdd = (e) => {
  391 + if (!e) {
  392 + getActionFormValueFunc();
  393 + actionData.push(getActionFormValue as never);
  394 + setTimeout(() => {
  395 + proxy.$refs.actionBindRef?.updateFieldDeviceId(optionsItemDeviceId.value);
  396 + }, 10);
767 397 } else {
768   - try {
769   - unref(editConditionPushData).pop();
770   - } catch (e) {
771   - return e;
772   - }
  398 + //TODO
773 399 }
774 400 };
775   -
776   - //默认新增执行动作
777   - const defaultAddAction = () => {
778   - if (unref(addActionPushData).length == 0) {
779   - addAction();
  401 + const actionClickRemove = (e) => {
  402 + if (!e) {
  403 + actionData.pop();
  404 + } else {
  405 + editActionData.value.pop();
780 406 }
781 407 };
782   - //新增执行动作
783   - const addAction = () => {
784   - if (!unref(isUpdate)) {
785   - refActionChildDataFunc();
786   - unref(addActionPushData).push(refActionChildData as never);
787   - try {
788   - setTimeout(() => {
789   - proxy.$refs.refActionChild.updateFieldDeviceId(optionsItemArray.value);
790   - }, 20);
791   - } catch (e) {
792   - return e;
793   - }
  408 + const submitOrEditFunc = (e) => {
  409 + if (!e) {
  410 + getTriggerFormValueFunc();
  411 + concatTrigger = triggerData.concat(getTriggerFormValue);
  412 + //去除第一个空对象
  413 + concatTrigger.shift();
  414 + concatTrigger = concatTrigger.map((m) => formatTriggerData(m));
  415 + getConditionFormValueFunc();
  416 + concatCondition = conditionData.concat(getConditionFormValue);
  417 + //去除第一个空对象
  418 + concatCondition.shift();
  419 + concatCondition = concatCondition.map((m) => formatConditionData(m));
  420 + getActionFormValueFunc();
  421 + concatAction = actionData.concat(getActionFormValue);
  422 + // 去除第一个空对象;
  423 + concatAction.shift();
794 424 } else {
795   - isNoChange.value = false;
796   - unref(editActionPushData).push(refActionChildData as never);
797   - refActionChildDataFunc();
798   - pushEditActionArray.value.push(refActionChildData);
799   - try {
800   - setTimeout(() => {
801   - proxy.$refs.refActionChild.updateFieldDeviceId({
802   - status: 'edit',
803   - item: optionsEditArray.value,
804   - });
805   - }, 20);
806   - } catch (e) {
807   - return e;
808   - }
809   - refActionChildData = {};
  425 + //TODO
810 426 }
811 427 };
812   - const removeAction = () => {
813   - if (!unref(isUpdate)) {
814   - try {
815   - unref(addActionPushData).pop();
816   - } catch (e) {
817   - return e;
818   - }
  428 +
  429 + const handleSubmit = async (e) => {
  430 + let basicFormValue = await validate();
  431 + if (!basicFormValue) return;
  432 + if (!e) {
  433 + submitOrEditFunc(e);
  434 + let isKongNum = 0;
  435 + concatAction.forEach((f) => {
  436 + isKongNum = Object.keys(f).length;
  437 + });
  438 + if (concatAction.length == 1 && isKongNum == 0)
  439 + return createMessage.error('请填写执行动作');
  440 + postAddOrEditData = {
  441 + ...basicFormValue,
  442 + ...{
  443 + triggers: concatTrigger,
  444 + },
  445 + ...{
  446 + doConditions: concatCondition,
  447 + },
  448 + ...{
  449 + doActions: concatAction,
  450 + },
  451 + };
  452 + await screenLinkPageAddApi(postAddOrEditData);
  453 + createMessage.success('新增成功');
  454 + closeDrawer();
  455 + emit('success');
819 456 } else {
820   - try {
821   - unref(editActionPushData).pop();
822   - } catch (e) {
823   - return e;
824   - }
  457 + submitOrEditFunc(e);
  458 + postAddOrEditData = {
  459 + ...basicFormValue,
  460 + ...{ id: getId.value },
  461 + ...{ tenantId: getTenantId.value },
  462 + };
  463 + await screenLinkPageUpdateApi(postAddOrEditData);
  464 + createMessage.success('编辑成功');
  465 + closeDrawer();
  466 + emit('success');
825 467 }
826 468 };
  469 + const handleClose = () => {
  470 + closeDrawer();
  471 + };
827 472
828 473 return {
829   - handleClose,
830   - newFilterMap,
831   - newConditionFilterMap,
832   - newActionFilterMap,
833   - editTriggerPushData,
834   - editConditionPushData,
835   - editActionPushData,
836   - isUpdate,
837   - clearActionsAllDevice,
838   - getDeviceInfo,
839   - getDeviceInfo1,
840   - getDeviceInfo2,
841   - resetActionsAllArrayFunc,
842   - addActionPushData,
843   - defaultAddAction,
844   - refActionChild,
845   - addAction,
846   - removeAction,
847   - addConditionPushData,
848   - refConditionChild,
849   - addCondition,
850   - removeCondition,
851   - clearAllArrayFunc,
852   - removeTrigger,
853   - addTriggerPushData,
854   - addTriggerData,
855   - addTrigger,
856   - getConditionChildData,
857   - refTriggerChild,
858   - getChildData,
859   - getAllFormData,
860 474 registerDrawer,
861 475 registerForm,
862   - getTitle,
  476 + triggerData,
  477 + triggerClickAdd,
  478 + triggerClickRemove,
  479 + conditionClickAdd,
  480 + conditionClickRemove,
  481 + actionClickAdd,
  482 + actionClickRemove,
  483 + triggerBindRef,
  484 + conditionBindRef,
  485 + actionBindRef,
863 486 handleSubmit,
  487 + handleClose,
  488 + drawerStatus,
  489 + conditionData,
  490 + actionData,
  491 + editTriggerData,
  492 + editConditionData,
  493 + editActionData,
  494 + getTriggerFatherEntryIdData,
  495 + getConditionFatherEntryIdData,
  496 + getActionFatherEntryIdData,
864 497 };
865 498 },
866 499 });
867 500 </script>
868 501
869   -<style lang="less" scoped>
870   - .condition-style {
871   - :deep .ant-calendar-picker {
872   - width: 24.9vw !important;
873   - }
874   - }
875   -</style>
  502 +<style lang="less" scoped></style>
... ...