Jacob
1 天以前 6a0a2c52a4ea8049909b8d7a40d0c2d098b5e74c
pages/zone/index.vue
....@@ -20,8 +20,9 @@
2020 <view v-else>
2121 <view class="expireTime" v-if="expireTime && expireTime.length">
2222 <text>专区将在</text>
23
- <text v-for="(val, index) in expireTime" :key="index">
24
- <text class="num">{{ val }}</text>{{ expireTimeUnit[index] }}
23
+ <text v-for="(item, index) in expireTime" :key="index">
24
+ <text class="num"><text v-for="(char, ci) in item.digits" :key="ci"
25
+ class="digit">{{ char }}</text></text>{{ item.unit }}
2526 </text>
2627 <text>{{ startOrEnd }}</text>
2728 </view>
....@@ -71,7 +72,8 @@
7172 </view>
7273 </view>
7374 <view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery && info.lotteryBanner">
74
- <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix">
75
+ <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix"
76
+ :style="{ height: lotteryBannerHeight }">
7577 </image>
7678 </view>
7779 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -588,7 +590,7 @@
588590 showMenu: false,
589591 selectedMenuArr: [],
590592 expireTime: [],
591
- expireTimeUnit: [],
593
+ countdownToken: 0,
592594 isPageShow: false,
593595 loginBackFn: null,
594596 errText: '',
....@@ -621,6 +623,7 @@
621623 stockEmpty: true,
622624 urlOption: {},
623625 homeTop: '200',
626
+ lotteryBannerHeight: '', //抽奖banner预计算高度(rpx),空字符串表示未取到,按原逻辑自适应
624627 hasNewPop: false,
625628 leftCoupon: {},
626629 rightCoupon: {},
....@@ -1295,6 +1298,9 @@
12951298 })
12961299 },
12971300 validAlert(data) {
1301
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1302
+ this.countdownToken++
1303
+ const token = this.countdownToken
12981304 const {
12991305 startTime,
13001306 expireTime
....@@ -1313,17 +1319,17 @@
13131319 let minutes = startTimetamp.getMinutes()
13141320 minutes = minutes < 10 ? '0' + minutes : minutes;
13151321
1316
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1322
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13171323 this.startOrEnd = "后开启"
13181324 return
1319
- }
1320
- }
1321
- if (expireTime) {
1322
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1323
- if (expireTimetamp < nowTimestamp) {
1325
+ }
1326
+ }
1327
+ if (expireTime) {
1328
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1329
+ if (expireTimetamp < nowTimestamp) {
13241330 return
1325
- }
1326
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1331
+ }
1332
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13271333 this.startOrEnd = "后结束"
13281334 }
13291335 },
....@@ -1445,6 +1451,21 @@
14451451 this.$refs.popNewuserRef.show()
14461452 }
14471453 },
1454
+ // 预取抽奖banner真实宽高,计算出高度后再渲染,避免加载前被组件默认高度(225px)撑大
1455
+ setLotteryBannerSize(info) {
1456
+ let that = this
1457
+ that.lotteryBannerHeight = ''
1458
+ if (!info || !info.isLottery || !info.lotteryBanner) return
1459
+ uni.getImageInfo({
1460
+ src: info.lotteryBanner,
1461
+ success: (img) => {
1462
+ if (img.width > 0 && img.height > 0) {
1463
+ that.lotteryBannerHeight = (690 * img.height / img.width).toFixed(2) + 'rpx'
1464
+ }
1465
+ },
1466
+ fail: () => { }
1467
+ })
1468
+ },
14481469 getZoneDetail: function () {
14491470 let that = this;
14501471 let belong = this.$store.getters.belong;
....@@ -1452,6 +1473,11 @@
14521473 console.log('专区详情入参::', params)
14531474 getZoneDetail(that.id, params).then(res => {
14541475 that.info = res.data;
1476
+<<<<<<< Updated upstream
1477
+=======
1478
+ //that.info.zoneType=8;
1479
+ that.setLotteryBannerSize(res.data);
1480
+>>>>>>> Stashed changes
14551481 that.updateZoneShareMenu();
14561482 if (res.data.zoneType == 6) {
14571483 that.setYueyangZone()
....@@ -1461,7 +1487,7 @@
14611487 that.homeTop = that.getHomeTop(0.4)
14621488 }
14631489 that.expireTime = [];
1464
- that.expireTimeUnit = [];
1490
+ that.countdownToken++;
14651491 that.where.page = 1;
14661492 that.getGoodList()
14671493 that.validAlert(res.data)
....@@ -1487,8 +1513,9 @@
14871513 }
14881514 });
14891515 },
1490
- countdownTimer(expireTime, type) {
1516
+ countdownTimer(expireTime, type, token) {
14911517 if (!expireTime) return
1518
+ if (token !== undefined && token !== this.countdownToken) return
14921519 let that = this;
14931520 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
14941521 const endTimestamp = new Date(expireTime).getTime();
....@@ -1500,56 +1527,56 @@
15001527 if (type == 'end') {
15011528 if (diff <= 0) {
15021529 this.expireTime = []
1503
- this.expireTimeUnit = []
15041530 return
15051531 } else { }
15061532 } else if (type == 'start') {
15071533 if (diff <= 0) {
15081534 this.expireTime = []
1509
- this.expireTimeUnit = []
15101535 const expireTime2 = that.info.expireTime
15111536 if (expireTime2) {
15121537 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15131538 if (expireTimetamp < nowTimestamp) {
15141539 return
15151540 }
1516
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1541
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15171542 this.startOrEnd = "后结束"
15181543 }
15191544 return
15201545 }
15211546 }
1547
+ const pad = num => (num < 10 ? '0' + num : String(num))
15221548 const res = []
1523
- const unit = []
15241549 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15251550 diff %= (1000 * 60 * 60 * 24)
1526
- if (days > 0) {
1527
- res.push(days);
1528
- unit.push('日')
1529
- }
15301551 // 转换为小时、分钟、秒
15311552 const hours = Math.floor(diff / (1000 * 60 * 60));
15321553 diff %= (1000 * 60 * 60); // 剩余毫秒数
1533
- if (hours > 0) {
1534
- res.push(hours < 10 ? '0' + hours : hours);
1535
- unit.push('时')
1536
- }
15371554 const minutes = Math.floor(diff / (1000 * 60));
1538
- if (minutes > 0) {
1539
- res.push(minutes < 10 ? '0' + minutes : minutes);
1540
- unit.push('分')
1541
- }
15421555 diff %= (1000 * 60); // 剩余毫秒数
15431556 const seconds = Math.floor(diff / 1000);
1544
- if (seconds > 0) {
1545
- res.push(seconds < 10 ? '0' + seconds : seconds);
1546
- unit.push('秒')
1557
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1558
+ if (days > 0) {
1559
+ res.push({
1560
+ digits: pad(days).split(''),
1561
+ unit: '日'
1562
+ })
15471563 }
1564
+ res.push({
1565
+ digits: pad(hours).split(''),
1566
+ unit: '时'
1567
+ })
1568
+ res.push({
1569
+ digits: pad(minutes).split(''),
1570
+ unit: '分'
1571
+ })
1572
+ res.push({
1573
+ digits: pad(seconds).split(''),
1574
+ unit: '秒'
1575
+ })
15481576 this.expireTime = res
1549
- this.expireTimeUnit = unit
15501577 if (this.isPageShow) {
15511578 setTimeout(() => {
1552
- that.countdownTimer(expireTime, type)
1579
+ that.countdownTimer(expireTime, type, token)
15531580 }, 1000)
15541581 }
15551582 },
....@@ -2082,11 +2109,22 @@
20822109 padding: 15rpx;
20832110 padding-left: 30rpx;
20842111 color: #979797;
2112
+ font-size: 26rpx;
20852113
20862114 .num {
2115
+ display: inline-block;
20872116 color: #000000;
20882117 background: #FFE20E;
2089
- padding: 0 10rpx;
2118
+ padding: 0 6rpx;
2119
+ margin: 0 4rpx;
2120
+ vertical-align: middle;
2121
+ }
2122
+
2123
+ /* 每个数字固定宽度,避免倒计时跳动时宽度忽长忽短 */
2124
+ .digit {
2125
+ display: inline-block;
2126
+ width: 19rpx;
2127
+ text-align: center;
20902128 }
20912129 }
20922130 </style>