HomePageWarning.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <template>
  2. <ChartsContainer title="紧急通知" class="home-page-warning">
  3. <!-- 紧急通知 -->
  4. <div class="urgent-notice" v-if="noticeList.length > 0">
  5. <div class="notice-carousel">
  6. <transition name="slide-up-down" mode="out-in">
  7. <div :key="currentNotice && currentNotice.noticeId" class="notice-content">
  8. {{ currentNotice && currentNotice.noticeTitle ? currentNotice.noticeTitle : '暂无通知' }}
  9. </div>
  10. </transition>
  11. </div>
  12. </div>
  13. </ChartsContainer>
  14. </template>
  15. <script setup>
  16. import ChartsContainer from '../ChartsContainer.vue'
  17. import { ref, onMounted, onUnmounted } from 'vue'
  18. import { listNotice } from '@/api/system/notice'
  19. // 紧急通知数据
  20. const noticeList = ref([])
  21. const currentIndex = ref(0)
  22. const currentNotice = ref(null)
  23. const timer = ref(null)
  24. // 获取公告数据
  25. const fetchNoticeData = async () => {
  26. try {
  27. const response = await listNotice({
  28. status: '0',
  29. noticeType: 1,
  30. pageSize: 999
  31. })
  32. // 假设response.rows包含公告列表
  33. noticeList.value = response.rows || []
  34. if (noticeList.value.length > 0) {
  35. currentNotice.value = noticeList.value[0]
  36. if (timer.value) {
  37. clearInterval(timer.value)
  38. }
  39. // 数据加载完成后启动轮播
  40. startCarousel()
  41. }
  42. } catch (error) {
  43. console.error('获取公告数据失败:', error)
  44. }
  45. }
  46. // 开始轮播
  47. const startCarousel = () => {
  48. if (noticeList.value.length <= 1) return
  49. timer.value = setInterval(() => {
  50. currentIndex.value = (currentIndex.value + 1) % noticeList.value.length
  51. currentNotice.value = noticeList.value[currentIndex.value]
  52. }, 3000) // 3秒轮播一次
  53. }
  54. // 组件挂载时获取数据
  55. onMounted(() => {
  56. fetchNoticeData()
  57. })
  58. // 组件卸载时清理定时器
  59. onUnmounted(() => {
  60. if (timer.value) {
  61. clearInterval(timer.value)
  62. }
  63. })
  64. </script>
  65. <style lang="scss" scoped>
  66. .home-page-warning {
  67. width: 80%; /* 缩小宽度到80% */
  68. max-width: 400px; /* 设置最大宽度 */
  69. :deep(.chartsContainer) {
  70. width: 100%;
  71. height: 100%;
  72. display: flex;
  73. align-items: center;
  74. justify-content: center;
  75. }
  76. .urgent-notice {
  77. background: rgba(255, 255, 255, 0.05);
  78. border: 2px solid #044878;
  79. border-radius: 8px;
  80. padding: 10px;
  81. display: flex;
  82. align-items: center;
  83. gap: 15px;
  84. width: 100%;
  85. .notice-title {
  86. font-size: 16px;
  87. font-weight: bold;
  88. color: #35D8FF;
  89. white-space: nowrap;
  90. }
  91. .divider {
  92. width: 1px;
  93. height: 20px;
  94. background: #35D8FF;
  95. }
  96. .notice-carousel {
  97. flex: 1;
  98. overflow: hidden;
  99. height: 24px;
  100. line-height: 24px;
  101. position: relative;
  102. .notice-content {
  103. position: absolute;
  104. top: 0;
  105. left: 0;
  106. width: 100%;
  107. white-space: nowrap;
  108. overflow: hidden;
  109. text-overflow: ellipsis;
  110. font-size: 14px;
  111. color: #35D8FF;
  112. }
  113. // 上下滚动动画
  114. .slide-up-down-enter-active,
  115. .slide-up-down-leave-active {
  116. transition: all 0.5s ease;
  117. }
  118. .slide-up-down-enter-from {
  119. transform: translateY(24px);
  120. opacity: 0;
  121. }
  122. .slide-up-down-leave-to {
  123. transform: translateY(-24px);
  124. opacity: 0;
  125. }
  126. }
  127. }
  128. }
  129. </style>