|
|
- <template>
- <view class="card">
- <image class="card-bg" :src="data.url" mode="scaleToFill"></image>
-
- <view class="flex card-bar">
- <uv-count-down
- v-if="time"
- :time="time"
- format="DD:HH:mm:ss"
- autoStart
- millisecond
- @change="onChange">
- <view class="flex countdown">
- 距开始<text class="count">{{ timeData.days }}</text>天
- <text class="count">{{ timeData.hours>10?timeData.hours:'0'+timeData.hours}}</text>:<text class="count">{{ timeData.minutes }}</text>:<text class="count">{{ timeData.seconds }}</text>
- </view>
- </uv-count-down>
- <button class="flex btn">进入直播间</button>
- </view>
- </view>
- </template>
-
- <script>
- import dayjs from "dayjs";
- import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
-
- dayjs.extend(isSameOrBefore);
-
- export default {
- props: {
- data: {
- type: Object,
- default() {
- return {}
- }
- }
- },
- data() {
- return {
- time: null,
- timeData: {}
- }
- },
- watch: {
- data: {
- handler() {
- this.updateCountdown()
- },
- immediate: true,
- deep: true,
- }
- },
- methods: {
- onChange(e) {
- this.timeData = e
- },
- updateCountdown() {
-
- let current = dayjs()
- let startTime = dayjs(this.data.startTime)
-
- if (startTime.isSameOrBefore(current)) {
- this.time = null
- return
- }
-
- this.time = startTime.diff(current, 'millisecond')
-
- },
- },
- }
- </script>
-
- <style scoped lang="scss">
- .card {
- position: relative;
- width: 100%;
- height: 316rpx;
- border-radius: 40rpx;
- overflow: hidden;
- box-shadow: -5rpx -5rpx 10rpx 0 #FFFFFF,
- 10rpx 10rpx 20rpx 0 #AAAACC80,
- 4rpx 4rpx 10rpx 0 #AAAACC40,
- -2rpx -2rpx 5rpx 0 #FFFFFF;
-
- &-bg {
- width: 100%;
- height: 100%;
- }
-
- &-bar {
- justify-content: space-between;
- position: absolute;
- left: 0;
- bottom: 0;
- width: 100%;
- padding: 13rpx 32rpx;
- background: #FFFFFF69;
- box-sizing: border-box;
-
- .countdown {
- font-family: PingFang SC;
- font-weight: 400;
- font-size: 28rpx;
- line-height: 1.4;
- color: #252545;
-
- .count {
- margin: 0 8rpx;
- display: inline-flex;
- align-items: center;
- justify-content: center;
- min-width: 40rpx;
- height: 40rpx;
- background: #0000002B;
- border-radius: 8rpx;
- }
- }
-
- .btn {
- font-family: PingFang SC;
- font-weight: 600;
- font-size: 24rpx;
- line-height: 1.5;
- color: #252545;
- padding: 7rpx 16rpx;
- border-radius: 24rpx;
- background: #FFFFFF;
- }
- }
- }
- </style>
|