StatsSection.vue 2.9 KB

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