Jacob
1 天以前 106fc09e267f67bb35a279ed1bf71068a61e73c4
pages/zone/index.vue
....@@ -20,13 +20,32 @@
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>
2829 <view class="head_img">
2930 <image :src="info.image"></image>
31
+ </view>
32
+ <view v-if="info.zoneType == 8 && info.info" class="rich-content">
33
+ <rich-text :nodes="info.info"></rich-text>
34
+ </view>
35
+ <view v-if="info.zoneType == 8 && info.uploadVideo" class="video-wrap">
36
+ <view v-show="!videoControls" style="width:100%;height:750rpx">
37
+ <video id="zoneVideo" :src='info.uploadVideo' objectFit="contain" controls
38
+ style="width:100%;height:100%" show-center-play-btn="true" show-mute-btn="true" muted="true"
39
+ show-fullscreen-btn="true" auto-pause-if-navigate :custom-cache="false"
40
+ :enable-progress-gesture="true" show-progress="false"
41
+ :poster="info.uploadVideoImg || info.image" @pause="zoneVideoPause"></video>
42
+ </view>
43
+ <view class="video-poster" v-show="videoControls">
44
+ <image class="image" :src="info.uploadVideoImg || info.image"></image>
45
+ </view>
46
+ <view class="video-stop" v-show="videoControls" @tap="bindZoneVideoPlay">
47
+ <image class="image" src="https://ossacmall.bluedeer.com.cn/app/static/images/stop.png"></image>
48
+ </view>
3049 </view>
3150 <view class="tag-wrap-container" :style="'top:' + (marTop) + 'px;'" v-if="info.zoneType == 7">
3251 <view class="tag-wrap">
....@@ -70,9 +89,10 @@
7089 </view>
7190 </view>
7291 </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">
92
+ <view @click="goLottery" class="lottery_banner"
93
+ v-if="info && info.isLottery && info.lotteryBanner && lotteryBannerReady">
94
+ <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix"
95
+ :style="{ height: lotteryBannerHeight }">
7696 </image>
7797 </view>
7898 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -589,7 +609,7 @@
589609 showMenu: false,
590610 selectedMenuArr: [],
591611 expireTime: [],
592
- expireTimeUnit: [],
612
+ countdownToken: 0,
593613 isPageShow: false,
594614 loginBackFn: null,
595615 errText: '',
....@@ -599,6 +619,8 @@
599619 isYueyangZone: false,
600620 isOpen: false, // 默认收起,false收起/true展开
601621 currentIndex: -1, // 默认选中第一个【全部】
622
+ videoControls: true, // 专区活动视频是否显示海报+播放按钮
623
+ zoneVideoContext: '', // 活动视频播放上下文
602624 partitionList: [],
603625 partitionProject: {},
604626 tagList: [],
....@@ -622,6 +644,8 @@
622644 stockEmpty: true,
623645 urlOption: {},
624646 homeTop: '200',
647
+ lotteryBannerHeight: '', //抽奖banner预计算高度(rpx),空字符串表示未取到,按原逻辑自适应
648
+ lotteryBannerReady: false, //是否已拿到banner尺寸(或已确认拿不到),未就绪前不渲染,避免首帧撑高
625649 hasNewPop: false,
626650 leftCoupon: {},
627651 rightCoupon: {},
....@@ -838,6 +862,17 @@
838862 }
839863 },
840864 methods: {
865
+ /**
866
+ * 专区活动视频:点击海报播放按钮后播放
867
+ */
868
+ bindZoneVideoPlay() {
869
+ if (!this.zoneVideoContext) {
870
+ this.zoneVideoContext = uni.createVideoContext('zoneVideo', this);
871
+ }
872
+ this.$set(this, 'videoControls', false);
873
+ this.zoneVideoContext.play();
874
+ },
875
+ zoneVideoPause() { },
841876 handleCouponRule() {
842877 this.$refs.personalAndShareCouponRuleRef.show(this.info.ruleContentText)
843878 },
....@@ -1296,6 +1331,9 @@
12961331 })
12971332 },
12981333 validAlert(data) {
1334
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1335
+ this.countdownToken++
1336
+ const token = this.countdownToken
12991337 const {
13001338 startTime,
13011339 expireTime
....@@ -1314,17 +1352,17 @@
13141352 let minutes = startTimetamp.getMinutes()
13151353 minutes = minutes < 10 ? '0' + minutes : minutes;
13161354
1317
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1355
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13181356 this.startOrEnd = "后开启"
13191357 return
1320
- }
1321
- }
1322
- if (expireTime) {
1323
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1324
- if (expireTimetamp < nowTimestamp) {
1358
+ }
1359
+ }
1360
+ if (expireTime) {
1361
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1362
+ if (expireTimetamp < nowTimestamp) {
13251363 return
1326
- }
1327
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1364
+ }
1365
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13281366 this.startOrEnd = "后结束"
13291367 }
13301368 },
....@@ -1446,6 +1484,29 @@
14461484 this.$refs.popNewuserRef.show()
14471485 }
14481486 },
1487
+ // 预取抽奖banner真实宽高,计算出高度后再渲染,避免加载前被组件默认高度(225px)撑大
1488
+ setLotteryBannerSize(info) {
1489
+ let that = this
1490
+ that.lotteryBannerHeight = ''
1491
+ that.lotteryBannerReady = false
1492
+ if (!info || !info.isLottery || !info.lotteryBanner) {
1493
+ that.lotteryBannerReady = true
1494
+ return
1495
+ }
1496
+ uni.getImageInfo({
1497
+ src: info.lotteryBanner,
1498
+ success: (img) => {
1499
+ if (img.width > 0 && img.height > 0) {
1500
+ that.lotteryBannerHeight = (690 * img.height / img.width).toFixed(2) + 'rpx'
1501
+ }
1502
+ that.lotteryBannerReady = true
1503
+ },
1504
+ fail: (err) => {
1505
+ console.warn('抽奖banner尺寸预取失败,回退为自适应', err)
1506
+ that.lotteryBannerReady = true
1507
+ }
1508
+ })
1509
+ },
14491510 getZoneDetail: function () {
14501511 let that = this;
14511512 let belong = this.$store.getters.belong;
....@@ -1453,6 +1514,7 @@
14531514 console.log('专区详情入参::', params)
14541515 getZoneDetail(that.id, params).then(res => {
14551516 that.info = res.data;
1517
+ that.setLotteryBannerSize(res.data);
14561518 that.updateZoneShareMenu();
14571519 if (res.data.zoneType == 6) {
14581520 that.setYueyangZone()
....@@ -1462,7 +1524,7 @@
14621524 that.homeTop = that.getHomeTop(0.4)
14631525 }
14641526 that.expireTime = [];
1465
- that.expireTimeUnit = [];
1527
+ that.countdownToken++;
14661528 that.where.page = 1;
14671529 that.getGoodList()
14681530 that.validAlert(res.data)
....@@ -1488,8 +1550,9 @@
14881550 }
14891551 });
14901552 },
1491
- countdownTimer(expireTime, type) {
1553
+ countdownTimer(expireTime, type, token) {
14921554 if (!expireTime) return
1555
+ if (token !== undefined && token !== this.countdownToken) return
14931556 let that = this;
14941557 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
14951558 const endTimestamp = new Date(expireTime).getTime();
....@@ -1501,56 +1564,56 @@
15011564 if (type == 'end') {
15021565 if (diff <= 0) {
15031566 this.expireTime = []
1504
- this.expireTimeUnit = []
15051567 return
15061568 } else { }
15071569 } else if (type == 'start') {
15081570 if (diff <= 0) {
15091571 this.expireTime = []
1510
- this.expireTimeUnit = []
15111572 const expireTime2 = that.info.expireTime
15121573 if (expireTime2) {
15131574 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15141575 if (expireTimetamp < nowTimestamp) {
15151576 return
15161577 }
1517
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1578
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15181579 this.startOrEnd = "后结束"
15191580 }
15201581 return
15211582 }
15221583 }
1584
+ const pad = num => (num < 10 ? '0' + num : String(num))
15231585 const res = []
1524
- const unit = []
15251586 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15261587 diff %= (1000 * 60 * 60 * 24)
1527
- if (days > 0) {
1528
- res.push(days);
1529
- unit.push('日')
1530
- }
15311588 // 转换为小时、分钟、秒
15321589 const hours = Math.floor(diff / (1000 * 60 * 60));
15331590 diff %= (1000 * 60 * 60); // 剩余毫秒数
1534
- if (hours > 0) {
1535
- res.push(hours < 10 ? '0' + hours : hours);
1536
- unit.push('时')
1537
- }
15381591 const minutes = Math.floor(diff / (1000 * 60));
1539
- if (minutes > 0) {
1540
- res.push(minutes < 10 ? '0' + minutes : minutes);
1541
- unit.push('分')
1542
- }
15431592 diff %= (1000 * 60); // 剩余毫秒数
15441593 const seconds = Math.floor(diff / 1000);
1545
- if (seconds > 0) {
1546
- res.push(seconds < 10 ? '0' + seconds : seconds);
1547
- unit.push('秒')
1594
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1595
+ if (days > 0) {
1596
+ res.push({
1597
+ digits: pad(days).split(''),
1598
+ unit: '日'
1599
+ })
15481600 }
1601
+ res.push({
1602
+ digits: pad(hours).split(''),
1603
+ unit: '时'
1604
+ })
1605
+ res.push({
1606
+ digits: pad(minutes).split(''),
1607
+ unit: '分'
1608
+ })
1609
+ res.push({
1610
+ digits: pad(seconds).split(''),
1611
+ unit: '秒'
1612
+ })
15491613 this.expireTime = res
1550
- this.expireTimeUnit = unit
15511614 if (this.isPageShow) {
15521615 setTimeout(() => {
1553
- that.countdownTimer(expireTime, type)
1616
+ that.countdownTimer(expireTime, type, token)
15541617 }, 1000)
15551618 }
15561619 },
....@@ -1637,13 +1700,11 @@
16371700 .lottery_banner {
16381701 margin: 15rpx auto;
16391702 width: 690rpx;
1640
- height: 120rpx;
16411703 text-align: center;
16421704 }
16431705
16441706 .lottery_bannerImg {
16451707 width: 690rpx;
1646
- height: 120rpx;
16471708 }
16481709
16491710 .tag-wrap-container {
....@@ -1869,6 +1930,48 @@
18691930 }
18701931 }
18711932
1933
+.rich-content {
1934
+ padding: 24rpx 30rpx;
1935
+ background-color: #fff;
1936
+}
1937
+
1938
+.video-wrap {
1939
+ position: relative;
1940
+ width: 100%;
1941
+ height: 750rpx;
1942
+ background-color: #000;
1943
+}
1944
+
1945
+.video-wrap .video-poster {
1946
+ position: absolute;
1947
+ top: 0;
1948
+ left: 0;
1949
+ width: 100%;
1950
+ height: 750rpx;
1951
+ z-index: 9;
1952
+}
1953
+
1954
+.video-wrap .video-poster .image {
1955
+ width: 100%;
1956
+ height: 100%;
1957
+}
1958
+
1959
+.video-wrap .video-stop {
1960
+ position: absolute;
1961
+ top: 50%;
1962
+ left: 50%;
1963
+ width: 136rpx;
1964
+ height: 136rpx;
1965
+ margin-top: -68rpx;
1966
+ margin-left: -68rpx;
1967
+ z-index: 9;
1968
+}
1969
+
1970
+.video-wrap .video-stop .image {
1971
+ width: 100%;
1972
+ height: 100%;
1973
+}
1974
+
18721975 .toolbarList {
18731976 width: 750rpx;
18741977 position: -webkit-sticky;
....@@ -2085,11 +2188,22 @@
20852188 padding: 15rpx;
20862189 padding-left: 30rpx;
20872190 color: #979797;
2191
+ font-size: 26rpx;
20882192
20892193 .num {
2194
+ display: inline-block;
20902195 color: #000000;
20912196 background: #FFE20E;
2092
- padding: 0 10rpx;
2197
+ padding: 0 6rpx;
2198
+ margin: 0 4rpx;
2199
+ vertical-align: middle;
2200
+ }
2201
+
2202
+ /* 每个数字固定宽度,避免倒计时跳动时宽度忽长忽短 */
2203
+ .digit {
2204
+ display: inline-block;
2205
+ width: 19rpx;
2206
+ text-align: center;
20932207 }
20942208 }
20952209 </style>