StatsSection.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <div class="stats-container">
  3. <div class="stats-bg-wrapper">
  4. <img class="stats-bg" src="/images/home/home-bg.png" alt="首页背景" />
  5. <section class="stats-section">
  6. <NuxtPicture class="stats-figure" src="/images/home/home-d.png" alt="游戏盾"></NuxtPicture>
  7. <div class="stats-row">
  8. <div class="stat-item">
  9. <div class="stat-label">今日攻击次数</div>
  10. <div class="stat-value">{{ formatNumber(stats.ccAttacks) }}</div>
  11. </div>
  12. <div class="stat-item">
  13. <div class="stat-label">今日拦截次数</div>
  14. <div class="stat-value">{{ formatNumber(stats.wafBlocks) }}</div>
  15. </div>
  16. </div>
  17. <div class="stat-item state-other">
  18. <div class="stat-label">今日DDoS攻击峰值</div>
  19. <div class="stat-value">{{ formatNumber(stats.ddosPeak) }}</div>
  20. </div>
  21. </section>
  22. </div>
  23. </div>
  24. </template>
  25. <script setup>
  26. import { onMounted, onUnmounted } from 'vue'
  27. import { storeToRefs } from 'pinia'
  28. const statsStore = useStatsStore()
  29. const { stats } = storeToRefs(statsStore)
  30. let intervalId = null
  31. onMounted(() => {
  32. intervalId = statsStore.startAutoIncrement()
  33. })
  34. onUnmounted(() => {
  35. if (intervalId) {
  36. statsStore.stopAutoIncrement(intervalId)
  37. }
  38. })
  39. const formatNumber = (num) => {
  40. return num.toLocaleString()
  41. }
  42. </script>
  43. <style scoped lang="scss">
  44. .stats-container {
  45. width: 100%;
  46. display: flex;
  47. justify-content: center;
  48. }
  49. .stats-bg-wrapper {
  50. position: relative;
  51. width: 100%;
  52. height: 800px;
  53. .stats-bg {
  54. display: flex;
  55. justify-content: center;
  56. position: absolute;
  57. top: 50%;
  58. left: 50%;
  59. transform: translate(-50%, -50%);
  60. width: 1400px;
  61. height: auto;
  62. }
  63. }
  64. .stats-section {
  65. width: 100%;
  66. height: 100%;
  67. position: absolute;
  68. top: 0;
  69. left: 0;
  70. display: flex;
  71. align-items: center;
  72. justify-content: center;
  73. overflow: hidden;
  74. .stats-row {
  75. position: absolute;
  76. top: 40%;
  77. left: 50%;
  78. transform: translateX(-50%) translateY(-50%);
  79. display: flex;
  80. align-items: center;
  81. justify-content: center;
  82. z-index: 1;
  83. }
  84. .stats-figure {
  85. position: absolute;
  86. top: 40%;
  87. left: 50%;
  88. transform: translateX(-50%) translateY(-50%);
  89. object-fit: contain;
  90. pointer-events: none;
  91. z-index: 0;
  92. will-change: transform;
  93. animation: float 3s ease-in-out infinite;
  94. :deep(img) {
  95. width: 180px;
  96. height: auto;
  97. }
  98. }
  99. @keyframes float {
  100. 0% {
  101. transform: translateX(-50%) translateY(-50%);
  102. }
  103. 50% {
  104. transform: translateX(-50%) translateY(calc(-50% - 20px));
  105. }
  106. 100% {
  107. transform: translateX(-50%) translateY(-50%);
  108. }
  109. }
  110. .state-other {
  111. position: absolute;
  112. top: 60px;
  113. }
  114. .stat-item {
  115. display: flex;
  116. flex-direction: column;
  117. align-items: center;
  118. justify-content: space-between;
  119. margin: 0 300px;
  120. z-index: 1;
  121. .stat-label {
  122. font-size: 24px;
  123. font-weight: 400;
  124. line-height: 24px;
  125. color: #ffffff;
  126. text-align: center;
  127. margin-bottom: 20px;
  128. }
  129. .stat-value {
  130. font-size: 56px;
  131. font-weight: 700;
  132. line-height: 56px;
  133. color: #a182ff;
  134. text-align: center;
  135. }
  136. }
  137. }
  138. </style>