2025-12-11 22:33:31 +08:00
|
|
|
<template>
|
|
|
|
|
<view class="picture_message_container" @click="clickMediaItem">
|
|
|
|
|
<u--image
|
|
|
|
|
:showLoading="true"
|
|
|
|
|
width="120"
|
|
|
|
|
:height="maxHeight"
|
|
|
|
|
mode="widthFix"
|
|
|
|
|
v-if="src"
|
|
|
|
|
:src="src"
|
|
|
|
|
@load="onLoaded"
|
|
|
|
|
@click="clickMediaItem">
|
|
|
|
|
<template v-slot:loading>
|
|
|
|
|
<u-loading-icon color="red"></u-loading-icon>
|
|
|
|
|
</template>
|
|
|
|
|
</u--image>
|
2025-12-17 08:47:58 +08:00
|
|
|
<u--image
|
|
|
|
|
v-else
|
|
|
|
|
:showLoading="true"
|
|
|
|
|
width="120"
|
|
|
|
|
mode="widthFix"
|
|
|
|
|
src="/static/images/sync_error.png">
|
|
|
|
|
</u--image>
|
2025-12-11 22:33:31 +08:00
|
|
|
</view>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
import util from "@/util"
|
|
|
|
|
import md5 from "md5";
|
|
|
|
|
export default {
|
|
|
|
|
name: "PictureMessageContainer",
|
|
|
|
|
props: {
|
|
|
|
|
message: Object,
|
|
|
|
|
conversationID:String,
|
|
|
|
|
},
|
|
|
|
|
data() {
|
2026-01-09 09:15:59 +08:00
|
|
|
//console.log(this.message);
|
2025-12-11 22:33:31 +08:00
|
|
|
return {
|
|
|
|
|
loadingWidth: "120px",
|
|
|
|
|
src:"",
|
|
|
|
|
coverCachePath:"",
|
|
|
|
|
coverDownloading:false,
|
|
|
|
|
coverExists:false,
|
|
|
|
|
coverDownloadProgress:"",
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
computed: {
|
|
|
|
|
maxHeight() {
|
|
|
|
|
const imageHeight = this.message.pictureElem.sourcePicture.height;
|
|
|
|
|
const imageWidth = this.message.pictureElem.sourcePicture.width;
|
|
|
|
|
const aspectRatio = imageHeight / imageWidth;
|
|
|
|
|
return 120 * aspectRatio;
|
2026-02-09 03:03:22 +08:00
|
|
|
}
|
|
|
|
|
},
|
2025-12-11 22:33:31 +08:00
|
|
|
created() {
|
|
|
|
|
this.init();
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
|
|
|
|
async init(){
|
|
|
|
|
const self = this;
|
|
|
|
|
let url = "";
|
2026-02-15 19:40:36 +08:00
|
|
|
const pictureElem = this.message.pictureElem;
|
2025-12-11 22:33:31 +08:00
|
|
|
// 如果有远程 snapshotUrl,则下载到 coverCachePath
|
2026-02-15 19:40:36 +08:00
|
|
|
let snapshotUrl = pictureElem?.sourcePath;
|
|
|
|
|
if(snapshotUrl && await util.fileExsit(snapshotUrl)){
|
|
|
|
|
self.src = snapshotUrl;
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
snapshotUrl = (pictureElem?.sourcePicture.url ?? pictureElem.bigPicture?.url);
|
2026-02-09 03:03:22 +08:00
|
|
|
if(!snapshotUrl){
|
|
|
|
|
console.log(this.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-02-15 19:40:36 +08:00
|
|
|
console.log(snapshotUrl);
|
2025-12-27 07:08:30 +08:00
|
|
|
util.cacheFile(snapshotUrl,`${this.conversationID}`).then((fn)=>{
|
2025-12-17 08:47:58 +08:00
|
|
|
self.coverDownloading = false;
|
2025-12-27 07:08:30 +08:00
|
|
|
self.src = fn;
|
2026-02-15 19:40:36 +08:00
|
|
|
console.log(fn);
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
getShowPath(url){
|
|
|
|
|
return new Promise((resolve,reject)=>{
|
|
|
|
|
if(url.startsWith('file')||url.startsWith('_')||url.startsWith('http')||url.startsWith('blob')){
|
|
|
|
|
return resolve(url);
|
|
|
|
|
}
|
|
|
|
|
plus.io.resolveLocalFileSystemURL(url, function(entry) {
|
|
|
|
|
return resolve(entry.toLocalURL());
|
|
|
|
|
}, function(e) {
|
|
|
|
|
console.log(e);
|
|
|
|
|
resolve(url);
|
|
|
|
|
});
|
|
|
|
|
|
2025-12-17 08:47:58 +08:00
|
|
|
});
|
2025-12-11 22:33:31 +08:00
|
|
|
},
|
|
|
|
|
clickMediaItem() {
|
|
|
|
|
uni.previewImage({
|
|
|
|
|
current: 0,
|
2025-12-17 08:47:58 +08:00
|
|
|
//urls: [this.message.pictureElem.sourcePicture.url],
|
2025-12-27 07:08:30 +08:00
|
|
|
urls: [this.src],
|
2025-12-11 22:33:31 +08:00
|
|
|
indicator: "none",
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
onLoaded() {
|
|
|
|
|
this.loadingWidth = "auto";
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
|
.picture_message_container {
|
|
|
|
|
position: relative;
|
|
|
|
|
border-radius: 16rpx;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
}
|
|
|
|
|
</style>
|