u-column-notice.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <template>
  2. <view
  3. class="u-notice"
  4. @tap="clickHandler"
  5. >
  6. <slot name="icon">
  7. <view
  8. class="u-notice__left-icon"
  9. v-if="icon"
  10. >
  11. <u-icon
  12. :name="icon"
  13. :color="color"
  14. size="19"
  15. ></u-icon>
  16. </view>
  17. </slot>
  18. <swiper
  19. :disable-touch="disableTouch"
  20. :vertical="step ? false : true"
  21. circular
  22. :interval="duration"
  23. :autoplay="true"
  24. class="u-notice__swiper"
  25. @change="noticeChange"
  26. >
  27. <swiper-item
  28. v-for="(item, index) in text"
  29. :key="index"
  30. class="u-notice__swiper__item"
  31. >
  32. <text
  33. class="u-notice__swiper__item__text u-line-1"
  34. :style="[textStyle]"
  35. >{{ item }}</text>
  36. </swiper-item>
  37. </swiper>
  38. <view
  39. class="u-notice__right-icon"
  40. v-if="['link', 'closable'].includes(mode)"
  41. >
  42. <u-icon
  43. v-if="mode === 'link'"
  44. name="arrow-right"
  45. :size="17"
  46. :color="color"
  47. ></u-icon>
  48. <u-icon
  49. v-if="mode === 'closable'"
  50. name="close"
  51. :size="16"
  52. :color="color"
  53. @click="close"
  54. ></u-icon>
  55. </view>
  56. </view>
  57. </template>
  58. <script>
  59. import props from './props.js';
  60. import mpMixin from '../../libs/mixin/mpMixin.js';
  61. import mixin from '../../libs/mixin/mixin.js';
  62. /**
  63. * ColumnNotice 滚动通知中的垂直滚动 内部组件
  64. * @description 该组件用于滚动通告场景,是其中的垂直滚动方式
  65. * @tutorial https://ijry.github.io/uview-plus/components/noticeBar.html
  66. * @property {Array} text 显示的内容,字符串
  67. * @property {String} icon 是否显示左侧的音量图标 ( 默认 'volume' )
  68. * @property {String} mode 通告模式,link-显示右箭头,closable-显示右侧关闭图标
  69. * @property {String} color 文字颜色,各图标也会使用文字颜色 ( 默认 '#f9ae3d' )
  70. * @property {String} bgColor 背景颜色 ( 默认 '#fdf6ec' )
  71. * @property {String | Number} fontSize 字体大小,单位px ( 默认 14 )
  72. * @property {String | Number} speed 水平滚动时的滚动速度,即每秒滚动多少px(rpx),这有利于控制文字无论多少时,都能有一个恒定的速度 ( 默认 80 )
  73. * @property {Boolean} step direction = row时,是否使用步进形式滚动 ( 默认 false )
  74. * @property {String | Number} duration 滚动一个周期的时间长,单位ms ( 默认 1500 )
  75. * @property {Boolean} disableTouch 是否禁止用手滑动切换 目前HX2.6.11,只支持App 2.5.5+、H5 2.5.5+、支付宝小程序、字节跳动小程序 ( 默认 true )
  76. * @example
  77. */
  78. export default {
  79. mixins: [mpMixin, mixin, props],
  80. watch: {
  81. text: {
  82. immediate: true,
  83. handler(newValue, oldValue) {
  84. if(!uni.$u.test.array(newValue)) {
  85. uni.$u.error('noticebar组件direction为column时,要求text参数为数组形式')
  86. }
  87. }
  88. }
  89. },
  90. computed: {
  91. // 文字内容的样式
  92. textStyle() {
  93. let style = {}
  94. style.color = this.color
  95. style.fontSize = uni.$u.addUnit(this.fontSize)
  96. return style
  97. },
  98. // 垂直或者水平滚动
  99. vertical() {
  100. if (this.mode == 'horizontal') return false
  101. else return true
  102. },
  103. },
  104. data() {
  105. return {
  106. index:0
  107. }
  108. },
  109. emits: ["click", "close"],
  110. methods: {
  111. noticeChange(e){
  112. this.index = e.detail.current
  113. },
  114. // 点击通告栏
  115. clickHandler() {
  116. this.$emit('click', this.index)
  117. },
  118. // 点击关闭按钮
  119. close() {
  120. this.$emit('close')
  121. }
  122. }
  123. };
  124. </script>
  125. <style lang="scss" scoped>
  126. @import "../../libs/css/components.scss";
  127. .u-notice {
  128. @include flex;
  129. align-items: center;
  130. justify-content: space-between;
  131. &__left-icon {
  132. align-items: center;
  133. margin-right: 5px;
  134. }
  135. &__right-icon {
  136. margin-left: 5px;
  137. align-items: center;
  138. }
  139. &__swiper {
  140. height: 16px;
  141. @include flex;
  142. align-items: center;
  143. flex: 1;
  144. &__item {
  145. @include flex;
  146. align-items: center;
  147. overflow: hidden;
  148. &__text {
  149. font-size: 14px;
  150. color: $u-warning;
  151. }
  152. }
  153. }
  154. }
  155. </style>