tn-notice-bar.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <template>
  2. <view
  3. v-if="showNotice"
  4. class="tn-notice-bar-class tn-notice-bar"
  5. :style="{
  6. borderRadius: radius + 'rpx'
  7. }"
  8. >
  9. <block v-if="mode === 'horizontal' && circular">
  10. <tn-row-notice
  11. :backgroundColor="backgroundColor"
  12. :fontColor="fontColor"
  13. :fontSize="fontSize"
  14. :fontUnit="fontUnit"
  15. :list="list"
  16. :show="show"
  17. :playStatus="playStatus"
  18. :leftIcon="leftIcon"
  19. :leftIconName="leftIconName"
  20. :leftIconSize="leftIconSize"
  21. :rightIcon="rightIcon"
  22. :rightIconName="rightIconName"
  23. :rightIconSize="rightIconSize"
  24. :closeBtn="closeBtn"
  25. :autoplay="autoplay"
  26. :radius="radius"
  27. :padding="padding"
  28. :speed="speed"
  29. @click="click"
  30. @close="close"
  31. @clickLeft="clickLeftIcon"
  32. @clickRight="clickRightIcon"
  33. ></tn-row-notice>
  34. </block>
  35. <block v-if="mode === 'vertical' || (mode === 'horizontal' && !circular)">
  36. <tn-column-notice
  37. :backgroundColor="backgroundColor"
  38. :fontColor="fontColor"
  39. :fontSize="fontSize"
  40. :fontUnit="fontUnit"
  41. :list="list"
  42. :show="show"
  43. :mode="mode"
  44. :playStatus="playStatus"
  45. :leftIcon="leftIcon"
  46. :leftIconName="leftIconName"
  47. :leftIconSize="leftIconSize"
  48. :rightIcon="rightIcon"
  49. :rightIconName="rightIconName"
  50. :rightIconSize="rightIconSize"
  51. :closeBtn="closeBtn"
  52. :autoplay="autoplay"
  53. :radius="radius"
  54. :padding="padding"
  55. :duration="duration"
  56. @click="click"
  57. @close="close"
  58. @clickLeft="clickLeftIcon"
  59. @clickRight="clickRightIcon"
  60. @end="end"
  61. ></tn-column-notice>
  62. </block>
  63. </view>
  64. </template>
  65. <script>
  66. import componentsColorMixin from '../../libs/mixin/components_color.js'
  67. export default {
  68. name: 'tn-notice-bar',
  69. mixins: [componentsColorMixin],
  70. props: {
  71. // 显示的内容
  72. list: {
  73. type: Array,
  74. default() {
  75. return []
  76. }
  77. },
  78. // 是否显示
  79. show: {
  80. type: Boolean,
  81. default: true
  82. },
  83. // 播放状态
  84. // play -> 播放 paused -> 暂停
  85. playStatus: {
  86. type: String,
  87. default: 'play'
  88. },
  89. // 滚动方向
  90. // horizontal -> 水平滚动 vertical -> 垂直滚动
  91. mode: {
  92. type: String,
  93. default: 'horizontal'
  94. },
  95. // 是否显示左边图标
  96. leftIcon: {
  97. type: Boolean,
  98. default: true
  99. },
  100. // 左边图标的名称
  101. leftIconName: {
  102. type: String,
  103. default: 'sound'
  104. },
  105. // 左边图标的大小
  106. leftIconSize: {
  107. type: Number,
  108. default: 34
  109. },
  110. // 是否显示右边的图标
  111. rightIcon: {
  112. type: Boolean,
  113. default: false
  114. },
  115. // 右边图标的名称
  116. rightIconName: {
  117. type: String,
  118. default: 'right'
  119. },
  120. // 右边图标的大小
  121. rightIconSize: {
  122. type: Number,
  123. default: 26
  124. },
  125. // 是否显示关闭按钮
  126. closeBtn: {
  127. type: Boolean,
  128. default: false
  129. },
  130. // 圆角
  131. radius: {
  132. type: Number,
  133. default: 0
  134. },
  135. // 内边距
  136. padding: {
  137. type: String,
  138. default: '18rpx 24rpx'
  139. },
  140. // 自动播放
  141. autoplay: {
  142. type: Boolean,
  143. default: true
  144. },
  145. // 滚动周期
  146. duration: {
  147. type: Number,
  148. default: 2000
  149. },
  150. // 水平滚动时的速度,即每秒滚动多少rpx
  151. speed: {
  152. type: Number,
  153. default: 160
  154. },
  155. // 水平滚动的时候是否采用衔接的模式
  156. circular: {
  157. type: Boolean,
  158. default: true
  159. },
  160. // 没有数据时是否显示通知
  161. autoHidden: {
  162. type: Boolean,
  163. default: true
  164. }
  165. },
  166. computed: {
  167. // 当设置了show为false,或者autoHidden为true且list为空时,不显示通知
  168. showNotice() {
  169. if (this.show === false || (this.autoHidden && this.list.length === 0)) return false
  170. else return true
  171. }
  172. },
  173. data() {
  174. return {
  175. }
  176. },
  177. methods: {
  178. // 点击了通知栏
  179. click(index) {
  180. this.$emit('click', index)
  181. },
  182. // 点击了关闭按钮
  183. close() {
  184. this.$emit('close')
  185. },
  186. // 点击了左边图标
  187. clickLeftIcon() {
  188. this.$emit('clickLeft')
  189. },
  190. // 点击了右边图标
  191. clickRightIcon() {
  192. this.$emit('clickRight')
  193. },
  194. // 一个周期滚动结束
  195. end() {
  196. this.$emit('end')
  197. }
  198. }
  199. }
  200. </script>
  201. <style lang="scss" scoped>
  202. .tn-notice-bar {
  203. overflow: hidden;
  204. }
  205. </style>