uv-column-notice.vue 4.4 KB

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