chat-app/src/components/talk/message/ImageMessage.vue

94 lines
1.9 KiB
Vue
Raw Normal View History

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,
height: 0
}
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,
height: props.extra.height
}
}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,
height: 298
}
2024-11-22 01:06:37 +00:00
}
2024-12-06 08:55:15 +00:00
if(info.width<300){
return {
width: 300,
height: info.height / (info.width / 300)
}
}
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,
height: info.height
2024-11-22 01:06:37 +00:00
}
}
return {
2024-12-19 03:02:47 +00:00
width: 350,
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"
:class="{ left: data.float === 'left' }"
>
2024-12-06 08:55:15 +00:00
<div class="image-container">
2024-12-13 05:09:38 +00:00
<!-- <image
:src="extra.url"
mode="scaleToFill"
2024-12-19 03:02:47 +00:00
:width="img.width" :height="img.height"
2024-12-13 05:09:38 +00:00
/> -->
2024-12-19 03:02:47 +00:00
<tm-image preview :width="img.width" :height="img.height" :src="extra.url" />
2024-12-06 08:55:15 +00:00
<wd-circle custom-class="circleProgress" v-if="props.data.uploadCurrent && props.data.uploadCurrent<100" v-model="props.data.uploadCurrent" color="#ffffff" layer-color="#E3E3E3"></wd-circle>
</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;
border-radius: 16rpx 0 16rpx 16rpx;
background-color: #46299D;
min-width: 40rpx;
min-height: 40rpx;
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-06 08:55:15 +00:00
.image-container {
position: relative;
.circleProgress {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1;
}
}
2024-11-22 01:06:37 +00:00
</style>