q-previewImage.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <view class="previewImage" v-if="show" @tap="close">
  3. <view class="page" v-if="urls.length > 0">
  4. <text class="text">{{ current + 1 }} / {{ urls.length }}</text>
  5. </view>
  6. <swiper class="swiper" :current="current" @change="swiperChange" @touchstart="handleTouchStart" @touchend="handleTouchEnd">
  7. <swiper-item v-for="(item, index) in urls" :key="index">
  8. <movable-area class="movable-area" scale-area>
  9. <movable-view class="movable-view" direction="all" :inertia="true" damping="100" scale="true" scale-min="1" scale-max="4" :scale-value="scale">
  10. <scroll-view scroll-y="true" class="uni-scroll-view">
  11. <view class="scroll-view"><image :key="index" class="image" :src="item" mode="widthFix" @longpress="onLongpress(item)" /></view>
  12. </scroll-view>
  13. </movable-view>
  14. </movable-area>
  15. </swiper-item>
  16. </swiper>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. props: {
  22. urls: {
  23. type: Array,
  24. required: true,
  25. default: () => {
  26. return [];
  27. }
  28. }
  29. },
  30. data() {
  31. return {
  32. show: false,
  33. current: 0, //当前页
  34. scale: 1,
  35. isZooming: false // 是否处于缩放状态
  36. };
  37. },
  38. methods: {
  39. //打开
  40. open(current) {
  41. this.current = this.urls.findIndex(item => item === current);
  42. this.show = true;
  43. this.$emit('open');
  44. },
  45. //关闭
  46. close() {
  47. if (!this.isZooming) {
  48. this.show = false;
  49. this.current = 0;
  50. this.$emit('close');
  51. }
  52. },
  53. //图片改变
  54. swiperChange(e) {
  55. this.current = e.detail.current;
  56. },
  57. //监听长按
  58. onLongpress(e) {
  59. this.$emit('onLongpress', e);
  60. },
  61. handleTouchStart() {
  62. this.isZooming = true;
  63. },
  64. handleTouchEnd() {
  65. this.isZooming = false;
  66. }
  67. }
  68. };
  69. </script>
  70. <style lang="scss" scoped>
  71. .previewImage {
  72. z-index: 9999;
  73. position: fixed;
  74. top: 0;
  75. left: 0;
  76. width: 100%;
  77. height: 100%;
  78. background-color: #000000;
  79. .swiper {
  80. width: 100%;
  81. height: 100vh;
  82. swiper-item {
  83. .movable-area {
  84. height: 100%;
  85. width: 100%;
  86. .movable-view {
  87. width: 100%;
  88. min-height: 100%;
  89. .uni-scroll-view{
  90. height: 100vh;
  91. }
  92. .scroll-view {
  93. display: flex;
  94. align-items: center;
  95. justify-content: center;
  96. min-height: 100vh;
  97. .image {
  98. width: 100%;
  99. height: auto;
  100. }
  101. }
  102. }
  103. }
  104. }
  105. }
  106. .page {
  107. position: absolute;
  108. z-index: 9999;
  109. width: 100%;
  110. top: 60rpx;
  111. text-align: center;
  112. .text {
  113. color: #fff;
  114. font-size: 32rpx;
  115. background-color: rgba(0, 0, 0, 0.5);
  116. padding: 3rpx 16rpx;
  117. border-radius: 20rpx;
  118. user-select: none;
  119. }
  120. }
  121. }
  122. </style>