blob: dd8bd3182d5dc207dd116b6c306c9ee59b3622d3 [file] [log] [blame]
guangchao.xu070005a2020-12-07 09:56:40 +08001<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 :disable-touch="disableTouch" @change="change" :autoplay="autoplay && playState == 'play'" :vertical="vertical" circular :interval="duration" class="u-swiper">
16 <swiper-item v-for="(item, index) in list" :key="index" class="u-swiper-item">
17 <view
18 class="u-news-item u-line-1"
19 :style="[textStyle]"
20 @tap="click(index)"
21 :class="['u-type-' + type]"
22 >
23 {{ item }}
24 </view>
25 </swiper-item>
26 </swiper>
27 <view class="u-icon-wrap">
28 <u-icon @click="getMore" class="u-right-icon" v-if="moreIcon" name="arrow-right" :size="26" :color="computeColor"></u-icon>
29 <u-icon @click="close" class="u-right-icon" v-if="closeIcon" name="close" :size="24" :color="computeColor"></u-icon>
30 </view>
31 </view>
32</template>
33
34<script>
35export 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(index) {
171 this.$emit('click', index);
172 },
173 // 点击关闭按钮
174 close() {
175 this.$emit('close');
176 },
177 // 点击更多箭头按钮
178 getMore() {
179 this.$emit('getMore');
180 },
181 change(e) {
182 let index = e.detail.current;
183 if(index == this.list.length - 1) {
184 this.$emit('end');
185 }
186 }
187 }
188};
189</script>
190
191<style lang="scss" scoped>
192@import "../../libs/css/style.components.scss";
193
194.u-notice-bar {
195 width: 100%;
196 @include vue-flex;
197 align-items: center;
198 justify-content: center;
199 flex-wrap: nowrap;
200 padding: 18rpx 24rpx;
201 overflow: hidden;
202}
203
204.u-swiper {
205 font-size: 26rpx;
206 height: 32rpx;
207 @include vue-flex;
208 align-items: center;
209 flex: 1;
210 margin-left: 12rpx;
211}
212
213.u-swiper-item {
214 @include vue-flex;
215 align-items: center;
216 overflow: hidden;
217}
218
219.u-news-item {
220 overflow: hidden;
221}
222
223.u-right-icon {
224 margin-left: 12rpx;
225 /* #ifndef APP-NVUE */
226 display: inline-flex;
227 /* #endif */
228 align-items: center;
229}
230
231.u-left-icon {
232 /* #ifndef APP-NVUE */
233 display: inline-flex;
234 /* #endif */
235 align-items: center;
236}
237</style>