Kaynağa Gözat

更新新英语切换

wangxy 2 ay önce
ebeveyn
işleme
318e4fdf24
2 değiştirilmiş dosya ile 29 ekleme ve 4 silme
  1. 6 4
      pages/wordList/wordList.vue
  2. 23 0
      utils/common.js

+ 6 - 4
pages/wordList/wordList.vue

@@ -9,7 +9,9 @@
 			<view class="ezy-border-body">
           <view  class="word-title-box" style="display: flex;overflow-x: auto;" v-if="listData.jieNumberList && listData.jieNumberList.length >0">
 					<view :id="'item-' + item.jieId" class="title-item" v-for="(item,index) in listData.jieNumberList" @click="handleTitleClick(item)"
-						:key="item.jieId" :class="{active: listData.activeIndex == index}">Unit{{item.number}}</view>
+						:key="item.jieId" :class="{active: listData.activeIndex == index}" 
+						v-show="isTargetInSameGroup(listData.jieNumberList, listData.jieNumberList[listData.activeIndex],item.jieId)">  
+						Unit{{item.number}}</view>
           </view>
 
 				<swiper class="word-list-swiper-box" :indicator-dots="false" :autoplay="false" :circular="false" :current="listData.activeIndex"
@@ -62,8 +64,8 @@
 </template>
 
 <script setup>
-	import {reactive,ref,nextTick} from "vue";
-	import {toast,getDataFromStr,useActiveDomIntoView} from "@/utils/common";
+	import {reactive,ref,nextTick,computed} from "vue";
+	import {toast,getDataFromStr,useActiveDomIntoView,isTargetInSameGroup} from "@/utils/common";
 	import {onLoad} from "@dcloudio/uni-app";
 	import {getWordZhangList,getWordZhangListYK,} from "@/api/word.js";
 	import cacheManager from '@/utils/cacheManager.js';
@@ -105,7 +107,7 @@
 		}
 		
 	});
-
+	
 	onLoad((options) => {
 		routerOpt = options;
 		if (!cacheManager.get('auth')) {

+ 23 - 0
utils/common.js

@@ -205,4 +205,27 @@ export function useActiveDomIntoView(classNameParent, classNameActive) {
 			container.scrollTo({ left: targetPos });
 		}
 	});
+}
+
+
+export function isTargetInSameGroup(arr, currentElement, targetJieId) {
+  // 1. 参数校验
+  if (!Array.isArray(arr) || arr.length === 0) return false;
+  if (!currentElement || !targetJieId) return false;
+
+  // 2. 将数组拆分为4个一组的二维数组
+  const chunkSize = 4;
+  const groupedArray = [];
+  for (let i = 0; i < arr.length; i += chunkSize) {
+    groupedArray.push(arr.slice(i, i + chunkSize));
+  }
+
+  // 3. 查找包含当前元素的子数组
+  const currentGroup = groupedArray.find(group => 
+    group.some(item => item.jieId === currentElement.jieId)
+  );
+
+  // 4. 判断目标jieId是否在该子数组中
+  if (!currentGroup) return false;
+  return currentGroup.some(item => item.jieId === targetJieId);
 }