普兆健康管家前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.4 KiB

  1. <template>
  2. <view class="card">
  3. <image class="card-bg" :src="data.url" mode="scaleToFill"></image>
  4. <view class="flex card-bar">
  5. <view class="flex countdown" v-if="countdown">
  6. 距开始<text class="count">{{ countdown.day }}</text>
  7. <text class="count">{{ countdown.hour }}</text>:<text class="count">{{ countdown.minute }}</text>:<text class="count">{{ countdown.second }}</text>
  8. </view>
  9. <button class="flex btn">进入直播间</button>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. import dayjs from "dayjs";
  15. import isSameOrBefore from 'dayjs/plugin/isSameOrBefore'
  16. dayjs.extend(isSameOrBefore);
  17. export default {
  18. props: {
  19. data: {
  20. type: Object,
  21. default() {
  22. return {}
  23. }
  24. }
  25. },
  26. data() {
  27. return {
  28. timer: null,
  29. countdown: null,
  30. }
  31. },
  32. watch: {
  33. data: {
  34. handler() {
  35. this.updateCountdown()
  36. },
  37. immediate: true,
  38. deep: true,
  39. }
  40. },
  41. methods: {
  42. updateCountdown() {
  43. this.timer && clearTimeout(this.timer)
  44. let current = dayjs()
  45. let startTime = dayjs(this.data.startTime)
  46. if (startTime.isSameOrBefore(current)) {
  47. this.countdown = null
  48. return
  49. }
  50. let countdown = {
  51. day: 0,
  52. hour: 0,
  53. minute: 0,
  54. second: 0,
  55. }
  56. let day = Math.floor(startTime.diff(current, 'day', true))
  57. countdown.day = day
  58. let hour = Math.floor(startTime.diff(current, 'hour', true))
  59. countdown.hour = hour - day * 24
  60. countdown.hour = countdown.hour < 10 ? `0${countdown.hour}` : countdown.hour
  61. let minute = Math.floor(startTime.diff(current, 'minute', true))
  62. countdown.minute = minute - hour * 60
  63. countdown.minute = countdown.minute < 10 ? `0${countdown.minute}` : countdown.minute
  64. let second = startTime.diff(current, 'second')
  65. countdown.second = second - minute * 60
  66. countdown.second = countdown.second < 10 ? `0${countdown.second}` : countdown.second
  67. this.countdown = countdown
  68. this.timer = setTimeout(() => {
  69. this.updateCountdown()
  70. }, 1000)
  71. },
  72. },
  73. }
  74. </script>
  75. <style scoped lang="scss">
  76. .card {
  77. position: relative;
  78. width: 100%;
  79. height: 316rpx;
  80. border-radius: 40rpx;
  81. overflow: hidden;
  82. box-shadow: -5rpx -5rpx 10rpx 0 #FFFFFF,
  83. 10rpx 10rpx 20rpx 0 #AAAACC80,
  84. 4rpx 4rpx 10rpx 0 #AAAACC40,
  85. -2rpx -2rpx 5rpx 0 #FFFFFF;
  86. &-bg {
  87. width: 100%;
  88. height: 100%;
  89. }
  90. &-bar {
  91. justify-content: space-between;
  92. position: absolute;
  93. left: 0;
  94. bottom: 0;
  95. width: 100%;
  96. padding: 13rpx 32rpx;
  97. background: #FFFFFF69;
  98. box-sizing: border-box;
  99. .countdown {
  100. font-family: PingFang SC;
  101. font-weight: 400;
  102. font-size: 28rpx;
  103. line-height: 1.4;
  104. color: #252545;
  105. .count {
  106. margin: 0 8rpx;
  107. display: inline-flex;
  108. align-items: center;
  109. justify-content: center;
  110. min-width: 40rpx;
  111. height: 40rpx;
  112. background: #0000002B;
  113. border-radius: 8rpx;
  114. }
  115. }
  116. .btn {
  117. font-family: PingFang SC;
  118. font-weight: 600;
  119. font-size: 24rpx;
  120. line-height: 1.5;
  121. color: #252545;
  122. padding: 7rpx 16rpx;
  123. border-radius: 24rpx;
  124. background: #FFFFFF;
  125. }
  126. }
  127. }
  128. </style>