chat-app/src/components/talk/message/ImageMessage.vue
wangyifeng e7ec387735
Some checks are pending
Check / lint (push) Waiting to run
Check / typecheck (push) Waiting to run
Check / build (build, 18.x, ubuntu-latest) (push) Waiting to run
Check / build (build, 18.x, windows-latest) (push) Waiting to run
Check / build (build:app, 18.x, ubuntu-latest) (push) Waiting to run
Check / build (build:app, 18.x, windows-latest) (push) Waiting to run
Check / build (build:mp-weixin, 18.x, ubuntu-latest) (push) Waiting to run
Check / build (build:mp-weixin, 18.x, windows-latest) (push) Waiting to run
处理文件上传中友好提示;处理文件上传失败场景图标展示;解决图片上传loading问题;替换所有进度条颜色更醒目;
2025-03-30 16:22:29 +08:00

129 lines
2.5 KiB
Vue

<script lang="ts" setup>
import { getImageInfo } from '@/utils/functions'
import { computed } from 'vue'
const props = defineProps<{
extra: any
data: any
maxWidth?: Boolean
}>()
const img = computed(() => {
// console.log(props.extra);
let info = {
width: 0,
height: 0,
}
if (props.extra.url.includes('blob:http://')) {
info = {
width: props.extra.width,
height: props.extra.height,
}
} else {
info = getImageInfo(props.extra.url)
}
if (info.width == 0 || info.height == 0) {
return {
width: 450,
height: 298,
}
}
if (info.width < 300) {
return {
width: 300,
height: info.height / (info.width / 300),
}
}
if (info.width < 350) {
return {
width: info.width,
height: info.height,
}
}
return {
width: 350,
height: info.height / (info.width / 350),
}
})
</script>
<template>
<section
class="im-message-image"
:class="{
left: data.float === 'left',
right: data.float === 'right',
}"
>
<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>
</section>
</template>
<style lang="less" scoped>
.im-message-image {
overflow: hidden;
padding: 20rpx 18rpx;
border-radius: 0;
background-color: #fff;
min-width: 40rpx;
min-height: 40rpx;
max-width: 532rpx;
&.left {
background-color: #fff;
border-radius: 0 16rpx 16rpx 16rpx;
}
&.right {
background-color: #46299d;
border-radius: 16rpx 0 16rpx 16rpx;
}
}
.image-container {
position: relative;
.circleProgress {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 1;
}
}
.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%;
}
</style>