bding 1 gadu atpakaļ
vecāks
revīzija
72da663f80
1 mainītis faili ar 40 papildinājumiem un 0 dzēšanām
  1. 40 0
      pages/index/index.vue

+ 40 - 0
pages/index/index.vue

@@ -144,6 +144,7 @@ export default {
       dataListLable: [], // 标签的数据
       actIdLable: "", // 标签选择后的ID
       isTopHeight: "",
+      lableArrList: [],
     };
   },
   computed: {
@@ -328,6 +329,23 @@ export default {
     async lableKeysHandler(item) {
       let actId = [];
       this.$set(item, "isAct", !item.isAct);
+      if (item.isAct) {
+        let index = this.lableArrList.findIndex((val) => val === item);
+        console.log(index);
+        index >= 0 ? (this.lableArrList = this.lableArrList.splice(index, 1)) : "";
+        this.lableArrList.push(item);
+        const firstIndex = this.findFirstIntersectingObjectIndex(this.lableArrList);
+        console.log(this.lableArrList, firstIndex);
+        if (firstIndex >= 0) {
+          this.dataListLable.forEach((item) => {
+            if (item === this.lableArrList[firstIndex]) {
+              item.isAct = !item.isAct;
+            }
+          });
+          this.lableArrList = this.lableArrList.splice(firstIndex, 1);
+        }
+      }
+
       this.lableIsRows.forEach((item) => {
         item.forEach((_) => {
           _.isAct && actId.push(_.TagId);
@@ -341,6 +359,28 @@ export default {
         TagId: item.TagId,
       });
     },
+    findFirstIntersectingObjectIndex(arr) {
+      for (let i = 0; i < arr.length - 1; i++) {
+        for (let j = i + 1; j < arr.length; j++) {
+          const checklist1 = arr[i].CheckList;
+          const checklist2 = arr[j].CheckList;
+
+          if (this.checklistsHaveIntersection(checklist1, checklist2)) {
+            return i;
+          }
+        }
+      }
+
+      return -1; // 没有找到相交的对象,返回 -1
+    },
+    checklistsHaveIntersection(arr1, arr2) {
+      for (const item of arr1) {
+        if (arr2.includes(item)) {
+          return true;
+        }
+      }
+      return false;
+    },
     // 或者标签内容
     async homeTagListCustom() {
       const res = await Home.homeTagListCustom();