sin-barrage.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <template>
  2. <view class="padding-tb barrage margin-top" :style="{bottom:bottom+'rpx',left:left+'rpx',backgroundColor:'#fcf5f5'}">
  3. <view class="text-lg text-bold linestyle" style="position: absolute;top: 20rpx;width: 100%;text-align: center;color:#fa3534;">
  4. 最新参与用户
  5. </view>
  6. <view class="flex flex-direction align-center justify-center">
  7. <transition-group name="barrage" class="">
  8. <view class="barrage-item" v-for="(item,index) in barrageList" :key="item.id">
  9. <!-- <image class="barrage-image" :src="item.image"></image> -->
  10. <view class="barrage-text" :style="{color:color,background:background,opacity:opacity}">
  11. <text>{{item.text}}</text>
  12. <text>{{item.phone}}</text>
  13. <text>{{item.time}}</text>
  14. </view>
  15. </view>
  16. </transition-group>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: "sinBarrage",
  23. props: {
  24. list: {
  25. type: Array || Object,
  26. default () {
  27. return {}
  28. }
  29. },
  30. rows: {
  31. type: Number,
  32. default: 3
  33. },
  34. color: {
  35. type: String,
  36. default: '#FFFFFF'
  37. },
  38. background: {
  39. type: String,
  40. default: '#000000'
  41. },
  42. opacity: {
  43. type: Number,
  44. default: 0.7
  45. },
  46. left: {
  47. type: Number,
  48. // default: 35
  49. },
  50. bottom: {
  51. type: Number,
  52. // default: 120
  53. },
  54. msec: {
  55. type: Number,
  56. default: 2000
  57. }
  58. },
  59. data() {
  60. return {
  61. barrageList: []
  62. }
  63. },
  64. created() {
  65. setInterval(() => {
  66. /** 此处逻辑:
  67. * 设定A数组为展示数组(默认3条数据),B数组为源数组(n条数据)
  68. * 首次进入页面,因A数组为空,所以根据rows设定每次从B数组头部取1条数据移入A数组尾部
  69. * 此后,在每个定时周期内,把A数组头部第1条数据移出来,并移入B数组尾部
  70. * 同时把B数组头部第1条数据移出来,并移入A数组尾部
  71. * 如此循环即可
  72. */
  73. if (this.barrageList.length < this.rows) {
  74. this.barrageList.push(this.list[0])
  75. this.list.splice(0, 1)
  76. } else {
  77. let objAFristItem = this.barrageList[0]
  78. this.barrageList.splice(objAFristItem, 1)
  79. this.list.push(objAFristItem)
  80. let objBFirstItem = this.list[0]
  81. this.list.splice(objBFirstItem, 1)
  82. this.barrageList.push(objBFirstItem)
  83. }
  84. }, this.msec)
  85. },
  86. watch: {
  87. }
  88. }
  89. </script>
  90. <style lang="scss">
  91. .barrage-item {
  92. transition: all 1s;
  93. }
  94. .barrage-enter {
  95. opacity: 0;
  96. transform: translateY(30px);
  97. }
  98. .barrage-leave-to {
  99. opacity: 0;
  100. transform: translateY(0px);
  101. }
  102. .barrage-enter-active {
  103. // position: absolute;
  104. }
  105. .barrage-leave-active {
  106. // transition: all .3s;
  107. }
  108. .linestyle::after{
  109. content: '';
  110. display: inline-block;
  111. width: 20rpx;
  112. height: 3rpx;
  113. background-color: #000;
  114. position: absolute;
  115. top: 20rpx;
  116. margin-left: 10rpx;
  117. }
  118. .linestyle::before{
  119. content: '';
  120. display: inline-block;
  121. width: 20rpx;
  122. height: 3rpx;
  123. background-color: #000;
  124. position: absolute;
  125. top: 20rpx;
  126. margin-left: -35rpx;
  127. }
  128. .barrage {
  129. // position: absolute;
  130. position: relative;
  131. height: 320rpx;
  132. display: flex;
  133. flex-direction: column;
  134. justify-content: flex-end;
  135. border-radius: 30rpx;
  136. width: 100%;
  137. box-shadow: 0 0 50rpx 0 rgba(0, 0, 0, 0.1);
  138. .barrage-item {
  139. margin-top: 10rpx;
  140. .barrage-image {
  141. display: inline-block;
  142. vertical-align: middle;
  143. width: 60rpx !important;
  144. height: 60rpx !important;
  145. margin-right: 10rpx;
  146. border-radius: 30rpx;
  147. }
  148. .barrage-text {
  149. font-size: 26rpx;
  150. // vertical-align: middle;
  151. color: #FFFFFF;
  152. padding: 10rpx 20rpx;
  153. border-radius: 30rpx;
  154. background: #000000;
  155. opacity: 0.7;
  156. display: flex;
  157. align-items: center;
  158. justify-content: space-around;
  159. width: 400rpx;
  160. }
  161. }
  162. }
  163. </style>