image-item.vue 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <movable-area
  3. class="image-item"
  4. scale-area
  5. >
  6. <movable-view
  7. class="image-item"
  8. direction="all"
  9. :out-of-bounds="false"
  10. :inertia="true"
  11. damping="90"
  12. friction="2"
  13. scale="true"
  14. scale-min="1"
  15. scale-max="4"
  16. scale-value="1"
  17. >
  18. <img
  19. class="image-preview"
  20. :class="[isWidth ? 'is-width' : 'isHeight']"
  21. mode="widthFix"
  22. :style="{
  23. transform: `scale(${props.zoom}) rotate(${props.rotate}deg)`,
  24. }"
  25. :src="props.src"
  26. :date-src="props.src"
  27. @click.stop
  28. >
  29. </movable-view>
  30. </movable-area>
  31. </template>
  32. <script setup lang="ts">
  33. import { computed } from '../../../adapter-vue';
  34. import { IMessageModel } from '@tencentcloud/chat-uikit-engine';
  35. const props = defineProps({
  36. zoom: {
  37. type: Number,
  38. default: 1,
  39. },
  40. rotate: {
  41. type: Number,
  42. default: 0,
  43. },
  44. src: {
  45. type: String,
  46. default: '',
  47. },
  48. messageItem: {
  49. type: Object,
  50. default: () => ({} as IMessageModel),
  51. },
  52. });
  53. const isWidth = computed(() => {
  54. const { width = 0, height = 0 }
  55. = props.messageItem?.payload?.imageInfoArray?.[0] || {};
  56. return width >= height;
  57. });
  58. </script>
  59. <style lang="scss">
  60. .image-item {
  61. width: 100%;
  62. height: 100%;
  63. display: flex;
  64. align-items: center;
  65. justify-content: center;
  66. overflow: hidden;
  67. }
  68. .image-preview {
  69. max-width: 100%;
  70. max-height: 100%;
  71. transition: transform 0.1s ease 0s;
  72. pointer-events: auto;
  73. }
  74. .is-width {
  75. width: 100%;
  76. }
  77. </style>