RiskWarning.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div class="panel-box risk-warning">
  3. <div class="corner-deco tl"></div><div class="corner-deco tr"></div>
  4. <div class="corner-deco bl"></div><div class="corner-deco br"></div>
  5. <div class="panel-title">实验室实时风险预警</div>
  6. <div class="panel-content">
  7. <div class="warning-header">
  8. <div class="warning-count">{{ totalMonth }}</div>
  9. <div class="warning-count-label">本月预警响应总数</div>
  10. <div class="warning-sub-counts">
  11. <span class="sub-count emergency">应急 {{ emergencyCount }}</span>
  12. <span class="sub-count violation">违规带离 {{ violationCount }}</span>
  13. </div>
  14. </div>
  15. <div class="warning-scroll-wrap" ref="scrollWrap" @mouseenter="paused=true" @mouseleave="paused=false">
  16. <div ref="scrollInner" class="warning-scroll-inner">
  17. <div class="warning-item" v-for="(item, idx) in displayList" :key="idx">
  18. <div class="w-lab">{{ item.lab }}</div>
  19. <div class="w-sensor" :style="{ color: categoryColor(item.category) }">异常: {{ item.type }}</div>
  20. <div class="w-time">{{ item.time }}</div>
  21. </div>
  22. </div>
  23. </div>
  24. </div>
  25. </div>
  26. </template>
  27. <script>
  28. import { getRiskWarningList } from '@/api'
  29. export default {
  30. name: 'RiskWarning',
  31. data() {
  32. return {
  33. totalMonth: 0,
  34. emergencyCount: 0,
  35. violationCount: 0,
  36. list: [],
  37. paused: false,
  38. scrollTimer: null,
  39. scrollY: 0,
  40. timer: null
  41. }
  42. },
  43. computed: {
  44. displayList() {
  45. if(this.list[2]){
  46. return [...this.list, ...this.list]
  47. }else{
  48. return [...this.list]
  49. }
  50. }
  51. },
  52. async mounted() {
  53. await this.loadData()
  54. this.timer = setInterval(this.loadData, 5 * 60 * 1000)
  55. },
  56. beforeDestroy() {
  57. if (this.scrollTimer) cancelAnimationFrame(this.scrollTimer)
  58. clearInterval(this.timer)
  59. },
  60. methods: {
  61. async loadData() {
  62. try {
  63. const res = await getRiskWarningList()
  64. this.totalMonth = res.data.totalMonth
  65. this.emergencyCount = res.data.emergencyCount
  66. this.violationCount = res.data.violationCount
  67. this.list = res.data.list
  68. if (!this.scrollTimer) {
  69. this.$nextTick(() => setTimeout(() => this.startScroll(), 500))
  70. }
  71. } catch (e) {
  72. console.error('RiskWarning:', e)
  73. }
  74. },
  75. categoryColor(category) {
  76. if (category === '应急预警') return '#FFB020'
  77. if (category === '违规带离') return '#A78BFA'
  78. return '#FFB020'
  79. },
  80. startScroll() {
  81. const wrap = this.$refs.scrollWrap
  82. const inner = this.$refs.scrollInner
  83. if (!wrap || !inner) return
  84. const halfHeight = inner.scrollHeight / 2
  85. if (halfHeight <= wrap.offsetHeight) return
  86. const speed = 0.4
  87. this.scrollY = 0
  88. const step = () => {
  89. if (!this.paused) {
  90. this.scrollY += speed
  91. if (this.scrollY >= halfHeight) this.scrollY -= halfHeight
  92. inner.style.transform = `translateY(${-this.scrollY}px)`
  93. }
  94. this.scrollTimer = requestAnimationFrame(step)
  95. }
  96. this.scrollTimer = requestAnimationFrame(step)
  97. }
  98. }
  99. }
  100. </script>
  101. <style lang="scss" scoped>
  102. .risk-warning {
  103. display: flex;
  104. flex-direction: column;
  105. }
  106. .warning-header {
  107. display: flex;
  108. align-items: center;
  109. gap: 12px;
  110. margin-bottom: 10px;
  111. flex-shrink: 0;
  112. }
  113. .warning-count {
  114. font-size: 28px;
  115. font-weight: 700;
  116. color: $accent-orange;
  117. font-family: 'Courier New', monospace;
  118. text-shadow: 0 0 10px rgba(255,176,32,0.4);
  119. animation: warnCountGlow 2s ease-in-out infinite;
  120. }
  121. @keyframes warnCountGlow {
  122. 0%, 100% { text-shadow: 0 0 8px rgba(255,176,32,0.3); }
  123. 50% { text-shadow: 0 0 20px rgba(255,176,32,0.6), 0 0 40px rgba(255,176,32,0.2); }
  124. }
  125. .warning-count-label {
  126. font-size: 12px;
  127. color: $text-secondary;
  128. }
  129. .warning-sub-counts {
  130. margin-left: auto;
  131. display: flex;
  132. gap: 8px;
  133. }
  134. .sub-count {
  135. font-size: 11px;
  136. padding: 2px 8px;
  137. border-radius: 10px;
  138. &.emergency {
  139. color: #FFB020;
  140. background: rgba(255, 176, 32, 0.1);
  141. border: 1px solid rgba(255, 176, 32, 0.3);
  142. }
  143. &.violation {
  144. color: #A78BFA;
  145. background: rgba(167, 139, 250, 0.1);
  146. border: 1px solid rgba(167, 139, 250, 0.3);
  147. }
  148. }
  149. .warning-sub-counts {
  150. margin-left: auto;
  151. display: flex;
  152. gap: 8px;
  153. }
  154. .sub-count {
  155. font-size: 11px;
  156. padding: 2px 8px;
  157. border-radius: 10px;
  158. &.emergency {
  159. color: #FFB020;
  160. background: rgba(255, 176, 32, 0.12);
  161. border: 1px solid rgba(255, 176, 32, 0.3);
  162. }
  163. &.violation {
  164. color: #A78BFA;
  165. background: rgba(167, 139, 250, 0.12);
  166. border: 1px solid rgba(167, 139, 250, 0.3);
  167. }
  168. }
  169. .warning-scroll-wrap {
  170. flex: 1;
  171. overflow: hidden;
  172. min-height: 0;
  173. }
  174. .null-data-text{
  175. text-align: center;
  176. line-height:130px;
  177. }
  178. .warning-item {
  179. padding: 8px 12px;
  180. margin-bottom: 6px;
  181. border-radius: 4px;
  182. background: rgba(255,176,32,0.04);
  183. border-left: 3px solid $accent-orange;
  184. transition: all 0.3s ease;
  185. animation: warnBorderPulse 3s ease-in-out infinite;
  186. &:hover {
  187. background: rgba(255,176,32,0.08);
  188. transform: translateX(3px);
  189. }
  190. }
  191. @keyframes warnBorderPulse {
  192. 0%, 100% { border-left-color: rgba(255,176,32,0.6); }
  193. 50% { border-left-color: $accent-orange; box-shadow: -2px 0 8px rgba(255,176,32,0.15); }
  194. }
  195. .w-lab {
  196. font-size: 13px;
  197. font-weight: 600;
  198. color: #fff;
  199. }
  200. .w-sensor {
  201. font-size: 12px;
  202. color: $accent-orange;
  203. margin: 2px 0;
  204. }
  205. .w-time {
  206. font-size: 11px;
  207. color: $text-secondary;
  208. margin-top: 4px;
  209. }
  210. </style>