FaceMessageRender.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <view class="media_message_container" @click="clickMediaItem">
  3. <u--image :showLoading="true" width="200" :height="maxHeight" mode="widthFix"
  4. :src="getImgUrl" @click="clickMediaItem">
  5. <template v-slot:loading>
  6. <u-loading-icon color="red"></u-loading-icon>
  7. </template>
  8. </u--image>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: "FaceMessageRender",
  14. props: {
  15. message: Object,
  16. },
  17. data() {
  18. return {
  19. faceElem: {}
  20. };
  21. },
  22. mounted() {
  23. this.faceElem = JSON.parse(this.message.faceElem.data)
  24. },
  25. computed: {
  26. getImgUrl() {
  27. return this.faceElem.url;
  28. },
  29. maxHeight() {
  30. const aspectRatio = this.faceElem.height / this.faceElem.width;
  31. return 200 * aspectRatio;
  32. },
  33. },
  34. methods: {
  35. clickMediaItem() {
  36. const list = [this.faceElem.url];
  37. const idx = 0;
  38. uni.previewImage({
  39. current: 0,
  40. urls: [this.faceElem.url],
  41. longPressActions: {
  42. itemList: ['保存图片'],
  43. success(data) {
  44. uni.downloadFile({
  45. url: list[idx],
  46. success(res) {
  47. console.log(res)
  48. let url = res.tempFilePath
  49. uni.saveImageToPhotosAlbum({
  50. filePath: url,
  51. success() {
  52. uni.showToast({
  53. title: '已保存到系统相册',
  54. icon: "none"
  55. })
  56. },
  57. fail(err) {
  58. uni.showToast({
  59. title: '保存失败',
  60. icon: "none"
  61. })
  62. }
  63. })
  64. }
  65. })
  66. }
  67. },
  68. fail(err) {
  69. console.log(err);
  70. },
  71. });
  72. },
  73. },
  74. };
  75. </script>
  76. <style lang="scss" scoped>
  77. .media_message_container {
  78. position: relative;
  79. border-radius: 16rpx;
  80. overflow: hidden;
  81. .play_icon {
  82. width: 48px;
  83. height: 48px;
  84. position: absolute;
  85. top: 50%;
  86. left: 50%;
  87. transform: translate(-50%, -50%);
  88. }
  89. .video_duration {
  90. position: absolute;
  91. bottom: 12rpx;
  92. right: 24rpx;
  93. color: #fff;
  94. }
  95. }
  96. </style>