MediaMessageRender.vue 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="media_message_container" @click="clickMediaItem">
  3. <!-- <view :style="{height:wrapperHeight}" class="media_message_container"> -->
  4. <u--image
  5. :showLoading="true"
  6. width="150"
  7. :height="maxHeight"
  8. mode="widthFix"
  9. :src="getImgUrl"
  10. @click="clickMediaItem"
  11. style="background-color: #e5e5e5;">
  12. <template v-slot:loading>
  13. <u-loading-icon color="red"></u-loading-icon>
  14. </template>
  15. </u--image>
  16. <image
  17. v-if="isVideo"
  18. class="play_icon"
  19. src="https://bjyjb-1362704775.cos.ap-chongqing.myqcloud.com/shop/image/chating_message_video_play.png"
  20. alt=""
  21. srcset=""
  22. />
  23. <text v-if="isVideo" class="video_duration">{{ getDuration }}</text>
  24. </view>
  25. </template>
  26. <script>
  27. import { mapGetters } from "vuex";
  28. import { checkFileIsExist } from "../../../../../util/common";
  29. import { secFormat } from "../../../../../util/imCommon";
  30. import { myPreview } from "../../../../../util/preview";
  31. import { MessageType } from "openim-uniapp-polyfill";
  32. export default {
  33. name: "",
  34. props: {
  35. message: Object,
  36. },
  37. data() {
  38. return {
  39. };
  40. },
  41. computed: {
  42. ...mapGetters([
  43. "storeCacheMap"
  44. ]),
  45. isVideo() {
  46. return this.message.contentType === MessageType.VideoMessage;
  47. },
  48. getImgUrl() {
  49. if (this.isVideo) {
  50. return this.message.videoElem.snapshotUrl;
  51. }
  52. return this.message.pictureElem.snapshotPicture?.url ?? this.message.pictureElem.sourcePath;
  53. },
  54. getDuration() {
  55. if (!this.isVideo) {
  56. return 0;
  57. }
  58. return secFormat(this.message.videoElem.duration);
  59. },
  60. maxHeight() {
  61. const imageHeight = this.isVideo
  62. ? this.message.videoElem.snapshotHeight
  63. : this.message.pictureElem.sourcePicture.height;
  64. const imageWidth = this.isVideo
  65. ? this.message.videoElem.snapshotWidth
  66. : this.message.pictureElem.sourcePicture.width;
  67. const aspectRatio = imageHeight / imageWidth;
  68. return 120 * aspectRatio;
  69. },
  70. },
  71. methods: {
  72. async clickMediaItem() {
  73. if (this.isVideo) {
  74. const path = this.storeCacheMap[this.message.clientMsgID]?.path;
  75. const localPath = await checkFileIsExist({
  76. key: this.message.clientMsgID,
  77. path
  78. })
  79. const previewVideoUrl = localPath || this.message.videoElem.videoUrl
  80. uni.navigateTo({
  81. url: `/pages_im/pages/conversation/previewVideo/index?clientMsgID=${this.message.clientMsgID}&previewVideoUrl=${previewVideoUrl}&snapshotUrl=${this.message.videoElem.snapshotUrl}`,
  82. });
  83. } else {
  84. const list = this.$store.getters.storePreviewImageList;
  85. const idx = list.findIndex((item) => item === this.message.pictureElem.sourcePicture.url);
  86. myPreview(idx, list)
  87. }
  88. },
  89. },
  90. };
  91. </script>
  92. <style lang="scss" scoped>
  93. .media_message_container {
  94. position: relative;
  95. border-radius: 16rpx;
  96. overflow: hidden;
  97. .play_icon {
  98. width: 48px;
  99. height: 48px;
  100. position: absolute;
  101. top: 50%;
  102. left: 50%;
  103. transform: translate(-50%, -50%);
  104. }
  105. .video_duration {
  106. position: absolute;
  107. bottom: 12rpx;
  108. right: 24rpx;
  109. color: #fff;
  110. }
  111. }
  112. </style>