a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
1
|
<template>
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
2
3
4
5
6
7
|
<el-image
:src="`${realSrc}`"
fit="cover"
:style="`width:${realWidth};height:${realHeight};`"
:preview-src-list="realSrcList"
>
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
8
9
10
11
12
13
14
|
<div slot="error" class="image-slot">
<i class="el-icon-picture-outline"></i>
</div>
</el-image>
</template>
<script>
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
15
|
import { isExternal } from "@/utils/validate";
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
16
17
|
export default {
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
18
|
name: "ImagePreview",
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
19
20
21
|
props: {
src: {
type: String,
|
1999ac4e
YunaiV
v3.8.4:修复图片预览组件sr...
|
22
|
default: ""
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
23
24
25
|
},
width: {
type: [Number, String],
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
26
|
default: ""
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
27
28
29
|
},
height: {
type: [Number, String],
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
30
|
default: ""
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
31
32
33
34
|
}
},
computed: {
realSrc() {
|
1999ac4e
YunaiV
v3.8.4:修复图片预览组件sr...
|
35
36
37
|
if (!this.src) {
return;
}
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
38
39
40
|
let real_src = this.src.split(",")[0];
if (isExternal(real_src)) {
return real_src;
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
41
|
}
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
42
43
44
|
return process.env.VUE_APP_BASE_API + real_src;
},
realSrcList() {
|
1999ac4e
YunaiV
v3.8.4:修复图片预览组件sr...
|
45
46
47
|
if (!this.src) {
return;
}
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
48
49
50
51
52
53
54
55
56
|
let real_src_list = this.src.split(",");
let srcList = [];
real_src_list.forEach(item => {
if (isExternal(item)) {
return srcList.push(item);
}
return srcList.push(process.env.VUE_APP_BASE_API + item);
});
return srcList;
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
57
58
|
},
realWidth() {
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
59
|
return typeof this.width == "string" ? this.width : `${this.width}px`;
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
60
61
|
},
realHeight() {
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
62
|
return typeof this.height == "string" ? this.height : `${this.height}px`;
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
63
|
}
|
bcceac5d
YunaiV
v3.8.1 预览组件支持多图显示
|
64
65
|
},
};
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
66
67
68
69
70
71
72
|
</script>
<style lang="scss" scoped>
.el-image {
border-radius: 5px;
background-color: #ebeef5;
box-shadow: 0 0 5px 1px #ccc;
|
d730c50d
xingyu4j
修复代码警告
|
73
|
:deep(.el-image__inner) {
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
74
75
76
77
78
79
|
transition: all 0.3s;
cursor: pointer;
&:hover {
transform: scale(1.2);
}
}
|
d730c50d
xingyu4j
修复代码警告
|
80
|
:deep(.image-slot) {
|
a3e8ee2b
YunaiV
v3.8.1 新增图片预览组件
|
81
82
83
84
85
86
87
88
89
90
|
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: #909399;
font-size: 30px;
}
}
</style>
|