Jacob
1 天以前 24b8f2afa92ce7bbe490185ecbab869c460b798b
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">
....@@ -71,7 +90,8 @@
7190 </view>
7291 </view>
7392 <view @click="goLottery" class="lottery_banner" v-if="info && info.isLottery && info.lotteryBanner">
74
- <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix">
93
+ <image class="lottery_bannerImg" :src="info.lotteryBanner" mode="widthFix"
94
+ :style="{ height: lotteryBannerHeight }">
7595 </image>
7696 </view>
7797 <view class="tag-img-container" v-if="info.zoneType == 7">
....@@ -588,7 +608,7 @@
588608 showMenu: false,
589609 selectedMenuArr: [],
590610 expireTime: [],
591
- expireTimeUnit: [],
611
+ countdownToken: 0,
592612 isPageShow: false,
593613 loginBackFn: null,
594614 errText: '',
....@@ -598,6 +618,8 @@
598618 isYueyangZone: false,
599619 isOpen: false, // 默认收起,false收起/true展开
600620 currentIndex: -1, // 默认选中第一个【全部】
621
+ videoControls: true, // 专区活动视频是否显示海报+播放按钮
622
+ zoneVideoContext: '', // 活动视频播放上下文
601623 partitionList: [],
602624 partitionProject: {},
603625 tagList: [],
....@@ -621,6 +643,7 @@
621643 stockEmpty: true,
622644 urlOption: {},
623645 homeTop: '200',
646
+ lotteryBannerHeight: '', //抽奖banner预计算高度(rpx),空字符串表示未取到,按原逻辑自适应
624647 hasNewPop: false,
625648 leftCoupon: {},
626649 rightCoupon: {},
....@@ -837,6 +860,17 @@
837860 }
838861 },
839862 methods: {
863
+ /**
864
+ * 专区活动视频:点击海报播放按钮后播放
865
+ */
866
+ bindZoneVideoPlay() {
867
+ if (!this.zoneVideoContext) {
868
+ this.zoneVideoContext = uni.createVideoContext('zoneVideo', this);
869
+ }
870
+ this.$set(this, 'videoControls', false);
871
+ this.zoneVideoContext.play();
872
+ },
873
+ zoneVideoPause() { },
840874 handleCouponRule() {
841875 this.$refs.personalAndShareCouponRuleRef.show(this.info.ruleContentText)
842876 },
....@@ -1295,6 +1329,9 @@
12951329 })
12961330 },
12971331 validAlert(data) {
1332
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1333
+ this.countdownToken++
1334
+ const token = this.countdownToken
12981335 const {
12991336 startTime,
13001337 expireTime
....@@ -1313,17 +1350,17 @@
13131350 let minutes = startTimetamp.getMinutes()
13141351 minutes = minutes < 10 ? '0' + minutes : minutes;
13151352
1316
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1353
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13171354 this.startOrEnd = "后开启"
13181355 return
1319
- }
1320
- }
1321
- if (expireTime) {
1322
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1323
- if (expireTimetamp < nowTimestamp) {
1356
+ }
1357
+ }
1358
+ if (expireTime) {
1359
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1360
+ if (expireTimetamp < nowTimestamp) {
13241361 return
1325
- }
1326
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1362
+ }
1363
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13271364 this.startOrEnd = "后结束"
13281365 }
13291366 },
....@@ -1445,6 +1482,21 @@
14451482 this.$refs.popNewuserRef.show()
14461483 }
14471484 },
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
+ },
14481500 getZoneDetail: function () {
14491501 let that = this;
14501502 let belong = this.$store.getters.belong;
....@@ -1452,6 +1504,7 @@
14521504 console.log('专区详情入参::', params)
14531505 getZoneDetail(that.id, params).then(res => {
14541506 that.info = res.data;
1507
+ that.setLotteryBannerSize(res.data);
14551508 that.updateZoneShareMenu();
14561509 if (res.data.zoneType == 6) {
14571510 that.setYueyangZone()
....@@ -1461,7 +1514,7 @@
14611514 that.homeTop = that.getHomeTop(0.4)
14621515 }
14631516 that.expireTime = [];
1464
- that.expireTimeUnit = [];
1517
+ that.countdownToken++;
14651518 that.where.page = 1;
14661519 that.getGoodList()
14671520 that.validAlert(res.data)
....@@ -1487,8 +1540,9 @@
14871540 }
14881541 });
14891542 },
1490
- countdownTimer(expireTime, type) {
1543
+ countdownTimer(expireTime, type, token) {
14911544 if (!expireTime) return
1545
+ if (token !== undefined && token !== this.countdownToken) return
14921546 let that = this;
14931547 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
14941548 const endTimestamp = new Date(expireTime).getTime();
....@@ -1500,56 +1554,56 @@
15001554 if (type == 'end') {
15011555 if (diff <= 0) {
15021556 this.expireTime = []
1503
- this.expireTimeUnit = []
15041557 return
15051558 } else { }
15061559 } else if (type == 'start') {
15071560 if (diff <= 0) {
15081561 this.expireTime = []
1509
- this.expireTimeUnit = []
15101562 const expireTime2 = that.info.expireTime
15111563 if (expireTime2) {
15121564 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15131565 if (expireTimetamp < nowTimestamp) {
15141566 return
15151567 }
1516
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1568
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15171569 this.startOrEnd = "后结束"
15181570 }
15191571 return
15201572 }
15211573 }
1574
+ const pad = num => (num < 10 ? '0' + num : String(num))
15221575 const res = []
1523
- const unit = []
15241576 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15251577 diff %= (1000 * 60 * 60 * 24)
1526
- if (days > 0) {
1527
- res.push(days);
1528
- unit.push('日')
1529
- }
15301578 // 转换为小时、分钟、秒
15311579 const hours = Math.floor(diff / (1000 * 60 * 60));
15321580 diff %= (1000 * 60 * 60); // 剩余毫秒数
1533
- if (hours > 0) {
1534
- res.push(hours < 10 ? '0' + hours : hours);
1535
- unit.push('时')
1536
- }
15371581 const minutes = Math.floor(diff / (1000 * 60));
1538
- if (minutes > 0) {
1539
- res.push(minutes < 10 ? '0' + minutes : minutes);
1540
- unit.push('分')
1541
- }
15421582 diff %= (1000 * 60); // 剩余毫秒数
15431583 const seconds = Math.floor(diff / 1000);
1544
- if (seconds > 0) {
1545
- res.push(seconds < 10 ? '0' + seconds : seconds);
1546
- unit.push('秒')
1584
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1585
+ if (days > 0) {
1586
+ res.push({
1587
+ digits: pad(days).split(''),
1588
+ unit: '日'
1589
+ })
15471590 }
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
+ })
15481603 this.expireTime = res
1549
- this.expireTimeUnit = unit
15501604 if (this.isPageShow) {
15511605 setTimeout(() => {
1552
- that.countdownTimer(expireTime, type)
1606
+ that.countdownTimer(expireTime, type, token)
15531607 }, 1000)
15541608 }
15551609 },
....@@ -1866,6 +1920,48 @@
18661920 }
18671921 }
18681922
1923
+.rich-content {
1924
+ padding: 24rpx 30rpx;
1925
+ background-color: #fff;
1926
+}
1927
+
1928
+.video-wrap {
1929
+ position: relative;
1930
+ width: 100%;
1931
+ height: 750rpx;
1932
+ background-color: #000;
1933
+}
1934
+
1935
+.video-wrap .video-poster {
1936
+ position: absolute;
1937
+ top: 0;
1938
+ left: 0;
1939
+ width: 100%;
1940
+ height: 750rpx;
1941
+ z-index: 9;
1942
+}
1943
+
1944
+.video-wrap .video-poster .image {
1945
+ width: 100%;
1946
+ height: 100%;
1947
+}
1948
+
1949
+.video-wrap .video-stop {
1950
+ position: absolute;
1951
+ top: 50%;
1952
+ left: 50%;
1953
+ width: 136rpx;
1954
+ height: 136rpx;
1955
+ margin-top: -68rpx;
1956
+ margin-left: -68rpx;
1957
+ z-index: 9;
1958
+}
1959
+
1960
+.video-wrap .video-stop .image {
1961
+ width: 100%;
1962
+ height: 100%;
1963
+}
1964
+
18691965 .toolbarList {
18701966 width: 750rpx;
18711967 position: -webkit-sticky;
....@@ -2082,11 +2178,22 @@
20822178 padding: 15rpx;
20832179 padding-left: 30rpx;
20842180 color: #979797;
2181
+ font-size: 26rpx;
20852182
20862183 .num {
2184
+ display: inline-block;
20872185 color: #000000;
20882186 background: #FFE20E;
2089
- 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;
20902197 }
20912198 }
20922199 </style>