Jacob
1 天以前 24b8f2afa92ce7bbe490185ecbab869c460b798b
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>
....@@ -88,9 +89,9 @@
8889 </view>
8990 </view>
9091 </view>
91
- <view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery">
92
- <image class="lottery_bannerImg"
93
- src="https://ossacmall.bluedeer.com.cn/app/static/images/zone_lotteryBanner.gif" mode="widthFix">
92
+ <view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery && info.lotteryBanner">
93
+ <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix"
94
+ :style="{ height: lotteryBannerHeight }">
9495 </image>
9596 </view>
9697 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -607,7 +608,7 @@
607608 showMenu: false,
608609 selectedMenuArr: [],
609610 expireTime: [],
610
- expireTimeUnit: [],
611
+ countdownToken: 0,
611612 isPageShow: false,
612613 loginBackFn: null,
613614 errText: '',
....@@ -642,6 +643,7 @@
642643 stockEmpty: true,
643644 urlOption: {},
644645 homeTop: '200',
646
+ lotteryBannerHeight: '', //抽奖banner预计算高度(rpx),空字符串表示未取到,按原逻辑自适应
645647 hasNewPop: false,
646648 leftCoupon: {},
647649 rightCoupon: {},
....@@ -1327,6 +1329,9 @@
13271329 })
13281330 },
13291331 validAlert(data) {
1332
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1333
+ this.countdownToken++
1334
+ const token = this.countdownToken
13301335 const {
13311336 startTime,
13321337 expireTime
....@@ -1345,17 +1350,17 @@
13451350 let minutes = startTimetamp.getMinutes()
13461351 minutes = minutes < 10 ? '0' + minutes : minutes;
13471352
1348
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1353
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13491354 this.startOrEnd = "后开启"
13501355 return
1351
- }
1352
- }
1353
- if (expireTime) {
1354
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1355
- if (expireTimetamp < nowTimestamp) {
1356
+ }
1357
+ }
1358
+ if (expireTime) {
1359
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1360
+ if (expireTimetamp < nowTimestamp) {
13561361 return
1357
- }
1358
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1362
+ }
1363
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13591364 this.startOrEnd = "后结束"
13601365 }
13611366 },
....@@ -1477,6 +1482,21 @@
14771482 this.$refs.popNewuserRef.show()
14781483 }
14791484 },
1485
+ // 预取抽奖banner真实宽高,计算出高度后再渲染,避免加载前被组件默认高度(225px)撑大
1486
+ setLotteryBannerSize(info) {
1487
+ let that = this
1488
+ that.lotteryBannerHeight = ''
1489
+ if (!info || !info.isLottery || !info.lotteryBanner) return
1490
+ uni.getImageInfo({
1491
+ src: info.lotteryBanner,
1492
+ success: (img) => {
1493
+ if (img.width > 0 && img.height > 0) {
1494
+ that.lotteryBannerHeight = (690 * img.height / img.width).toFixed(2) + 'rpx'
1495
+ }
1496
+ },
1497
+ fail: () => { }
1498
+ })
1499
+ },
14801500 getZoneDetail: function () {
14811501 let that = this;
14821502 let belong = this.$store.getters.belong;
....@@ -1484,7 +1504,7 @@
14841504 console.log('专区详情入参::', params)
14851505 getZoneDetail(that.id, params).then(res => {
14861506 that.info = res.data;
1487
- //that.info.zoneType=8;
1507
+ that.setLotteryBannerSize(res.data);
14881508 that.updateZoneShareMenu();
14891509 if (res.data.zoneType == 6) {
14901510 that.setYueyangZone()
....@@ -1494,7 +1514,7 @@
14941514 that.homeTop = that.getHomeTop(0.4)
14951515 }
14961516 that.expireTime = [];
1497
- that.expireTimeUnit = [];
1517
+ that.countdownToken++;
14981518 that.where.page = 1;
14991519 that.getGoodList()
15001520 that.validAlert(res.data)
....@@ -1520,8 +1540,9 @@
15201540 }
15211541 });
15221542 },
1523
- countdownTimer(expireTime, type) {
1543
+ countdownTimer(expireTime, type, token) {
15241544 if (!expireTime) return
1545
+ if (token !== undefined && token !== this.countdownToken) return
15251546 let that = this;
15261547 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
15271548 const endTimestamp = new Date(expireTime).getTime();
....@@ -1533,56 +1554,56 @@
15331554 if (type == 'end') {
15341555 if (diff <= 0) {
15351556 this.expireTime = []
1536
- this.expireTimeUnit = []
15371557 return
15381558 } else { }
15391559 } else if (type == 'start') {
15401560 if (diff <= 0) {
15411561 this.expireTime = []
1542
- this.expireTimeUnit = []
15431562 const expireTime2 = that.info.expireTime
15441563 if (expireTime2) {
15451564 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15461565 if (expireTimetamp < nowTimestamp) {
15471566 return
15481567 }
1549
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1568
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15501569 this.startOrEnd = "后结束"
15511570 }
15521571 return
15531572 }
15541573 }
1574
+ const pad = num => (num < 10 ? '0' + num : String(num))
15551575 const res = []
1556
- const unit = []
15571576 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15581577 diff %= (1000 * 60 * 60 * 24)
1559
- if (days > 0) {
1560
- res.push(days);
1561
- unit.push('日')
1562
- }
15631578 // 转换为小时、分钟、秒
15641579 const hours = Math.floor(diff / (1000 * 60 * 60));
15651580 diff %= (1000 * 60 * 60); // 剩余毫秒数
1566
- if (hours > 0) {
1567
- res.push(hours < 10 ? '0' + hours : hours);
1568
- unit.push('时')
1569
- }
15701581 const minutes = Math.floor(diff / (1000 * 60));
1571
- if (minutes > 0) {
1572
- res.push(minutes < 10 ? '0' + minutes : minutes);
1573
- unit.push('分')
1574
- }
15751582 diff %= (1000 * 60); // 剩余毫秒数
15761583 const seconds = Math.floor(diff / 1000);
1577
- if (seconds > 0) {
1578
- res.push(seconds < 10 ? '0' + seconds : seconds);
1579
- unit.push('秒')
1584
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1585
+ if (days > 0) {
1586
+ res.push({
1587
+ digits: pad(days).split(''),
1588
+ unit: '日'
1589
+ })
15801590 }
1591
+ res.push({
1592
+ digits: pad(hours).split(''),
1593
+ unit: '时'
1594
+ })
1595
+ res.push({
1596
+ digits: pad(minutes).split(''),
1597
+ unit: '分'
1598
+ })
1599
+ res.push({
1600
+ digits: pad(seconds).split(''),
1601
+ unit: '秒'
1602
+ })
15811603 this.expireTime = res
1582
- this.expireTimeUnit = unit
15831604 if (this.isPageShow) {
15841605 setTimeout(() => {
1585
- that.countdownTimer(expireTime, type)
1606
+ that.countdownTimer(expireTime, type, token)
15861607 }, 1000)
15871608 }
15881609 },
....@@ -1669,13 +1690,11 @@
16691690 .lottery_banner {
16701691 margin: 15rpx auto;
16711692 width: 690rpx;
1672
- height: 120rpx;
16731693 text-align: center;
16741694 }
16751695
16761696 .lottery_bannerImg {
16771697 width: 690rpx;
1678
- height: 120rpx;
16791698 }
16801699
16811700 .tag-wrap-container {
....@@ -2159,11 +2178,22 @@
21592178 padding: 15rpx;
21602179 padding-left: 30rpx;
21612180 color: #979797;
2181
+ font-size: 26rpx;
21622182
21632183 .num {
2184
+ display: inline-block;
21642185 color: #000000;
21652186 background: #FFE20E;
2166
- padding: 0 10rpx;
2187
+ padding: 0 6rpx;
2188
+ margin: 0 4rpx;
2189
+ vertical-align: middle;
2190
+ }
2191
+
2192
+ /* 每个数字固定宽度,避免倒计时跳动时宽度忽长忽短 */
2193
+ .digit {
2194
+ display: inline-block;
2195
+ width: 19rpx;
2196
+ text-align: center;
21672197 }
21682198 }
21692199 </style>