u-notice-bar.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <template>
  2. <view class="u-notice-bar-wrap" v-if="isShow" :style="{
  3. borderRadius: borderRadius + 'rpx',
  4. }">
  5. <block >
  6. <ujp-column-notice
  7. :type="type"
  8. :color="color"
  9. :bgColor="bgColor"
  10. :list="list"
  11. :volumeIcon="volumeIcon"
  12. :moreIcon="moreIcon"
  13. :closeIcon="closeIcon"
  14. :mode="mode"
  15. :volumeSize="volumeSize"
  16. :disable-touch="disableTouch"
  17. :fontSize="fontSize"
  18. :duration="duration"
  19. :playState="playState"
  20. :padding="padding"
  21. @getMore="getMore"
  22. @close="close"
  23. @click="click"
  24. @end="end"
  25. >
  26. </ujp-column-notice>
  27. </block>
  28. </view>
  29. </template>
  30. <script>
  31. /**
  32. * noticeBar 滚动通知
  33. * @description 该组件用于滚动通告场景,有多种模式可供选择
  34. * @tutorial https://www.uviewui.com/components/noticeBar.html
  35. * @property {Array} list 滚动内容,数组形式,见上方说明
  36. * @property {String} type 显示的主题(默认warning)
  37. * @property {Boolean} volume-icon 是否显示小喇叭图标(默认true)
  38. * @property {Boolean} more-icon 是否显示右边的向右箭头(默认false)
  39. * @property {Boolean} close-icon 是否显示关闭图标(默认false)
  40. * @property {Boolean} autoplay 是否自动播放(默认true)
  41. * @property {String} color 文字颜色
  42. * @property {String Number} bg-color 背景颜色
  43. * @property {String} mode 滚动模式(默认horizontal)
  44. * @property {Boolean} show 是否显示(默认true)
  45. * @property {String Number} font-size 字体大小,单位rpx(默认28)
  46. * @property {String Number} volume-size 左边喇叭的大小(默认34)
  47. * @property {String Number} duration 滚动周期时长,只对步进模式有效,横向衔接模式无效,单位ms(默认2000)
  48. * @property {String Number} speed 水平滚动时的滚动速度,即每秒移动多少距离,只对水平衔接方式有效,单位rpx(默认160)
  49. * @property {String Number} font-size 字体大小,单位rpx(默认28)
  50. * @property {Boolean} is-circular mode为horizontal时,指明是否水平衔接滚动(默认true)
  51. * @property {String} play-state 播放状态,play - 播放,paused - 暂停(默认play)
  52. * @property {String Nubmer} border-radius 通知栏圆角(默认为0)
  53. * @property {String Nubmer} padding 内边距,字符串,与普通的内边距css写法一直(默认"18rpx 24rpx")
  54. * @property {Boolean} no-list-hidden 列表为空时,是否显示组件(默认false)
  55. * @property {Boolean} disable-touch 是否禁止通过手动滑动切换通知,只有mode = vertical,或者mode = horizontal且is-circular = false时有效(默认true)
  56. * @event {Function} click 点击通告文字触发,只有mode = vertical,或者mode = horizontal且is-circular = false时有效
  57. * @event {Function} close 点击右侧关闭图标触发
  58. * @event {Function} getMore 点击右侧向右图标触发
  59. * @event {Function} end 列表的消息每次被播放一个周期时触发,只有mode = vertical,或者mode = horizontal且is-circular = false时有效
  60. * @example <u-notice-bar :more-icon="true" :list="list"></u-notice-bar>
  61. */
  62. export default {
  63. name: "u-notice-bar",
  64. props: {
  65. // 显示的内容,数组
  66. list: {
  67. type: Array,
  68. default() {
  69. return [];
  70. }
  71. },
  72. // 显示的主题,success|error|primary|info|warning
  73. type: {
  74. type: String,
  75. default: 'warning'
  76. },
  77. // 是否显示左侧的音量图标
  78. volumeIcon: {
  79. type: Boolean,
  80. default: true
  81. },
  82. // 音量喇叭的大小
  83. volumeSize: {
  84. type: [Number, String],
  85. default: 34
  86. },
  87. // 是否显示右侧的右箭头图标
  88. moreIcon: {
  89. type: Boolean,
  90. default: false
  91. },
  92. // 是否显示右侧的关闭图标
  93. closeIcon: {
  94. type: Boolean,
  95. default: false
  96. },
  97. // 是否自动播放
  98. autoplay: {
  99. type: Boolean,
  100. default: false
  101. },
  102. // 文字颜色,各图标也会使用文字颜色
  103. color: {
  104. type: String,
  105. default: ''
  106. },
  107. // 背景颜色
  108. bgColor: {
  109. type: String,
  110. default: ''
  111. },
  112. // 滚动方向,horizontal-水平滚动,vertical-垂直滚动
  113. mode: {
  114. type: String,
  115. default: 'horizontal'
  116. },
  117. // 是否显示
  118. show: {
  119. type: Boolean,
  120. default: true
  121. },
  122. // 字体大小,单位rpx
  123. fontSize: {
  124. type: [Number, String],
  125. default: 28
  126. },
  127. // 滚动一个周期的时间长,单位ms
  128. duration: {
  129. type: [Number, String],
  130. default: 2000
  131. },
  132. // 水平滚动时的滚动速度,即每秒滚动多少rpx,这有利于控制文字无论多少时,都能有一个恒定的速度
  133. speed: {
  134. type: [Number, String],
  135. default: 160
  136. },
  137. // 水平滚动时,是否采用衔接形式滚动
  138. // 水平衔接模式,采用的是swiper组件,水平滚动
  139. isCircular: {
  140. type: Boolean,
  141. default: true
  142. },
  143. // 播放状态,play-播放,paused-暂停
  144. playState: {
  145. type: String,
  146. default: 'play'
  147. },
  148. // 是否禁止用手滑动切换
  149. // 目前HX2.6.11,只支持App 2.5.5+、H5 2.5.5+、支付宝小程序、字节跳动小程序
  150. disableTouch: {
  151. type: Boolean,
  152. default: true
  153. },
  154. // 滚动通知设置圆角
  155. borderRadius: {
  156. type: [Number, String],
  157. default: 0
  158. },
  159. // 通知的边距
  160. padding: {
  161. type: [Number, String],
  162. default: '18rpx 24rpx'
  163. },
  164. // list列表为空时,是否显示组件
  165. noListHidden: {
  166. type: Boolean,
  167. default: true
  168. }
  169. },
  170. computed: {
  171. // 如果设置show为false,或者设置了noListHidden为true,且list长度又为零的话,隐藏组件
  172. isShow() {
  173. if(this.show == false || (this.noListHidden == true && this.list.length == 0)) return false;
  174. else return true;
  175. }
  176. },
  177. methods: {
  178. // 点击通告栏
  179. click(index) {
  180. this.$emit('click', index);
  181. },
  182. // 点击关闭按钮
  183. close() {
  184. this.$emit('close');
  185. },
  186. // 点击更多箭头按钮
  187. getMore() {
  188. this.$emit('getMore');
  189. },
  190. // 滚动一个周期结束,只对垂直,或者水平步进形式有效
  191. end() {
  192. this.$emit('end');
  193. }
  194. }
  195. };
  196. </script>
  197. <style lang="scss" scoped>
  198. //@import "../../libs/css/style.components.scss";
  199. .u-notice-bar-wrap {
  200. overflow: hidden;
  201. }
  202. .u-notice-bar {
  203. padding: 18rpx 24rpx;
  204. overflow: hidden;
  205. }
  206. .u-direction-row {
  207. // @include vue-flex;
  208. display: flex;
  209. align-items: center;
  210. justify-content: space-between;
  211. }
  212. .u-left-icon {
  213. //@include vue-flex;
  214. display: flex;
  215. align-items: center;
  216. }
  217. .u-notice-box {
  218. flex: 1;
  219. //@include vue-flex;
  220. display: flex;
  221. overflow: hidden;
  222. margin-left: 12rpx;
  223. }
  224. .u-right-icon {
  225. margin-left: 12rpx;
  226. //@include vue-flex;
  227. display: flex;
  228. align-items: center;
  229. }
  230. @keyframes u-loop-animation {
  231. 0% {
  232. transform: translate3d(0, 0, 0);
  233. }
  234. 100% {
  235. transform: translate3d(-100%, 0, 0);
  236. }
  237. }
  238. </style>