index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <view class="image_msg_container">
  3. <u--image
  4. @click="onPrevieImage"
  5. mode="aspectFit"
  6. :src="msgBody.thumb || msgBody.url"
  7. :width="imgSize.width"
  8. :height="imgSize.height"
  9. :radius="5 + 'px'"
  10. >
  11. </u--image>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. msgBody: {
  18. type: Object,
  19. default: () => ({}),
  20. },
  21. },
  22. computed: {
  23. imgSize() {
  24. let imgSize = {
  25. width: '',
  26. height: '',
  27. };
  28. if (this.msgBody.width > 1000 || this.msgBody.height > 1000) {
  29. imgSize.width = this.msgBody.width / 10 + 'px';
  30. imgSize.height = this.msgBody.height / 10 + 'px';
  31. } else if (
  32. this.msgBody.width > 800 < 1000 ||
  33. this.msgBody.height > 800 < 1000
  34. ) {
  35. imgSize.width = this.msgBody.width / 3 + 'px';
  36. imgSize.height = this.msgBody.height / 3 + 'px';
  37. } else if (this.msgBody.width < 100 || this.msgBody.height < 100) {
  38. imgSize.width = this.msgBody.width + 'px';
  39. imgSize.height = this.msgBody.height + 'px';
  40. } else {
  41. imgSize.width = this.msgBody.width / 2 + 'px';
  42. imgSize.height = this.msgBody.height / 2 + 'px';
  43. }
  44. return imgSize;
  45. },
  46. },
  47. data() {
  48. return {
  49. src: 'https://cdn.uviewui.com/uview/album/1.jpg',
  50. };
  51. },
  52. methods: {
  53. onPrevieImage() {
  54. uni.previewImage({
  55. urls: [this.msgBody.url],
  56. });
  57. },
  58. },
  59. };
  60. </script>
  61. <style scoped></style>