From 76005787a10f1cf2e26f1b0c1672836b7d633ed2 Mon Sep 17 00:00:00 2001
From: Jacob <hlnie@tohours.com>
Date: 星期五, 23 十月 2026 13:26:14 +0800
Subject: [PATCH] fix: 抽奖banner预取尺寸就绪后再渲染避免首帧撑高页面

---
 pages/zone/index.vue |  122 ++++++++++++++++++++++++++++------------
 1 files changed, 85 insertions(+), 37 deletions(-)

diff --git a/pages/zone/index.vue b/pages/zone/index.vue
index 0c11d9b..cf02da0 100644
--- a/pages/zone/index.vue
+++ b/pages/zone/index.vue
@@ -20,8 +20,9 @@
 		<view v-else>
 			<view class="expireTime" v-if="expireTime && expireTime.length">
 				<text>涓撳尯灏嗗湪</text>
-				<text v-for="(val, index) in expireTime" :key="index">
-					<text class="num">{{ val }}</text>{{ expireTimeUnit[index] }}
+				<text v-for="(item, index) in expireTime" :key="index">
+					<text class="num"><text v-for="(char, ci) in item.digits" :key="ci"
+							class="digit">{{ char }}</text></text>{{ item.unit }}
 				</text>
 				<text>{{ startOrEnd }}</text>
 			</view>
@@ -70,8 +71,10 @@
 					</view>
 				</view>
 			</view>
-			<view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery && info.lotteryBanner">
-				<image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix">
+			<view @click="goLottery" class="lottery_banner"
+				v-if="info && info.isLottery && info.lotteryBanner && lotteryBannerReady">
+				<image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix"
+					:style="{ height: lotteryBannerHeight }">
 				</image>
 			</view>
 			<view class="tag-img-container" v-if="info.zoneType == 7">
@@ -588,7 +591,7 @@
 			showMenu: false,
 			selectedMenuArr: [],
 			expireTime: [],
-			expireTimeUnit: [],
+			countdownToken: 0,
 			isPageShow: false,
 			loginBackFn: null,
 			errText: '',
@@ -621,6 +624,8 @@
 			stockEmpty: true,
 			urlOption: {},
 			homeTop: '200',
+			lotteryBannerHeight: '', //鎶藉banner棰勮绠楅珮搴︼紙rpx锛夛紝绌哄瓧绗︿覆琛ㄧず鏈彇鍒帮紝鎸夊師閫昏緫鑷�傚簲
+			lotteryBannerReady: false, //鏄惁宸叉嬁鍒癰anner灏哄锛堟垨宸茬‘璁ゆ嬁涓嶅埌锛夛紝鏈氨缁墠涓嶆覆鏌擄紝閬垮厤棣栧抚鎾戦珮
 			hasNewPop: false,
 			leftCoupon: {},
 			rightCoupon: {},
@@ -1295,6 +1300,9 @@
 			})
 		},
 		validAlert(data) {
+			// 姣忔閲嶆柊璁$畻鍓嶄綔搴熸棫鐨勫�掕鏃堕摼锛岄伩鍏嶅鏉″畾鏃跺櫒鍚屾椂鍒锋柊瀵艰嚧鏁板瓧璺冲姩
+			this.countdownToken++
+			const token = this.countdownToken
 			const {
 				startTime,
 				expireTime
@@ -1313,17 +1321,17 @@
 					let minutes = startTimetamp.getMinutes()
 					minutes = minutes < 10 ? '0' + minutes : minutes;
 
-					this.countdownTimer(startTime.split('-').join('/'), 'start')
+					this.countdownTimer(startTime.split('-').join('/'), 'start', token)
 					this.startOrEnd = "鍚庡紑鍚�"
 					return
-				}
-			}
-			if (expireTime) {
-				const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
-				if (expireTimetamp < nowTimestamp) {
+					}
+					}
+					if (expireTime) {
+					const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
+					if (expireTimetamp < nowTimestamp) {
 					return
-				}
-				this.countdownTimer(expireTime.split('-').join('/'), 'end')
+					}
+					this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
 				this.startOrEnd = "鍚庣粨鏉�"
 			}
 		},
@@ -1445,6 +1453,29 @@
 				this.$refs.popNewuserRef.show()
 			}
 		},
