2024-11-22 01:06:37 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { getImageInfo } from '@/utils/functions'
|
2024-12-19 03:02:47 +00:00
|
|
|
import { computed } from 'vue'
|
2024-11-22 01:06:37 +00:00
|
|
|
|
2024-12-06 08:55:15 +00:00
|
|
|
const props = defineProps<{
|
2024-11-26 08:51:36 +00:00
|
|
|
extra: any
|
|
|
|
data: any
|
2024-11-22 01:06:37 +00:00
|
|
|
maxWidth?: Boolean
|
|
|
|
}>()
|
|
|
|
|
2024-12-19 03:02:47 +00:00
|
|
|
const img = computed(() => {
|
2024-12-06 08:55:15 +00:00
|
|
|
// console.log(props.extra);
|
|
|
|
let info = {
|
|
|
|
width: 0,
|
2025-03-30 08:22:29 +00:00
|
|
|
height: 0,
|
2024-12-06 08:55:15 +00:00
|
|
|
}
|
2024-12-19 03:02:47 +00:00
|
|
|
if (props.extra.url.includes('blob:http://')) {
|
2024-12-06 08:55:15 +00:00
|
|
|
info = {
|
|
|
|
width: props.extra.width,
|
2025-03-30 08:22:29 +00:00
|
|
|
height: props.extra.height,
|
2024-12-06 08:55:15 +00:00
|
|
|
}
|
2025-03-30 08:22:29 +00:00
|
|
|
} else {
|
2024-12-19 03:02:47 +00:00
|
|
|
info = getImageInfo(props.extra.url)
|
2024-12-06 08:55:15 +00:00
|
|
|
}
|
|
|
|
|
2024-11-22 01:06:37 +00:00
|
|
|
if (info.width == 0 || info.height == 0) {
|
2024-11-26 08:51:36 +00:00
|
|
|
return {
|
|
|
|
width: 450,
|
2025-03-30 08:22:29 +00:00
|
|
|
height: 298,
|
2024-11-26 08:51:36 +00:00
|
|
|
}
|
2024-11-22 01:06:37 +00:00
|
|
|
}
|
2025-03-30 08:22:29 +00:00
|
|
|
if (info.width < 300) {
|
2024-12-06 08:55:15 +00:00
|
|
|
return {
|
|
|
|
width: 300,
|
2025-03-30 08:22:29 +00:00
|
|
|
height: info.height / (info.width / 300),
|
2024-12-06 08:55:15 +00:00
|
|
|
}
|
|
|
|
}
|
2024-11-22 01:06:37 +00:00
|
|
|
|
2024-12-19 03:02:47 +00:00
|
|
|
if (info.width < 350) {
|
2024-11-22 01:06:37 +00:00
|
|
|
return {
|
2024-11-26 08:51:36 +00:00
|
|
|
width: info.width,
|
2025-03-30 08:22:29 +00:00
|
|
|
height: info.height,
|
2024-11-22 01:06:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2024-12-19 03:02:47 +00:00
|
|
|
width: 350,
|
2025-03-30 08:22:29 +00:00
|
|
|
height: info.height / (info.width / 350),
|
2024-11-22 01:06:37 +00:00
|
|
|
}
|
2024-12-19 03:02:47 +00:00
|
|
|
})
|
2024-11-22 01:06:37 +00:00
|
|
|
</script>
|
|
|
|
<template>
|
|
|
|
<section
|
|
|
|
class="im-message-image"
|
2024-12-20 08:59:58 +00:00
|
|
|
:class="{
|
|
|
|
left: data.float === 'left',
|
2025-03-30 08:22:29 +00:00
|
|
|
right: data.float === 'right',
|
2024-12-20 08:59:58 +00:00
|
|
|
}"
|
2024-11-22 01:06:37 +00:00
|
|
|
>
|
2025-03-30 08:22:29 +00:00
|
|
|
<div class="image-container">
|
|
|
|
<div class="relative">
|
|
|
|
<tm-image
|
|
|
|
preview
|
|
|
|
:width="img.width"
|
|
|
|
:height="img.height"
|
|
|
|
:src="extra.url"
|
|
|
|
model="aspectFill"
|
|
|
|
/>
|
|
|
|
<wd-circle
|
|
|
|
custom-class="circleProgress"
|
|
|
|
v-if="data.uploadStatus === 1"
|
|
|
|
v-model="props.data.uploadCurrent"
|
|
|
|
color="#46299d"
|
|
|
|
layer-color="#E3E3E3"
|
|
|
|
></wd-circle>
|
|
|
|
<div class="upload-failed" v-if="data.uploadStatus === 3">
|
|
|
|
<tm-icon :font-size="20" name="tmicon-times" color="#fff"></tm-icon>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-11-22 01:06:37 +00:00
|
|
|
</section>
|
|
|
|
</template>
|
|
|
|
<style lang="less" scoped>
|
|
|
|
.im-message-image {
|
|
|
|
overflow: hidden;
|
2024-11-26 08:51:36 +00:00
|
|
|
padding: 20rpx 18rpx;
|
2024-12-20 08:59:58 +00:00
|
|
|
border-radius: 0;
|
|
|
|
background-color: #fff;
|
2024-11-26 08:51:36 +00:00
|
|
|
min-width: 40rpx;
|
|
|
|
min-height: 40rpx;
|
2024-12-20 08:59:58 +00:00
|
|
|
max-width: 532rpx;
|
2024-11-22 01:06:37 +00:00
|
|
|
|
|
|
|
&.left {
|
2024-11-26 08:51:36 +00:00
|
|
|
background-color: #fff;
|
|
|
|
border-radius: 0 16rpx 16rpx 16rpx;
|
2024-11-22 01:06:37 +00:00
|
|
|
}
|
2024-12-20 08:59:58 +00:00
|
|
|
|
|
|
|
&.right {
|
2025-03-30 08:22:29 +00:00
|
|
|
background-color: #46299d;
|
2024-12-20 08:59:58 +00:00
|
|
|
border-radius: 16rpx 0 16rpx 16rpx;
|
|
|
|
}
|
2024-11-22 01:06:37 +00:00
|
|
|
}
|
2024-12-06 08:55:15 +00:00
|
|
|
.image-container {
|
2025-03-30 08:22:29 +00:00
|
|
|
position: relative;
|
2024-12-06 08:55:15 +00:00
|
|
|
|
|
|
|
.circleProgress {
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
left: 50%;
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
z-index: 1;
|
|
|
|
}
|
|
|
|
}
|
2025-03-30 08:22:29 +00:00
|
|
|
.upload-failed {
|
|
|
|
position: absolute;
|
|
|
|
top: 50%;
|
|
|
|
left: 50%;
|
|
|
|
transform: translate(-50%, -50%);
|
|
|
|
z-index: 1;
|
|
|
|
width: 40rpx;
|
|
|
|
height: 40rpx;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
background: #ff4d4f;
|
|
|
|
border-radius: 50%;
|
|
|
|
}
|
2024-11-22 01:06:37 +00:00
|
|
|
</style>
|