You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
3.4 KiB

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