card-cover.js
1.33 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
import placeholderImg from '@/assets/lbp-picture-placeholder.png'
function getDefaultStyle (img, isPlaceholder) {
return {
position: 'absolute',
top: 0,
left: 0,
zIndex: 0,
height: '100%',
width: '100%',
backgroundSize: isPlaceholder ? 'contain' : 'cover',
backgroundRepeat: 'no-repeat',
backgroundImage: `url(${img})`
}
}
export default {
props: {
qrcodeUrl: String,
coverImageUrl: String
},
methods: {
getCover (img, isPlaceholder = false) {
const width = 70
const style = {
...getDefaultStyle(img, isPlaceholder),
zIndex: 1,
width: `${width}%`,
margin: `0 ${50 - width / 2}%`
}
return [
<div style={style}></div>
]
},
getCoverBg (img, isQrcode = false) {
const style = {
...getDefaultStyle(img),
filter: !isQrcode && 'blur(10px)'
}
return [
<div style={style}></div>
]
}
},
render (h) {
let covers = [this.getCover(placeholderImg, true/** isPlaceholder */)]
const coverImg = this.coverImageUrl
if (this.qrcodeUrl) {
covers = this.getCoverBg(this.qrcodeUrl, true)
} else if (coverImg) {
covers = [this.getCover(coverImg), this.getCoverBg(coverImg)]
}
return <div class="card-cover-wrapper" >
{covers}
</div>
}
}