Files
klp-oa/klp-ui/src/components/ImagePreview/index.vue
砂糖 9d92e6e865 feat(设备管理): 新增设备管理相关功能模块
新增设备类型管理、备品备件管理、设备检修记录等功能模块
新增设备参数管理、备件变动记录、库存变动等功能
新增设备状态管理、检修计划管理等功能
优化图片预览组件,支持从OSS获取图片
2025-10-20 17:18:16 +08:00

102 lines
2.0 KiB
Vue

<template>
<el-image
:src="`${realSrc}`"
fit="cover"
:style="`width:${realWidth};height:${realHeight};`"
:preview-src-list="realSrcList"
>
<div slot="error" class="image-slot">
<i class="el-icon-picture-outline"></i>
</div>
</el-image>
</template>
<script>
import { listByIds } from "@/api/system/oss";
export default {
name: "ImagePreview",
props: {
src: {
type: String,
default: ""
},
width: {
type: [Number, String],
default: "50px"
},
height: {
type: [Number, String],
default: "50px"
}
},
data() {
return {
urls: ''
}
},
watch: {
src: {
handler(newVal, oldVal) {
if (newVal !== oldVal && newVal !== '') {
listByIds(newVal).then(response => {
this.urls = response.data.map(item => item.url).join(',');
})
}
},
immediate: true
}
},
computed: {
realSrc() {
if (!this.src) {
return;
}
let real_src = this.urls.split(",")[0];
return real_src;
},
realSrcList() {
if (!this.src) {
return;
}
let real_src_list = this.urls.split(",");
let srcList = [];
real_src_list.forEach(item => {
return srcList.push(item);
});
return srcList;
},
realWidth() {
return typeof this.width == "string" ? this.width : `${this.width}px`;
},
realHeight() {
return typeof this.height == "string" ? this.height : `${this.height}px`;
}
},
};
</script>
<style lang="scss" scoped>
.el-image {
border-radius: 5px;
background-color: #ebeef5;
box-shadow: 0 0 5px 1px #ccc;
::v-deep .el-image__inner {
transition: all 0.3s;
cursor: pointer;
&:hover {
transform: scale(1.2);
}
}
::v-deep .image-slot {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
color: #909399;
font-size: 30px;
}
}
</style>