u-column-notice.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. <template>
  2. <view
  3. :class="[
  4. type ? `u-type-${type}-light-bg` : ''
  5. ]"
  6. :style="{
  7. background: computeBgColor,
  8. padding: padding
  9. }"
  10. class="u-notice-bar"
  11. >
  12. <view class="u-icon-wrap">
  13. <u-icon v-if="volumeIcon" :color="computeColor" :size="volumeSize" class="u-left-icon"
  14. name="volume-fill"></u-icon>
  15. </view>
  16. <swiper :autoplay="autoplay && playState == 'play'" :disable-touch="disableTouch" :interval="duration"
  17. :vertical="vertical" circular class="u-swiper" @change="change">
  18. <swiper-item v-for="(item, index) in list" :key="index" class="u-swiper-item">
  19. <view
  20. :class="['u-type-' + type]"
  21. :style="[textStyle]"
  22. class="u-news-item u-line-1"
  23. @tap="click(index)"
  24. >
  25. {{ item }}
  26. </view>
  27. </swiper-item>
  28. </swiper>
  29. <view class="u-icon-wrap">
  30. <u-icon v-if="moreIcon" :color="computeColor" :size="26" class="u-right-icon" name="arrow-right"
  31. @click="getMore"></u-icon>
  32. <u-icon v-if="closeIcon" :color="computeColor" :size="24" class="u-right-icon" name="close"
  33. @click="close"></u-icon>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. export default {
  39. props: {
  40. // 显示的内容,数组
  41. list: {
  42. type: Array,
  43. default() {
  44. return [];
  45. }
  46. },
  47. // 显示的主题,success|error|primary|info|warning
  48. type: {
  49. type: String,
  50. default: 'warning'
  51. },
  52. // 是否显示左侧的音量图标
  53. volumeIcon: {
  54. type: Boolean,
  55. default: true
  56. },
  57. // 是否显示右侧的右箭头图标
  58. moreIcon: {
  59. type: Boolean,
  60. default: false
  61. },
  62. // 是否显示右侧的关闭图标
  63. closeIcon: {
  64. type: Boolean,
  65. default: false
  66. },
  67. // 是否自动播放
  68. autoplay: {
  69. type: Boolean,
  70. default: true
  71. },
  72. // 文字颜色,各图标也会使用文字颜色
  73. color: {
  74. type: String,
  75. default: ''
  76. },
  77. // 背景颜色
  78. bgColor: {
  79. type: String,
  80. default: ''
  81. },
  82. // 滚动方向,row-水平滚动,column-垂直滚动
  83. direction: {
  84. type: String,
  85. default: 'row'
  86. },
  87. // 是否显示
  88. show: {
  89. type: Boolean,
  90. default: true
  91. },
  92. // 字体大小,单位rpx
  93. fontSize: {
  94. type: [Number, String],
  95. default: 26
  96. },
  97. // 滚动一个周期的时间长,单位ms
  98. duration: {
  99. type: [Number, String],
  100. default: 2000
  101. },
  102. // 音量喇叭的大小
  103. volumeSize: {
  104. type: [Number, String],
  105. default: 34
  106. },
  107. // 水平滚动时的滚动速度,即每秒滚动多少rpx,这有利于控制文字无论多少时,都能有一个恒定的速度
  108. speed: {
  109. type: Number,
  110. default: 160
  111. },
  112. // 水平滚动时,是否采用衔接形式滚动
  113. isCircular: {
  114. type: Boolean,
  115. default: true
  116. },
  117. // 滚动方向,horizontal-水平滚动,vertical-垂直滚动
  118. mode: {
  119. type: String,
  120. default: 'horizontal'
  121. },
  122. // 播放状态,play-播放,paused-暂停
  123. playState: {
  124. type: String,
  125. default: 'play'
  126. },
  127. // 是否禁止用手滑动切换
  128. // 目前HX2.6.11,只支持App 2.5.5+、H5 2.5.5+、支付宝小程序、字节跳动小程序
  129. disableTouch: {
  130. type: Boolean,
  131. default: true
  132. },
  133. // 通知的边距
  134. padding: {
  135. type: [Number, String],
  136. default: '18rpx 24rpx'
  137. }
  138. },
  139. computed: {
  140. // 计算字体颜色,如果没有自定义的,就用uview主题颜色
  141. computeColor() {
  142. if (this.color) return this.color;
  143. // 如果是无主题,就默认使用content-color
  144. else if (this.type == 'none') return '#606266';
  145. else return this.type;
  146. },
  147. // 文字内容的样式
  148. textStyle() {
  149. let style = {};
  150. if (this.color) style.color = this.color;
  151. else if (this.type == 'none') style.color = '#606266';
  152. style.fontSize = this.fontSize + 'rpx';
  153. return style;
  154. },
  155. // 垂直或者水平滚动
  156. vertical() {
  157. if (this.mode == 'horizontal') return false;
  158. else return true;
  159. },
  160. // 计算背景颜色
  161. computeBgColor() {
  162. if (this.bgColor) return this.bgColor;
  163. else if (this.type == 'none') return 'transparent';
  164. }
  165. },
  166. data() {
  167. return {
  168. // animation: false
  169. };
  170. },
  171. methods: {
  172. // 点击通告栏
  173. click(index) {
  174. this.$emit('click', index);
  175. },
  176. // 点击关闭按钮
  177. close() {
  178. this.$emit('close');
  179. },
  180. // 点击更多箭头按钮
  181. getMore() {
  182. this.$emit('getMore');
  183. },
  184. change(e) {
  185. let index = e.detail.current;
  186. if (index == this.list.length - 1) {
  187. this.$emit('end');
  188. }
  189. }
  190. }
  191. };
  192. </script>
  193. <style lang="scss" scoped>
  194. @import "../../libs/css/style.components.scss";
  195. .u-notice-bar {
  196. width: 100%;
  197. @include vue-flex;
  198. align-items: center;
  199. justify-content: center;
  200. flex-wrap: nowrap;
  201. padding: 18 rpx 24 rpx;
  202. overflow: hidden;
  203. }
  204. .u-swiper {
  205. font-size: 26 rpx;
  206. height: 32 rpx;
  207. @include vue-flex;
  208. align-items: center;
  209. flex: 1;
  210. margin-left: 12 rpx;
  211. }
  212. .u-swiper-item {
  213. @include vue-flex;
  214. align-items: center;
  215. overflow: hidden;
  216. }
  217. .u-news-item {
  218. overflow: hidden;
  219. }
  220. .u-right-icon {
  221. margin-left: 12 rpx;
  222. /* #ifndef APP-NVUE */
  223. display: inline-flex;
  224. /* #endif */
  225. align-items: center;
  226. }
  227. .u-left-icon {
  228. /* #ifndef APP-NVUE */
  229. display: inline-flex;
  230. /* #endif */
  231. align-items: center;
  232. }
  233. </style>