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,8 +89,10 @@
7089 </view>
7190 </view>
7291 </view>
73
- <view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery && info.lotteryBanner">
74
- <image class="lottery_bannerImg" :src="info.lotteryBanner" 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 }">
7596 </image>
7697 </view>
7798 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -588,7 +609,7 @@
588609 showMenu: false,
589610 selectedMenuArr: [],
590611 expireTime: [],
591
- expireTimeUnit: [],
612
+ countdownToken: 0,
592613 isPageShow: false,
593614 loginBackFn: null,
594615 errText: '',
....@@ -598,6 +619,8 @@
598619 isYueyangZone: false,
599620 isOpen: false, // 默认收起,false收起/true展开
600621 currentIndex: -1, // 默认选中第一个【全部】
622
+ videoControls: true, // 专区活动视频是否显示海报+播放按钮
623
+ zoneVideoContext: '', // 活动视频播放上下文
601624 partitionList: [],
602625 partitionProject: {},
603626 tagList: [],
....@@ -621,6 +644,8 @@
621644 stockEmpty: true,
622645 urlOption: {},
623646 homeTop: '200',
647
+ lotteryBannerHeight: '', //抽奖banner预计算高度(rpx),空字符串表示未取到,按原逻辑自适应
648
+ lotteryBannerReady: false, //是否已拿到banner尺寸(或已确认拿不到),未就绪前不渲染,避免首帧撑高
624649 hasNewPop: false,
625650 leftCoupon: {},
626651 rightCoupon: {},
....@@ -837,6 +862,17 @@
837862 }
838863 },
839864 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() { },
840876 handleCouponRule() {
841877 this.$refs.personalAndShareCouponRuleRef.show(this.info.ruleContentText)
842878 },
....@@ -1295,6 +1331,9 @@
12951331 })
12961332 },
12971333 validAlert(data) {
1334
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1335
+ this.countdownToken++
1336
+ const token = this.countdownToken
12981337 const {
12991338 startTime,
13001339 expireTime
....@@ -1313,17 +1352,17 @@
13131352 let minutes = startTimetamp.getMinutes()
13141353 minutes = minutes < 10 ? '0' + minutes : minutes;
13151354
1316
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1355
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13171356 this.startOrEnd = "后开启"
13181357 return
1319
- }
1320
- }
1321
- if (expireTime) {
1322
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1323
- if (expireTimetamp < nowTimestamp) {
1358
+ }
1359
+ }
1360
+ if (expireTime) {
1361
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1362
+ if (expireTimetamp < nowTimestamp) {
13241363 return
1325
- }
1326
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1364
+ }
1365
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13271366 this.startOrEnd = "后结束"
13281367 }
13291368 },
....@@ -1445,6 +1484,29 @@
14451484 this.$refs.popNewuserRef.show()
14461485 }
14471486 },
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
+ },
14481510 getZoneDetail: function () {
14491511 let that = this;
14501512 let belong = this.$store.getters.belong;
....@@ -1452,6 +1514,7 @@
14521514 console.log('专区详情入参::', params)
14531515 getZoneDetail(that.id, params).then(res => {
14541516 that.info = res.data;
1517
+ that.setLotteryBannerSize(res.data);
14551518 that.updateZoneShareMenu();
14561519 if (res.data.zoneType == 6) {
14571520 that.setYueyangZone()
....@@ -1461,7 +1524,7 @@
14611524 that.homeTop = that.getHomeTop(0.4)
14621525 }
14631526 that.expireTime = [];
1464
- that.expireTimeUnit = [];
1527
+ that.countdownToken++;
14651528 that.where.page = 1;
14661529 that.getGoodList()
14671530 that.validAlert(res.data)
....@@ -1487,8 +1550,9 @@
14871550 }
14881551 });
14891552 },
1490
- countdownTimer(expireTime, type) {
1553
+ countdownTimer(expireTime, type, token) {
14911554 if (!expireTime) return
1555
+ if (token !== undefined && token !== this.countdownToken) return
14921556 let that = this;
14931557 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
14941558 const endTimestamp = new Date(expireTime).getTime();
....@@ -1500,56 +1564,56 @@
15001564 if (type == 'end') {
15011565 if (diff <= 0) {
15021566 this.expireTime = []
1503
- this.expireTimeUnit = []
15041567 return
15051568 } else { }
15061569 } else if (type == 'start') {
15071570 if (diff <= 0) {
15081571 this.expireTime = []
1509
- this.expireTimeUnit = []
15101572 const expireTime2 = that.info.expireTime
15111573 if (expireTime2) {
15121574 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15131575 if (expireTimetamp < nowTimestamp) {
15141576 return
15151577 }
1516
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1578
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15171579 this.startOrEnd = "后结束"
15181580 }
15191581 return
15201582 }
15211583 }
1584
+ const pad = num => (num < 10 ? '0' + num : String(num))
15221585 const res = []
1523
- const unit = []
15241586 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15251587 diff %= (1000 * 60 * 60 * 24)
1526
- if (days > 0) {
1527
- res.push(days);
1528
- unit.push('日')
1529
- }
15301588 // 转换为小时、分钟、秒
15311589 const hours = Math.floor(diff / (1000 * 60 * 60));
15321590 diff %= (1000 * 60 * 60); // 剩余毫秒数
1533
- if (hours > 0) {
1534
- res.push(hours < 10 ? '0' + hours : hours);
1535
- unit.push('时')
1536
- }
15371591 const minutes = Math.floor(diff / (1000 * 60));
1538
- if (minutes > 0) {
1539
- res.push(minutes < 10 ? '0' + minutes : minutes);
1540
- unit.push('分')
1541
- }
15421592 diff %= (1000 * 60); // 剩余毫秒数
15431593 const seconds = Math.floor(diff / 1000);
1544
- if (seconds > 0) {
1545
- res.push(seconds < 10 ? '0' + seconds : seconds);
1546
- unit.push('秒')
1594
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1595
+ if (days > 0) {
1596
+ res.push({
1597
+ digits: pad(days).split(''),
1598
+ unit: '日'
1599
+ })
15471600 }
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
+ })
15481613 this.expireTime = res
1549
- this.expireTimeUnit = unit
15501614 if (this.isPageShow) {
15511615 setTimeout(() => {
1552
- that.countdownTimer(expireTime, type)
1616
+ that.countdownTimer(expireTime, type, token)
15531617 }, 1000)
15541618 }
15551619 },
....@@ -1866,6 +1930,48 @@
18661930 }
18671931 }
18681932
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
+
18691975 .toolbarList {
18701976 width: 750rpx;
18711977 position: -webkit-sticky;
....@@ -2082,11 +2188,22 @@
20822188 padding: 15rpx;
20832189 padding-left: 30rpx;
20842190 color: #979797;
2191
+ font-size: 26rpx;
20852192
20862193 .num {
2194
+ display: inline-block;
20872195 color: #000000;
20882196 background: #FFE20E;
2089
- 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;
20902207 }
20912208 }
20922209 </style>