1
0

u-notice-bar.vue 7.3 KB

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