Commit d6954312ba4a32d08ce67107274c776e9d912983
1 parent
a5b42b0f
fix:修复场景联动新增数据重复问题,fix:修复场景联动编辑数据重复问题
Showing
1 changed file
with
105 additions
and
38 deletions
@@ -167,7 +167,7 @@ | @@ -167,7 +167,7 @@ | ||
167 | import AddTriggerForm from './addForm/trigger.vue'; | 167 | import AddTriggerForm from './addForm/trigger.vue'; |
168 | import AddConditiForm from './addForm/condition.vue'; | 168 | import AddConditiForm from './addForm/condition.vue'; |
169 | import AddActionForm from './addForm/doaction.vue'; | 169 | import AddActionForm from './addForm/doaction.vue'; |
170 | - import { IAddTrigger, IAddCondition, IAddAction } from './index'; | 170 | + import { IAddTrigger } from './index'; |
171 | import { Button } from '/@/components/Button'; | 171 | import { Button } from '/@/components/Button'; |
172 | 172 | ||
173 | export default defineComponent({ | 173 | export default defineComponent({ |
@@ -184,8 +184,6 @@ | @@ -184,8 +184,6 @@ | ||
184 | setup(_, { emit }) { | 184 | setup(_, { emit }) { |
185 | const { proxy } = getCurrentInstance(); | 185 | const { proxy } = getCurrentInstance(); |
186 | const lastEditRefTriggerChildDataArray = ref<[]>([]); | 186 | const lastEditRefTriggerChildDataArray = ref<[]>([]); |
187 | - const lastEditRefConditionChildDataArray = ref<[]>([]); | ||
188 | - const lastEditRefActionChildDataArray = ref<[]>([]); | ||
189 | const lastRefTriggerChildDataArray = ref<[]>([]); | 187 | const lastRefTriggerChildDataArray = ref<[]>([]); |
190 | const lastRefConditionChildDataArray = ref<[]>([]); | 188 | const lastRefConditionChildDataArray = ref<[]>([]); |
191 | const lastRefActionChildDataArray = ref<[]>([]); | 189 | const lastRefActionChildDataArray = ref<[]>([]); |
@@ -200,20 +198,6 @@ | @@ -200,20 +198,6 @@ | ||
200 | compare: '', | 198 | compare: '', |
201 | value: '', | 199 | value: '', |
202 | }); | 200 | }); |
203 | - const addConditionData = reactive<IAddCondition>({ | ||
204 | - triggerType: '', | ||
205 | - entityId: '', | ||
206 | - createTime: '', | ||
207 | - updateTime: '', | ||
208 | - compare: '', | ||
209 | - value: '', | ||
210 | - }); | ||
211 | - const addActionData = reactive<IAddAction>({ | ||
212 | - outTarget: '', | ||
213 | - deviceId: '', | ||
214 | - command: '', | ||
215 | - sceneLinkageId: '', | ||
216 | - }); | ||
217 | const addTriggerPushData = ref<[]>([]); | 201 | const addTriggerPushData = ref<[]>([]); |
218 | const addConditionPushData = ref<[]>([]); | 202 | const addConditionPushData = ref<[]>([]); |
219 | const addActionPushData = ref<[]>([]); | 203 | const addActionPushData = ref<[]>([]); |
@@ -240,8 +224,8 @@ | @@ -240,8 +224,8 @@ | ||
240 | const newActionFilterMap = ref<[]>([]); | 224 | const newActionFilterMap = ref<[]>([]); |
241 | let filterNewConditionArr = []; | 225 | let filterNewConditionArr = []; |
242 | const pushEditArray = ref<any>([{}]); | 226 | const pushEditArray = ref<any>([{}]); |
243 | - const pushEditConditionArray = []; | ||
244 | - const pushEditActionArray = []; | 227 | + const pushEditConditionArray = ref<any>([{}]); |
228 | + const pushEditActionArray = ref<any>([{}]); | ||
245 | let filterArrayTrigger = []; | 229 | let filterArrayTrigger = []; |
246 | const filterArrayCondition = ref<[]>([]); | 230 | const filterArrayCondition = ref<[]>([]); |
247 | const filterArrayAction = ref<[]>([]); | 231 | const filterArrayAction = ref<[]>([]); |
@@ -316,6 +300,10 @@ | @@ -316,6 +300,10 @@ | ||
316 | try { | 300 | try { |
317 | pushEditArray.value = []; | 301 | pushEditArray.value = []; |
318 | pushEditArray.value.length = 0; | 302 | pushEditArray.value.length = 0; |
303 | + pushEditConditionArray.value.length = 0; | ||
304 | + pushEditConditionArray.value = []; | ||
305 | + pushEditActionArray.value = []; | ||
306 | + pushEditActionArray.value.length = 0; | ||
319 | newFilterMap.value = []; | 307 | newFilterMap.value = []; |
320 | newConditionFilterMap.value = []; | 308 | newConditionFilterMap.value = []; |
321 | newActionFilterMap.value = []; | 309 | newActionFilterMap.value = []; |
@@ -377,6 +365,8 @@ | @@ -377,6 +365,8 @@ | ||
377 | const getTitle = computed(() => (!unref(isUpdate) ? '新增场景联动' : '编辑场景联动')); | 365 | const getTitle = computed(() => (!unref(isUpdate) ? '新增场景联动' : '编辑场景联动')); |
378 | const handleClose = () => { | 366 | const handleClose = () => { |
379 | pushEditArray.value.length = 0; | 367 | pushEditArray.value.length = 0; |
368 | + pushEditConditionArray.value.length = 0; | ||
369 | + pushEditActionArray.value.length = 0; | ||
380 | lastRefTriggerChildDataArray.value.length = 0; | 370 | lastRefTriggerChildDataArray.value.length = 0; |
381 | lastRefTriggerChildDataArray.value = []; | 371 | lastRefTriggerChildDataArray.value = []; |
382 | lastRefConditionChildDataArray.value.length = 0; | 372 | lastRefConditionChildDataArray.value.length = 0; |
@@ -484,10 +474,20 @@ | @@ -484,10 +474,20 @@ | ||
484 | Object.assign(getAllFormData, triggersObj, conditionsObj, actionsObj); | 474 | Object.assign(getAllFormData, triggersObj, conditionsObj, actionsObj); |
485 | } else { | 475 | } else { |
486 | let kongTriggerObj = {}; | 476 | let kongTriggerObj = {}; |
477 | + let kongConditionObj = {}; | ||
478 | + let kongActionObj = {}; | ||
487 | editTriggerPushData.value.forEach((f) => { | 479 | editTriggerPushData.value.forEach((f) => { |
488 | kongTriggerObj = f; | 480 | kongTriggerObj = f; |
489 | pushEditArray.value.push(kongTriggerObj); | 481 | pushEditArray.value.push(kongTriggerObj); |
490 | }); | 482 | }); |
483 | + editConditionPushData.value.forEach((f) => { | ||
484 | + kongConditionObj = f; | ||
485 | + pushEditConditionArray.value.push(kongConditionObj); | ||
486 | + }); | ||
487 | + editActionPushData.value.forEach((f) => { | ||
488 | + kongActionObj = f; | ||
489 | + pushEditActionArray.value.push(kongActionObj); | ||
490 | + }); | ||
491 | refTriggerChildDataFunc(); | 491 | refTriggerChildDataFunc(); |
492 | let newTriggerArray = pushEditArray.value.concat(refTriggerChildData); | 492 | let newTriggerArray = pushEditArray.value.concat(refTriggerChildData); |
493 | newTriggerArray = newTriggerArray.filter((f) => Object.keys(f).length !== 0); | 493 | newTriggerArray = newTriggerArray.filter((f) => Object.keys(f).length !== 0); |
@@ -495,13 +495,20 @@ | @@ -495,13 +495,20 @@ | ||
495 | triggersObj = { | 495 | triggersObj = { |
496 | triggers: isNoChange.value ? editTriggerPushData.value : newTriggerArray, | 496 | triggers: isNoChange.value ? editTriggerPushData.value : newTriggerArray, |
497 | }; | 497 | }; |
498 | - console.log(triggersObj); | ||
499 | - // conditionsObj = { | ||
500 | - // doConditions: newConditionArray, | ||
501 | - // }; | ||
502 | - // actionsObj = { | ||
503 | - // doActions: newActionArray, | ||
504 | - // }; | 498 | + refConditionChildDataFunc(); |
499 | + let newConditionArray = pushEditConditionArray.value.concat(refConditionChildData); | ||
500 | + newConditionArray = newConditionArray.filter((f) => Object.keys(f).length !== 0); | ||
501 | + newConditionArray.shift(); | ||
502 | + conditionsObj = { | ||
503 | + doConditions: newConditionArray, | ||
504 | + }; | ||
505 | + refActionChildDataFunc(); | ||
506 | + let newActionArray = pushEditActionArray.value.concat(refActionChildData); | ||
507 | + newActionArray = newActionArray.filter((f) => Object.keys(f).length !== 0); | ||
508 | + newActionArray.shift(); | ||
509 | + actionsObj = { | ||
510 | + doActions: newActionArray, | ||
511 | + }; | ||
505 | Object.assign(getAllFormData, triggersObj, conditionsObj, actionsObj); | 512 | Object.assign(getAllFormData, triggersObj, conditionsObj, actionsObj); |
506 | } | 513 | } |
507 | }; | 514 | }; |
@@ -525,10 +532,13 @@ | @@ -525,10 +532,13 @@ | ||
525 | getAllFormData.tenantId = getTenantId.value; | 532 | getAllFormData.tenantId = getTenantId.value; |
526 | refTriggerChildData = {}; | 533 | refTriggerChildData = {}; |
527 | pushEditArray.value.length = 0; | 534 | pushEditArray.value.length = 0; |
528 | - // await screenLinkPageUpdateApi(getAllFormData); | ||
529 | - // createMessage.success('场景联动编辑成功'); | ||
530 | - // closeDrawer(); | ||
531 | - // emit('success'); | 535 | + pushEditConditionArray.value.length = 0; |
536 | + pushEditActionArray.value.length = 0; | ||
537 | + console.log('edit data', getAllFormData); | ||
538 | + await screenLinkPageUpdateApi(getAllFormData); | ||
539 | + createMessage.success('场景联动编辑成功'); | ||
540 | + closeDrawer(); | ||
541 | + emit('success'); | ||
532 | } | 542 | } |
533 | }; | 543 | }; |
534 | //新增触发器 | 544 | //新增触发器 |
@@ -604,8 +614,6 @@ | @@ -604,8 +614,6 @@ | ||
604 | }, | 614 | }, |
605 | }; | 615 | }; |
606 | }); | 616 | }); |
607 | - console.log(pushEditArray.value); | ||
608 | - | ||
609 | try { | 617 | try { |
610 | setTimeout(() => { | 618 | setTimeout(() => { |
611 | proxy.$refs.refTriggerChild.updateFieldDeviceId(optionsItemArray.value); | 619 | proxy.$refs.refTriggerChild.updateFieldDeviceId(optionsItemArray.value); |
@@ -688,9 +696,61 @@ | @@ -688,9 +696,61 @@ | ||
688 | return e; | 696 | return e; |
689 | } | 697 | } |
690 | } else { | 698 | } else { |
699 | + isNoChange.value = false; | ||
700 | + unref(editConditionPushData).push(refConditionChildData as never); | ||
691 | refConditionChildDataFunc(); | 701 | refConditionChildDataFunc(); |
692 | - pushEditConditionArray.push(refConditionChildData as never); | ||
693 | - unref(editConditionPushData).push(addConditionData as never); | 702 | + pushEditConditionArray.value.push(refConditionChildData); |
703 | + pushEditConditionArray.value = pushEditConditionArray.value.map((m) => { | ||
704 | + return { | ||
705 | + triggerType: m?.triggerType, | ||
706 | + entityId: m?.entityId, | ||
707 | + triggerCondition: { | ||
708 | + condition: [ | ||
709 | + { | ||
710 | + key: { | ||
711 | + type: 'TIME_SERIES', | ||
712 | + key: 'CO2', | ||
713 | + }, | ||
714 | + valueType: | ||
715 | + m.type == 'NUMERIC1' | ||
716 | + ? 'NUMERIC' | ||
717 | + : m.type == 'NUMERIC2' | ||
718 | + ? 'NUMERIC' | ||
719 | + : 'NUMERIC', | ||
720 | + value: {}, | ||
721 | + predicate: { | ||
722 | + type: | ||
723 | + m.type == 'NUMERIC1' | ||
724 | + ? 'NUMERIC' | ||
725 | + : m.type == 'NUMERIC2' | ||
726 | + ? 'NUMERIC' | ||
727 | + : 'NUMERIC', | ||
728 | + value: { | ||
729 | + defaultValue: | ||
730 | + Number(m.value1) == null | ||
731 | + ? 0 | ||
732 | + : Number(m.value1) || Number(m.value2) == null | ||
733 | + ? 0 | ||
734 | + : Number(m.value2), | ||
735 | + }, | ||
736 | + operation: m.operation1 || m.operatio2, | ||
737 | + }, | ||
738 | + }, | ||
739 | + ], | ||
740 | + spec: { | ||
741 | + type: 'SIMPLE', | ||
742 | + }, | ||
743 | + }, | ||
744 | + }; | ||
745 | + }); | ||
746 | + try { | ||
747 | + setTimeout(() => { | ||
748 | + proxy.$refs.refConditionChild.updateFieldDeviceId(optionsItemArray.value); | ||
749 | + }, 150); | ||
750 | + } catch (e) { | ||
751 | + return e; | ||
752 | + } | ||
753 | + refConditionChildData = {}; | ||
694 | } | 754 | } |
695 | }; | 755 | }; |
696 | const removeCondition = () => { | 756 | const removeCondition = () => { |
@@ -703,7 +763,6 @@ | @@ -703,7 +763,6 @@ | ||
703 | } else { | 763 | } else { |
704 | try { | 764 | try { |
705 | unref(editConditionPushData).splice(0, 1); | 765 | unref(editConditionPushData).splice(0, 1); |
706 | - lastEditRefConditionChildDataArray.value.pop(); | ||
707 | } catch (e) { | 766 | } catch (e) { |
708 | return e; | 767 | return e; |
709 | } | 768 | } |
@@ -729,9 +788,18 @@ | @@ -729,9 +788,18 @@ | ||
729 | return e; | 788 | return e; |
730 | } | 789 | } |
731 | } else { | 790 | } else { |
791 | + isNoChange.value = false; | ||
792 | + unref(editActionPushData).push(refActionChildData as never); | ||
732 | refActionChildDataFunc(); | 793 | refActionChildDataFunc(); |
733 | - pushEditActionArray.push(refActionChildData as never); | ||
734 | - unref(editActionPushData).push(addActionData as never); | 794 | + pushEditActionArray.value.push(refActionChildData); |
795 | + try { | ||
796 | + setTimeout(() => { | ||
797 | + proxy.$refs.refActionChild.updateFieldDeviceId(optionsItemArray.value); | ||
798 | + }, 150); | ||
799 | + } catch (e) { | ||
800 | + return e; | ||
801 | + } | ||
802 | + refActionChildData = {}; | ||
735 | } | 803 | } |
736 | }; | 804 | }; |
737 | const removeAction = () => { | 805 | const removeAction = () => { |
@@ -744,7 +812,6 @@ | @@ -744,7 +812,6 @@ | ||
744 | } else { | 812 | } else { |
745 | try { | 813 | try { |
746 | unref(editActionPushData).splice(0, 1); | 814 | unref(editActionPushData).splice(0, 1); |
747 | - lastEditRefActionChildDataArray.value.pop(); | ||
748 | } catch (e) { | 815 | } catch (e) { |
749 | return e; | 816 | return e; |
750 | } | 817 | } |