u-notice-bar.vue 3.2 KB

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