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

55 lines
1.0 KiB
Vue
Raw Normal View History

2024-11-22 01:06:37 +00:00
<script lang="ts" setup>
import { getImageInfo } from '@/utils/functions'
defineProps<{
2024-11-26 08:51:36 +00:00
extra: any
data: any
2024-11-22 01:06:37 +00:00
maxWidth?: Boolean
}>()
const img = (src: string, width = 200) => {
const info = getImageInfo(src)
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
}
if (info.width < width) {
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-11-26 08:51:36 +00:00
width: width,
height: info.height / (info.width / width)
2024-11-22 01:06:37 +00:00
}
}
</script>
<template>
<section
class="im-message-image"
:class="{ left: data.float === 'left' }"
>
2024-11-26 08:51:36 +00:00
<tm-image preview :width="img(extra.url,450).width" :height="img(extra.url,450).height" :src="extra.url" />
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
}
}
</style>