+		// 棰勫彇鎶藉banner鐪熷疄瀹介珮锛岃绠楀嚭楂樺害鍚庡啀娓叉煋锛岄伩鍏嶅姞杞藉墠琚粍浠堕粯璁ら珮搴�(225px)鎾戝ぇ
+		setLotteryBannerSize(info) {
+			let that = this
+			that.lotteryBannerHeight = ''
+			that.lotteryBannerReady = false
+			if (!info || !info.isLottery || !info.lotteryBanner) {
+				that.lotteryBannerReady = true
+				return
+			}
+			uni.getImageInfo({
+				src: info.lotteryBanner,
+				success: (img) => {
+					if (img.width > 0 && img.height > 0) {
+						that.lotteryBannerHeight = (690 * img.height / img.width).toFixed(2) + 'rpx'
+					}
+					that.lotteryBannerReady = true
+				},
+				fail: (err) => {
+					console.warn('鎶藉banner灏哄棰勫彇澶辫触锛屽洖閫�涓鸿嚜閫傚簲', err)
+					that.lotteryBannerReady = true
+				}
+			})
+		},
 		getZoneDetail: function () {
 			let that = this;
 			let belong = this.$store.getters.belong;
@@ -1452,6 +1483,11 @@
 			console.log('涓撳尯璇︽儏鍏ュ弬锛氾細', params)
 			getZoneDetail(that.id, params).then(res => {
 				that.info = res.data;
+<<<<<<< Updated upstream
+=======
+				//that.info.zoneType=8;
+				that.setLotteryBannerSize(res.data);
+>>>>>>> Stashed changes
 				that.updateZoneShareMenu();
 				if (res.data.zoneType == 6) {
 					that.setYueyangZone()
@@ -1461,7 +1497,7 @@
 						that.homeTop = that.getHomeTop(0.4)
 					}
 					that.expireTime = [];
-					that.expireTimeUnit = [];
+					that.countdownToken++;
 					that.where.page = 1;
 					that.getGoodList()
 					that.validAlert(res.data)
@@ -1487,8 +1523,9 @@
 				}
 			});
 		},
-		countdownTimer(expireTime, type) {
+		countdownTimer(expireTime, type, token) {
 			if (!expireTime) return
+			if (token !== undefined && token !== this.countdownToken) return
 			let that = this;
 			// 缁撴潫鏃堕棿鐨勬椂闂存埑锛堥渶浼犲叆涓�涓湁鏁堢殑鏃ユ湡瀵硅薄鎴栨椂闂存埑锛�
 			const endTimestamp = new Date(expireTime).getTime();
@@ -1500,56 +1537,56 @@
 			if (type == 'end') {
 				if (diff <= 0) {
 					this.expireTime = []
-					this.expireTimeUnit = []
 					return
 				} else { }
 			} else if (type == 'start') {
 				if (diff <= 0) {
 					this.expireTime = []
-					this.expireTimeUnit = []
 					const expireTime2 = that.info.expireTime
 					if (expireTime2) {
 						const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
 						if (expireTimetamp < nowTimestamp) {
 							return
 						}
-						this.countdownTimer(expireTime2.split('-').join('/'), 'end')
+						this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
 						this.startOrEnd = "鍚庣粨鏉�"
 					}
 					return
 				}
 			}
+			const pad = num => (num < 10 ? '0' + num : String(num))
 			const res = []
-			const unit = []
 			const days = Math.floor(diff / (1000 * 60 * 60 * 24))
 			diff %= (1000 * 60 * 60 * 24)
-			if (days > 0) {
-				res.push(days);
-				unit.push('鏃�')
-			}
 			// 杞崲涓哄皬鏃躲�佸垎閽熴�佺
 			const hours = Math.floor(diff / (1000 * 60 * 60));
 			diff %= (1000 * 60 * 60); // 鍓╀綑姣鏁�
-			if (hours > 0) {
-				res.push(hours < 10 ? '0' + hours : hours);
-				unit.push('鏃�')
-			}
 			const minutes = Math.floor(diff / (1000 * 60));
-			if (minutes > 0) {
-				res.push(minutes < 10 ? '0' + minutes : minutes);
-				unit.push('鍒�')
-			}
 			diff %= (1000 * 60); // 鍓╀綑姣鏁�
 			const seconds = Math.floor(diff / 1000);
-			if (seconds > 0) {
-				res.push(seconds < 10 ? '0' + seconds : seconds);
-				unit.push('绉�')
+			// 澶╂暟涓� 0 鏃朵笉灞曠ず锛屾椂/鍒�/绉掑缁堝睍绀猴紙琛� 0锛夛紝淇濊瘉鍊掕鏃堕暱搴︾ǔ瀹�
+			if (days > 0) {
+				res.push({
+					digits: pad(days).split(''),
+					unit: '鏃�'
+				})
 			}
+			res.push({
+				digits: pad(hours).split(''),
+				unit: '鏃�'
+			})
+			res.push({
+				digits: pad(minutes).split(''),
+				unit: '鍒�'
+			})
+			res.push({
+				digits: pad(seconds).split(''),
+				unit: '绉�'
+			})
 			this.expireTime = res
-			this.expireTimeUnit = unit
 			if (this.isPageShow) {
 				setTimeout(() => {
-					that.countdownTimer(expireTime, type)
+					that.countdownTimer(expireTime, type, token)
 				}, 1000)
 			}
 		},
@@ -2082,11 +2119,22 @@
 	padding: 15rpx;
 	padding-left: 30rpx;
 	color: #979797;
+	font-size: 26rpx;
 
 	.num {
+		display: inline-block;
 		color: #000000;
 		background: #FFE20E;
-		padding: 0 10rpx;
+		padding: 0 6rpx;
+		margin: 0 4rpx;
+		vertical-align: middle;
+	}
+
+	/* 姣忎釜鏁板瓧鍥哄畾瀹藉害锛岄伩鍏嶅�掕鏃惰烦鍔ㄦ椂瀹藉害蹇介暱蹇界煭 */
+	.digit {
+		display: inline-block;
+		width: 19rpx;
+		text-align: center;
 	}
 }
 </style>
\ No newline at end of file

--
Gitblit v1.4.0