tui-image-group.vue
3.16 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
157
158
159
160
161
162
163
164
<template>
<view
class="tui-image-container"
:style="{ marginBottom: multiLine ? `-${distance}rpx` : 0 }"
:class="{ 'tui-image-direction': direction == 'column', 'tui-image__warp': multiLine }"
>
<view
v-for="(item, index) in imageList"
:key="index"
class="tui-image__itembox"
:style="{
width: width,
height: height,
borderRadius: radius,
marginLeft: direction == 'column' || multiLine ? 0 : (index && distance) + 'rpx',
marginRight: multiLine ? distance + 'rpx' : 0,
marginBottom: multiLine ? distance + 'rpx' : 0,
marginTop: direction == 'row' ? 0 : (index && distance) + 'rpx'
}"
@tap="bindClick(index, item.id)"
>
<image
class="tui-image-item"
:mode="mode"
:lazy-load="lazyLoad"
fade-show="fadeShow"
:webp="webp"
:show-menu-by-longpress="longpress"
@error="error"
@load="load"
:style="{ width: width, height: height, borderRadius: radius, borderWidth: borderWidth, borderColor: borderColor }"
:src="item.src"
></image>
<slot></slot>
</view>
</view>
</template>
<script>
export default {
name: 'tuiImageGroup',
emits: ['errorEvent','loaded','click'],
props: {
//图片集合
/*
[{id:1,src:"1.png"}]
*/
imageList: {
type: Array,
default: () => {
return [];
}
},
//图片宽度
width: {
type: String,
default: '120rpx'
},
//图片高度
height: {
type: String,
default: '120rpx'
},
//图片边框宽度 rpx
borderWidth: {
type: String,
default: '0'
},
//图片边框颜色 可传rgba
borderColor: {
type: String,
default: '#fff'
},
//图片圆角
radius: {
type: String,
default: '50%'
},
//图片裁剪、缩放的模式
mode: {
type: String,
default: 'scaleToFill'
},
//图片懒加载。只针对page与scroll-view下的image有效
lazyLoad: {
type: Boolean,
default: true
},
//图片显示动画效果 | 仅App-nvue 2.3.4+ Android有效
fadeShow: {
type: Boolean,
default: true
},
//默认不解析 webP 格式,只支持网络资源 | 微信小程序2.9.0
webp: {
type: Boolean,
default: false
},
//开启长按图片显示识别小程序码菜单 | 微信小程序2.7.0
longpress: {
type: Boolean,
default: false
},
//是否组合排列
isGroup: {
type: Boolean,
default: false
},
//排列方向 row ,column
direction: {
type: String,
default: 'row'
},
//偏移距离 rpx
distance: {
type: [Number, String],
default: -16
},
//是否可多行展示,排列方向 row时生效,distance需设置为大于0的数
multiLine: {
type: Boolean,
default: false
}
},
data() {
return {};
},
methods: {
error(e) {
this.$emit('errorEvent', e);
},
load(e) {
this.$emit('loaded', e);
},
bindClick(index, id) {
this.$emit('click', {
index: index,
id: id || ''
});
}
}
};
</script>
<style scoped>
.tui-image-container {
display: inline-flex;
align-items: center;
}
.tui-image-direction {
flex-direction: column;
}
.tui-image__warp {
flex-wrap: wrap;
}
.tui-image__itembox {
position: relative;
}
.tui-image-item {
border-style: solid;
flex-shrink: 0;
display: block;
}
</style>