lbp-background.js
1.98 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
/*
* @Author: ly525
* @Date: 2019-11-24 18:51:58
* @LastEditors: ly525
* @LastEditTime: 2020-04-23 23:17:55
* @FilePath: /luban-h5/front-end/h5/src/components/plugins/lbp-background.js
* @Github: https://github.com/ly525/luban-h5
* @Description: luban-h5 background image/color component/plugin
* @Copyright 2018 - 2019 luban-h5. All Rights Reserved
*/
export default {
name: 'lbp-background',
render () {
let style = {
width: '100%',
height: '100%'
}
if (this.imgSrc) {
style = {
...style,
'background-size': 'cover',
'background-position': '50% 50%',
'background-origin': 'content-box',
'background-image': `url(${this.imgSrc})`
}
} else {
style = {
...style,
backgroundColor: this.backgroundColor
}
}
return (
// [知识点:CSS] : https://codesandbox.io/s/ziyuansuzindexzaigao-wufafugaifuyuansudexiongdiyuansu-n15rd?file=/index.html
<div style="width: 100%; height: 100%; overflow: hidden; position: absolute; z-index: 0; opacity: 1;">
<div style={style}></div>
</div>
)
},
props: {
imgSrc: {
type: String,
default: '',
editor: {
type: 'lbs-image-gallery',
label: '图片',
prop: {
type: 'textarea'
}
}
},
backgroundColor: {
type: String,
// Q: 为什么 transparent 无效?
// A: 注意,根据 MDN 文档,颜色选择器的 value 只能是:# + 6个16进制字符串
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/color#Value
// The value of an <input> element of type color is always a DOMString which contains a 7-character string specifying an RGB color in hexadecimal format.
default: 'rgba(255, 255, 255, 0.2)',
editor: {
type: 'el-color-picker',
label: '背景颜色',
prop: {
size: 'mini',
showAlpha: true
},
require: true
}
}
}
}