金诚优选前端代码
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.

235 lines
5.2 KiB

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