FaceMessageRender.vue 1.8 KB

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