海南旅游项目 前端仓库
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.

240 lines
5.1 KiB

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