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.
 
 
 

125 regels
4.0 KiB

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