uni-events-helper-wx
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.

156 lines
3.6 KiB

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