countdown.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. <template>
  2. <view class="countdown">
  3. <custom-nav :title="pageTitle"></custom-nav>
  4. <view class="content" v-if="countdown > 0">
  5. <view class="text">尊敬的 {{ userServerInfo.name || nickName }},您好,您参加的大卫博士学位争霸赛还未开赛,请耐心等待。 距离开赛时间还剩:</view>
  6. <image src="../../static/icon/countdown.png" mode=""></image>
  7. <view class="countdownnum">
  8. <text class="days">{{ days }}</text>
  9. <text>{{ hours }}</text>
  10. <text>{{ minutes }}</text>
  11. <text>{{ seconds }}</text>
  12. </view>
  13. </view>
  14. <view v-else style="text-align: center;" class="started">已开赛</view>
  15. </view>
  16. </template>
  17. <script>
  18. export default {
  19. data() {
  20. return {
  21. pageTitle: '开赛倒计时',
  22. countdown: 0,
  23. days: '',
  24. hours: '',
  25. minutes: '',
  26. seconds: '',
  27. nickName: ''
  28. };
  29. },
  30. computed: {
  31. userServerInfo () { //用户服务器信息
  32. return this.$store.state.userServerInfo
  33. },
  34. userWeixinInfo () { //用户服务器信息
  35. return this.$store.state.userWeixinInfo
  36. }
  37. },
  38. onShow() {
  39. this.nickName = this.userServerInfo.name
  40. },
  41. methods: {
  42. computCountdown () {
  43. this.countdown = +this.userServerInfo.start_time - +new Date
  44. this.days = (parseInt(this.countdown / (1000 * 60 * 60 * 24)) + '')
  45. this.hours = (parseInt(this.countdown % (1000 * 60 * 60 * 24) / (1000 * 60 * 60)) + '').length === 1 ?
  46. '0' + parseInt(this.countdown % (1000 * 60 * 60 * 24) / (1000 * 60 * 60)) :
  47. parseInt(this.countdown % (1000 * 60 * 60 * 24) / (1000 * 60 * 60))
  48. this.minutes = (parseInt(this.countdown % (1000 * 60 * 60 * 24) % (1000 * 60 * 60) / (1000 * 60)) + '').length === 1 ?
  49. '0' + parseInt(this.countdown % (1000 * 60 * 60 * 24) % (1000 * 60 * 60) / (1000 * 60)) :
  50. parseInt(this.countdown % (1000 * 60 * 60 * 24) % (1000 * 60 * 60) / (1000 * 60))
  51. this.seconds = (parseInt(this.countdown % (1000 * 60 * 60 * 24) % (1000 * 60 * 60) % (1000 * 60) / 1000) + '').length === 1 ?
  52. '0' + parseInt(this.countdown % (1000 * 60 * 60 * 24) % (1000 * 60 * 60) % (1000 * 60) / 1000) :
  53. parseInt(this.countdown % (1000 * 60 * 60 * 24) % (1000 * 60 * 60) % (1000 * 60) / 1000)
  54. }
  55. },
  56. created() {
  57. if (this.userServerInfo.status === 1 || this.userServerInfo.status === 4) {
  58. this.computCountdown()
  59. }
  60. this.timer = setInterval(() => {
  61. if (this.userServerInfo.status === 1 || this.userServerInfo.status === 4) {
  62. this.computCountdown()
  63. } else {
  64. clearInterval(this.timer)
  65. }
  66. }, 1000)
  67. },
  68. beforeDestroy() {
  69. clearInterval(this.timer)
  70. }
  71. }
  72. </script>
  73. <style lang="scss" scoped>
  74. .countdown {
  75. @include page();
  76. .content {
  77. box-sizing: border-box;
  78. padding: 180rpx 110rpx 0;
  79. position: relative;
  80. font-size: 32rpx;
  81. font-weight:400;
  82. color: rgba(75,75,75,1);
  83. line-height: 48rpx;
  84. image {
  85. margin-top: 90rpx;
  86. width: 100%;
  87. height: 361rpx;
  88. }
  89. .countdownnum {
  90. position: absolute;
  91. width: 486rpx;
  92. height: 52rpx;
  93. top: 684rpx;
  94. left: 50%;
  95. transform: translateX(-50%);
  96. color: #FFFFFF;
  97. text {
  98. &.days {
  99. width: 42rpx;
  100. }
  101. float: left;
  102. width: 80rpx;
  103. margin-left: 40rpx;
  104. font-size: 60rpx;
  105. }
  106. }
  107. }
  108. }
  109. </style>