木邻有你前端代码仓库
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.

191 lines
4.3 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months 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. type: 0
  55. })
  56. this.bannerList = res.result.records.map(item => item.image)
  57. },
  58. // 获取公告列表
  59. async queryNoticeList() {
  60. const res = await this.$api.home.queryNoticeList({
  61. pageNo: 1,
  62. pageSize: 4,
  63. })
  64. this.noticeList = res.result.records
  65. },
  66. // 开始滚动动画
  67. startScroll() {
  68. this.scrollTimer = setInterval(() => {
  69. this.currentIndex = (this.currentIndex + 1) % this.noticeList.length
  70. const animation = uni.createAnimation({
  71. duration: 500,
  72. timingFunction: 'ease-in-out'
  73. })
  74. animation.translateY(-this.currentIndex * 30).step()
  75. this.animationData = animation.export()
  76. }, 2000)
  77. },
  78. // 停止滚动动画
  79. stopScroll() {
  80. if (this.scrollTimer) {
  81. clearInterval(this.scrollTimer)
  82. this.scrollTimer = null
  83. }
  84. }
  85. },
  86. async mounted() {
  87. console.log('出发喽');
  88. await this.queryBannerList()
  89. await this.queryNoticeList()
  90. // 启动公告滚动
  91. this.startScroll()
  92. },
  93. beforeDestroy() {
  94. // 清理定时器
  95. this.stopScroll()
  96. },
  97. }
  98. </script>
  99. <style lang="scss" scoped>
  100. .volunteer-header {
  101. width: 100%;
  102. .swiper-container {
  103. position: relative;
  104. margin: 20rpx;
  105. border-radius: 20rpx;
  106. overflow: hidden;
  107. .header-title {
  108. position: absolute;
  109. bottom: 20rpx;
  110. left: 20rpx;
  111. z-index: 10;
  112. display: flex;
  113. flex-direction: column;
  114. background-color: rgba(0,0,0,0.4);
  115. padding: 10rpx 20rpx;
  116. border-radius: 10rpx;
  117. .title-text {
  118. font-size: 36rpx;
  119. font-weight: bold;
  120. color: #fff;
  121. }
  122. .date-text {
  123. font-size: 28rpx;
  124. color: #2c5e2e;
  125. margin-top: 6rpx;
  126. }
  127. }
  128. .dove-icon {
  129. position: absolute;
  130. right: 20rpx;
  131. bottom: 20rpx;
  132. z-index: 10;
  133. width: 70rpx;
  134. height: 70rpx;
  135. background-color: #fff;
  136. border-radius: 50%;
  137. padding: 10rpx;
  138. }
  139. }
  140. .notice-bar {
  141. display: flex;
  142. align-items: center;
  143. background-color: #fff;
  144. padding: 10rpx 20rpx;
  145. margin: 0 20rpx 20rpx;
  146. border-radius: 12rpx;
  147. box-shadow: 2rpx 3rpx 2rpx 2rpx #3a94e1; ;
  148. // border-bottom: 1rpx solid #3A94E1;
  149. .horn-icon {
  150. width: 40rpx;
  151. height: 40rpx;
  152. margin-right: 10rpx;
  153. }
  154. .notice-scroll-container {
  155. flex: 1;
  156. height: 60rpx;
  157. overflow: hidden;
  158. position: relative;
  159. }
  160. .notice-scroll {
  161. position: absolute;
  162. top: 0;
  163. left: 0;
  164. width: 100%;
  165. }
  166. .notice-text {
  167. display: block;
  168. height: 60rpx;
  169. line-height: 60rpx;
  170. font-size: 28rpx;
  171. color: #000;
  172. font-weight: 700;
  173. white-space: nowrap;
  174. overflow: hidden;
  175. text-overflow: ellipsis;
  176. }
  177. }
  178. }
  179. </style>