Jacob
4 天以前 f564a64d3c99b4d300e54e038446227a440bba48
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">
....@@ -588,7 +607,7 @@
588607 showMenu: false,
589608 selectedMenuArr: [],
590609 expireTime: [],
591
- expireTimeUnit: [],
610
+ countdownToken: 0,
592611 isPageShow: false,
593612 loginBackFn: null,
594613 errText: '',
....@@ -598,6 +617,8 @@
598617 isYueyangZone: false,
599618 isOpen: false, // 默认收起,false收起/true展开
600619 currentIndex: -1, // 默认选中第一个【全部】
620
+ videoControls: true, // 专区活动视频是否显示海报+播放按钮
621
+ zoneVideoContext: '', // 活动视频播放上下文
601622 partitionList: [],
602623 partitionProject: {},
603624 tagList: [],
....@@ -837,6 +858,17 @@
837858 }
838859 },
839860 methods: {
861
+ /**
862
+ * 专区活动视频:点击海报播放按钮后播放
863
+ */
864
+ bindZoneVideoPlay() {
865
+ if (!this.zoneVideoContext) {
866
+ this.zoneVideoContext = uni.createVideoContext('zoneVideo', this);
867
+ }
868
+ this.$set(this, 'videoControls', false);
869
+ this.zoneVideoContext.play();
870
+ },
871
+ zoneVideoPause() { },
840872 handleCouponRule() {
841873 this.$refs.personalAndShareCouponRuleRef.show(this.info.ruleContentText)
842874 },
....@@ -1295,6 +1327,9 @@
12951327 })
12961328 },
12971329 validAlert(data) {
1330
+ // 每次重新计算前作废旧的倒计时链,避免多条定时器同时刷新导致数字跳动
1331
+ this.countdownToken++
1332
+ const token = this.countdownToken
12981333 const {
12991334 startTime,
13001335 expireTime
....@@ -1313,17 +1348,17 @@
13131348 let minutes = startTimetamp.getMinutes()
13141349 minutes = minutes < 10 ? '0' + minutes : minutes;
13151350
1316
- this.countdownTimer(startTime.split('-').join('/'), 'start')
1351
+ this.countdownTimer(startTime.split('-').join('/'), 'start', token)
13171352 this.startOrEnd = "后开启"
13181353 return
1319
- }
1320
- }
1321
- if (expireTime) {
1322
- const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1323
- if (expireTimetamp < nowTimestamp) {
1354
+ }
1355
+ }
1356
+ if (expireTime) {
1357
+ const expireTimetamp = new Date(expireTime.split('-').join('/')).getTime();
1358
+ if (expireTimetamp < nowTimestamp) {
13241359 return
1325
- }
1326
- this.countdownTimer(expireTime.split('-').join('/'), 'end')
1360
+ }
1361
+ this.countdownTimer(expireTime.split('-').join('/'), 'end', token)
13271362 this.startOrEnd = "后结束"
13281363 }
13291364 },
....@@ -1452,6 +1487,7 @@
14521487 console.log('专区详情入参::', params)
14531488 getZoneDetail(that.id, params).then(res => {
14541489 that.info = res.data;
1490
+ //that.info.zoneType=8;
14551491 that.updateZoneShareMenu();
14561492 if (res.data.zoneType == 6) {
14571493 that.setYueyangZone()
....@@ -1461,7 +1497,7 @@
14611497 that.homeTop = that.getHomeTop(0.4)
14621498 }
14631499 that.expireTime = [];
1464
- that.expireTimeUnit = [];
1500
+ that.countdownToken++;
14651501 that.where.page = 1;
14661502 that.getGoodList()
14671503 that.validAlert(res.data)
....@@ -1487,8 +1523,9 @@
14871523 }
14881524 });
14891525 },
1490
- countdownTimer(expireTime, type) {
1526
+ countdownTimer(expireTime, type, token) {
14911527 if (!expireTime) return
1528
+ if (token !== undefined && token !== this.countdownToken) return
14921529 let that = this;
14931530 // 结束时间的时间戳(需传入一个有效的日期对象或时间戳)
14941531 const endTimestamp = new Date(expireTime).getTime();
....@@ -1500,56 +1537,56 @@
15001537 if (type == 'end') {
15011538 if (diff <= 0) {
15021539 this.expireTime = []
1503
- this.expireTimeUnit = []
15041540 return
15051541 } else { }
15061542 } else if (type == 'start') {
15071543 if (diff <= 0) {
15081544 this.expireTime = []
1509
- this.expireTimeUnit = []
15101545 const expireTime2 = that.info.expireTime
15111546 if (expireTime2) {
15121547 const expireTimetamp = new Date(expireTime2.split('-').join('/')).getTime();
15131548 if (expireTimetamp < nowTimestamp) {
15141549 return
15151550 }
1516
- this.countdownTimer(expireTime2.split('-').join('/'), 'end')
1551
+ this.countdownTimer(expireTime2.split('-').join('/'), 'end', token)
15171552 this.startOrEnd = "后结束"
15181553 }
15191554 return
15201555 }
15211556 }
1557
+ const pad = num => (num < 10 ? '0' + num : String(num))
15221558 const res = []
1523
- const unit = []
15241559 const days = Math.floor(diff / (1000 * 60 * 60 * 24))
15251560 diff %= (1000 * 60 * 60 * 24)
1526
- if (days > 0) {
1527
- res.push(days);
1528
- unit.push('日')
1529
- }
15301561 // 转换为小时、分钟、秒
15311562 const hours = Math.floor(diff / (1000 * 60 * 60));
15321563 diff %= (1000 * 60 * 60); // 剩余毫秒数
1533
- if (hours > 0) {
1534
- res.push(hours < 10 ? '0' + hours : hours);
1535
- unit.push('时')
1536
- }
15371564 const minutes = Math.floor(diff / (1000 * 60));
1538
- if (minutes > 0) {
1539
- res.push(minutes < 10 ? '0' + minutes : minutes);
1540
- unit.push('分')
1541
- }
15421565 diff %= (1000 * 60); // 剩余毫秒数
15431566 const seconds = Math.floor(diff / 1000);
1544
- if (seconds > 0) {
1545
- res.push(seconds < 10 ? '0' + seconds : seconds);
1546
- unit.push('秒')
1567
+ // 天数为 0 时不展示,时/分/秒始终展示(补 0),保证倒计时长度稳定
1568
+ if (days > 0) {
1569
+ res.push({
1570
+ digits: pad(days).split(''),
1571
+ unit: '日'
1572
+ })
15471573 }
1574
+ res.push({
1575
+ digits: pad(hours).split(''),
1576
+ unit: '时'
1577
+ })
1578
+ res.push({
1579
+ digits: pad(minutes).split(''),
1580
+ unit: '分'
1581
+ })
1582
+ res.push({
1583
+ digits: pad(seconds).split(''),
1584
+ unit: '秒'
1585
+ })
15481586 this.expireTime = res
1549
- this.expireTimeUnit = unit
15501587 if (this.isPageShow) {
15511588 setTimeout(() => {
1552
- that.countdownTimer(expireTime, type)
1589
+ that.countdownTimer(expireTime, type, token)
15531590 }, 1000)
15541591 }
15551592 },
....@@ -1866,6 +1903,48 @@
18661903 }
18671904 }
18681905
1906
+.rich-content {
1907
+ padding: 24rpx 30rpx;
1908
+ background-color: #fff;
1909
+}
1910
+
1911
+.video-wrap {
1912
+ position: relative;
1913
+ width: 100%;
1914
+ height: 750rpx;
1915
+ background-color: #000;
1916
+}
1917
+
1918
+.video-wrap .video-poster {
1919
+ position: absolute;
1920
+ top: 0;
1921
+ left: 0;
1922
+ width: 100%;
1923
+ height: 750rpx;
1924
+ z-index: 9;
1925
+}
1926
+
1927
+.video-wrap .video-poster .image {
1928
+ width: 100%;
1929
+ height: 100%;
1930
+}
1931
+
1932
+.video-wrap .video-stop {
1933
+ position: absolute;
1934
+ top: 50%;
1935
+ left: 50%;
1936
+ width: 136rpx;
1937
+ height: 136rpx;
1938
+ margin-top: -68rpx;
1939
+ margin-left: -68rpx;
1940
+ z-index: 9;
1941
+}
1942
+
1943
+.video-wrap .video-stop .image {
1944
+ width: 100%;
1945
+ height: 100%;
1946
+}
1947
+
18691948 .toolbarList {
18701949 width: 750rpx;
18711950 position: -webkit-sticky;
....@@ -2082,11 +2161,22 @@
20822161 padding: 15rpx;
20832162 padding-left: 30rpx;
20842163 color: #979797;
2164
+ font-size: 26rpx;
20852165
20862166 .num {
2167
+ display: inline-block;
20872168 color: #000000;
20882169 background: #FFE20E;
2089
- padding: 0 10rpx;
2170
+ padding: 0 6rpx;
2171
+ margin: 0 4rpx;
2172
+ vertical-align: middle;
2173
+ }
2174
+
2175
+ /* 每个数字固定宽度,避免倒计时跳动时宽度忽长忽短 */
2176
+ .digit {
2177
+ display: inline-block;
2178
+ width: 19rpx;
2179
+ text-align: center;
20902180 }
20912181 }
20922182 </style>