页面样式修改

This commit is contained in:
cwchen 2025-11-17 18:35:39 +08:00
parent 3faf971775
commit d2d8b89f1c
1 changed files with 14 additions and 27 deletions

View File

@ -18,7 +18,6 @@
fit="fill" fit="fill"
hide-on-click-modal hide-on-click-modal
:style="imageStyle" :style="imageStyle"
@load="handleImageLoad"
> >
<div slot="error" class="image-error"> <div slot="error" class="image-error">
<i class="el-icon-picture"></i> <i class="el-icon-picture"></i>
@ -59,7 +58,6 @@ export default {
documentKey: '', documentKey: '',
mode: 'view', mode: 'view',
type: 'desktop', type: 'desktop',
imageDimensions: null,
} }
}, },
props: { props: {
@ -102,6 +100,16 @@ export default {
fileTypeValue: { fileTypeValue: {
type: [Number, String], type: [Number, String],
default: '2' default: '2'
},
//
imageWidth: {
type: [Number, String],
default: 600
},
//
imageHeight: {
type: [Number, String],
default: 400
} }
}, },
computed: { computed: {
@ -122,18 +130,11 @@ export default {
return this.previewSrcList.length > 0 ? this.previewSrcList : [this.imageUrl] return this.previewSrcList.length > 0 ? this.previewSrcList : [this.imageUrl]
}, },
imageStyle() { imageStyle() {
if (!this.imageDimensions) { const width = typeof this.imageWidth === 'number' ? `${this.imageWidth}px` : this.imageWidth
return {} const height = typeof this.imageHeight === 'number' ? `${this.imageHeight}px` : this.imageHeight
}
const maxWidth = 600
const maxHeight = 400
const widthRatio = maxWidth / this.imageDimensions.width
const heightRatio = maxHeight / this.imageDimensions.height
const ratio = Math.min(widthRatio, heightRatio, 1)
return { return {
width: `${Math.round(this.imageDimensions.width * ratio)}px`, width,
height: `${Math.round(this.imageDimensions.height * ratio)}px` height
} }
}, },
}, },
@ -149,15 +150,6 @@ export default {
handleImageClick() { handleImageClick() {
this.$emit('image-click', this.imageUrl) this.$emit('image-click', this.imageUrl)
}, },
handleImageLoad(event) {
const { naturalWidth, naturalHeight } = event?.target || {}
if (naturalWidth && naturalHeight) {
this.imageDimensions = {
width: naturalWidth,
height: naturalHeight
}
}
},
handleDocumentReady() { handleDocumentReady() {
console.log('文档已准备就绪') console.log('文档已准备就绪')
}, },
@ -170,11 +162,6 @@ export default {
handleInitialized() { handleInitialized() {
console.log('初始化完成') console.log('初始化完成')
}, },
},
watch: {
imageUrl() {
this.imageDimensions = null
}
} }
} }
</script> </script>