u-notice-bar.vue 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <template>
  2. <view class="u-notice-bar" v-if="show" :style="[{
  3. backgroundColor: bgColor
  4. }, $u.addStyle(customStyle)]">
  5. <template v-if="direction === 'column' || (direction === 'row' && step)">
  6. <u-column-notice :color="color" :bgColor="bgColor" :text="text" :mode="mode" :step="step" :icon="icon" :disable-touch="disableTouch" :fontSize="fontSize" :duration="duration" @close="close" @click="click"></u-column-notice>
  7. </template>
  8. <template v-else>
  9. <u-row-notice :color="color" :bgColor="bgColor" :text="text" :mode="mode" :fontSize="fontSize" :speed="speed" :url="url" :linkType="linkType" :icon="icon" @close="close" @click="click"></u-row-notice>
  10. </template>
  11. </view>
  12. </template>
  13. <script>
  14. import props from './props.js';
  15. /**
  16. * noticeBar 滚动通知
  17. * @description 该组件用于滚动通告场景,有多种模式可供选择
  18. * @tutorial https://www.uviewui.com/components/noticeBar.html
  19. * @property {Array | String} text 显示的内容,数组
  20. * @property {String} direction 通告滚动模式,row-横向滚动,column-竖向滚动 ( 默认 'row' )
  21. * @property {Boolean} step direction = row时,是否使用步进形式滚动 ( 默认 false )
  22. * @property {String} icon 是否显示左侧的音量图标 ( 默认 'volume' )
  23. * @property {String} mode 通告模式,link-显示右箭头,closable-显示右侧关闭图标
  24. * @property {String} color 文字颜色,各图标也会使用文字颜色 ( 默认 '#f9ae3d' )
  25. * @property {String} bgColor 背景颜色 ( 默认 '#fdf6ec' )
  26. * @property {String | Number} speed 水平滚动时的滚动速度,即每秒滚动多少px(px),这有利于控制文字无论多少时,都能有一个恒定的速度 ( 默认 80 )
  27. * @property {String | Number} fontSize 字体大小 ( 默认 14 )
  28. * @property {String | Number} duration 滚动一个周期的时间长,单位ms ( 默认 2000 )
  29. * @property {Boolean} disableTouch 是否禁止用手滑动切换 目前HX2.6.11,只支持App 2.5.5+、H5 2.5.5+、支付宝小程序、字节跳动小程序(默认34) ( 默认 true )
  30. * @property {String} url 跳转的页面路径
  31. * @property {String} linkType 页面跳转的类型 ( 默认 navigateTo )
  32. * @property {Object} customStyle 定义需要用到的外部样式
  33. *
  34. * @event {Function} click 点击通告文字触发
  35. * @event {Function} close 点击右侧关闭图标触发
  36. * @example <u-notice-bar :more-icon="true" :list="list"></u-notice-bar>
  37. */
  38. export default {
  39. name: "u-notice-bar",
  40. mixins: [uni.$u.mpMixin, uni.$u.mixin, props],
  41. data () {
  42. return {
  43. show: true
  44. }
  45. },
  46. methods: {
  47. // 点击通告栏
  48. click (index) {
  49. this.$emit('click', index)
  50. if (this.url && this.linkType) {
  51. // 此方法写在mixin中,另外跳转的url和linkType参数也在mixin的props中
  52. this.openPage()
  53. }
  54. },
  55. // 点击关闭按钮
  56. close () {
  57. this.show = false
  58. this.$emit('close')
  59. }
  60. }
  61. };
  62. </script>
  63. <style lang="scss" scoped>
  64. @import "../../libs/css/components.scss";
  65. .u-notice-bar {
  66. overflow: hidden;
  67. padding: 9px 12px;
  68. flex: 1;
  69. }
  70. </style>