u-column-notice.vue 5.7 KB

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