u-column-notice.vue 4.6 KB

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