tn-column-notice.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view
  3. class="tn-column-notice-class tn-column-notice"
  4. :class="[backgroundColorClass]"
  5. :style="[noticeStyle]"
  6. >
  7. <!-- 左图标 -->
  8. <view class="tn-column-notice__icon">
  9. <view
  10. v-if="leftIcon"
  11. class="tn-column-notice__icon--left"
  12. :class="[`tn-icon-${leftIconName}`,fontColorClass]"
  13. :style="[fontStyle('leftIcon')]"
  14. @tap="clickLeftIcon"></view>
  15. </view>
  16. <!-- 滚动显示内容 -->
  17. <swiper class="tn-column-notice__swiper" :style="[swiperStyle]" :vertical="vertical" circular :autoplay="autoplay && playStatus === 'play'" :interval="duration" @change="change">
  18. <swiper-item v-for="(item, index) in list" :key="index" class="tn-column-notice__swiper--item">
  19. <view
  20. class="tn-column-notice__swiper--content tn-text-ellipsis"
  21. :class="[fontColorClass]"
  22. :style="[fontStyle()]"
  23. @tap="click(index)"
  24. >{{ item }}</view>
  25. </swiper-item>
  26. </swiper>
  27. <!-- 右图标 -->
  28. <view class="tn-column-notice__icon">
  29. <view
  30. v-if="rightIcon"
  31. class="tn-column-notice__icon--right"
  32. :class="[`tn-icon-${rightIconName}`,fontColorClass]"
  33. :style="[fontStyle('rightIcon')]"
  34. @tap="clickRightIcon"></view>
  35. <view
  36. v-if="closeBtn"
  37. class="tn-column-notice__icon--right"
  38. :class="[`tn-icon-close`,fontColorClass]"
  39. :style="[fontStyle('close')]"
  40. @tap="close"></view>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. import componentsColorMixin from '../../libs/mixin/components_color.js'
  46. export default {
  47. name: 'tn-column-notice',
  48. mixins: [componentsColorMixin],
  49. props: {
  50. // 显示的内容
  51. list: {
  52. type: Array,
  53. default() {
  54. return []
  55. }
  56. },
  57. // 是否显示
  58. show: {
  59. type: Boolean,
  60. default: true
  61. },
  62. // 播放状态
  63. // play -> 播放 paused -> 暂停
  64. playStatus: {
  65. type: String,
  66. default: 'play'
  67. },
  68. // 滚动方向
  69. // horizontal -> 水平滚动 vertical -> 垂直滚动
  70. mode: {
  71. type: String,
  72. default: 'horizontal'
  73. },
  74. // 是否显示左边图标
  75. leftIcon: {
  76. type: Boolean,
  77. default: true
  78. },
  79. // 左边图标的名称
  80. leftIconName: {
  81. type: String,
  82. default: 'sound'
  83. },
  84. // 左边图标的大小
  85. leftIconSize: {
  86. type: Number,
  87. default: 34
  88. },
  89. // 是否显示右边的图标
  90. rightIcon: {
  91. type: Boolean,
  92. default: false
  93. },
  94. // 右边图标的名称
  95. rightIconName: {
  96. type: String,
  97. default: 'right'
  98. },
  99. // 右边图标的大小
  100. rightIconSize: {
  101. type: Number,
  102. default: 26
  103. },
  104. // 是否显示关闭按钮
  105. closeBtn: {
  106. type: Boolean,
  107. default: false
  108. },
  109. // 圆角
  110. radius: {
  111. type: Number,
  112. default: 0
  113. },
  114. // 内边距
  115. padding: {
  116. type: String,
  117. default: '18rpx 24rpx'
  118. },
  119. // 自动播放
  120. autoplay: {
  121. type: Boolean,
  122. default: true
  123. },
  124. // 滚动周期
  125. duration: {
  126. type: Number,
  127. default: 2000
  128. }
  129. },
  130. computed: {
  131. fontStyle() {
  132. return (type) => {
  133. let style = {}
  134. style.color = this.fontColorStyle ? this.fontColorStyle : ''
  135. style.fontSize = this.fontSizeStyle ? this.fontSizeStyle : ''
  136. if (type === 'leftIcon' && this.leftIconSize) {
  137. style.fontSize = this.leftIconSize + 'rpx'
  138. }
  139. if (type === 'rightIcon' && this.rightIconSize) {
  140. style.fontSize = this.rightIconSize + 'rpx'
  141. }
  142. if (type === 'close') {
  143. style.fontSize = '24rpx'
  144. }
  145. return style
  146. }
  147. },
  148. noticeStyle() {
  149. let style = {}
  150. style.backgroundColor = this.backgroundColorStyle ? this.backgroundColorStyle : 'transparent'
  151. if (this.padding) style.padding = this.padding
  152. return style
  153. },
  154. swiperStyle() {
  155. let style = {}
  156. style.height = this.fontSize ? this.fontSize + 6 + this.fontUnit : '32rpx'
  157. style.lineHeight = style.height
  158. return style
  159. },
  160. // 标记是否为垂直
  161. vertical() {
  162. if (this.mode === 'horizontal') return false
  163. else return true
  164. }
  165. },
  166. data() {
  167. return {
  168. }
  169. },
  170. watch: {
  171. },
  172. methods: {
  173. // 点击了通知栏
  174. click(index) {
  175. this.$emit('click', index)
  176. },
  177. // 点击了关闭按钮
  178. close() {
  179. this.$emit('close')
  180. },
  181. // 点击了左边图标
  182. clickLeftIcon() {
  183. this.$emit('clickLeft')
  184. },
  185. // 点击了右边图标
  186. clickRightIcon() {
  187. this.$emit('clickRight')
  188. },
  189. // 切换消息时间
  190. change(event) {
  191. let index = event.detail.current
  192. if (index === this.list.length - 1) {
  193. this.$emit('end')
  194. }
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .tn-column-notice {
  201. width: 100%;
  202. display: flex;
  203. flex-direction: row;
  204. align-items: center;
  205. justify-content: center;
  206. flex-wrap: nowrap;
  207. overflow: hidden;
  208. &__swiper {
  209. height: auto;
  210. flex: 1;
  211. display: flex;
  212. flex-direction: row;
  213. align-items: center;
  214. margin-left: 12rpx;
  215. &--item {
  216. display: flex;
  217. flex-direction: row;
  218. align-items: center;
  219. overflow: hidden;
  220. }
  221. &--content {
  222. overflow: hidden;
  223. }
  224. }
  225. &__icon {
  226. &--left {
  227. display: inline-flex;
  228. align-items: center;
  229. }
  230. &--right {
  231. margin-left: 12rpx;
  232. display: inline-flex;
  233. align-items: center;
  234. }
  235. }
  236. }
  237. </style>