tui-roll-news.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <template>
  2. <view class="tui-roll-news"
  3. :style="{background:background,width:!width?'100%':width+'rpx',padding:padding,borderRadius:radius+'rpx'}">
  4. <view class="tui-notice__shrink" @tap.stop="leftClick">
  5. <slot></slot>
  6. </view>
  7. <swiper :vertical="vertical" :autoplay="true" :circular="true" :interval="interval"
  8. class="tui-roll__news-swiper" :style="{height:height+'rpx'}">
  9. <swiper-item v-for="(item,index) in list" :key="index" class="tui-roll__news-item">
  10. <text class="tui-rollnews__text"
  11. :style="{color:color,fontSize:size+'rpx',fontWeight:bold?'bold':'',lines:lines,'-webkit-line-clamp':lines}"
  12. @tap="onClick(index)">{{item[prop] || ''}}</text>
  13. </swiper-item>
  14. </swiper>
  15. <view class="tui-notice__shrink" @tap.stop="rightClick">
  16. <slot name="right"></slot>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: "tui-roll-news",
  23. emits: ['click', 'leftClick', 'rightClick'],
  24. props: {
  25. list: {
  26. type: Array,
  27. default () {
  28. return []
  29. }
  30. },
  31. //list 显示key
  32. prop: {
  33. type: String,
  34. default: 'title'
  35. },
  36. width: {
  37. type: [Number, String],
  38. default: 0
  39. },
  40. //滚动消息高度
  41. height: {
  42. type: [Number, String],
  43. default: 80
  44. },
  45. //字体大小 rpx
  46. size: {
  47. type: [Number, String],
  48. default: 28
  49. },
  50. color: {
  51. type: String,
  52. default: '#333'
  53. },
  54. bold: {
  55. type: Boolean,
  56. default: false
  57. },
  58. background: {
  59. type: String,
  60. default: '#fff'
  61. },
  62. radius: {
  63. type: [Number, String],
  64. default: 0
  65. },
  66. padding: {
  67. type: String,
  68. default: '0 30rpx'
  69. },
  70. //内容显示行数,超出隐藏
  71. lines: {
  72. type: Number,
  73. default: 1
  74. },
  75. //自动切换时间间隔(毫秒)
  76. interval: {
  77. type: Number,
  78. default: 3000
  79. },
  80. //是否纵向滚动切换内容
  81. vertical: {
  82. type: Boolean,
  83. default: true
  84. }
  85. },
  86. data() {
  87. return {
  88. };
  89. },
  90. methods: {
  91. onClick(index) {
  92. const item = this.list[index]
  93. this.$emit('click', {
  94. index: index,
  95. item: item
  96. })
  97. },
  98. leftClick() {
  99. this.$emit('leftClick', {})
  100. },
  101. rightClick() {
  102. this.$emit('rightClick', {})
  103. }
  104. }
  105. }
  106. </script>
  107. <style scoped>
  108. .tui-roll-news {
  109. /* #ifndef APP-NVUE */
  110. display: flex;
  111. width: 100%;
  112. box-sizing: border-box;
  113. /* #endif */
  114. flex-direction: row;
  115. align-items: center;
  116. overflow: hidden;
  117. }
  118. .tui-notice__shrink {
  119. /* #ifndef APP-NVUE */
  120. flex-shrink: 0;
  121. display: flex;
  122. /* #endif */
  123. align-items: center;
  124. justify-content: center;
  125. /* #ifdef H5 */
  126. cursor: pointer;
  127. /* #endif */
  128. }
  129. .tui-roll__news-swiper {
  130. flex: 1;
  131. }
  132. .tui-roll__news-item {
  133. /* #ifndef APP-NVUE */
  134. width: 100%;
  135. display: flex;
  136. /* #endif */
  137. align-items: center;
  138. }
  139. .tui-rollnews__text {
  140. /* #ifndef APP-NVUE */
  141. display: -webkit-box;
  142. overflow: hidden;
  143. word-break: break-all;
  144. white-space: normal;
  145. -webkit-box-orient: vertical;
  146. /* #endif */
  147. overflow: hidden;
  148. }
  149. </style>