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>
....@@ -70,9 +71,9 @@
7071 </view>
7172 </view>
7273 </view>
73
- <view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery">
74
- <image class="lottery_bannerImg"
75
- src="https://ossacmall.bluedeer.com.cn/app/static/images/zone_lotteryBanner.gif" mode="widthFix">
74
+ <view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery && info.lotteryBanner">
75
+ <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix"
76
+ :style="{ height: lotteryBannerHeight }">
7677 </image>
7778 </view>
7879 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -589,7 +590,7 @@
589590 showMenu: false,
590591 selectedMenuArr: [],
591592 expireTime: [],
592
- expireTimeUnit: [],
593
+ countdownToken: 0,
593594 isPageShow: false,
594595 loginBackFn: null,
595596 errText: '',
....@@ -622,6 +623,7 @@
622623 stockEmpty: true,
623624 urlOption: {},
624625 homeTop: '200',
626
+ lotteryBannerHeight: '', //抽奖banner预计算高度(rpx),空字符串表示未取到,按原逻辑自适应
625627 hasNewPop: false,
626628 leftCoupon: {},
627629 rightCoupon: {},
....@@ -1296,6 +1298,9 @@
12961298 })
12971299 },
12981300 validAlert(data) {
1301
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1302
+ this.countdownToken++
1303
+ const token = this.countdownToken
12991304 const {
13001305 startTime,
13011306 expireTime
....@@ -1314,17 +1319,17 @@
13141319 let minutes = startTimetamp.getMinutes()
13151320 minutes = minutes < 10 ? '0' + minutes : minutes;
13161321
1317
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1322
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13181323 this.startOrEnd = "后开启"
13191324 return
1320
- }
1321
- }
1322
- if (expireTime) {
1323
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1324
- if (expireTimetamp < nowTimestamp) {
1325
+ }
1326
+ }
1327
+ if (expireTime) {
1328
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1329
+ if (expireTimetamp < nowTimestamp) {
13251330 return
1326
- }
1327
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1331
+ }
1332
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13281333 this.startOrEnd = "后结束"
13291334 }
13301335 },
....@@ -1446,6 +1451,21 @@
14461451 this.$refs.popNewuserRef.show()
14471452 }
14481453 },
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
+ },
14491469 getZoneDetail: function () {
14501470 let that = this;
14511471 let belong = this.$store.getters.belong;
....@@ -1453,6 +1473,11 @@
14531473 console.log('专区详情入参::', params)
14541474 getZoneDetail(that.id, params).then(res => {
14551475 that.info = res.data;
1476
+<<<<<<< Updated upstream
1477
+=======
1478
+ //that.info.zoneType=8;
1479
+ that.setLotteryBannerSize(res.data);
1480
+>>>>>>> Stashed changes
14561481 that.updateZoneShareMenu();
14571482 if (res.data.zoneType == 6) {
14581483 that.setYueyangZone()
....@@ -1462,7 +1487,7 @@
14621487 that.homeTop = that.getHomeTop(0.4)
14631488 }
14641489 that.expireTime = [];
1465
- that.expireTimeUnit = [];
1490
+ that.countdownToken++;
14661491 that.where.page = 1;
14671492 that.getGoodList()
14681493 that.validAlert(res.data)
....@@ -1488,8 +1513,9 @@
14881513 }
14891514 });
14901515 },
1491
- countdownTimer(expireTime, type) {
1516
+ countdownTimer(expireTime, type, token) {
14921517 if (!expireTime) return
1518
+ if (token !== undefined && token !== this.countdownToken) return
14931519 let that = this;
14941520 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
14951521 const endTimestamp = new Date(expireTime).getTime();
....@@ -1501,56 +1527,56 @@
15011527 if (type == 'end') {
15021528 if (diff <= 0) {
15031529 this.expireTime = []
1504
- this.expireTimeUnit = []
15051530 return
15061531 } else { }
15071532 } else if (type == 'start') {
15081533 if (diff <= 0) {
15091534 this.expireTime = []
1510
- this.expireTimeUnit = []
15111535 const expireTime2 = that.info.expireTime
15121536 if (expireTime2) {
15131537 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15141538 if (expireTimetamp < nowTimestamp) {
15151539 return
15161540 }
1517
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1541
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15181542 this.startOrEnd = "后结束"
15191543 }
15201544 return
15211545 }
15221546 }
1547
+ const pad = num => (num < 10 ? '0' + num : String(num))
15231548 const res = []
1524
- const unit = []
15251549 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15261550 diff %= (1000 * 60 * 60 * 24)
1527
- if (days > 0) {
1528
- res.push(days);
1529
- unit.push('日')
1530
- }
15311551 // 转换为小时、分钟、秒
15321552 const hours = Math.floor(diff / (1000 * 60 * 60));
15331553 diff %= (1000 * 60 * 60); // 剩余毫秒数
1534
- if (hours > 0) {
1535
- res.push(hours < 10 ? '0' + hours : hours);
1536
- unit.push('时')
1537
- }
15381554 const minutes = Math.floor(diff / (1000 * 60));
1539
- if (minutes > 0) {
1540
- res.push(minutes < 10 ? '0' + minutes : minutes);
1541
- unit.push('分')
1542
- }
15431555 diff %= (1000 * 60); // 剩余毫秒数
15441556 const seconds = Math.floor(diff / 1000);
1545
- if (seconds > 0) {
1546
- res.push(seconds < 10 ? '0' + seconds : seconds);
1547
- unit.push('秒')
1557
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1558
+ if (days > 0) {
1559
+ res.push({
1560
+ digits: pad(days).split(''),
1561
+ unit: '日'
1562
+ })
15481563 }
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
+ })
15491576 this.expireTime = res
1550
- this.expireTimeUnit = unit
15511577 if (this.isPageShow) {
15521578 setTimeout(() => {
1553
- that.countdownTimer(expireTime, type)
1579
+ that.countdownTimer(expireTime, type, token)
15541580 }, 1000)
15551581 }
15561582 },
....@@ -1637,13 +1663,11 @@
16371663 .lottery_banner {
16381664 margin: 15rpx auto;
16391665 width: 690rpx;
1640
- height: 120rpx;
16411666 text-align: center;
16421667 }
16431668
16441669 .lottery_bannerImg {
16451670 width: 690rpx;
1646
- height: 120rpx;
16471671 }
16481672
16491673 .tag-wrap-container {
....@@ -2085,11 +2109,22 @@
20852109 padding: 15rpx;
20862110 padding-left: 30rpx;
20872111 color: #979797;
2112
+ font-size: 26rpx;
20882113
20892114 .num {
2115
+ display: inline-block;
20902116 color: #000000;
20912117 background: #FFE20E;
2092
- 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;
20932128 }
20942129 }
20952130 </style>