Parcourir la source

更新新英语切换

wangxy il y a 2 mois
Parent
commit
2ca1493cd1
2 fichiers modifiés avec 23 ajouts et 19 suppressions
  1. 9 10
      pages/wordList/wordList.vue
  2. 14 9
      utils/useSwiper.js

+ 9 - 10
pages/wordList/wordList.vue

@@ -13,7 +13,7 @@
 						:key="item.jieId" :class="{active: listData.activeIndex == index}">Unit{{item.number}}</view>
 				</scroll-view>
 
-				<swiper class="word-list-swiper-box" :indicator-dots="false" :autoplay="false" :circular="false"
+				<swiper class="word-list-swiper-box" :indicator-dots="false" :autoplay="false" :circular="false" :current="listData.activeIndex"
 					@change="handleSwiperChange" :disable-touch="!swiperData.isAllowed">
 					<swiper-item class="word-list-swiper-item" v-for="citem in unitList" :key="citem.jieId" @touchstart="handleTouchStart"
 						@touchend="handleTouchEnd">
@@ -24,9 +24,6 @@
 							<!-- 单词 -->
 							<view class="word-list-item" v-for="(item,index) in citem.wordList" :key="index"
 								@click="toWord(item)" :class="{active: item.wcFlag == 1}">
-
-
-
 								<view class="item-word">
 									<view class="word-text">
 										<text v-for="(word, wordIndex) in item.chaifen" :key="wordIndex"
@@ -102,7 +99,8 @@
 	const {
 		swiperData,
 		handleTouchStart,
-		handleTouchEnd
+		handleTouchEnd,
+      userCode
 	} = useSwiper(listData, (userCode) => {
 		console.log('userCode',userCode)
 		
@@ -135,13 +133,14 @@
 				listData.activeIndex = 0; // 强制回退
 			});
 			swiperData.isAllowed = false; // 重置状态
-			return;
 		}
+    if (userCode.value == 'VIP') {
+      listData.activeIndex = e.detail.current;
+      // unit滚动到指定位置
+      findWordLeft(listData.activeIndex)
+      handleTitleClick(listData.jieNumberList[listData.activeIndex])
+    }
 
-		listData.activeIndex = e.detail.current;
-		// unit滚动到指定位置
-		findWordLeft(listData.activeIndex)
-		handleTitleClick(listData.jieNumberList[listData.activeIndex])
 	}
 
 

+ 14 - 9
utils/useSwiper.js

@@ -5,13 +5,17 @@ import {getUserIdentity} from "@/utils/common.js"
 
 export function useSwiper(Da, noticeYK) {
 	
-	const useCode = getUserIdentity()
+	const userCode = getUserIdentity()
 	
 	const swiperData = reactive({
 		startX: 0, // 触摸起点X坐标
-		isAllowed: false // 是否允许切
+		isAllowed: true // 是否允许切
 	})
 
+	if (userCode!='VIP') {
+		swiperData.isAllowed = false;
+	}
+
 	// 1. 触摸开始:记录起点
 	function handleTouchStart(e) {
 		swiperData.startX = e.touches[0].pageX;
@@ -27,20 +31,20 @@ export function useSwiper(Da, noticeYK) {
 		if (absDeltaX > 10 && checkBusinessCondition()) {
 			swiperData.isAllowed = true;
 			// 根据方向更新索引
-			if (deltaX > 0 && Da.currentIndex > 0) {
-				Da.currentIndex--; // 向右滑,上一页
-			} else if (deltaX < 0 && Da.currentIndex < swiperData.list.length - 1) {
-				Da.currentIndex++; // 向左滑,下一页
+			if (deltaX > 0 && Da.activeIndex > 0) {
+				Da.activeIndex--; // 向右滑,上一页
+			} else if (deltaX < 0 && Da.activeIndex < Da.jieNumberList.length - 1) {
+				Da.activeIndex++; // 向左滑,下一页
 			}
 		} else {
 			swiperData.isAllowed = false;
-			noticeYK(useCode)
+			noticeYK(userCode)
 		}
 	}
 
 	// 4. 业务条件校验(示例)
 	function checkBusinessCondition() {
-		if (useCode != 'VIP') {
+		if (userCode != 'VIP') {
 			return false
 		}
 		return true
@@ -48,7 +52,8 @@ export function useSwiper(Da, noticeYK) {
 	}
 	
 	return {
-		swiperData, 
+		swiperData,
+		userCode,
 		handleTouchStart,
 		handleTouchEnd
 	}