Commit d6954312ba4a32d08ce67107274c776e9d912983

Authored by fengtao
1 parent a5b42b0f

fix:修复场景联动新增数据重复问题,fix:修复场景联动编辑数据重复问题

... ... @@ -167,7 +167,7 @@
167 167 import AddTriggerForm from './addForm/trigger.vue';
168 168 import AddConditiForm from './addForm/condition.vue';
169 169 import AddActionForm from './addForm/doaction.vue';
170   - import { IAddTrigger, IAddCondition, IAddAction } from './index';
  170 + import { IAddTrigger } from './index';
171 171 import { Button } from '/@/components/Button';
172 172
173 173 export default defineComponent({
... ... @@ -184,8 +184,6 @@
184 184 setup(_, { emit }) {
185 185 const { proxy } = getCurrentInstance();
186 186 const lastEditRefTriggerChildDataArray = ref<[]>([]);
187   - const lastEditRefConditionChildDataArray = ref<[]>([]);
188   - const lastEditRefActionChildDataArray = ref<[]>([]);
189 187 const lastRefTriggerChildDataArray = ref<[]>([]);
190 188 const lastRefConditionChildDataArray = ref<[]>([]);
191 189 const lastRefActionChildDataArray = ref<[]>([]);
... ... @@ -200,20 +198,6 @@
200 198 compare: '',
201 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 201 const addTriggerPushData = ref<[]>([]);
218 202 const addConditionPushData = ref<[]>([]);
219 203 const addActionPushData = ref<[]>([]);
... ... @@ -240,8 +224,8 @@
240 224 const newActionFilterMap = ref<[]>([]);
241 225 let filterNewConditionArr = [];
242 226 const pushEditArray = ref<any>([{}]);
243   - const pushEditConditionArray = [];
244   - const pushEditActionArray = [];
  227 + const pushEditConditionArray = ref<any>([{}]);
  228 + const pushEditActionArray = ref<any>([{}]);
245 229 let filterArrayTrigger = [];
246 230 const filterArrayCondition = ref<[]>([]);
247 231 const filterArrayAction = ref<[]>([]);
... ... @@ -316,6 +300,10 @@
316 300 try {
317 301 pushEditArray.value = [];
318 302 pushEditArray.value.length = 0;
  303 + pushEditConditionArray.value.length = 0;
  304 + pushEditConditionArray.value = [];
  305 + pushEditActionArray.value = [];
  306 + pushEditActionArray.value.length = 0;
319 307 newFilterMap.value = [];
320 308 newConditionFilterMap.value = [];
321 309 newActionFilterMap.value = [];
... ... @@ -377,6 +365,8 @@
377 365 const getTitle = computed(() => (!unref(isUpdate) ? '新增场景联动' : '编辑场景联动'));
378 366 const handleClose = () => {
379 367 pushEditArray.value.length = 0;
  368 + pushEditConditionArray.value.length = 0;
  369 + pushEditActionArray.value.length = 0;
380 370 lastRefTriggerChildDataArray.value.length = 0;
381 371 lastRefTriggerChildDataArray.value = [];
382 372 lastRefConditionChildDataArray.value.length = 0;
... ... @@ -484,10 +474,20 @@
484 474 Object.assign(getAllFormData, triggersObj, conditionsObj, actionsObj);
485 475 } else {
486 476 let kongTriggerObj = {};
  477 + let kongConditionObj = {};
  478 + let kongActionObj = {};
487 479 editTriggerPushData.value.forEach((f) => {
488 480 kongTriggerObj = f;
489 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 491 refTriggerChildDataFunc();
492 492 let newTriggerArray = pushEditArray.value.concat(refTriggerChildData);
493 493 newTriggerArray = newTriggerArray.filter((f) => Object.keys(f).length !== 0);
... ... @@ -495,13 +495,20 @@
495 495 triggersObj = {
496 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 512 Object.assign(getAllFormData, triggersObj, conditionsObj, actionsObj);
506 513 }
507 514 };
... ... @@ -525,10 +532,13 @@
525 532 getAllFormData.tenantId = getTenantId.value;
526 533 refTriggerChildData = {};
527 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 614 },
605 615 };
606 616 });
607   - console.log(pushEditArray.value);
608   -
609 617 try {
610 618 setTimeout(() => {
611 619 proxy.$refs.refTriggerChild.updateFieldDeviceId(optionsItemArray.value);
... ... @@ -688,9 +696,61 @@
688 696 return e;
689 697 }
690 698 } else {
  699 + isNoChange.value = false;
  700 + unref(editConditionPushData).push(refConditionChildData as never);
691 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 756 const removeCondition = () => {
... ... @@ -703,7 +763,6 @@
703 763 } else {
704 764 try {
705 765 unref(editConditionPushData).splice(0, 1);
706   - lastEditRefConditionChildDataArray.value.pop();
707 766 } catch (e) {
708 767 return e;
709 768 }
... ... @@ -729,9 +788,18 @@
729 788 return e;
730 789 }
731 790 } else {
  791 + isNoChange.value = false;
  792 + unref(editActionPushData).push(refActionChildData as never);
732 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 805 const removeAction = () => {
... ... @@ -744,7 +812,6 @@
744 812 } else {
745 813 try {
746 814 unref(editActionPushData).splice(0, 1);
747   - lastEditRefActionChildDataArray.value.pop();
748 815 } catch (e) {
749 816 return e;
750 817 }
... ...