浏览代码

紧急修正:防止频道页组件超出实际数据量

紧急修正:防止频道页组件超出实际数据量
dangyunlong 1 天之前
父节点
当前提交
d72aaee348
共有 1 个文件被更改,包括 13 次插入12 次删除
  1. 13 12
      pages/[dir]/index.html.vue

+ 13 - 12
pages/[dir]/index.html.vue

@@ -136,7 +136,7 @@ const response:any = await requestDataPromise('/client/indexData', {
     },
 });
 const templateData = response.data.template.class;
-console.log(templateData)
+//console.log(templateData)
 //2.2.1循环一下模板数据,把所有需要请求后端内容的组件里面imgSize和textSize拿出来
 const getIndex = ref<number>(0);
 for(let item of templateData){
@@ -177,36 +177,37 @@ if (mkdata.code == 200) {
     for(let item of mkdata.data){
         childData.value.push(item.child)
     }
-    //把data中的childData拿出来
-    //console.log(childData.value)
     let dataSort = ref<number>(0);
+    const childDataLength = childData.value.length;
+    //如果当前循环的这个组件数据长度已经超过了所有子频道的总数居量,则从0开始循环
+    //此操作是为了防止B端创建的组件数超过了后台的导航数量
     for(let item of templateData){
         if(item.sectorName == 'scrollTextSector'){
-            item.componentList[0].componentData.data = childData.value[dataSort.value]
+            item.componentList[0].componentData.data = childData.value[dataSort.value % childDataLength];
             dataSort.value++;
         }
         if(item.sectorName == 'manyPictureSector'){
-            item.componentList[0].componentData.data = childData.value[dataSort.value]
+            item.componentList[0].componentData.data = childData.value[dataSort.value % childDataLength];
             dataSort.value++;
-            item.componentList[1].componentData.data = childData.value[dataSort.value]
+            item.componentList[1].componentData.data = childData.value[dataSort.value % childDataLength];
             dataSort.value++;
         }
         if(item.sectorName == 'commentSector'){
-            item.componentList[0].componentData.data = childData.value[dataSort.value]
+            item.componentList[0].componentData.data = childData.value[dataSort.value % childDataLength];
             dataSort.value++;
-            item.componentList[1].componentData.data = childData.value[dataSort.value]
+            item.componentList[1].componentData.data = childData.value[dataSort.value % childDataLength];
             dataSort.value++;
         }
         if(item.sectorName == 'listSector'){
-            item.componentList[0].componentData.data = childData.value[dataSort.value]
+            item.componentList[0].componentData.data = childData.value[dataSort.value % childDataLength];
             dataSort.value++;
-            item.componentList[1].componentData.data = childData.value[dataSort.value]
+            item.componentList[1].componentData.data = childData.value[dataSort.value % childDataLength];
             dataSort.value++;
-            item.componentList[2].componentData.data = childData.value[dataSort.value]
+            item.componentList[2].componentData.data = childData.value[dataSort.value % childDataLength];
             dataSort.value++;
         }
     }
-    console.log(templateData)
+    //console.log(templateData)
 }
 //2.5广告数据
 const adData:any = ref([]);