木邻有你前端代码仓库
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

189 lines
4.3 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. <template>
  2. <view class="volunteer-header">
  3. <view class="swiper-container" >
  4. <uv-swiper :list="bannerList" indicator indicatorMode="dot" height="270rpx" circular></uv-swiper>
  5. <!-- <view class="header-title">
  6. <text class="title-text">国际志愿者日</text>
  7. <text class="date-text">12/05</text>
  8. </view> -->
  9. <!-- <image class="dove-icon" src="/static/路径 6665@2x.png" mode="aspectFit"></image> -->
  10. </view>
  11. <view class="notice-bar" @click="goToAnnouncement">
  12. <image class="horn-icon" src="/static/首页_小喇叭.png" mode="aspectFit"></image>
  13. <view class="notice-scroll-container">
  14. <view class="notice-scroll" :animation="animationData">
  15. <text class="notice-text" v-for="(notice, index) in noticeList" :key="index">
  16. {{ notice.title }}
  17. </text>
  18. </view>
  19. </view>
  20. <uv-icon name="arrow-right" color="#999" size="14"></uv-icon>
  21. </view>
  22. </view>
  23. </template>
  24. <script>
  25. export default {
  26. name: 'VolunteerHeader',
  27. data() {
  28. return {
  29. bannerList: [
  30. '/static/bannerImage.png',
  31. '/static/bannerImage.png',
  32. '/static/bannerImage.png',
  33. ],
  34. noticeList: [
  35. { id: 1, title: '【重要通知】志愿者服务活动报名开始啦,欢迎大家踊跃参与!' },
  36. { id: 2, title: '【活动预告】本周六将举办环保志愿活动,期待您的参与' },
  37. { id: 3, title: '【表彰通知】优秀志愿者表彰大会将于下周举行' },
  38. { id: 4, title: '【温馨提醒】请各位志愿者及时更新个人信息' }
  39. ],
  40. animationData: {},
  41. currentIndex: 0,
  42. scrollTimer: null
  43. }
  44. },
  45. methods: {
  46. goToAnnouncement() {
  47. // 跳转到公告页面
  48. uni.navigateTo({
  49. url: '/subPages/index/announcement'
  50. })
  51. },
  52. async queryBannerList() {
  53. const res = await this.$api.home.queryBannerList()
  54. this.bannerList = res.result.records.map(item => item.image)
  55. },
  56. // 获取公告列表
  57. async queryNoticeList() {
  58. const res = await this.$api.home.queryNoticeList({
  59. pageNo: 1,
  60. pageSize: 4,
  61. })
  62. this.noticeList = res.result.records
  63. },
  64. // 开始滚动动画
  65. startScroll() {
  66. this.scrollTimer = setInterval(() => {
  67. this.currentIndex = (this.currentIndex + 1) % this.noticeList.length
  68. const animation = uni.createAnimation({
  69. duration: 500,
  70. timingFunction: 'ease-in-out'
  71. })
  72. animation.translateY(-this.currentIndex * 30).step()
  73. this.animationData = animation.export()
  74. }, 2000)
  75. },
  76. // 停止滚动动画
  77. stopScroll() {
  78. if (this.scrollTimer) {
  79. clearInterval(this.scrollTimer)
  80. this.scrollTimer = null
  81. }
  82. }
  83. },
  84. async mounted() {
  85. console.log('出发喽');
  86. await this.queryBannerList()
  87. await this.queryNoticeList()
  88. // 启动公告滚动
  89. this.startScroll()
  90. },
  91. beforeDestroy() {
  92. // 清理定时器
  93. this.stopScroll()
  94. },
  95. }
  96. </script>
  97. <style lang="scss" scoped>
  98. .volunteer-header {
  99. width: 100%;
  100. .swiper-container {
  101. position: relative;
  102. margin: 20rpx;
  103. border-radius: 20rpx;
  104. overflow: hidden;
  105. .header-title {
  106. position: absolute;
  107. bottom: 20rpx;
  108. left: 20rpx;
  109. z-index: 10;
  110. display: flex;
  111. flex-direction: column;
  112. background-color: rgba(0,0,0,0.4);
  113. padding: 10rpx 20rpx;
  114. border-radius: 10rpx;
  115. .title-text {
  116. font-size: 36rpx;
  117. font-weight: bold;
  118. color: #fff;
  119. }
  120. .date-text {
  121. font-size: 28rpx;
  122. color: #2c5e2e;
  123. margin-top: 6rpx;
  124. }
  125. }
  126. .dove-icon {
  127. position: absolute;
  128. right: 20rpx;
  129. bottom: 20rpx;
  130. z-index: 10;
  131. width: 70rpx;
  132. height: 70rpx;
  133. background-color: #fff;
  134. border-radius: 50%;
  135. padding: 10rpx;
  136. }
  137. }
  138. .notice-bar {
  139. display: flex;
  140. align-items: center;
  141. background-color: #fff;
  142. padding: 20rpx;
  143. margin: 0 20rpx 20rpx;
  144. border-radius: 12rpx;
  145. // 如何只显示底部阴影
  146. box-shadow: 0rpx 1rpx 0rpx 0rpx #3a94e1; ;
  147. // border-bottom: 1rpx solid #3A94E1;
  148. .horn-icon {
  149. width: 40rpx;
  150. height: 40rpx;
  151. margin-right: 10rpx;
  152. }
  153. .notice-scroll-container {
  154. flex: 1;
  155. height: 60rpx;
  156. overflow: hidden;
  157. position: relative;
  158. }
  159. .notice-scroll {
  160. position: absolute;
  161. top: 0;
  162. left: 0;
  163. width: 100%;
  164. }
  165. .notice-text {
  166. display: block;
  167. height: 60rpx;
  168. line-height: 60rpx;
  169. font-size: 28rpx;
  170. color: $uni-text-color;
  171. white-space: nowrap;
  172. overflow: hidden;
  173. text-overflow: ellipsis;
  174. }
  175. }
  176. }
  177. </style>