tui-roll-news.vue
2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<template>
<view class="tui-roll-news"
:style="{background:background,width:!width?'100%':width+'rpx',padding:padding,borderRadius:radius+'rpx'}">
<view class="tui-notice__shrink" @tap.stop="leftClick">
<slot></slot>
</view>
<swiper :vertical="vertical" :autoplay="true" :circular="true" :interval="interval"
class="tui-roll__news-swiper" :style="{height:height+'rpx'}">
<swiper-item v-for="(item,index) in list" :key="index" class="tui-roll__news-item">
<text class="tui-rollnews__text"
:style="{color:color,fontSize:size+'rpx',fontWeight:bold?'bold':'',lines:lines,'-webkit-line-clamp':lines}"
@tap="onClick(index)">{{item[prop] || ''}}</text>
</swiper-item>
</swiper>
<view class="tui-notice__shrink" @tap.stop="rightClick">
<slot name="right"></slot>
</view>
</view>
</template>
<script>
export default {
name: "tui-roll-news",
emits: ['click', 'leftClick', 'rightClick'],
props: {
list: {
type: Array,
default () {
return []
}
},
//list 显示key
prop: {
type: String,
default: 'title'
},
width: {
type: [Number, String],
default: 0
},
//滚动消息高度
height: {
type: [Number, String],
default: 80
},
//字体大小 rpx
size: {
type: [Number, String],
default: 28
},
color: {
type: String,
default: '#333'
},
bold: {
type: Boolean,
default: false
},
background: {
type: String,
default: '#fff'
},
radius: {
type: [Number, String],
default: 0
},
padding: {
type: String,
default: '0 30rpx'
},
//内容显示行数,超出隐藏
lines: {
type: Number,
default: 1
},
//自动切换时间间隔(毫秒)
interval: {
type: Number,
default: 3000
},
//是否纵向滚动切换内容
vertical: {
type: Boolean,
default: true
}
},
data() {
return {
};
},
methods: {
onClick(index) {
const item = this.list[index]
this.$emit('click', {
index: index,
item: item
})
},
leftClick() {
this.$emit('leftClick', {})
},
rightClick() {
this.$emit('rightClick', {})
}
}
}
</script>
<style scoped>
.tui-roll-news {
/* #ifndef APP-NVUE */
display: flex;
width: 100%;
box-sizing: border-box;
/* #endif */
flex-direction: row;
align-items: center;
overflow: hidden;
}
.tui-notice__shrink {
/* #ifndef APP-NVUE */
flex-shrink: 0;
display: flex;
/* #endif */
align-items: center;
justify-content: center;
/* #ifdef H5 */
cursor: pointer;
/* #endif */
}
.tui-roll__news-swiper {
flex: 1;
}
.tui-roll__news-item {
/* #ifndef APP-NVUE */
width: 100%;
display: flex;
/* #endif */
align-items: center;
}
.tui-rollnews__text {
/* #ifndef APP-NVUE */
display: -webkit-box;
overflow: hidden;
word-break: break-all;
white-space: normal;
-webkit-box-orient: vertical;
/* #endif */
overflow: hidden;
}
</style>