StatsSection.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. .stats-bg {
  53. width: 100%;
  54. height: auto;
  55. display: block;
  56. }
  57. }
  58. .stats-section {
  59. width: 100%;
  60. height: 100%;
  61. position: absolute;
  62. top: 0;
  63. left: 0;
  64. display: flex;
  65. align-items: center;
  66. justify-content: center;
  67. overflow: hidden;
  68. .stats-row {
  69. position: absolute;
  70. top: 40%;
  71. left: 50%;
  72. transform: translateX(-50%) translateY(-50%);
  73. display: flex;
  74. align-items: center;
  75. justify-content: center;
  76. z-index: 1;
  77. }
  78. .stats-figure {
  79. position: absolute;
  80. top: 40%;
  81. left: 50%;
  82. transform: translateX(-50%) translateY(-50%);
  83. width: 226.059px;
  84. height: 305.118px;
  85. object-fit: contain;
  86. pointer-events: none;
  87. z-index: 0;
  88. will-change: transform;
  89. animation: float 3s ease-in-out infinite;
  90. }
  91. @keyframes float {
  92. 0% {
  93. transform: translateX(-50%) translateY(-50%);
  94. }
  95. 50% {
  96. transform: translateX(-50%) translateY(calc(-50% - 20px));
  97. }
  98. 100% {
  99. transform: translateX(-50%) translateY(-50%);
  100. }
  101. }
  102. .state-other {
  103. position: absolute;
  104. top: 100px;
  105. }
  106. .stat-item {
  107. display: flex;
  108. flex-direction: column;
  109. align-items: center;
  110. justify-content: space-between;
  111. margin: 0 300px;
  112. z-index: 1;
  113. .stat-label {
  114. font-size: 24px;
  115. font-weight: 400;
  116. line-height: 24px;
  117. color: #ffffff;
  118. text-align: center;
  119. margin-bottom: 20px;
  120. }
  121. .stat-value {
  122. font-size: 56px;
  123. font-weight: 700;
  124. line-height: 56px;
  125. color: #a182ff;
  126. text-align: center;
  127. }
  128. }
  129. }
  130. </style>