index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <section class="wrap__four">
  3. <img src="@/public/images/banner02.png" class="banner-bg" />
  4. <div class="mask-bg"></div>
  5. <div class="wrap__four-body">
  6. <div class="wrap__four-total trans-300">
  7. <!-- <span>10,117,195</span> -->
  8. <!-- <a-statistic title="" :value="statisticNumber" /> -->
  9. <a-statistic title="" :value="computeStatisticValue(Date.now())" />
  10. </div>
  11. <div class="wrap__four-desc trans-300">
  12. <span>{{ $t('system["包裹运送到全球,而且还在不断增加..."]') }}</span>
  13. </div>
  14. <div class="wrap__four-tips">
  15. <span>{{ $t('system["自 Vava buy.com 成立以来"]') }}</span>
  16. </div>
  17. </div>
  18. </section>
  19. </template>
  20. <script setup lang="ts">
  21. import { ref, onBeforeUnmount, onMounted } from 'vue'
  22. const statisticNumber = ref<number>(0)
  23. const statisticTimer = ref<number>(-1)
  24. const computeDelay = ref<number>(1000 * 60 * 60 * 1)
  25. const statisticStorageKey: string = 'statistic_time'
  26. // 获取统计值
  27. function initForStatistic() {
  28. statisticNumber.value = getStatisticValue()
  29. const nowTime = Date.now()
  30. const oldTime = !!localStorage.getItem(statisticStorageKey)
  31. ? Number(localStorage.getItem(statisticStorageKey))
  32. : nowTime
  33. let step_temp = Math.floor((nowTime - oldTime) / computeDelay.value)
  34. console.log('(nowTime - oldTime)', nowTime - oldTime)
  35. console.log('step_temp', step_temp)
  36. if (step_temp > 0) {
  37. statisticNumber.value = computeStatisticValue(oldTime + computeDelay.value * step_temp)
  38. localStorage.setItem(statisticStorageKey, `${oldTime + computeDelay.value * step_temp}`)
  39. } else {
  40. !localStorage.getItem(statisticStorageKey) &&
  41. localStorage.setItem(statisticStorageKey, `${nowTime}`)
  42. }
  43. }
  44. function getStatisticValue(): number {
  45. let oldVal: string | null = localStorage.getItem(statisticStorageKey)
  46. const nowTime: number = Date.now()
  47. let result: number = computeStatisticValue(!!oldVal ? Number(oldVal) : nowTime)
  48. return result
  49. }
  50. // 计算统计值
  51. function computeStatisticValue(value: number): number {
  52. return Number((value / (1000 * 60 * 60)).toFixed(0))
  53. }
  54. // 添加计时器
  55. function addInterval(delay = 1000 * 30) {
  56. statisticTimer.value = setInterval(() => {
  57. initForStatistic()
  58. }, delay)
  59. }
  60. // 移除计时器
  61. function removeInterval() {
  62. clearInterval(statisticTimer.value)
  63. statisticTimer.value = -1
  64. }
  65. /* ------------------------------ 生命周期钩子 ------------------------------ */
  66. onMounted(() => {
  67. initForStatistic()
  68. addInterval()
  69. })
  70. onBeforeUnmount(() => {
  71. removeInterval()
  72. })
  73. </script>
  74. <style lang="less" scoped>
  75. .wrap__four {
  76. display: flex;
  77. justify-content: center;
  78. position: relative;
  79. width: 100%;
  80. height: auto;
  81. .banner-bg {
  82. width: 100%;
  83. max-width: 1200px;
  84. max-width: 75rem;
  85. height: auto;
  86. min-height: 260px;
  87. object-fit: cover;
  88. }
  89. .mask-bg {
  90. position: absolute;
  91. top: 0;
  92. right: 0;
  93. bottom: 0;
  94. left: 0;
  95. background: linear-gradient(270deg, #000000 0%, rgba(0, 0, 0, 0) 100%);
  96. }
  97. .wrap__four-body {
  98. position: absolute;
  99. top: 50%;
  100. left: 50%;
  101. transform: translate(-50%, -50%);
  102. text-align: center;
  103. .wrap__four-total {
  104. margin-bottom: 30px;
  105. margin-bottom: 1.875rem;
  106. :deep(.ant-statistic-content-value-int) {
  107. font-family: Poppins;
  108. font-size: 120px;
  109. font-size: 7.5rem;
  110. font-weight: 600;
  111. color: #ffffff;
  112. }
  113. }
  114. .wrap__four-desc {
  115. font-family: Source Han Sans;
  116. font-size: 26px;
  117. font-size: 1.625rem;
  118. font-weight: bold;
  119. font-variation-settings: 'opsz' auto;
  120. font-feature-settings: 'kern' on;
  121. color: #ffffff;
  122. }
  123. .wrap__four-tips {
  124. margin-top: 80px;
  125. margin-top: 5rem;
  126. font-family: Source Han Sans;
  127. font-weight: 500;
  128. font-size: 15px;
  129. font-size: 0.9375rem;
  130. color: rgba(255, 255, 255, 0.75);
  131. }
  132. }
  133. }
  134. </style>
  135. <style lang="less" scoped>
  136. @import url(./css/styles@1200.less);
  137. @import url(./css/styles@1024.less);
  138. @import url(./css/styles@768.less);
  139. </style>