3
0

u-column-notice.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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';
  60. import { mpMixin } from '../../libs/mixin/mpMixin';
  61. import { mixin } from '../../libs/mixin/mixin';
  62. import { addUnit, error } from '../../libs/function/index';
  63. import test from '../../libs/function/test';
  64. /**
  65. * ColumnNotice 滚动通知中的垂直滚动 内部组件
  66. * @description 该组件用于滚动通告场景,是其中的垂直滚动方式
  67. * @tutorial https://ijry.github.io/uview-plus/components/noticeBar.html
  68. * @property {Array} text 显示的内容,字符串
  69. * @property {String} icon 是否显示左侧的音量图标 ( 默认 'volume' )
  70. * @property {String} mode 通告模式,link-显示右箭头,closable-显示右侧关闭图标
  71. * @property {String} color 文字颜色,各图标也会使用文字颜色 ( 默认 '#f9ae3d' )
  72. * @property {String} bgColor 背景颜色 ( 默认 '#fdf6ec' )
  73. * @property {String | Number} fontSize 字体大小,单位px ( 默认 14 )
  74. * @property {String | Number} speed 水平滚动时的滚动速度,即每秒滚动多少px(rpx),这有利于控制文字无论多少时,都能有一个恒定的速度 ( 默认 80 )
  75. * @property {Boolean} step direction = row时,是否使用步进形式滚动 ( 默认 false )
  76. * @property {String | Number} duration 滚动一个周期的时间长,单位ms ( 默认 1500 )
  77. * @property {Boolean} disableTouch 是否禁止用手滑动切换 目前HX2.6.11,只支持App 2.5.5+、H5 2.5.5+、支付宝小程序、字节跳动小程序 ( 默认 true )
  78. * @example
  79. */
  80. export default {
  81. mixins: [mpMixin, mixin, props],
  82. watch: {
  83. text: {
  84. immediate: true,
  85. handler(newValue, oldValue) {
  86. if(!test.array(newValue)) {
  87. error('noticebar组件direction为column时,要求text参数为数组形式')
  88. }
  89. }
  90. }
  91. },
  92. computed: {
  93. // 文字内容的样式
  94. textStyle() {
  95. let style = {}
  96. style.color = this.color
  97. style.fontSize = addUnit(this.fontSize)
  98. return style
  99. },
  100. // 垂直或者水平滚动
  101. vertical() {
  102. if (this.mode == 'horizontal') return false
  103. else return true
  104. },
  105. },
  106. data() {
  107. return {
  108. index:0
  109. }
  110. },
  111. emits: ["click", "close"],
  112. methods: {
  113. noticeChange(e){
  114. this.index = e.detail.current
  115. },
  116. // 点击通告栏
  117. clickHandler() {
  118. this.$emit('click', this.index)
  119. },
  120. // 点击关闭按钮
  121. close() {
  122. this.$emit('close')
  123. }
  124. }
  125. };
  126. </script>
  127. <style lang="scss" scoped>
  128. @import "../../libs/css/components.scss";
  129. .u-notice {
  130. @include flex;
  131. align-items: center;
  132. justify-content: space-between;
  133. &__left-icon {
  134. align-items: center;
  135. margin-right: 5px;
  136. }
  137. &__right-icon {
  138. margin-left: 5px;
  139. align-items: center;
  140. }
  141. &__swiper {
  142. height: 16px;
  143. @include flex;
  144. align-items: center;
  145. flex: 1;
  146. &__item {
  147. @include flex;
  148. align-items: center;
  149. overflow: hidden;
  150. &__text {
  151. font-size: 14px;
  152. color: $u-warning;
  153. }
  154. }
  155. }
  156. }
  157. </style>