u-column-notice.vue 5.8 KB

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